diff --git a/minecraft/1.11.2/src/main/java/nova/core/wrapper/mc/forge/v1_11_2/wrapper/block/backward/BWBlock.java b/minecraft/1.11.2/src/main/java/nova/core/wrapper/mc/forge/v1_11_2/wrapper/block/backward/BWBlock.java index 8e6d0d0fb..f0aa340b0 100644 --- a/minecraft/1.11.2/src/main/java/nova/core/wrapper/mc/forge/v1_11_2/wrapper/block/backward/BWBlock.java +++ b/minecraft/1.11.2/src/main/java/nova/core/wrapper/mc/forge/v1_11_2/wrapper/block/backward/BWBlock.java @@ -51,6 +51,7 @@ import nova.core.util.shape.Cuboid; import nova.core.world.World; import nova.core.wrapper.mc.forge.v1_11_2.util.WrapperEvent; +import nova.core.wrapper.mc.forge.v1_11_2.wrapper.VectorConverter; import nova.core.wrapper.mc.forge.v1_11_2.wrapper.block.world.WorldConverter; import nova.core.wrapper.mc.forge.v1_11_2.wrapper.cuboid.CuboidConverter; import nova.core.wrapper.mc.forge.v1_11_2.wrapper.data.DataConverter; @@ -124,7 +125,7 @@ public BWBlock(IBlockState blockState, World world, Vector3D pos) { true ); return aabbs.stream() - .map(aabb -> (Cuboid) Game.natives().toNova(aabb)) + .map(CuboidConverter.instance()::toNova) .map(cuboid -> cuboid.subtract(pos)) .collect(Collectors.toSet()); }).setSelectionBoxes(entity -> { @@ -205,7 +206,7 @@ public int meta() { } public BlockPos blockPos() { - return new BlockPos(x(), y(), z()); + return VectorConverter.instance().toNative(position()); } public IBlockAccess blockAccess() { diff --git a/minecraft/1.11.2/src/main/java/nova/core/wrapper/mc/forge/v1_11_2/wrapper/block/backward/BWBlockFactory.java b/minecraft/1.11.2/src/main/java/nova/core/wrapper/mc/forge/v1_11_2/wrapper/block/backward/BWBlockFactory.java index e247d5c1c..8e298b2e6 100644 --- a/minecraft/1.11.2/src/main/java/nova/core/wrapper/mc/forge/v1_11_2/wrapper/block/backward/BWBlockFactory.java +++ b/minecraft/1.11.2/src/main/java/nova/core/wrapper/mc/forge/v1_11_2/wrapper/block/backward/BWBlockFactory.java @@ -37,4 +37,14 @@ public BWBlockFactory(Block block) { public Block getBlock() { return block; } + + @Override + public String getLocalizedName() { + return getBlock().getLocalizedName(); + } + + @Override + public String getUnlocalizedName() { + return getBlock().getUnlocalizedName(); + } } diff --git a/minecraft/1.11.2/src/main/java/nova/core/wrapper/mc/forge/v1_11_2/wrapper/block/backward/BWBlockTransform.java b/minecraft/1.11.2/src/main/java/nova/core/wrapper/mc/forge/v1_11_2/wrapper/block/backward/BWBlockTransform.java index 5432d03b6..e988b474a 100644 --- a/minecraft/1.11.2/src/main/java/nova/core/wrapper/mc/forge/v1_11_2/wrapper/block/backward/BWBlockTransform.java +++ b/minecraft/1.11.2/src/main/java/nova/core/wrapper/mc/forge/v1_11_2/wrapper/block/backward/BWBlockTransform.java @@ -19,6 +19,7 @@ */ package nova.core.wrapper.mc.forge.v1_11_2.wrapper.block.backward; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; @@ -70,14 +71,20 @@ public void setWorld(World world) { net.minecraft.world.World oldWorld = Game.natives().toNative(this.world); net.minecraft.world.World newWorld = Game.natives().toNative(world); Optional tileEntity = Optional.ofNullable(oldWorld.getTileEntity(pos)); - newWorld.setBlockState(pos, block.blockState()); + Optional nbt = Optional.empty(); if (tileEntity.isPresent()) { - newWorld.setTileEntity(pos, tileEntity.get()); - tileEntity.get().setWorld(newWorld); - } else { - newWorld.setTileEntity(pos, null); + NBTTagCompound compound = new NBTTagCompound(); + tileEntity.get().writeToNBT(compound); + nbt = Optional.of(compound); } + newWorld.setBlockState(pos, block.blockState()); + oldWorld.removeTileEntity(pos); oldWorld.setBlockToAir(pos); + Optional newTileEntity = Optional.ofNullable(newWorld.getTileEntity(pos)); + if (newTileEntity.isPresent() && nbt.isPresent()) { + newTileEntity.get().readFromNBT(nbt.get()); + } + this.world = world; } @Override @@ -86,13 +93,22 @@ public void setPosition(Vector3D position) { BlockPos newPos = VectorConverter.instance().toNative(position); net.minecraft.world.World world = Game.natives().toNative(this.world); Optional tileEntity = Optional.ofNullable(blockAccess().getTileEntity(oldPos)); - world.setBlockState(newPos, block.blockState()); + Optional nbt = Optional.empty(); if (tileEntity.isPresent()) { - world.setTileEntity(newPos, tileEntity.get()); - tileEntity.get().setPos(newPos); - } else { - world.setTileEntity(newPos, null); + NBTTagCompound compound = new NBTTagCompound(); + tileEntity.get().writeToNBT(compound); + compound.setInteger("x", newPos.getX()); + compound.setInteger("y", newPos.getY()); + compound.setInteger("z", newPos.getZ()); + nbt = Optional.of(compound); } + world.setBlockState(newPos, block.blockState()); + world.removeTileEntity(oldPos); world.setBlockToAir(oldPos); + Optional newTileEntity = Optional.ofNullable(blockAccess().getTileEntity(newPos)); + if (newTileEntity.isPresent() && nbt.isPresent()) { + newTileEntity.get().readFromNBT(nbt.get()); + } + this.position = position; } } diff --git a/minecraft/1.11.2/src/main/java/nova/core/wrapper/mc/forge/v1_11_2/wrapper/block/forward/FWBlockTransform.java b/minecraft/1.11.2/src/main/java/nova/core/wrapper/mc/forge/v1_11_2/wrapper/block/forward/FWBlockTransform.java index 5393dd85c..d8fdf3eb1 100644 --- a/minecraft/1.11.2/src/main/java/nova/core/wrapper/mc/forge/v1_11_2/wrapper/block/forward/FWBlockTransform.java +++ b/minecraft/1.11.2/src/main/java/nova/core/wrapper/mc/forge/v1_11_2/wrapper/block/forward/FWBlockTransform.java @@ -20,15 +20,15 @@ package nova.core.wrapper.mc.forge.v1_11_2.wrapper.block.forward; -import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; import nova.core.block.Block; import nova.core.component.transform.BlockTransform; +import nova.core.retention.Data; +import nova.core.retention.Storable; import nova.core.world.World; import nova.core.wrapper.mc.forge.v1_11_2.wrapper.VectorConverter; import nova.core.wrapper.mc.forge.v1_11_2.wrapper.block.world.WorldConverter; -import nova.internal.core.Game; import org.apache.commons.math3.geometry.euclidean.threed.Vector3D; import java.util.Optional; @@ -38,9 +38,9 @@ */ public class FWBlockTransform extends BlockTransform { - public final Block block; - public final World world; - public final Vector3D position; + private Block block; + private World world; + private Vector3D position; public FWBlockTransform(Block block, World world, Vector3D position) { this.block = block; @@ -68,28 +68,39 @@ public IBlockAccess blockAccess() { @Override public void setWorld(World world) { - BlockPos pos = blockPos(); - Optional tileEntity = Optional.ofNullable(blockAccess().getTileEntity(pos)); world.setBlock(position, block.getFactory()); - tileEntity.ifPresent(te -> { - net.minecraft.world.World newWorld = Game.natives().toNative(world); - newWorld.setTileEntity(pos, te); - te.setWorld(newWorld); - }); + Optional data = Optional.empty(); + if (block instanceof Storable) { + data = Optional.of(new Data()); + ((Storable) block).save(data.get()); + } this.world.removeBlock(position); + Optional newBlock = world.getBlock(position); + if (newBlock.isPresent()) { + block = newBlock.get(); + if (newBlock.get() instanceof Storable && data.isPresent()) { + ((Storable) newBlock.get()).load(data.get()); + } + } + this.world = world; } @Override public void setPosition(Vector3D position) { - BlockPos oldPos = blockPos(); - BlockPos newPos = VectorConverter.instance().toNative(position); - Optional tileEntity = Optional.ofNullable(blockAccess().getTileEntity(oldPos)); world.setBlock(position, block.getFactory()); - tileEntity.ifPresent(te -> { - net.minecraft.world.World world = Game.natives().toNative(this.world); - world.setTileEntity(newPos, te); - te.setPos(newPos); - }); + Optional data = Optional.empty(); + if (block instanceof Storable) { + data = Optional.of(new Data()); + ((Storable) block).save(data.get()); + } world.removeBlock(this.position); + Optional newBlock = world.getBlock(position); + if (newBlock.isPresent()) { + block = newBlock.get(); + if (newBlock.get() instanceof Storable && data.isPresent()) { + ((Storable) newBlock.get()).load(data.get()); + } + } + this.position = position; } } diff --git a/minecraft/1.11.2/src/main/java/nova/core/wrapper/mc/forge/v1_11_2/wrapper/block/forward/FWTile.java b/minecraft/1.11.2/src/main/java/nova/core/wrapper/mc/forge/v1_11_2/wrapper/block/forward/FWTile.java index 6696c7e27..3fa5b4fb9 100644 --- a/minecraft/1.11.2/src/main/java/nova/core/wrapper/mc/forge/v1_11_2/wrapper/block/forward/FWTile.java +++ b/minecraft/1.11.2/src/main/java/nova/core/wrapper/mc/forge/v1_11_2/wrapper/block/forward/FWTile.java @@ -45,7 +45,6 @@ import java.io.IOException; import java.util.Optional; - import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -70,6 +69,9 @@ public Block getBlock() { } public void setBlock(Block block) { + if (block.components.has(TEBlockTransform.class)) + block.components.remove(TEBlockTransform.class); + block.components.getOrAdd(new TEBlockTransform(this)); this.block = block; } @@ -85,6 +87,8 @@ public SPacketUpdateTileEntity getUpdatePacket() { @Override public void validate() { super.validate(); + if (block.components.has(TEBlockTransform.class)) + block.components.remove(TEBlockTransform.class); block.components.getOrAdd(new TEBlockTransform(this)); if (cacheData != null && block instanceof Storable) { @@ -179,6 +183,7 @@ private FWPacketUpdateTileEntity(Packet packet, BlockPos blockPosIn, int meta } @Override + @SuppressWarnings("unchecked") public void processPacket(INetHandlerPlayClient handler) { super.processPacket(handler); try { diff --git a/minecraft/1.11.2/src/main/java/nova/core/wrapper/mc/forge/v1_11_2/wrapper/block/forward/FWTileLoader.java b/minecraft/1.11.2/src/main/java/nova/core/wrapper/mc/forge/v1_11_2/wrapper/block/forward/FWTileLoader.java index 0c1a0211c..f9470e90f 100644 --- a/minecraft/1.11.2/src/main/java/nova/core/wrapper/mc/forge/v1_11_2/wrapper/block/forward/FWTileLoader.java +++ b/minecraft/1.11.2/src/main/java/nova/core/wrapper/mc/forge/v1_11_2/wrapper/block/forward/FWTileLoader.java @@ -21,21 +21,14 @@ package nova.core.wrapper.mc.forge.v1_11_2.wrapper.block.forward; import net.minecraft.nbt.NBTTagCompound; -import net.minecraftforge.fluids.capability.CapabilityFluidHandler; import nova.core.block.Block; import nova.core.block.BlockFactory; import nova.core.component.Updater; -import nova.core.component.fluid.SidedTankProvider; -import nova.core.util.Direction; import nova.core.wrapper.mc.forge.v1_11_2.asm.lib.ComponentInjector; import nova.core.wrapper.mc.forge.v1_11_2.util.WrapperEvent; import nova.internal.core.Game; -import java.util.Arrays; -import java.util.HashSet; import java.util.Optional; -import java.util.Set; -import java.util.function.Predicate; /** * @author Vic Nightfall diff --git a/minecraft/1.11.2/src/main/java/nova/core/wrapper/mc/forge/v1_11_2/wrapper/block/forward/FWTileRenderer.java b/minecraft/1.11.2/src/main/java/nova/core/wrapper/mc/forge/v1_11_2/wrapper/block/forward/FWTileRenderer.java index 0d141fb28..3bf3b151f 100644 --- a/minecraft/1.11.2/src/main/java/nova/core/wrapper/mc/forge/v1_11_2/wrapper/block/forward/FWTileRenderer.java +++ b/minecraft/1.11.2/src/main/java/nova/core/wrapper/mc/forge/v1_11_2/wrapper/block/forward/FWTileRenderer.java @@ -24,7 +24,6 @@ import net.minecraft.client.renderer.texture.TextureMap; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; -import net.minecraft.tileentity.TileEntity; import nova.core.block.Block; import nova.core.component.renderer.DynamicRenderer; import nova.core.wrapper.mc.forge.v1_11_2.render.RenderUtility; diff --git a/minecraft/1.11.2/src/main/java/nova/core/wrapper/mc/forge/v1_11_2/wrapper/block/forward/TEBlockTransform.java b/minecraft/1.11.2/src/main/java/nova/core/wrapper/mc/forge/v1_11_2/wrapper/block/forward/TEBlockTransform.java index 923bd53aa..1c8852c1e 100644 --- a/minecraft/1.11.2/src/main/java/nova/core/wrapper/mc/forge/v1_11_2/wrapper/block/forward/TEBlockTransform.java +++ b/minecraft/1.11.2/src/main/java/nova/core/wrapper/mc/forge/v1_11_2/wrapper/block/forward/TEBlockTransform.java @@ -20,13 +20,16 @@ package nova.core.wrapper.mc.forge.v1_11_2.wrapper.block.forward; import net.minecraft.util.math.BlockPos; +import net.minecraft.world.IBlockAccess; +import nova.core.block.Block; import nova.core.component.transform.BlockTransform; import nova.core.world.World; import nova.core.wrapper.mc.forge.v1_11_2.wrapper.VectorConverter; import nova.core.wrapper.mc.forge.v1_11_2.wrapper.block.world.WorldConverter; -import nova.internal.core.Game; import org.apache.commons.math3.geometry.euclidean.threed.Vector3D; +import java.util.Objects; + /** * @author ExE Boss */ @@ -38,6 +41,10 @@ public TEBlockTransform(FWTile tileEntity) { this.tileEntity = tileEntity; } + public Block block() { + return tileEntity.block; + } + @Override public Vector3D position() { return VectorConverter.instance().toNova(tileEntity.getPos()); @@ -48,28 +55,25 @@ public World world() { return WorldConverter.instance().toNova(tileEntity.getWorld()); } - public net.minecraft.world.World mcWorld() { + public BlockPos blockPos() { + return tileEntity.getPos(); + } + + public IBlockAccess blockAccess() { return tileEntity.getWorld(); } @Override - public void setWorld(nova.core.world.World world) { - nova.core.world.World originalWorld = world(); - Vector3D originalPosition = position(); - world.setBlock(position(), tileEntity.block.getFactory()); - net.minecraft.world.World mcWorld = Game.natives().toNative(world); - mcWorld.setTileEntity(tileEntity.getPos(), tileEntity); - tileEntity.setWorld(mcWorld); - originalWorld.removeBlock(originalPosition); + public void setWorld(World world) { + world().setBlock(position(), tileEntity.block.getFactory()); + world().removeBlock(position()); + Objects.requireNonNull((FWTile) WorldConverter.instance().toNative(world).getTileEntity(blockPos())).setBlock(tileEntity.block); } @Override public void setPosition(Vector3D position) { - Vector3D originalPosition = position(); world().setBlock(position, tileEntity.block.getFactory()); - BlockPos newPos = VectorConverter.instance().toNative(position); - mcWorld().setTileEntity(newPos, tileEntity); - tileEntity.setPos(newPos); - world().removeBlock(originalPosition); + world().removeBlock(position()); + Objects.requireNonNull((FWTile) blockAccess().getTileEntity(VectorConverter.instance().toNative(position))).setBlock(tileEntity.block); } }