add pipe display item
This commit is contained in:
parent
6e5a1b7e37
commit
b4daadcb45
17 changed files with 322 additions and 112 deletions
|
@ -119,6 +119,7 @@ import common.packet.SPacketTimeUpdate;
|
||||||
import common.packet.SPacketTrades;
|
import common.packet.SPacketTrades;
|
||||||
import common.packet.SPacketUpdateDisplay;
|
import common.packet.SPacketUpdateDisplay;
|
||||||
import common.packet.SPacketUpdateHealth;
|
import common.packet.SPacketUpdateHealth;
|
||||||
|
import common.packet.SPacketUpdatePipe;
|
||||||
import common.rng.Random;
|
import common.rng.Random;
|
||||||
import common.sound.PositionedSound;
|
import common.sound.PositionedSound;
|
||||||
import common.sound.Sound;
|
import common.sound.Sound;
|
||||||
|
@ -126,6 +127,7 @@ import common.tileentity.TileEntity;
|
||||||
import common.tileentity.TileEntityChest;
|
import common.tileentity.TileEntityChest;
|
||||||
import common.tileentity.Device;
|
import common.tileentity.Device;
|
||||||
import common.tileentity.TileEntityDisplay;
|
import common.tileentity.TileEntityDisplay;
|
||||||
|
import common.tileentity.TileEntityItemPipe;
|
||||||
import common.tileentity.TileEntitySign;
|
import common.tileentity.TileEntitySign;
|
||||||
import common.util.BlockPos;
|
import common.util.BlockPos;
|
||||||
import common.util.Pair;
|
import common.util.Pair;
|
||||||
|
@ -1267,6 +1269,15 @@ public class ClientPlayer implements IClientPlayer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void handleUpdatePipe(SPacketUpdatePipe packet) {
|
||||||
|
NetHandler.checkThread(packet, this, this.gm, this.world);
|
||||||
|
if(this.gm.world.isBlockLoaded(packet.getPos())) {
|
||||||
|
TileEntity te = this.gm.world.getTileEntity(packet.getPos());
|
||||||
|
if(te instanceof TileEntityItemPipe pipe)
|
||||||
|
pipe.setDisplayedItem(packet.getItem());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the progressbar of the opened window to the specified value
|
* Sets the progressbar of the opened window to the specified value
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
package client.renderer.tileentity;
|
||||||
|
|
||||||
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
|
import client.Client;
|
||||||
|
import client.renderer.GlState;
|
||||||
|
import client.renderer.blockmodel.IBakedModel;
|
||||||
|
import client.renderer.entity.RenderItem;
|
||||||
|
import client.renderer.texture.TextureMap;
|
||||||
|
import common.item.ItemStack;
|
||||||
|
import common.tileentity.TileEntityItemPipe;
|
||||||
|
|
||||||
|
public class ItemPipeRenderer extends ElementRenderer<TileEntityItemPipe> {
|
||||||
|
public void renderElements(TileEntityItemPipe te, double x, double y, double z, float partialTicks) {
|
||||||
|
ItemStack itemstack = te.getDisplayedItem();
|
||||||
|
if(itemstack == null)
|
||||||
|
return;
|
||||||
|
Client.CLIENT.getTextureManager().bindTexture(TextureMap.BLOCKS);
|
||||||
|
GlState.enableRescaleNormal();
|
||||||
|
GlState.alphaFunc(GL11.GL_GREATER, 0.1F);
|
||||||
|
GlState.enableBlend();
|
||||||
|
GlState.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO);
|
||||||
|
RenderItem itemRenderer = Client.CLIENT.getRenderItem();
|
||||||
|
IBakedModel ibakedmodel = itemRenderer.getItemModelMesher().getItemModel(itemstack);
|
||||||
|
GL11.glPushMatrix();
|
||||||
|
GL11.glTranslatef((float)x + 0.5F, (float)y + 0.5f, (float)z + 0.5F);
|
||||||
|
if(ibakedmodel.isGui3d())
|
||||||
|
GL11.glScalef(0.5F, 0.5F, 0.5F);
|
||||||
|
itemRenderer.renderItem(itemstack, ibakedmodel);
|
||||||
|
GL11.glPopMatrix();
|
||||||
|
GlState.disableRescaleNormal();
|
||||||
|
GlState.disableBlend();
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,6 +9,7 @@ import common.collect.Maps;
|
||||||
import common.entity.Entity;
|
import common.entity.Entity;
|
||||||
import common.tileentity.TileEntity;
|
import common.tileentity.TileEntity;
|
||||||
import common.tileentity.TileEntityDisplay;
|
import common.tileentity.TileEntityDisplay;
|
||||||
|
import common.tileentity.TileEntityItemPipe;
|
||||||
import common.tileentity.TileEntitySign;
|
import common.tileentity.TileEntitySign;
|
||||||
import common.util.BlockPos;
|
import common.util.BlockPos;
|
||||||
import common.world.World;
|
import common.world.World;
|
||||||
|
@ -29,6 +30,7 @@ public class SpecialRenderer {
|
||||||
private SpecialRenderer() {
|
private SpecialRenderer() {
|
||||||
this.renderers.put(TileEntitySign.class, new SignRenderer());
|
this.renderers.put(TileEntitySign.class, new SignRenderer());
|
||||||
this.renderers.put(TileEntityDisplay.class, new DisplayRenderer());
|
this.renderers.put(TileEntityDisplay.class, new DisplayRenderer());
|
||||||
|
this.renderers.put(TileEntityItemPipe.class, new ItemPipeRenderer());
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T extends TileEntity> ElementRenderer<T> getRenderer(Class<? extends TileEntity> clazz) {
|
private <T extends TileEntity> ElementRenderer<T> getRenderer(Class<? extends TileEntity> clazz) {
|
||||||
|
|
BIN
client/src/main/resources/textures/blocks/suction_pipe.png
Executable file
BIN
client/src/main/resources/textures/blocks/suction_pipe.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 173 B |
Binary file not shown.
After Width: | Height: | Size: 178 B |
|
@ -0,0 +1,57 @@
|
||||||
|
package common.block.tech;
|
||||||
|
|
||||||
|
import common.model.Model;
|
||||||
|
import common.model.Model.ModelProvider;
|
||||||
|
import common.properties.Property;
|
||||||
|
import common.properties.PropertyBool;
|
||||||
|
import common.util.BlockPos;
|
||||||
|
import common.util.Clientside;
|
||||||
|
import common.util.Facing;
|
||||||
|
import common.world.IWorldAccess;
|
||||||
|
import common.world.State;
|
||||||
|
|
||||||
|
public abstract class BlockDirectionalPipe extends BlockPipe {
|
||||||
|
public static final PropertyBool DOWN = PropertyBool.create("down");
|
||||||
|
public static final PropertyBool UP = PropertyBool.create("up");
|
||||||
|
public static final PropertyBool NORTH = PropertyBool.create("north");
|
||||||
|
public static final PropertyBool EAST = PropertyBool.create("east");
|
||||||
|
public static final PropertyBool SOUTH = PropertyBool.create("south");
|
||||||
|
public static final PropertyBool WEST = PropertyBool.create("west");
|
||||||
|
|
||||||
|
public BlockDirectionalPipe() {
|
||||||
|
this.setDefaultState(this.getBaseState().withProperty(FACING, Facing.DOWN).withProperty(DOWN, false).withProperty(UP, false).withProperty(NORTH, false).withProperty(EAST, false).withProperty(SOUTH, false).withProperty(WEST, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
public State getState(State state, IWorldAccess world, BlockPos pos) {
|
||||||
|
return state.withProperty(DOWN, this.canConnectTo(world.getState(pos.down()).getBlock()))
|
||||||
|
.withProperty(UP, this.canConnectTo(world.getState(pos.up()).getBlock()))
|
||||||
|
.withProperty(NORTH, this.canConnectTo(world.getState(pos.north()).getBlock()))
|
||||||
|
.withProperty(EAST, this.canConnectTo(world.getState(pos.east()).getBlock()))
|
||||||
|
.withProperty(SOUTH, this.canConnectTo(world.getState(pos.south()).getBlock()))
|
||||||
|
.withProperty(WEST, this.canConnectTo(world.getState(pos.west()).getBlock()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public State getItemState() {
|
||||||
|
return this.getState().withProperty(FACING, Facing.EAST).withProperty(DOWN, false).withProperty(UP, false).withProperty(NORTH, false).withProperty(EAST, true).withProperty(SOUTH, false).withProperty(WEST, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Property[] getUnsavedProperties() {
|
||||||
|
return new Property[] {NORTH, SOUTH, DOWN, UP, WEST, EAST};
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Property[] getProperties() {
|
||||||
|
return new Property[] {FACING, DOWN, UP, NORTH, EAST, WEST, SOUTH};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Clientside
|
||||||
|
public Model getModel(ModelProvider provider, String name, State state) {
|
||||||
|
Facing dir = state.getValue(FACING);
|
||||||
|
boolean down = state.getValue(DOWN);
|
||||||
|
boolean up = state.getValue(UP);
|
||||||
|
boolean north = state.getValue(NORTH);
|
||||||
|
boolean south = state.getValue(SOUTH);
|
||||||
|
boolean west = state.getValue(WEST);
|
||||||
|
boolean east = state.getValue(EAST);
|
||||||
|
return getPipeModel(provider, name, dir, down, up, north, south, west, east);
|
||||||
|
}
|
||||||
|
}
|
15
common/src/main/java/common/block/tech/BlockItemPipe.java
Normal file
15
common/src/main/java/common/block/tech/BlockItemPipe.java
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
package common.block.tech;
|
||||||
|
|
||||||
|
import common.block.Block;
|
||||||
|
import common.tileentity.TileEntity;
|
||||||
|
import common.tileentity.TileEntityItemPipe;
|
||||||
|
|
||||||
|
public class BlockItemPipe extends BlockDirectionalPipe {
|
||||||
|
public boolean canConnectTo(Block block) {
|
||||||
|
return block instanceof BlockMachine || block instanceof BlockItemPipe || block instanceof BlockSuctionPipe || block instanceof BlockChest;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TileEntity createNewTileEntity() {
|
||||||
|
return new TileEntityItemPipe(false);
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,13 +9,13 @@ import common.block.Material;
|
||||||
import common.entity.Entity;
|
import common.entity.Entity;
|
||||||
import common.entity.npc.EntityNPC;
|
import common.entity.npc.EntityNPC;
|
||||||
import common.entity.types.EntityLiving;
|
import common.entity.types.EntityLiving;
|
||||||
|
import common.init.Items;
|
||||||
import common.item.CheatTab;
|
import common.item.CheatTab;
|
||||||
|
import common.item.ItemStack;
|
||||||
import common.model.Model;
|
import common.model.Model;
|
||||||
import common.model.Model.ModelProvider;
|
import common.model.Model.ModelProvider;
|
||||||
import common.properties.Property;
|
|
||||||
import common.properties.PropertyBool;
|
|
||||||
import common.tileentity.TileEntity;
|
import common.tileentity.TileEntity;
|
||||||
import common.tileentity.TileEntityPipe;
|
import common.tileentity.TileEntityItemPipe;
|
||||||
import common.util.BlockPos;
|
import common.util.BlockPos;
|
||||||
import common.util.BoundingBox;
|
import common.util.BoundingBox;
|
||||||
import common.util.Clientside;
|
import common.util.Clientside;
|
||||||
|
@ -25,51 +25,24 @@ import common.world.State;
|
||||||
import common.world.World;
|
import common.world.World;
|
||||||
import common.world.AWorldServer;
|
import common.world.AWorldServer;
|
||||||
|
|
||||||
public class BlockPipe extends Block implements ITileEntityProvider, Directional {
|
public abstract class BlockPipe extends Block implements ITileEntityProvider, Directional {
|
||||||
public static final PropertyBool DOWN = PropertyBool.create("down");
|
|
||||||
public static final PropertyBool UP = PropertyBool.create("up");
|
|
||||||
public static final PropertyBool NORTH = PropertyBool.create("north");
|
|
||||||
public static final PropertyBool EAST = PropertyBool.create("east");
|
|
||||||
public static final PropertyBool SOUTH = PropertyBool.create("south");
|
|
||||||
public static final PropertyBool WEST = PropertyBool.create("west");
|
|
||||||
|
|
||||||
private static boolean keepInventory;
|
private static boolean keepInventory;
|
||||||
|
|
||||||
public BlockPipe() {
|
public BlockPipe() {
|
||||||
super(Material.SOLID);
|
super(Material.SOLID);
|
||||||
this.setDefaultState(this.getBaseState().withProperty(FACING, Facing.DOWN).withProperty(DOWN, false).withProperty(UP, false).withProperty(NORTH, false).withProperty(EAST, false).withProperty(SOUTH, false).withProperty(WEST, false));
|
|
||||||
this.setTab(CheatTab.TECHNOLOGY);
|
this.setTab(CheatTab.TECHNOLOGY);
|
||||||
this.setBlockBounds(0.25f, 0.25f, 0.25f, 0.75f, 0.75f, 0.75f);
|
this.setBlockBounds(0.25f, 0.25f, 0.25f, 0.75f, 0.75f, 0.75f);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canConnectTo(Block block) {
|
public abstract boolean canConnectTo(Block block);
|
||||||
return block instanceof BlockMachine || block instanceof BlockPipe || block instanceof BlockChest;
|
|
||||||
}
|
|
||||||
|
|
||||||
public State getState(State state, IWorldAccess world, BlockPos pos) {
|
|
||||||
return state.withProperty(DOWN, this.canConnectTo(world.getState(pos.down()).getBlock()))
|
|
||||||
.withProperty(UP, this.canConnectTo(world.getState(pos.up()).getBlock()))
|
|
||||||
.withProperty(NORTH, this.canConnectTo(world.getState(pos.north()).getBlock()))
|
|
||||||
.withProperty(EAST, this.canConnectTo(world.getState(pos.east()).getBlock()))
|
|
||||||
.withProperty(SOUTH, this.canConnectTo(world.getState(pos.south()).getBlock()))
|
|
||||||
.withProperty(WEST, this.canConnectTo(world.getState(pos.west()).getBlock()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public State getItemState() {
|
public final void setBlockBounds(IWorldAccess world, BlockPos pos) {
|
||||||
return this.getState().withProperty(FACING, Facing.EAST).withProperty(DOWN, false).withProperty(UP, false).withProperty(NORTH, false).withProperty(EAST, true).withProperty(SOUTH, false).withProperty(WEST, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Property[] getUnsavedProperties() {
|
|
||||||
return new Property[] {NORTH, SOUTH, DOWN, UP, WEST, EAST};
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBlockBounds(IWorldAccess world, BlockPos pos) {
|
|
||||||
this.setBlockBounds(this.canConnectTo(world.getState(pos.west()).getBlock()) ? 0.0f : 0.25f, this.canConnectTo(world.getState(pos.down()).getBlock()) ? 0.0f : 0.25f,
|
this.setBlockBounds(this.canConnectTo(world.getState(pos.west()).getBlock()) ? 0.0f : 0.25f, this.canConnectTo(world.getState(pos.down()).getBlock()) ? 0.0f : 0.25f,
|
||||||
this.canConnectTo(world.getState(pos.north()).getBlock()) ? 0.0f : 0.25f, this.canConnectTo(world.getState(pos.east()).getBlock()) ? 1.0f : 0.75f,
|
this.canConnectTo(world.getState(pos.north()).getBlock()) ? 0.0f : 0.25f, this.canConnectTo(world.getState(pos.east()).getBlock()) ? 1.0f : 0.75f,
|
||||||
this.canConnectTo(world.getState(pos.up()).getBlock()) ? 1.0f : 0.75f, this.canConnectTo(world.getState(pos.south()).getBlock()) ? 1.0f : 0.75f);
|
this.canConnectTo(world.getState(pos.up()).getBlock()) ? 1.0f : 0.75f, this.canConnectTo(world.getState(pos.south()).getBlock()) ? 1.0f : 0.75f);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getCollisionBoxes(World world, BlockPos pos, State state, BoundingBox mask, List<BoundingBox> list, Entity collidingEntity) {
|
public final void getCollisionBoxes(World world, BlockPos pos, State state, BoundingBox mask, List<BoundingBox> list, Entity collidingEntity) {
|
||||||
this.setBlockBounds(0.25f, 0.25f, 0.25f, 0.75f, 0.75f, 0.75f);
|
this.setBlockBounds(0.25f, 0.25f, 0.25f, 0.75f, 0.75f, 0.75f);
|
||||||
super.getCollisionBoxes(world, pos, state, mask, list, collidingEntity);
|
super.getCollisionBoxes(world, pos, state, mask, list, collidingEntity);
|
||||||
if(this.canConnectTo(world.getState(pos.west()).getBlock())) {
|
if(this.canConnectTo(world.getState(pos.west()).getBlock())) {
|
||||||
|
@ -103,19 +76,27 @@ public class BlockPipe extends Block implements ITileEntityProvider, Directional
|
||||||
return this.getState().withProperty(FACING, facing.getOpposite());
|
return this.getState().withProperty(FACING, facing.getOpposite());
|
||||||
}
|
}
|
||||||
|
|
||||||
public TileEntity createNewTileEntity() {
|
|
||||||
return new TileEntityPipe();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean onUse(World world, BlockPos pos, State state, EntityNPC player, Facing side, float hitX, float hitY, float hitZ) {
|
public boolean onUse(World world, BlockPos pos, State state, EntityNPC player, Facing side, float hitX, float hitY, float hitZ) {
|
||||||
|
ItemStack stack = player.getHeldItem();
|
||||||
|
if(stack == null || stack.getItem() != Items.hoe)
|
||||||
|
return false;
|
||||||
if(world.client)
|
if(world.client)
|
||||||
return true;
|
return true;
|
||||||
TileEntity te = world.getTileEntity(pos);
|
TileEntity te = world.getTileEntity(pos);
|
||||||
if(te instanceof TileEntityPipe) {
|
if(te instanceof TileEntityItemPipe) {
|
||||||
state = state.cycleProperty(FACING);
|
Facing face = state.getValue(FACING);
|
||||||
|
for(int z = 0; z < Facing.values().length; z++) {
|
||||||
|
Facing dir = Facing.values()[(face.ordinal() + 1 + z) % Facing.values().length];
|
||||||
|
if(this.canConnectTo(world.getState(pos.offset(dir)).getBlock())) {
|
||||||
|
face = dir;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(face == state.getValue(FACING))
|
||||||
|
return true;
|
||||||
keepInventory = true;
|
keepInventory = true;
|
||||||
world.setState(pos, state, 3);
|
world.setState(pos, state.withProperty(FACING, face), 3);
|
||||||
world.setState(pos, state, 3);
|
world.setState(pos, state.withProperty(FACING, face), 3);
|
||||||
keepInventory = false;
|
keepInventory = false;
|
||||||
te.validate();
|
te.validate();
|
||||||
world.setTileEntity(pos, te);
|
world.setTileEntity(pos, te);
|
||||||
|
@ -126,46 +107,35 @@ public class BlockPipe extends Block implements ITileEntityProvider, Directional
|
||||||
public void onRemoved(AWorldServer worldIn, BlockPos pos, State state) {
|
public void onRemoved(AWorldServer worldIn, BlockPos pos, State state) {
|
||||||
if(!keepInventory) {
|
if(!keepInventory) {
|
||||||
TileEntity tileentity = worldIn.getTileEntity(pos);
|
TileEntity tileentity = worldIn.getTileEntity(pos);
|
||||||
if(tileentity instanceof TileEntityPipe)
|
if(tileentity instanceof TileEntityItemPipe)
|
||||||
dropItems(worldIn, pos, (TileEntityPipe)tileentity);
|
dropItems(worldIn, pos, (TileEntityItemPipe)tileentity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isFullCube() {
|
public final boolean isFullCube() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isOpaqueCube() {
|
public final boolean isOpaqueCube() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Clientside
|
@Clientside
|
||||||
public boolean canRender(IWorldAccess worldIn, BlockPos pos, Facing side) {
|
public final boolean canRender(IWorldAccess worldIn, BlockPos pos, Facing side) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Clientside
|
@Clientside
|
||||||
public boolean hasTransparency() {
|
public final boolean hasTransparency() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Property[] getProperties() {
|
public final boolean isMagnetic() {
|
||||||
return new Property[] {FACING, DOWN, UP, NORTH, EAST, WEST, SOUTH};
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isMagnetic() {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Clientside
|
@Clientside
|
||||||
public Model getModel(ModelProvider provider, String name, State state) {
|
protected static Model getPipeModel(ModelProvider provider, String name, Facing dir, boolean down, boolean up, boolean north, boolean south, boolean west, boolean east) {
|
||||||
Facing dir = state.getValue(FACING);
|
|
||||||
boolean down = state.getValue(DOWN);
|
|
||||||
boolean up = state.getValue(UP);
|
|
||||||
boolean north = state.getValue(NORTH);
|
|
||||||
boolean south = state.getValue(SOUTH);
|
|
||||||
boolean west = state.getValue(WEST);
|
|
||||||
boolean east = state.getValue(EAST);
|
|
||||||
String sel = name + "_selected";
|
String sel = name + "_selected";
|
||||||
Model model = provider.getModel(name);
|
Model model = provider.getModel(name);
|
||||||
if(!down || !up || !north || !south || !west || !east) {
|
if(!down || !up || !north || !south || !west || !east) {
|
||||||
|
@ -196,5 +166,5 @@ public class BlockPipe extends Block implements ITileEntityProvider, Directional
|
||||||
if(east)
|
if(east)
|
||||||
model.add(12, 4, 4, 16, 12, 12).du(dir == Facing.EAST ? sel : name).uv(4, 4, 8, 12).noCull().n(dir == Facing.EAST ? sel : name).uv(8, 4, 12, 12).noCull().s(dir == Facing.EAST ? sel : name).uv(4, 4, 8, 12).noCull();
|
model.add(12, 4, 4, 16, 12, 12).du(dir == Facing.EAST ? sel : name).uv(4, 4, 8, 12).noCull().n(dir == Facing.EAST ? sel : name).uv(8, 4, 12, 12).noCull().s(dir == Facing.EAST ? sel : name).uv(4, 4, 8, 12).noCull();
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
package common.block.tech;
|
||||||
|
|
||||||
|
import common.model.Model;
|
||||||
|
import common.model.Model.ModelProvider;
|
||||||
|
import common.properties.Property;
|
||||||
|
import common.util.Clientside;
|
||||||
|
import common.util.Facing;
|
||||||
|
import common.util.Facing.Axis;
|
||||||
|
import common.world.State;
|
||||||
|
|
||||||
|
public abstract class BlockStraightPipe extends BlockPipe {
|
||||||
|
public BlockStraightPipe() {
|
||||||
|
this.setDefaultState(this.getBaseState().withProperty(FACING, Facing.DOWN));
|
||||||
|
}
|
||||||
|
|
||||||
|
public State getItemState() {
|
||||||
|
return this.getState().withProperty(FACING, Facing.EAST);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Property[] getProperties() {
|
||||||
|
return new Property[] {FACING};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Clientside
|
||||||
|
public Model getModel(ModelProvider provider, String name, State state) {
|
||||||
|
Facing dir = state.getValue(FACING);
|
||||||
|
boolean y = dir.getAxis() == Axis.Y;
|
||||||
|
boolean z = dir.getAxis() == Axis.Z;
|
||||||
|
boolean x = dir.getAxis() == Axis.X;
|
||||||
|
return getPipeModel(provider, name, dir, y, y, z, z, x, x);
|
||||||
|
}
|
||||||
|
}
|
15
common/src/main/java/common/block/tech/BlockSuctionPipe.java
Normal file
15
common/src/main/java/common/block/tech/BlockSuctionPipe.java
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
package common.block.tech;
|
||||||
|
|
||||||
|
import common.block.Block;
|
||||||
|
import common.tileentity.TileEntity;
|
||||||
|
import common.tileentity.TileEntityItemPipe;
|
||||||
|
|
||||||
|
public class BlockSuctionPipe extends BlockStraightPipe {
|
||||||
|
public boolean canConnectTo(Block block) {
|
||||||
|
return block instanceof BlockMachine || block instanceof BlockItemPipe || block instanceof BlockChest;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TileEntity createNewTileEntity() {
|
||||||
|
return new TileEntityItemPipe(true);
|
||||||
|
}
|
||||||
|
}
|
|
@ -592,7 +592,8 @@ public abstract class BlockRegistry {
|
||||||
register("sticky_piston_head", (new BlockPistonHead(true)).setDisplay("Klebriger Kolben"));
|
register("sticky_piston_head", (new BlockPistonHead(true)).setDisplay("Klebriger Kolben"));
|
||||||
register("dispenser", (new BlockDispenser(false)).setHardness(3.5F).setSound(SoundType.STONE).setDisplay("Werfer"));
|
register("dispenser", (new BlockDispenser(false)).setHardness(3.5F).setSound(SoundType.STONE).setDisplay("Werfer"));
|
||||||
register("dropper", (new BlockDispenser(true)).setHardness(3.5F).setSound(SoundType.STONE).setDisplay("Spender"));
|
register("dropper", (new BlockDispenser(true)).setHardness(3.5F).setSound(SoundType.STONE).setDisplay("Spender"));
|
||||||
register("pipe", (new BlockPipe()).setHardness(3.0F).setResistance(8.0F).setSound(SoundType.STONE).setDisplay("Rohr"));
|
register("pipe", (new BlockItemPipe()).setHardness(3.0F).setResistance(8.0F).setSound(SoundType.STONE).setDisplay("Rohr"));
|
||||||
|
register("suction_pipe", (new BlockSuctionPipe()).setHardness(3.0F).setResistance(8.0F).setSound(SoundType.STONE).setDisplay("Saugrohr"));
|
||||||
register("tian_reactor", (new BlockTianReactor()).setHardness(3.0F).setResistance(8.0F).setSound(SoundType.STONE).setDisplay("Tianreaktor"));
|
register("tian_reactor", (new BlockTianReactor()).setHardness(3.0F).setResistance(8.0F).setSound(SoundType.STONE).setDisplay("Tianreaktor"));
|
||||||
|
|
||||||
register("rail", (new BlockRail()).setHardness(0.7F).setSound(SoundType.STONE).setDisplay("Schiene").setMiningTool(Equipment.PICKAXE, 0));
|
register("rail", (new BlockRail()).setHardness(0.7F).setSound(SoundType.STONE).setDisplay("Schiene").setMiningTool(Equipment.PICKAXE, 0));
|
||||||
|
|
|
@ -867,7 +867,8 @@ public abstract class Blocks {
|
||||||
public static final BlockFurnace neptunium_furnace = get("neptunium_furnace");
|
public static final BlockFurnace neptunium_furnace = get("neptunium_furnace");
|
||||||
public static final BlockFurnace plutonium_furnace = get("plutonium_furnace");
|
public static final BlockFurnace plutonium_furnace = get("plutonium_furnace");
|
||||||
public static final BlockFurnace titanium_furnace = get("titanium_furnace");
|
public static final BlockFurnace titanium_furnace = get("titanium_furnace");
|
||||||
public static final BlockPipe pipe = get("pipe");
|
public static final BlockItemPipe pipe = get("pipe");
|
||||||
|
public static final BlockSuctionPipe suction_pipe = get("suction_pipe");
|
||||||
|
|
||||||
private static <T extends Block> T get(String id) {
|
private static <T extends Block> T get(String id) {
|
||||||
T block = (T)BlockRegistry.byNameExact(id);
|
T block = (T)BlockRegistry.byNameExact(id);
|
||||||
|
|
|
@ -1245,6 +1245,7 @@ public abstract class Items {
|
||||||
public static final Item plutonium_furnace = get("plutonium_furnace");
|
public static final Item plutonium_furnace = get("plutonium_furnace");
|
||||||
public static final Item titanium_furnace = get("titanium_furnace");
|
public static final Item titanium_furnace = get("titanium_furnace");
|
||||||
public static final Item pipe = get("pipe");
|
public static final Item pipe = get("pipe");
|
||||||
|
public static final Item suction_pipe = get("suction_pipe");
|
||||||
|
|
||||||
private static <T extends Item> T get(String id) {
|
private static <T extends Item> T get(String id) {
|
||||||
T item = (T)ItemRegistry.byName(id);
|
T item = (T)ItemRegistry.byName(id);
|
||||||
|
|
|
@ -62,6 +62,7 @@ import common.packet.SPacketTimeUpdate;
|
||||||
import common.packet.SPacketTrades;
|
import common.packet.SPacketTrades;
|
||||||
import common.packet.SPacketUpdateDisplay;
|
import common.packet.SPacketUpdateDisplay;
|
||||||
import common.packet.SPacketUpdateHealth;
|
import common.packet.SPacketUpdateHealth;
|
||||||
|
import common.packet.SPacketUpdatePipe;
|
||||||
import common.sound.Sound;
|
import common.sound.Sound;
|
||||||
|
|
||||||
public interface IClientPlayer extends NetHandler {
|
public interface IClientPlayer extends NetHandler {
|
||||||
|
@ -139,4 +140,5 @@ public interface IClientPlayer extends NetHandler {
|
||||||
void handleServerConfig(SPacketServerConfig packet);
|
void handleServerConfig(SPacketServerConfig packet);
|
||||||
void handleCelestials(SPacketCelestials packet);
|
void handleCelestials(SPacketCelestials packet);
|
||||||
void handleDimensions(SPacketDimensions packet);
|
void handleDimensions(SPacketDimensions packet);
|
||||||
|
void handleUpdatePipe(SPacketUpdatePipe packet);
|
||||||
}
|
}
|
|
@ -99,6 +99,7 @@ import common.packet.SPacketTimeUpdate;
|
||||||
import common.packet.SPacketTrades;
|
import common.packet.SPacketTrades;
|
||||||
import common.packet.SPacketUpdateDisplay;
|
import common.packet.SPacketUpdateDisplay;
|
||||||
import common.packet.SPacketUpdateHealth;
|
import common.packet.SPacketUpdateHealth;
|
||||||
|
import common.packet.SPacketUpdatePipe;
|
||||||
|
|
||||||
public enum PacketRegistry {
|
public enum PacketRegistry {
|
||||||
HANDSHAKE {{
|
HANDSHAKE {{
|
||||||
|
@ -184,6 +185,7 @@ public enum PacketRegistry {
|
||||||
this.server(SPacketServerConfig.class);
|
this.server(SPacketServerConfig.class);
|
||||||
this.server(SPacketCelestials.class);
|
this.server(SPacketCelestials.class);
|
||||||
this.server(SPacketDimensions.class);
|
this.server(SPacketDimensions.class);
|
||||||
|
this.server(SPacketUpdatePipe.class);
|
||||||
|
|
||||||
this.client(CPacketKeepAlive.class);
|
this.client(CPacketKeepAlive.class);
|
||||||
this.client(CPacketMessage.class);
|
this.client(CPacketMessage.class);
|
||||||
|
|
45
common/src/main/java/common/packet/SPacketUpdatePipe.java
Normal file
45
common/src/main/java/common/packet/SPacketUpdatePipe.java
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
package common.packet;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import common.item.ItemStack;
|
||||||
|
import common.network.IClientPlayer;
|
||||||
|
import common.network.Packet;
|
||||||
|
import common.network.PacketBuffer;
|
||||||
|
import common.tileentity.TileEntityItemPipe;
|
||||||
|
import common.util.BlockPos;
|
||||||
|
|
||||||
|
public class SPacketUpdatePipe implements Packet<IClientPlayer> {
|
||||||
|
private BlockPos position;
|
||||||
|
private ItemStack item;
|
||||||
|
|
||||||
|
public SPacketUpdatePipe() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public SPacketUpdatePipe(TileEntityItemPipe tile) {
|
||||||
|
this.position = tile.getPos();
|
||||||
|
this.item = tile.getDisplayedItem();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void readPacketData(PacketBuffer buf) throws IOException {
|
||||||
|
this.position = buf.readBlockPos();
|
||||||
|
this.item = buf.readItemStack();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writePacketData(PacketBuffer buf) throws IOException {
|
||||||
|
buf.writeBlockPos(this.position);
|
||||||
|
buf.writeItemStack(this.item);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void processPacket(IClientPlayer handler) {
|
||||||
|
handler.handleUpdatePipe(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlockPos getPos() {
|
||||||
|
return this.position;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack getItem() {
|
||||||
|
return this.item;
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,21 +9,41 @@ import common.block.tech.BlockChest;
|
||||||
import common.block.tech.BlockPipe;
|
import common.block.tech.BlockPipe;
|
||||||
import common.entity.Entity;
|
import common.entity.Entity;
|
||||||
import common.entity.item.EntityItem;
|
import common.entity.item.EntityItem;
|
||||||
import common.entity.npc.EntityNPC;
|
|
||||||
import common.entity.types.EntityLiving;
|
import common.entity.types.EntityLiving;
|
||||||
import common.inventory.IInventory;
|
import common.inventory.IInventory;
|
||||||
import common.inventory.ISidedInventory;
|
import common.inventory.ISidedInventory;
|
||||||
import common.item.ItemStack;
|
import common.item.ItemStack;
|
||||||
|
import common.network.Packet;
|
||||||
|
import common.packet.SPacketUpdatePipe;
|
||||||
import common.tags.TagObject;
|
import common.tags.TagObject;
|
||||||
import common.util.BlockPos;
|
import common.util.BlockPos;
|
||||||
import common.util.BoundingBox;
|
import common.util.BoundingBox;
|
||||||
import common.util.Facing;
|
import common.util.Facing;
|
||||||
|
import common.util.Serverside;
|
||||||
import common.vars.Vars;
|
import common.vars.Vars;
|
||||||
import common.world.State;
|
import common.world.State;
|
||||||
|
|
||||||
public class TileEntityPipe extends TileEntity implements IInventory, ITickable {
|
public class TileEntityItemPipe extends TileEntity implements IInventory, ITickable {
|
||||||
|
private final boolean suck;
|
||||||
|
|
||||||
private ItemStack stack = null;
|
private ItemStack stack = null;
|
||||||
|
@Serverside
|
||||||
|
private ItemStack last = null;
|
||||||
|
private ItemStack display = null;
|
||||||
|
private ItemStack prevDisplay = null;
|
||||||
private int cooldown = -1;
|
private int cooldown = -1;
|
||||||
|
|
||||||
|
public TileEntityItemPipe(boolean suck) {
|
||||||
|
this.suck = suck;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack getDisplayedItem() {
|
||||||
|
return this.display == null ? this.prevDisplay : this.display;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDisplayedItem(ItemStack item) {
|
||||||
|
this.display = item;
|
||||||
|
}
|
||||||
|
|
||||||
public void readTags(TagObject tag) {
|
public void readTags(TagObject tag) {
|
||||||
super.readTags(tag);
|
super.readTags(tag);
|
||||||
|
@ -90,44 +110,42 @@ public class TileEntityPipe extends TileEntity implements IInventory, ITickable
|
||||||
this.stack = null;
|
this.stack = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isUseableByPlayer(EntityNPC player) {
|
|
||||||
return this.world.getTileEntity(this.pos) != this ? false : player.getDistanceSq((double)this.pos.getX() + 0.5D, (double)this.pos.getY() + 0.5D, (double)this.pos.getZ() + 0.5D) <= 64.0D;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void update() {
|
public void update() {
|
||||||
if(this.world != null && !this.world.client) {
|
if(this.world != null && !this.world.client) {
|
||||||
|
this.prevDisplay = this.display;
|
||||||
|
this.display = ItemStack.copy(this.stack);
|
||||||
|
|
||||||
--this.cooldown;
|
--this.cooldown;
|
||||||
|
|
||||||
if(!this.isOnTransferCooldown()) {
|
if(!this.isOnTransferCooldown()) {
|
||||||
this.setTransferCooldown(0);
|
this.setTransferCooldown(0);
|
||||||
this.updatePipe();
|
this.transferItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!ItemStack.allEquals(this.last, this.getDisplayedItem()))
|
||||||
|
this.world.markBlockForUpdate(this.pos);
|
||||||
|
this.last = this.getDisplayedItem();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean updatePipe() {
|
protected boolean transferItems() {
|
||||||
if(!this.isOnTransferCooldown()) {
|
if(!(this.getState().getBlock() instanceof BlockPipe) /* || !this.decrPower() */) // TODO: power
|
||||||
State state = this.getState();
|
return false;
|
||||||
if(!(state.getBlock() instanceof BlockPipe) /* || !this.decrPower() */) // TODO: power
|
boolean flag = false;
|
||||||
return false;
|
|
||||||
boolean flag = false;
|
|
||||||
|
|
||||||
if(!this.isEmpty()) {
|
if(!this.isEmpty()) {
|
||||||
flag = this.transferOut();
|
flag = this.transferOut();
|
||||||
}
|
|
||||||
|
|
||||||
if(!this.isFull()) {
|
|
||||||
flag |= this.transferIn(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(flag) {
|
|
||||||
this.setTransferCooldown(Vars.pipeDelay);
|
|
||||||
this.markDirty();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
if(!this.isFull()) {
|
||||||
|
flag |= this.transferIn();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(flag) {
|
||||||
|
this.setTransferCooldown(Vars.pipeDelay);
|
||||||
|
this.markDirty();
|
||||||
|
}
|
||||||
|
|
||||||
|
return flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isEmpty() {
|
private boolean isEmpty() {
|
||||||
|
@ -145,14 +163,18 @@ public class TileEntityPipe extends TileEntity implements IInventory, ITickable
|
||||||
public boolean isOnTransferCooldown() {
|
public boolean isOnTransferCooldown() {
|
||||||
return this.cooldown > 0;
|
return this.cooldown > 0;
|
||||||
}
|
}
|
||||||
|
//
|
||||||
public boolean mayTransfer() {
|
// public boolean mayTransfer() {
|
||||||
return this.cooldown <= 1;
|
// return this.cooldown <= 1;
|
||||||
}
|
// }
|
||||||
|
|
||||||
public int getColor() {
|
public int getColor() {
|
||||||
return 0x0040ff;
|
return 0x0040ff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Packet getDescriptionPacket() {
|
||||||
|
return new SPacketUpdatePipe(this);
|
||||||
|
}
|
||||||
|
|
||||||
// out
|
// out
|
||||||
|
|
||||||
|
@ -185,7 +207,7 @@ public class TileEntityPipe extends TileEntity implements IInventory, ITickable
|
||||||
|
|
||||||
protected boolean transferOut() {
|
protected boolean transferOut() {
|
||||||
State state = this.getState();
|
State state = this.getState();
|
||||||
IInventory iinventory = this.getInventory(this.pos.offset(state.getValue(BlockPipe.FACING)), false);
|
IInventory iinventory = this.getInventory(this.pos.offset(state.getValue(BlockPipe.FACING)), true, false);
|
||||||
if(iinventory == null)
|
if(iinventory == null)
|
||||||
return false;
|
return false;
|
||||||
Facing dir = state.getValue(BlockPipe.FACING).getOpposite();
|
Facing dir = state.getValue(BlockPipe.FACING).getOpposite();
|
||||||
|
@ -285,11 +307,11 @@ public class TileEntityPipe extends TileEntity implements IInventory, ITickable
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean transferIn(boolean suck) {
|
protected boolean transferIn() {
|
||||||
State state = this.getState();
|
State state = this.getState();
|
||||||
Facing facing = state.getValue(BlockPipe.FACING);
|
Facing facing = state.getValue(BlockPipe.FACING);
|
||||||
for(Facing dir : Facing.values()) {
|
for(Facing dir : Facing.values()) {
|
||||||
IInventory inv = dir == facing ? null : this.getInventory(this.pos.offset(dir), suck && dir == facing.getOpposite());
|
IInventory inv = (this.suck ? dir == facing.getOpposite() : dir != facing) ? this.getInventory(this.pos.offset(dir), false, this.suck) : null;
|
||||||
if(inv != null) {
|
if(inv != null) {
|
||||||
Facing opposite = dir.getOpposite();
|
Facing opposite = dir.getOpposite();
|
||||||
|
|
||||||
|
@ -316,7 +338,7 @@ public class TileEntityPipe extends TileEntity implements IInventory, ITickable
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(suck && dir == facing.getOpposite()) {
|
else if(this.suck && dir == facing.getOpposite()) {
|
||||||
for(EntityItem entity : this.findDroppedItems(this.pos.offset(dir))) {
|
for(EntityItem entity : this.findDroppedItems(this.pos.offset(dir))) {
|
||||||
if(putDropInInventoryAllSlots(this, entity)) {
|
if(putDropInInventoryAllSlots(this, entity)) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -358,15 +380,15 @@ public class TileEntityPipe extends TileEntity implements IInventory, ITickable
|
||||||
}
|
}
|
||||||
|
|
||||||
if(flag) {
|
if(flag) {
|
||||||
if(inventoryIn instanceof TileEntityPipe) {
|
// if(inventoryIn instanceof TileEntityItemPipe) {
|
||||||
TileEntityPipe pipe = (TileEntityPipe)inventoryIn;
|
// TileEntityItemPipe pipe = (TileEntityItemPipe)inventoryIn;
|
||||||
|
//
|
||||||
if(pipe.mayTransfer()) {
|
// if(pipe.mayTransfer()) {
|
||||||
pipe.setTransferCooldown(Vars.pipeDelay);
|
// pipe.setTransferCooldown(Vars.pipeDelay);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
inventoryIn.markDirty();
|
// inventoryIn.markDirty();
|
||||||
}
|
// }
|
||||||
|
|
||||||
inventoryIn.markDirty();
|
inventoryIn.markDirty();
|
||||||
}
|
}
|
||||||
|
@ -409,13 +431,13 @@ public class TileEntityPipe extends TileEntity implements IInventory, ITickable
|
||||||
return list.size() > 0 ? (IInventory)list.get(this.world.rand.zrange(list.size())) : null;
|
return list.size() > 0 ? (IInventory)list.get(this.world.rand.zrange(list.size())) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IInventory getInventory(BlockPos blockpos, boolean suck) {
|
private IInventory getInventory(BlockPos blockpos, boolean pipe, boolean suck) {
|
||||||
IInventory inv = null;
|
IInventory inv = null;
|
||||||
Block block = this.world.getState(blockpos).getBlock();
|
Block block = this.world.getState(blockpos).getBlock();
|
||||||
if(block instanceof ITileEntityProvider) {
|
if(block instanceof ITileEntityProvider) {
|
||||||
TileEntity te = this.world.getTileEntity(blockpos);
|
TileEntity te = this.world.getTileEntity(blockpos);
|
||||||
|
|
||||||
if(te instanceof IInventory) {
|
if(te instanceof IInventory && (pipe || !(te instanceof TileEntityItemPipe))) {
|
||||||
inv = (IInventory)te;
|
inv = (IInventory)te;
|
||||||
|
|
||||||
if(inv instanceof TileEntityChest && block instanceof BlockChest) {
|
if(inv instanceof TileEntityChest && block instanceof BlockChest) {
|
Loading…
Add table
Add a link
Reference in a new issue