From b0f33c3be1a0fa1a3400ee81493c3d895dc7d553 Mon Sep 17 00:00:00 2001 From: Sen Date: Sun, 6 Jul 2025 17:51:22 +0200 Subject: [PATCH] add basic displays --- .../java/client/network/ClientPlayer.java | 4 +- .../tileentity/TileEntityDisplayRenderer.java | 15 ++-- .../textures/blocks/display_area.png | Bin 0 -> 4559 bytes .../main/resources/textures/items/display.png | Bin 0 -> 4816 bytes .../resources/textures/items/display2.png | Bin 0 -> 4821 bytes .../resources/textures/items/display4.png | Bin 0 -> 4826 bytes .../common/block/ITileEntityProvider.java | 3 +- .../common/block/tech/BlockActiveDisplay.java | 71 ++++++++++++++++ .../java/common/block/tech/BlockBeacon.java | 2 +- .../common/block/tech/BlockBrewingStand.java | 2 +- .../java/common/block/tech/BlockChest.java | 2 +- .../block/tech/BlockDaylightDetector.java | 2 +- .../common/block/tech/BlockDispenser.java | 2 +- .../java/common/block/tech/BlockDisplay.java | 79 ++++-------------- .../java/common/block/tech/BlockDropper.java | 2 +- .../block/tech/BlockEnchantmentTable.java | 2 +- .../java/common/block/tech/BlockFurnace.java | 2 +- .../java/common/block/tech/BlockHopper.java | 2 +- .../block/tech/BlockInactiveDisplay.java | 52 ++++++++++++ .../java/common/block/tech/BlockMachine.java | 2 +- .../common/block/tech/BlockMobSpawner.java | 3 +- .../common/block/tech/BlockPistonMoving.java | 2 +- .../block/tech/BlockRedstoneComparator.java | 4 +- .../common/block/tech/BlockTianReactor.java | 3 +- .../java/common/block/tile/BlockBanner.java | 6 +- .../java/common/block/tile/BlockSign.java | 2 +- .../common/entity/item/EntityFireworks.java | 1 - .../main/java/common/init/BlockRegistry.java | 11 ++- common/src/main/java/common/init/Blocks.java | 7 +- common/src/main/java/common/init/Items.java | 2 + .../java/common/item/block/ItemBlock.java | 3 - .../common/packet/SPacketUpdateDisplay.java | 15 +++- .../packet/SPacketUpdateTileEntity.java | 15 ++-- .../java/common/tileentity/TileEntity.java | 55 +++--------- .../common/tileentity/TileEntityDisplay.java | 24 ++---- common/src/main/java/common/world/Chunk.java | 4 +- .../server/command/commands/CommandBlock.java | 6 +- .../src/main/java/server/world/Converter.java | 21 ++--- server/src/main/java/server/world/Region.java | 12 ++- .../main/java/server/world/WorldServer.java | 6 +- 40 files changed, 249 insertions(+), 197 deletions(-) create mode 100755 client/src/main/resources/textures/blocks/display_area.png create mode 100755 client/src/main/resources/textures/items/display.png create mode 100644 client/src/main/resources/textures/items/display2.png create mode 100644 client/src/main/resources/textures/items/display4.png create mode 100644 common/src/main/java/common/block/tech/BlockActiveDisplay.java create mode 100644 common/src/main/java/common/block/tech/BlockInactiveDisplay.java 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 TileEntitySpecialRendererpRtBbT_Fd*C0J<~l`JL7@FF~T4MiCA9r^f9zBhcgW`peqtx z4T++n;(|~cV^snaqC$DZI~g^uh)9rlk%*Fblu=x?)~p-W{dz!zN~%&;ZT@4XW~Tdn zzxR9J`+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Q3-~7+=XKyKr%pBQm9iv;IV^Th>KIB2}s+Fc~4oBT*TF_QP9gj?Miow9q_|rsv4x zI0uNI>oN6oR0^}A=dR~Ai}SP+1bLc*AgP`d9Apkdd-e&qdX}gR(qdx3^yn?uS9b1K zN`YdGDolZ^UbP@W#Gpm5JY zMGQncGZ^6%fM77Hgnua*(wi_M%#2qVYmi@PqVWLw4H@9qV*|qr%tEAZ81`x=jGf={ z)q57dV+24w803xg9h7TOt~XNPjlhG|H7M5`Dey+%!Rq?I$>sn0af-2ke?d<0uoSRP zQw1Khe2nq2I#HnTb{^dV0n0F3+(L&)6fj2kc!|o&gMrbP*BhdJANcx=fE3dY?GSJo zdfn_)Rm0xm`9Y^qzo-I->t*KAePI<9duyLIt@B-9!ro0Au0L{bbj9gyUjG>PGy1{l zpp))Y{Y2!WyhmSulG}DO?A($a*x|7Eic5SdhUEV{Zco+8(=Cz5D;5@b&1yY_RaBcz b#BH18TW5kze7&v+#1!eH6Lqyw>F@s!_&byS literal 0 HcmV?d00001 diff --git a/client/src/main/resources/textures/items/display.png b/client/src/main/resources/textures/items/display.png new file mode 100755 index 0000000000000000000000000000000000000000..30cdc1dc4d55bc91a7ba6595a01779270e47e963 GIT binary patch literal 4816 zcmeHKc~leE8V{muDo{nxS~Ns>iaN|BWQVvwA_NGaP~aikWHNzKvNRb?z)D5MT@cW^ zu&9VyP*AWem8wOah^Q!X9xfohR*#6j3Zk#LpnW$15l?&0JD&6UpGhW}``zF7yWjV_ z-~CQzQ*fZqc&pE?C=|+gv9E9m__Z}$7G~gk`m^6r3dQtkN@xVR1l3X18kL+##HnPm z8mHoVLQbLRZ=Vidnth*ZG0oN{*m{iWWc~8}Jyi9Ye^~=_Ym~P5eWPgB@ zsCD4(+5ES4E+H28S&_a@0X1Lui5YgeZFAtDf`Pt{n8VS@6|HnC!t<>@6M1t$=MfZ? z#r1C8upq2DtT>kk*Z7VVyUXotH-E^L0muXpOAou3rD!*5o3gxDo~?!HGy+k&ym zy~~u>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i6f&jP{{xli^BtW zCJtc?9D$fTTn_Qv-8m47(4~k}3L=xTj8rm=zeuG~pkO-*1sadTYGu4}!XP+*VX#<0 zW4H~jYP19=qNE%+2xtL>GD-g)8cHbe5E3=0N$0TWTsj88v>jgO7~Bt7L>c`G27ehllDpxaGct7ObCaG!34p5d5pb(cmzV zFdii;)p#iQC^nda7F~hMjBx_4!6_^ORmS6>dkmH9J3H|wr65J*JUN>ogWTD4Cd8CW z-61K9#et;mY#An(vbj=@{6luFN>1uf4ZbiQ=m@j|5N*FfujCUD(!hg`j(+C*RWPsnG4Ky#%3*q5rIHZ}O?fiwWp}qJER{+$X z7WpWBKgsn;u8&gSqrji4>yum`rNBplKULTNO)jhVk5jl3{0q{7hb6B|Pz`v{GL!oI z2r1(YZ{4ZwRA8}G`~F=^p^TkqxJ)Q}^CknMIVqNi%)8CaY#6p#L2=f=)FBow4CP+h znIp+aN5-u^+uJ&RNzk>al^0wbOv_zM_*;@g?aW>^Om*G}dC-5!yEmTZ)%^15Yf4-x zH1SeJT{tL%`7d!v} literal 0 HcmV?d00001 diff --git a/client/src/main/resources/textures/items/display2.png b/client/src/main/resources/textures/items/display2.png new file mode 100644 index 0000000000000000000000000000000000000000..c0c93cb8cc04c841b3b60b424f79ec56bc368bdb GIT binary patch literal 4821 zcmeHKc~nzp7LUk2KvCQXT5|$ZEt=$IUm(ho5F&(~ibau^yjRc)ut3Xu<0W<3m z0%AfHIGm~L$YQi{aIWKjFZyOV<=#6mbFJw@)9R!zmeY?f@~zpm+_YNn%K8gu zc6UeKnQ%GH+3z#?A(d-Z+O2yzv-WT5n331~!o9~lpbDZ~-GAPFV;$#lWUeUtXg@jM zZSR2hiGN=4B+aQS;M?7JGPo&n-yWxy?h;Wuxxt(JbRMPlTt)T5+qV-3o>d+Ea=<_6 z@imD$ahqu4Jct@D%3YwfNy;yRn)0TV{5ZAdQaIDDUN4=nv~m{v!cB8I`oMX5Ww_6T zi6y?7iV!a!@sWuO*?6N<>wz1NQy$s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(MSwB6((^I7K6l*vN%#E1amlS_82O$#(=>Z8DgOV zrJ!szzcl*rFzt&7^XuEG~;hWzZN*&O6X&h~5A? z(ZWfE$aIEv#j-6tPz(?jw)80=u-ZW_ykI>7V_JQjR;%I@EeQ}To}=ECC0PorQ6gY^jI`@pJNg@~z*0~V85`n|m>dr1 zCIuuTai|FB2Rfb0Rwy_$HfLD8QFen?ff->v5~u_^0@8@DnK`grf z1S5e~`?X+{k%B3fnenz_f6A{k@wWoT3>n}zYy-m!%tFfOFdWegw^^dAn8@B17{_TZ ziw$)9j^JYGDhvB_QfqN%FKhPh{(NU->!}>|f&b*%q?dBmR2ceJ73{2CerGl=xxT~m z_KJiwYS6k#z2?r{K1HDs*Bf15p6LB*Tb<3>8MxNC#`E8EqvPw2p2=92F(E#`Aa2>p zqAShw+rw5jc4U_N5b42!*6+=EwE^PrP+n;dW`pDQCfEOXpHrK${;G0apyMiE*F}Tp zaPC2-!oK5A@HJ~6vO1TOeX6@0cJTU2+Fv^1u4ZJ1y~=mNc}#+36 lOf5Tct;|WAFS=vSn`6k&5!+oc%>uRJ#KH(cLr`+={{W8`3_kz> literal 0 HcmV?d00001 diff --git a/client/src/main/resources/textures/items/display4.png b/client/src/main/resources/textures/items/display4.png new file mode 100644 index 0000000000000000000000000000000000000000..dfa0188ed52221409757f6bb8c136fd39cecc08b GIT binary patch literal 4826 zcmeHKdsGu=7EcjG5!7ydAubHVW(Dgc6OxdJ1W|*4As8j{vTBE!2@d2%GLnE|S5XnF zLPZo6#Rnqd`+>^Z)vB%H3#$mCf@lR47vBO!THG%I5zqFVJ)X1u&*UVTx%YQ}-@U)@ ze)nY36`_Gn4kH~H42Dy1kaRlu9c=mZ>kGc!UcJQ_j6Utj%1C-TW`gtvor+SE5S^qa zA<|5#7!3369c!np-Q(%FtnP3|luduzGX_O{-mTMPzgeg(MoP3ZYOBJFMy$?a`&YcI zJGHX&G?UfePCm@IVqip>yKKVwn#7!zE37@weou4RG+HF_>nC;HTemQ}rX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Lz(AV30#P}+Is_YNhcA;W0Qq9#Yc=Lk7IBB9V* zz~c)=??K_D!3a9h!pT8dT%Ofq*%mP<1_+B;`VMZNiAR3JuulpKMWCld4cU!vY(v=?4SP^zT=g|-|X$hT|DgD4|d zKgnw9I#FR{Lf2i_t(vkPB?z(}3NeOvm0-jYNy3^Z;OcVWb1`i!38qJPyS}qif7A*@ zOpHKQuA|GmsNvfsQ~c(4JPUAW!Q? zd3~6RX)bBm1t1uL3Xu1L3A+VjcNfgI%#3#x`?CK_6JIN!*N_2mT{bYhz$|3<48v~C zK)!$Gt9vj0%q1Y`(;^?G?O-**rP zUF7(M9WdPumQGL#FXe=tUcD4@luauYRVSvvj@^r4%qB&ZnVw4v8Jz~ z{JxWP$(rjA+MF4=rD$u4Jr`dx!lV3EK|4!XIq~^j{EpA^e#)Wn^q~i;I)!E7pV2># z{_3V318s-eb`|Gj*Hsl~kWr6qoK5zy&9jse-JK?fnzz-V(6=*&x-ZeKG7h|)x9UMr z+4dJv@t;rJ@^s+lR^(8h?7&}#6$o;tW_9LFgvW@?^z*-;%y(f#-YoIx3~*#DTaL;r y(4@UWdn(k+{aj>nobC;GAN 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); }