diff --git a/client/src/main/java/client/network/ClientPlayer.java b/client/src/main/java/client/network/ClientPlayer.java index 49f9a6ba..2119adbf 100755 --- a/client/src/main/java/client/network/ClientPlayer.java +++ b/client/src/main/java/client/network/ClientPlayer.java @@ -1322,8 +1322,8 @@ public class ClientPlayer implements IClientPlayer if(this.gm.world.isBlockLoaded(packet.getPos())) { TileEntity tileentity = this.gm.world.getTileEntity(packet.getPos()); - if(tileentity instanceof TileEntityDisplay display) { - System.arraycopy(packet.getPixels(), 0, display.data, 0, 256); + if(tileentity instanceof TileEntityDisplay display && display.data.length == packet.getPixels().length) { + System.arraycopy(packet.getPixels(), 0, display.data, 0, display.data.length); display.lastUpdated = System.currentTimeMillis(); display.markDirty(); } diff --git a/client/src/main/java/client/renderer/tileentity/TileEntityDisplayRenderer.java b/client/src/main/java/client/renderer/tileentity/TileEntityDisplayRenderer.java index 76606f6b..1a0c1976 100644 --- a/client/src/main/java/client/renderer/tileentity/TileEntityDisplayRenderer.java +++ b/client/src/main/java/client/renderer/tileentity/TileEntityDisplayRenderer.java @@ -57,8 +57,8 @@ public class TileEntityDisplayRenderer extends TileEntitySpecialRenderer span = removing ? null : this.getSpan(world, pos, state.getValue(FACING)); + if(span != null) { + removing = true; + for(BlockPos loc : BlockPos.getAllInBox(span.first(), span.second())) { + if(!loc.equals(pos)) + world.setState(loc, this.inactive.getState().withProperty(FACING, state.getValue(FACING)), 2); + } + removing = false; + } + } + + public boolean onBlockEventReceived(World world, BlockPos pos, State state, int id, int param) { + super.onBlockEventReceived(world, pos, state, id, param); + TileEntity tile = world.getTileEntity(pos); + return tile == null ? false : tile.receiveClientEvent(id, param); + } + + public TileEntity createNewTileEntity() { + return new TileEntityDisplay(this.density); + } + + protected Item getItemToRegister() { + return null; + } + + public boolean onBlockActivated(World worldIn, BlockPos pos, State state, EntityNPC playerIn, Facing side, float hitX, float hitY, float hitZ) { + if(!worldIn.client) { + Pair span = this.getSpan(worldIn, pos, state.getValue(FACING)); + if(span == null) + return true; + for(BlockPos loc : BlockPos.getAllInBox(span.first(), span.second())) { + worldIn.setState(loc, this.inactive.getState().withProperty(FACING, state.getValue(FACING)), 2); + } + } + return true; + } + + protected BlockDisplay getOtherBlock() { + return this.inactive; + } +} diff --git a/common/src/main/java/common/block/tech/BlockBeacon.java b/common/src/main/java/common/block/tech/BlockBeacon.java index 83986bca..8aeff8d0 100755 --- a/common/src/main/java/common/block/tech/BlockBeacon.java +++ b/common/src/main/java/common/block/tech/BlockBeacon.java @@ -51,7 +51,7 @@ public class BlockBeacon extends BlockContainer /** * Returns a new instance of a block's tile entity class. Called on placing the block. */ - public TileEntity createNewTileEntity(World worldIn) + public TileEntity createNewTileEntity() { return new TileEntityBeacon(); } diff --git a/common/src/main/java/common/block/tech/BlockBrewingStand.java b/common/src/main/java/common/block/tech/BlockBrewingStand.java index 2176b03b..a83efe3c 100755 --- a/common/src/main/java/common/block/tech/BlockBrewingStand.java +++ b/common/src/main/java/common/block/tech/BlockBrewingStand.java @@ -388,7 +388,7 @@ public class BlockBrewingStand extends BlockContainer /** * Returns a new instance of a block's tile entity class. Called on placing the block. */ - public TileEntity createNewTileEntity(World worldIn) + public TileEntity createNewTileEntity() { return new TileEntityBrewingStand(); } diff --git a/common/src/main/java/common/block/tech/BlockChest.java b/common/src/main/java/common/block/tech/BlockChest.java index 19f40489..b159f3ab 100755 --- a/common/src/main/java/common/block/tech/BlockChest.java +++ b/common/src/main/java/common/block/tech/BlockChest.java @@ -531,7 +531,7 @@ public class BlockChest extends BlockContainer implements Rotatable /** * Returns a new instance of a block's tile entity class. Called on placing the block. */ - public TileEntity createNewTileEntity(World worldIn) + public TileEntity createNewTileEntity() { return new TileEntityChest(); } diff --git a/common/src/main/java/common/block/tech/BlockDaylightDetector.java b/common/src/main/java/common/block/tech/BlockDaylightDetector.java index eb84deda..ee33b535 100755 --- a/common/src/main/java/common/block/tech/BlockDaylightDetector.java +++ b/common/src/main/java/common/block/tech/BlockDaylightDetector.java @@ -151,7 +151,7 @@ public class BlockDaylightDetector extends BlockContainer /** * Returns a new instance of a block's tile entity class. Called on placing the block. */ - public TileEntity createNewTileEntity(World worldIn) + public TileEntity createNewTileEntity() { return new TileEntityDaylightDetector(); } diff --git a/common/src/main/java/common/block/tech/BlockDispenser.java b/common/src/main/java/common/block/tech/BlockDispenser.java index b526f5cc..25db8a20 100755 --- a/common/src/main/java/common/block/tech/BlockDispenser.java +++ b/common/src/main/java/common/block/tech/BlockDispenser.java @@ -190,7 +190,7 @@ public class BlockDispenser extends BlockContainer implements Directional /** * Returns a new instance of a block's tile entity class. Called on placing the block. */ - public TileEntity createNewTileEntity(World worldIn) + public TileEntity createNewTileEntity() { return new TileEntityDispenser(); } diff --git a/common/src/main/java/common/block/tech/BlockDisplay.java b/common/src/main/java/common/block/tech/BlockDisplay.java index a9bddd44..cd920b75 100644 --- a/common/src/main/java/common/block/tech/BlockDisplay.java +++ b/common/src/main/java/common/block/tech/BlockDisplay.java @@ -1,49 +1,44 @@ package common.block.tech; import java.util.ArrayDeque; -import java.util.ArrayList; import java.util.HashSet; -import java.util.List; import java.util.Queue; import java.util.Set; import common.block.Block; -import common.block.BlockContainer; import common.block.Material; import common.block.Rotatable; -import common.block.liquid.BlockLiquid; -import common.block.liquid.BlockStaticLiquid; -import common.collect.Sets; -import common.entity.npc.EntityNPC; import common.entity.types.EntityLiving; -import common.init.Blocks; import common.item.CheatTab; import common.model.Model; import common.model.ModelProvider; import common.model.ModelRotation; import common.properties.Property; -import common.tileentity.TileEntity; -import common.tileentity.TileEntityDisplay; import common.util.BlockPos; import common.util.BoundingBox; import common.util.Facing; import common.util.Pair; -import common.util.Vec3i; -import common.world.AWorldServer; import common.world.IWorldAccess; import common.world.State; import common.world.World; -public class BlockDisplay extends BlockContainer implements Rotatable +public abstract class BlockDisplay extends Block implements Rotatable { - public BlockDisplay() + protected final int density; + + public BlockDisplay(int density) { super(Material.SOLID); - this.setLightLevel(1.0f); + this.density = density; this.setBlockBounds(0.0F, 0.0F, 1.0F - 0.0625F, 1.0F, 1.0F, 1.0F); this.setDefaultState(this.getBaseState().withProperty(FACING, Facing.NORTH)); this.setTab(CheatTab.TECHNOLOGY); + this.setFlatItemTexture(); } + + public int getDensity() { + return this.density; + } public void setBlockBoundsBasedOnState(IWorldAccess worldIn, BlockPos pos) { @@ -96,29 +91,15 @@ public class BlockDisplay extends BlockContainer implements Rotatable return false; } - /** - * Used to determine ambient occlusion and culling when rebuilding chunks for render - */ public boolean isOpaqueCube() { return false; } - /** - * Return true if an entity can be spawned inside the block (used to get the player's bed spawn location) - */ public boolean canSpawnInBlock() { return true; } - - /** - * Returns a new instance of a block's tile entity class. Called on placing the block. - */ - public TileEntity createNewTileEntity(World worldIn) - { - return new TileEntityDisplay(); - } public boolean isXrayVisible() { @@ -129,24 +110,17 @@ public class BlockDisplay extends BlockContainer implements Rotatable return this.getState().withProperty(FACING, facing.getAxis().isVertical() ? placer.getHorizontalFacing().getOpposite() : facing); } - public int getRenderType() { - return 3; - } - public boolean shouldSideBeRendered(IWorldAccess worldIn, BlockPos pos, Facing side) { return true; } - -// -// public Transforms getTransform() { -// return Transforms.LAYER; -// } public Model getModel(ModelProvider provider, String name, State state) { - return provider.getModel("iron_block").add(0, 0, 15, 16, 16, 16).n().noCull().s().du().we().rotate(ModelRotation.getNorthRot(state.getValue(FACING))); + return provider.getModel("iron_block").add(0, 0, 15, 16, 16, 16).n("display_area").noCull().s().du().we().rotate(ModelRotation.getNorthRot(state.getValue(FACING))); } + protected abstract BlockDisplay getOtherBlock(); + private boolean test(World world, BlockPos pos, BlockPos origin, Facing dir) { int radius = 9; if(pos.getX() < origin.getX() - radius || pos.getX() > origin.getX() + radius) @@ -156,14 +130,10 @@ public class BlockDisplay extends BlockContainer implements Rotatable if(pos.getZ() < origin.getZ() - radius || pos.getZ() > origin.getZ() + radius) return false; State state = world.getState(pos); - return state.getBlock() == this && state.getValue(FACING) == dir; + return (state.getBlock() == this || state.getBlock() == this.getOtherBlock()) && state.getValue(FACING) == dir; } - private Pair getSpan(World world, BlockPos origin) { - State state = world.getState(origin); - if(state.getBlock() != this) - return null; - Facing dir = state.getValue(FACING); + protected Pair getSpan(World world, BlockPos origin, Facing dir) { Queue queue = new ArrayDeque(); Set present = new HashSet(); Set visited = new HashSet(); @@ -213,23 +183,4 @@ public class BlockDisplay extends BlockContainer implements Rotatable } return new Pair(min, max); } - - public boolean onBlockActivated(World worldIn, BlockPos pos, State state, EntityNPC playerIn, Facing side, float hitX, float hitY, float hitZ) { - if(!worldIn.client) { - Pair span = this.getSpan(worldIn, pos); - if(span == null) - return true; - for(BlockPos loc : BlockPos.getAllInBox(span.first(), span.second())) { - TileEntity tileentity = worldIn.getTileEntity(loc); - if(tileentity instanceof TileEntityDisplay display) { - for(int z = 0; z < 16; z++) { - display.setPixel(worldIn.rand.zrange(16), worldIn.rand.zrange(16), worldIn.rand.zrange(0x8000000)); - } - display.markDirty(); - worldIn.markBlockForUpdate(loc); - } - } - } - return true; - } } diff --git a/common/src/main/java/common/block/tech/BlockDropper.java b/common/src/main/java/common/block/tech/BlockDropper.java index 1058fe3e..06a2e9a9 100755 --- a/common/src/main/java/common/block/tech/BlockDropper.java +++ b/common/src/main/java/common/block/tech/BlockDropper.java @@ -24,7 +24,7 @@ public class BlockDropper extends BlockDispenser /** * Returns a new instance of a block's tile entity class. Called on placing the block. */ - public TileEntity createNewTileEntity(World worldIn) + public TileEntity createNewTileEntity() { return new TileEntityDropper(); } diff --git a/common/src/main/java/common/block/tech/BlockEnchantmentTable.java b/common/src/main/java/common/block/tech/BlockEnchantmentTable.java index d242f818..63a67188 100755 --- a/common/src/main/java/common/block/tech/BlockEnchantmentTable.java +++ b/common/src/main/java/common/block/tech/BlockEnchantmentTable.java @@ -97,7 +97,7 @@ public class BlockEnchantmentTable extends BlockContainer /** * Returns a new instance of a block's tile entity class. Called on placing the block. */ - public TileEntity createNewTileEntity(World worldIn) + public TileEntity createNewTileEntity() { return new TileEntityEnchantmentTable(); } diff --git a/common/src/main/java/common/block/tech/BlockFurnace.java b/common/src/main/java/common/block/tech/BlockFurnace.java index 4fe9f887..10d193c5 100755 --- a/common/src/main/java/common/block/tech/BlockFurnace.java +++ b/common/src/main/java/common/block/tech/BlockFurnace.java @@ -168,7 +168,7 @@ public class BlockFurnace extends BlockContainer implements Rotatable /** * Returns a new instance of a block's tile entity class. Called on placing the block. */ - public TileEntity createNewTileEntity(World worldIn) + public TileEntity createNewTileEntity() { return new TileEntityFurnace(); } diff --git a/common/src/main/java/common/block/tech/BlockHopper.java b/common/src/main/java/common/block/tech/BlockHopper.java index 92105e84..3b596162 100755 --- a/common/src/main/java/common/block/tech/BlockHopper.java +++ b/common/src/main/java/common/block/tech/BlockHopper.java @@ -137,7 +137,7 @@ public class BlockHopper extends BlockContainer implements DirectionalDown /** * Returns a new instance of a block's tile entity class. Called on placing the block. */ - public TileEntity createNewTileEntity(World worldIn) + public TileEntity createNewTileEntity() { return new TileEntityHopper(); } diff --git a/common/src/main/java/common/block/tech/BlockInactiveDisplay.java b/common/src/main/java/common/block/tech/BlockInactiveDisplay.java new file mode 100644 index 00000000..2eeeb25c --- /dev/null +++ b/common/src/main/java/common/block/tech/BlockInactiveDisplay.java @@ -0,0 +1,52 @@ +package common.block.tech; + +import java.util.Arrays; + +import common.entity.npc.EntityNPC; +import common.init.BlockRegistry; +import common.item.Item; +import common.item.block.ItemBlock; +import common.tileentity.TileEntity; +import common.tileentity.TileEntityDisplay; +import common.util.BlockPos; +import common.util.Facing; +import common.util.Pair; +import common.world.State; +import common.world.World; + +public class BlockInactiveDisplay extends BlockDisplay { + private BlockActiveDisplay active; + + public BlockInactiveDisplay(int density) { + super(density * 16); + } + + protected void setActive(BlockActiveDisplay active) { + this.active = active; + } + + public boolean onBlockActivated(World worldIn, BlockPos pos, State state, EntityNPC playerIn, Facing side, float hitX, float hitY, float hitZ) { + if(!worldIn.client) { + Pair span = this.getSpan(worldIn, pos, state.getValue(FACING)); + if(span == null) + return true; + for(BlockPos loc : BlockPos.getAllInBox(span.first(), span.second())) { + worldIn.setState(loc, this.active.getState().withProperty(FACING, state.getValue(FACING)), 2); + TileEntity tileentity = worldIn.getTileEntity(loc); + if(tileentity instanceof TileEntityDisplay display) { + Arrays.fill(display.data, 0xff000000); + worldIn.markBlockForUpdate(loc); + } + } + } + return true; + } + + protected Item getItemToRegister() { + return new ItemBlock(this, BlockRegistry.getName(this)); + } + + protected BlockDisplay getOtherBlock() { + return this.active; + } +} diff --git a/common/src/main/java/common/block/tech/BlockMachine.java b/common/src/main/java/common/block/tech/BlockMachine.java index 23760ed9..e7ca5e07 100755 --- a/common/src/main/java/common/block/tech/BlockMachine.java +++ b/common/src/main/java/common/block/tech/BlockMachine.java @@ -26,7 +26,7 @@ public abstract class BlockMachine extends Block implements Rotatable, ITileEnti this.setTab(CheatTab.TECHNOLOGY); } - public abstract TileEntity createNewTileEntity(World worldIn); + public abstract TileEntity createNewTileEntity(); public void onBlockAdded(AWorldServer worldIn, BlockPos pos, State state) { this.updateState(worldIn, pos, state); diff --git a/common/src/main/java/common/block/tech/BlockMobSpawner.java b/common/src/main/java/common/block/tech/BlockMobSpawner.java index 12399c62..477c5aa2 100755 --- a/common/src/main/java/common/block/tech/BlockMobSpawner.java +++ b/common/src/main/java/common/block/tech/BlockMobSpawner.java @@ -2,10 +2,9 @@ package common.block.tech; import common.tileentity.TileEntity; import common.tileentity.TileEntityMobSpawner; -import common.world.World; public class BlockMobSpawner extends BlockMachine { - public TileEntity createNewTileEntity(World world) { + public TileEntity createNewTileEntity() { return new TileEntityMobSpawner(); } } diff --git a/common/src/main/java/common/block/tech/BlockPistonMoving.java b/common/src/main/java/common/block/tech/BlockPistonMoving.java index 558c7503..4eb472fa 100755 --- a/common/src/main/java/common/block/tech/BlockPistonMoving.java +++ b/common/src/main/java/common/block/tech/BlockPistonMoving.java @@ -36,7 +36,7 @@ public class BlockPistonMoving extends BlockContainer /** * Returns a new instance of a block's tile entity class. Called on placing the block. */ - public TileEntity createNewTileEntity(World worldIn) + public TileEntity createNewTileEntity() { return null; } diff --git a/common/src/main/java/common/block/tech/BlockRedstoneComparator.java b/common/src/main/java/common/block/tech/BlockRedstoneComparator.java index c1a37c26..7ab0f4b6 100755 --- a/common/src/main/java/common/block/tech/BlockRedstoneComparator.java +++ b/common/src/main/java/common/block/tech/BlockRedstoneComparator.java @@ -246,7 +246,7 @@ public class BlockRedstoneComparator extends BlockRedstoneDiode implements ITile public void onBlockAdded(AWorldServer worldIn, BlockPos pos, State state) { super.onBlockAdded(worldIn, pos, state); - worldIn.setTileEntity(pos, this.createNewTileEntity(worldIn)); + worldIn.setTileEntity(pos, this.createNewTileEntity()); } public void onBlockRemoved(AWorldServer worldIn, BlockPos pos, State state) @@ -269,7 +269,7 @@ public class BlockRedstoneComparator extends BlockRedstoneDiode implements ITile /** * Returns a new instance of a block's tile entity class. Called on placing the block. */ - public TileEntity createNewTileEntity(World worldIn) + public TileEntity createNewTileEntity() { return new TileEntityComparator(); } diff --git a/common/src/main/java/common/block/tech/BlockTianReactor.java b/common/src/main/java/common/block/tech/BlockTianReactor.java index 2af3248b..027f286f 100755 --- a/common/src/main/java/common/block/tech/BlockTianReactor.java +++ b/common/src/main/java/common/block/tech/BlockTianReactor.java @@ -8,10 +8,9 @@ import common.model.ModelRotation; import common.tileentity.TileEntity; import common.tileentity.TileEntityTianReactor; import common.world.State; -import common.world.World; public class BlockTianReactor extends BlockMachine { - public TileEntity createNewTileEntity(World world) { + public TileEntity createNewTileEntity() { return new TileEntityTianReactor(); } diff --git a/common/src/main/java/common/block/tile/BlockBanner.java b/common/src/main/java/common/block/tile/BlockBanner.java index 1b85f3b3..0a9c3650 100755 --- a/common/src/main/java/common/block/tile/BlockBanner.java +++ b/common/src/main/java/common/block/tile/BlockBanner.java @@ -73,7 +73,7 @@ public class BlockBanner extends BlockContainer implements Rotatable /** * Returns a new instance of a block's tile entity class. Called on placing the block. */ - public TileEntity createNewTileEntity(World worldIn) + public TileEntity createNewTileEntity() { return new TileEntityBanner(); } @@ -103,10 +103,6 @@ public class BlockBanner extends BlockContainer implements Rotatable ItemStack itemstack = new ItemStack(Items.banner); TagObject tag = new TagObject(); tileentity.writeTags(tag); - tag.remove("x"); - tag.remove("y"); - tag.remove("z"); - tag.remove("id"); itemstack.setTagInfo("BlockEntityTag", tag); spawnAsEntity(worldIn, pos, itemstack); } diff --git a/common/src/main/java/common/block/tile/BlockSign.java b/common/src/main/java/common/block/tile/BlockSign.java index 502e7d06..0b0ac934 100755 --- a/common/src/main/java/common/block/tile/BlockSign.java +++ b/common/src/main/java/common/block/tile/BlockSign.java @@ -80,7 +80,7 @@ public class BlockSign extends BlockContainer /** * Returns a new instance of a block's tile entity class. Called on placing the block. */ - public TileEntity createNewTileEntity(World worldIn) + public TileEntity createNewTileEntity() { return new TileEntitySign(); } diff --git a/common/src/main/java/common/entity/item/EntityFireworks.java b/common/src/main/java/common/entity/item/EntityFireworks.java index 06c7ed74..86b3e8b7 100755 --- a/common/src/main/java/common/entity/item/EntityFireworks.java +++ b/common/src/main/java/common/entity/item/EntityFireworks.java @@ -8,7 +8,6 @@ import common.model.ParticleType; import common.tags.TagObject; import common.util.ExtMath; import common.world.AWorldClient; -import common.world.AWorldServer; import common.world.World; public class EntityFireworks extends Entity diff --git a/common/src/main/java/common/init/BlockRegistry.java b/common/src/main/java/common/init/BlockRegistry.java index 250b7d19..062d53b0 100755 --- a/common/src/main/java/common/init/BlockRegistry.java +++ b/common/src/main/java/common/init/BlockRegistry.java @@ -92,6 +92,7 @@ import common.block.natural.BlockSoulSand; import common.block.natural.BlockStone; import common.block.natural.BlockTintedFire; import common.block.natural.BlockWeb; +import common.block.tech.BlockActiveDisplay; import common.block.tech.BlockAnvil; import common.block.tech.BlockBeacon; import common.block.tech.BlockBrewingStand; @@ -101,11 +102,11 @@ import common.block.tech.BlockChest; import common.block.tech.BlockCore; import common.block.tech.BlockDaylightDetector; import common.block.tech.BlockDispenser; -import common.block.tech.BlockDisplay; import common.block.tech.BlockDropper; import common.block.tech.BlockEnchantmentTable; import common.block.tech.BlockFurnace; import common.block.tech.BlockHopper; +import common.block.tech.BlockInactiveDisplay; import common.block.tech.BlockJukebox; import common.block.tech.BlockLever; import common.block.tech.BlockMobSpawner; @@ -462,7 +463,13 @@ public abstract class BlockRegistry { .setTab(CheatTab.DECORATION)); register("sign", (new BlockStandingSign()).setHardness(1.0F).setStepSound(SoundType.WOOD).setDisplay("Schild")); register("wall_sign", (new BlockWallSign()).setHardness(1.0F).setStepSound(SoundType.WOOD).setDisplay("Schild")); - register("display", (new BlockDisplay()).setHardness(1.0F).setStepSound(SoundType.STONE).setDisplay("Anzeige")); + for(int density : new int[] {1, 2, 4}) { + BlockInactiveDisplay display = (BlockInactiveDisplay)new BlockInactiveDisplay(density).setHardness(1.0F).setStepSound(SoundType.STONE).setDisplay("Displaymodul (" + (density * 16) + + "x" + (density * 16) + ")"); + register("display" + (density == 1 ? "" : density), display); + register("display" + (density == 1 ? "" : density) + "_on", new BlockActiveDisplay(display).setHardness(1.0F).setStepSound(SoundType.STONE).setDisplay("Displaymodul (" + (density * 16) + + "x" + (density * 16) + ")")); + } register("banner", (new BlockBannerStanding()).setHardness(1.0F).setStepSound(SoundType.WOOD).setDisplay("Banner")); register("wall_banner", (new BlockBannerHanging()).setHardness(1.0F).setStepSound(SoundType.WOOD).setDisplay("Banner")); diff --git a/common/src/main/java/common/init/Blocks.java b/common/src/main/java/common/init/Blocks.java index 36b37255..cf18d5a5 100755 --- a/common/src/main/java/common/init/Blocks.java +++ b/common/src/main/java/common/init/Blocks.java @@ -591,7 +591,12 @@ public abstract class Blocks { public static final BlockStairs floor_tiles_white_stairs = get("floor_tiles_white_stairs"); public static final BlockSlab pentagram_slab = get("pentagram_slab"); public static final BlockStairs pentagram_stairs = get("pentagram_stairs"); - public static final BlockDisplay display = get("display"); + public static final BlockInactiveDisplay display = get("display"); + public static final BlockInactiveDisplay display2 = get("display2"); + public static final BlockInactiveDisplay display4 = get("display4"); + public static final BlockActiveDisplay display_on = get("display_on"); + public static final BlockActiveDisplay display2_on = get("display2_on"); + public static final BlockActiveDisplay display4_on = get("display4_on"); private static T get(String id) { T block = (T)BlockRegistry.byNameExact(id); diff --git a/common/src/main/java/common/init/Items.java b/common/src/main/java/common/init/Items.java index 4f3f0b8d..de3b9007 100755 --- a/common/src/main/java/common/init/Items.java +++ b/common/src/main/java/common/init/Items.java @@ -973,6 +973,8 @@ public abstract class Items { public static final ItemSlab pentagram_slab = get("pentagram_slab"); public static final ItemBlock pentagram_stairs = get("pentagram_stairs"); public static final ItemBlock display = get("display"); + public static final ItemBlock display2 = get("display2"); + public static final ItemBlock display4 = get("display4"); private static T get(String id) { T item = (T)ItemRegistry.byName(id); diff --git a/common/src/main/java/common/item/block/ItemBlock.java b/common/src/main/java/common/item/block/ItemBlock.java index e60ac976..5fa3c516 100755 --- a/common/src/main/java/common/item/block/ItemBlock.java +++ b/common/src/main/java/common/item/block/ItemBlock.java @@ -114,9 +114,6 @@ public class ItemBlock extends Item tile.writeTags(tag); TagObject stackTag = stack.getTag().getObject("BlockEntityTag"); tag.merge(stackTag); - tag.setInt("x", pos.getX()); - tag.setInt("y", pos.getY()); - tag.setInt("z", pos.getZ()); if (!tag.equals(tileTag)) { diff --git a/common/src/main/java/common/packet/SPacketUpdateDisplay.java b/common/src/main/java/common/packet/SPacketUpdateDisplay.java index 98107bfe..bedf6f4f 100644 --- a/common/src/main/java/common/packet/SPacketUpdateDisplay.java +++ b/common/src/main/java/common/packet/SPacketUpdateDisplay.java @@ -2,36 +2,43 @@ package common.packet; import java.io.IOException; +import common.net.handler.codec.DecoderException; import common.network.IClientPlayer; import common.network.Packet; import common.network.PacketBuffer; import common.util.BlockPos; public class SPacketUpdateDisplay implements Packet { + private int density; private BlockPos position; private int[] pixels; public SPacketUpdateDisplay() { } - public SPacketUpdateDisplay(BlockPos pos, int[] pixels) { + public SPacketUpdateDisplay(int density, BlockPos pos, int[] pixels) { + this.density = density; this.position = pos; this.pixels = pixels; } public void readPacketData(PacketBuffer buf) throws IOException { + this.density = buf.readUnsignedByte() * 16; + if(this.density < 16 || this.density > 256) + throw new DecoderException("Incorrect density"); this.position = buf.readBlockPos(); - this.pixels = new int[256]; + this.pixels = new int[this.density * this.density]; - for(int i = 0; i < 256; ++i) { + for(int i = 0; i < this.density * this.density; ++i) { this.pixels[i] = 0xff000000 | buf.readUnsignedByte() << 16 | buf.readUnsignedByte() << 8 | buf.readUnsignedByte(); } } public void writePacketData(PacketBuffer buf) throws IOException { + buf.writeByte(this.density / 16); buf.writeBlockPos(this.position); - for(int i = 0; i < 256; ++i) { + for(int i = 0; i < this.density * this.density; ++i) { buf.writeByte((this.pixels[i] >> 16) & 255); buf.writeByte((this.pixels[i] >> 8) & 255); buf.writeByte(this.pixels[i] & 255); diff --git a/common/src/main/java/common/packet/SPacketUpdateTileEntity.java b/common/src/main/java/common/packet/SPacketUpdateTileEntity.java index f1420cf2..86cfdcb9 100755 --- a/common/src/main/java/common/packet/SPacketUpdateTileEntity.java +++ b/common/src/main/java/common/packet/SPacketUpdateTileEntity.java @@ -2,18 +2,20 @@ package common.packet; import java.io.IOException; -import common.init.TileRegistry; +import common.block.Block; +import common.init.BlockRegistry; import common.network.IClientPlayer; import common.network.Packet; import common.network.PacketBuffer; import common.tags.TagObject; import common.tileentity.TileEntity; import common.util.BlockPos; +import common.world.State; public class SPacketUpdateTileEntity implements Packet { private BlockPos blockPos; - private int type; + private Block type; private TagObject tag; public SPacketUpdateTileEntity() @@ -23,7 +25,7 @@ public class SPacketUpdateTileEntity implements Packet public SPacketUpdateTileEntity(TileEntity tile) { this.blockPos = tile.getPos(); - this.type = TileRegistry.CLASS_TO_ID.get(tile.getClass()); + this.type = tile.getBlockType(); tile.writeTags(this.tag = new TagObject()); } @@ -33,7 +35,8 @@ public class SPacketUpdateTileEntity implements Packet public void readPacketData(PacketBuffer buf) throws IOException { this.blockPos = buf.readBlockPos(); - this.type = buf.readUnsignedByte(); + State state = BlockRegistry.byId(buf.readVarInt()); + this.type = state == null ? null : state.getBlock(); this.tag = buf.readTag(); } @@ -43,7 +46,7 @@ public class SPacketUpdateTileEntity implements Packet public void writePacketData(PacketBuffer buf) throws IOException { buf.writeBlockPos(this.blockPos); - buf.writeByte((byte)this.type); + buf.writeVarInt(BlockRegistry.getId(this.type.getState())); buf.writeTag(this.tag); } @@ -62,7 +65,7 @@ public class SPacketUpdateTileEntity implements Packet public boolean isTileEntityType(TileEntity tile) { - return this.type == TileRegistry.CLASS_TO_ID.get(tile.getClass()); + return this.type == tile.getBlockType(); } public TagObject getTags() diff --git a/common/src/main/java/common/tileentity/TileEntity.java b/common/src/main/java/common/tileentity/TileEntity.java index 3d7e9cf3..b2120dda 100755 --- a/common/src/main/java/common/tileentity/TileEntity.java +++ b/common/src/main/java/common/tileentity/TileEntity.java @@ -1,13 +1,15 @@ package common.tileentity; import common.block.Block; +import common.block.ITileEntityProvider; +import common.init.BlockRegistry; import common.init.Blocks; -import common.init.TileRegistry; import common.log.Log; import common.network.Packet; import common.tags.TagObject; import common.util.BlockPos; import common.world.AWorldServer; +import common.world.Chunk; import common.world.State; import common.world.World; @@ -55,54 +57,23 @@ public abstract class TileEntity public void readTags(TagObject compound) { - this.pos = new BlockPos(compound.getInt("x"), compound.getInt("y"), compound.getInt("z")); } public void writeTags(TagObject compound) { - String s = (String)TileRegistry.CLASS_TO_NAME.get(this.getClass()); - - if (s == null) - { - throw new RuntimeException(this.getClass() + " is missing a mapping! This is a bug!"); - } - else - { - compound.setString("id", s); - compound.setInt("x", this.pos.getX()); - compound.setInt("y", this.pos.getY()); - compound.setInt("z", this.pos.getZ()); - } } - public static TileEntity createAndLoadEntity(TagObject tag) + public static TileEntity createAndLoadEntity(AWorldServer world, Chunk chunk, BlockPos pos, TagObject tag) { - TileEntity tileentity = null; - - try - { - Class oclass = (Class)TileRegistry.NAME_TO_CLASS.get(tag.getString("id")); - - if (oclass != null) - { - tileentity = (TileEntity)oclass.getConstructor().newInstance(); - } - } - catch (Exception exception) - { - exception.printStackTrace(); - } - - if (tileentity != null) - { - tileentity.readTags(tag); - } - else - { - Log.TICK.warn("Ignoriere Block-Objekt mit ID " + tag.getString("id")); - } - - return tileentity; + Block block = chunk.getState(pos).getBlock(); + if(!(block instanceof ITileEntityProvider provider)) { + Log.TICK.warn("Ignoriere Block-Objekt von unbekanntem Block %s in Chunk %d, %d", BlockRegistry.getName(block), chunk.xPos, chunk.zPos); + return null; + } + TileEntity te = provider.createNewTileEntity(); + te.setPos(pos); + te.readTags(tag); + return te; } public State getBlockState() diff --git a/common/src/main/java/common/tileentity/TileEntityDisplay.java b/common/src/main/java/common/tileentity/TileEntityDisplay.java index 11469a6a..65144b45 100644 --- a/common/src/main/java/common/tileentity/TileEntityDisplay.java +++ b/common/src/main/java/common/tileentity/TileEntityDisplay.java @@ -4,30 +4,20 @@ import java.util.Arrays; import common.network.Packet; import common.packet.SPacketUpdateDisplay; -import common.tags.TagObject; public class TileEntityDisplay extends TileEntity { - public int[] data = new int[256]; + public final int density; + public int[] data; public long lastUpdated; - public TileEntityDisplay() { + public TileEntityDisplay(int density) { + this.density = density; + this.data = new int[density * density]; Arrays.fill(this.data, 0xff000000); } - public void writeTags(TagObject compound) { - super.writeTags(compound); - compound.setIntArray("Pixels", this.data); - } - - public void readTags(TagObject compound) { - super.readTags(compound); - this.data = compound.getIntArray("Pixels"); - if(this.data.length != 256) - this.data = new int[256]; - } - public Packet getDescriptionPacket() { - return new SPacketUpdateDisplay(this.pos, this.data); + return new SPacketUpdateDisplay(this.density, this.pos, this.data); } public int getColor() { @@ -35,6 +25,6 @@ public class TileEntityDisplay extends TileEntity { } public void setPixel(int x, int y, int color) { - this.data[x + y * 16] = color | 0xff000000; + this.data[x + y * this.density] = color | 0xff000000; } } diff --git a/common/src/main/java/common/world/Chunk.java b/common/src/main/java/common/world/Chunk.java index 5c8846d3..67339045 100755 --- a/common/src/main/java/common/world/Chunk.java +++ b/common/src/main/java/common/world/Chunk.java @@ -392,7 +392,7 @@ public abstract class Chunk { TileEntity tile = this.getTileEntity(pos, TileEntity.EnumCreateEntityType.CHECK); if(tile == null) { - tile = ((ITileEntityProvider)block).createNewTileEntity(this.world); + tile = ((ITileEntityProvider)block).createNewTileEntity(); this.world.setTileEntity(pos, tile); } @@ -517,7 +517,7 @@ public abstract class Chunk { private TileEntity createNewTileEntity(BlockPos pos) { Block block = this.getBlock(pos); - return !block.hasTileEntity() ? null : ((ITileEntityProvider)block).createNewTileEntity(this.world); + return !block.hasTileEntity() ? null : ((ITileEntityProvider)block).createNewTileEntity(); } public TileEntity getTileEntity(BlockPos pos, TileEntity.EnumCreateEntityType type) { diff --git a/server/src/main/java/server/command/commands/CommandBlock.java b/server/src/main/java/server/command/commands/CommandBlock.java index ca569efa..ea6c95c7 100644 --- a/server/src/main/java/server/command/commands/CommandBlock.java +++ b/server/src/main/java/server/command/commands/CommandBlock.java @@ -49,12 +49,8 @@ public class CommandBlock extends Command { if(tile != null) { TagObject te = new TagObject(); tile.writeTags(te); - tag.setString("id", te.getString("id")); - tag.setInt("x", position.getX()); - tag.setInt("y", position.getY()); - tag.setInt("z", position.getZ()); te.merge(tag); - TileEntity newTile = TileEntity.createAndLoadEntity(te); + TileEntity newTile = TileEntity.createAndLoadEntity(world, world.getChunk(position), position, te); if(newTile != null) { world.removeTileEntity(position); world.setTileEntity(position, newTile); diff --git a/server/src/main/java/server/world/Converter.java b/server/src/main/java/server/world/Converter.java index b33f45a1..546b5354 100644 --- a/server/src/main/java/server/world/Converter.java +++ b/server/src/main/java/server/world/Converter.java @@ -111,7 +111,6 @@ import common.entity.item.EntityMinecart; import common.init.BlockRegistry; import common.init.Blocks; import common.init.EntityRegistry; -import common.init.TileRegistry; import common.log.Log; import common.rng.Random; import common.tags.TagObject; @@ -310,7 +309,7 @@ public abstract class Converter { private static final Random RANDOM = new Random(); private static final Map ENTITY_MAP = Maps.newHashMap(); - private static final Map TILE_MAP = Maps.newHashMap(); + private static final Map> TILE_MAP = Maps.newHashMap(); private static final State[] BLOCK_MAP = new State[65536]; private static final DyeColor[] COLOR_LOOKUP = new DyeColor[] { DyeColor.WHITE, DyeColor.ORANGE, DyeColor.MAGENTA, DyeColor.LIGHT_BLUE, DyeColor.YELLOW, DyeColor.LIME, DyeColor.PINK, DyeColor.GRAY, @@ -325,9 +324,8 @@ public abstract class Converter { } private static void mapTile(Class clazz, String ... names) { - String name = TileRegistry.CLASS_TO_NAME.get(clazz); for(String oldname : names) { - TILE_MAP.put(oldname, name); + TILE_MAP.put(oldname, clazz); } } @@ -1717,9 +1715,9 @@ public abstract class Converter { return (NbtTag)read(in, (byte)10); } - private static TagObject convertTile(NbtTag ent, String id) { + private static TagObject convertTile(NbtTag ent, Class clazz) { TagObject nent = new TagObject(); - if("Sign".equals(id)) { + if(clazz == TileEntitySign.class) { String[] signText = new String[4]; for(int i = 0; i < 4; ++i) { signText[i] = ent.getString("Text" + (i + 1)); @@ -1754,7 +1752,7 @@ public abstract class Converter { nent.setString("Text" + (i + 1), signText[i]); } } - else if("Comparator".equals(id)) { + else if(clazz == TileEntityComparator.class) { nent.setInt("OutputSignal", ent.getInt("OutputSignal")); } return nent; @@ -1883,13 +1881,12 @@ public abstract class Converter { entities = Lists.newArrayList(); for(NbtTag ent : ents) { TagObject nent = new TagObject(); - String mapped = TILE_MAP.get(trimColon(ent.getString("id"))); + Class mapped = TILE_MAP.get(trimColon(ent.getString("id"))); if(mapped != null) { nent = convertTile(ent, mapped); - nent.setString("id", mapped); - nent.setInt("x", ent.getInt("x")); - nent.setInt("y", ent.getInt("y")); - nent.setInt("z", ent.getInt("z")); + nent.setByte("x", (byte)(ent.getInt("x") & 15)); + nent.setShort("y", (short)ent.getInt("y")); + nent.setByte("z", (byte)(ent.getInt("z") & 15)); entities.add(nent); } } diff --git a/server/src/main/java/server/world/Region.java b/server/src/main/java/server/world/Region.java index 910b791b..a360fa26 100755 --- a/server/src/main/java/server/world/Region.java +++ b/server/src/main/java/server/world/Region.java @@ -36,6 +36,7 @@ import common.util.NibbleArray; import common.util.Util; import common.world.BlockArray; import common.world.State; +import common.world.World; public class Region { private static boolean makeMap(TagObject tag) { @@ -632,7 +633,13 @@ public class Region { if(tiles != null) { for(int n = 0; n < tiles.size(); ++n) { TagObject tile = tiles.get(n); - TileEntity tileentity = TileEntity.createAndLoadEntity(tile); + BlockPos pos = new BlockPos(tile.getByte("x"), tile.getShort("y"), tile.getByte("z")); + if(pos.getX() < 0 || pos.getX() >= 16 || pos.getZ() < 0 || pos.getZ() >= 16 || pos.getY() < -World.MAX_SIZE_Y || pos.getY() >= World.MAX_SIZE_Y) { + Log.TICK.warn("Ignoriere Block-Objekt mit ungültigen Koordinaten %d, %d, %d in Chunk %d, %d", pos.getX(), pos.getY(), pos.getZ(), chunk.xPos, chunk.zPos); + continue; + } + pos = new BlockPos(chunk.xPos << 4 | pos.getX(), pos.getY(), chunk.zPos << 4 | pos.getZ()); + TileEntity tileentity = TileEntity.createAndLoadEntity(world, chunk, pos, tile); if(tileentity != null) { chunk.addTileEntity(tileentity); @@ -752,6 +759,9 @@ public class Region { for(TileEntity tileentity : chunk.getTiles().values()) { TagObject tile = new TagObject(); tileentity.writeTags(tile); + tile.setByte("x", (byte)(tileentity.getPos().getX() & 15)); + tile.setShort("y", (short)tileentity.getPos().getY()); + tile.setByte("z", (byte)(tileentity.getPos().getZ() & 15)); tiles.add(tile); } diff --git a/server/src/main/java/server/world/WorldServer.java b/server/src/main/java/server/world/WorldServer.java index 586bafe1..d030387d 100755 --- a/server/src/main/java/server/world/WorldServer.java +++ b/server/src/main/java/server/world/WorldServer.java @@ -2186,11 +2186,7 @@ public final class WorldServer extends AWorldServer { if(block.getData() != null) { this.removeTileEntity(pos); TagObject tag = block.getData(); - tag.setString("id", tag.getString("id")); - tag.setInt("x", pos.getX()); - tag.setInt("y", pos.getY()); - tag.setInt("z", pos.getZ()); - TileEntity tileEntity = TileEntity.createAndLoadEntity(tag); + TileEntity tileEntity = TileEntity.createAndLoadEntity(this, chunk, pos, tag); if(tileEntity != null) { this.setTileEntity(pos, tileEntity); }