diff --git a/.gitignore b/.gitignore index 85a8428..d1ba226 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +/.idea/ /Pistronics-Repo/.gradle /Pistronics-Repo/.settings /Pistronics-Repo/.idea diff --git a/Pistronics-Repo/src/main/java/letiu/modbase/tiles/BaseTile.java b/Pistronics-Repo/src/main/java/letiu/modbase/tiles/BaseTile.java index 2198b47..e3b9ec8 100644 --- a/Pistronics-Repo/src/main/java/letiu/modbase/tiles/BaseTile.java +++ b/Pistronics-Repo/src/main/java/letiu/modbase/tiles/BaseTile.java @@ -9,54 +9,46 @@ import net.minecraft.network.play.server.S35PacketUpdateTileEntity; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; +import net.minecraft.world.World; public class BaseTile extends TileEntity { - public PTile data; - - @Override + public void updateEntity() { - data.update(); + this.data.update(); } - - @Override + public AxisAlignedBB getRenderBoundingBox() { - AxisAlignedBB box = data.getRenderBoundingBox(); - return box == null ? super.getRenderBoundingBox() : box; + AxisAlignedBB box = this.data.getRenderBoundingBox(); + return (box == null) ? super.getRenderBoundingBox() : box; } - - @Override + public Packet getDescriptionPacket() { super.getDescriptionPacket(); NBTTagCompound tag = NBTUtil.getNewCompound(); - this.writeToNBT(tag); - return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, tag); + writeToNBT(tag); + return (Packet)new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, tag); } - - @Override + public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) { readFromNBT(packet.func_148857_g()); } - - @Override + public void validate() { super.validate(); - data.postLoad(); + this.data.postLoad(); } - - @Override + public void writeToNBT(NBTTagCompound tagCompound) { super.writeToNBT(tagCompound); - tagCompound.setString("key", data.getKey()); - data.writeToNBT(tagCompound); + tagCompound.setString("key", this.data.getKey()); + this.data.writeToNBT(tagCompound); } - - @Override + public void readFromNBT(NBTTagCompound tagCompound) { super.readFromNBT(tagCompound); - data = TileData.getTile(tagCompound.getString("key")); - data.tileEntity = this; - data.readFromNBT(tagCompound); + this.data = TileData.getTile(tagCompound.getString("key")); + this.data.tileEntity = this; + this.data.readFromNBT(tagCompound); } - -} +} \ No newline at end of file diff --git a/Pistronics-Repo/src/main/java/letiu/modbase/util/ItemReference.java b/Pistronics-Repo/src/main/java/letiu/modbase/util/ItemReference.java index 708535d..c1a3e42 100644 --- a/Pistronics-Repo/src/main/java/letiu/modbase/util/ItemReference.java +++ b/Pistronics-Repo/src/main/java/letiu/modbase/util/ItemReference.java @@ -4,6 +4,7 @@ import letiu.pistronics.config.ConfigData; import letiu.pistronics.items.ItemSpade; import letiu.pistronics.util.BlockProxy; +import cpw.mods.fml.common.Loader; import net.minecraft.block.*; import net.minecraft.init.Blocks; import net.minecraft.init.Items; @@ -16,7 +17,10 @@ public class ItemReference { + public static boolean isTFCLoaded = Loader.isModLoaded("terrafirmacraftplus"); + public static final Item SLIME = Items.slime_ball; + public static final Block REDSTONE_TORCH = Blocks.redstone_torch; public static final Block REDSTONE_BLOCK = Blocks.redstone_block; @@ -41,10 +45,10 @@ public class ItemReference { public static final Item WHEAT_SEEDS = Items.wheat_seeds; public static final Item COMPARATOR = Items.comparator; public static final Item DIAMOND = Items.diamond; - - public static final Item BOW = Items.bow; - public static final Item ARROW = Items.arrow; - + + public static final Item BOW = TFCItems.bow; + public static final Item ARROW = TFCItems.arrow; + public static final Item ROTTEN_FLESH = Items.rotten_flesh; public static final Item POISONOUS_POTATO = Items.poisonous_potato; public static final Item SPIDER_EYE = Items.spider_eye; @@ -55,7 +59,7 @@ public class ItemReference { public static final Item MILK = Items.milk_bucket; public static final Item BOOK = Items.book; - + public static boolean isDye(ItemStack stack, int color) { if (stack == null) return false; switch (color) { @@ -86,11 +90,15 @@ public static int getStackDyeColor(ItemStack stack) { } return -1; } - + public static ItemStack getDye(int dmg) { - return new ItemStack(TFCItems.dye, 1, dmg); + if(isTFCLoaded) { + return new ItemStack(TFCItems.dye, 1, dmg); + } else { + return new ItemStack(Items.dye, 1, dmg); + } } - + public static boolean isHarvestTool(ItemStack stack) { if (stack == null) return false; Item item = stack.getItem(); diff --git a/Pistronics-Repo/src/main/java/letiu/modbase/util/NBTUtil.java b/Pistronics-Repo/src/main/java/letiu/modbase/util/NBTUtil.java index 8d62e05..50c963c 100644 --- a/Pistronics-Repo/src/main/java/letiu/modbase/util/NBTUtil.java +++ b/Pistronics-Repo/src/main/java/letiu/modbase/util/NBTUtil.java @@ -1,39 +1,37 @@ package letiu.modbase.util; import java.util.Set; - import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; public class NBTUtil { - public static final int TAG_COMPOUND_ID = NBTBase.NBTTypes.length - 2; - + public static NBTTagCompound getCompoundAt(NBTTagList list, int i) { return list.getCompoundTagAt(i); } - + public static NBTTagList getCompoundList(NBTTagCompound compound, String key) { return compound.getTagList(key, TAG_COMPOUND_ID); } - + public static boolean compare(NBTTagCompound nbt1, NBTTagCompound nbt2) { - - if (nbt1 == null && nbt2 == null) return true; - if (nbt1 == null && nbt2 != null) return false; - if (nbt1 != null && nbt2 == null) return false; - + if (nbt1 == null && nbt2 == null) + return true; + if (nbt1 == null && nbt2 != null) + return false; + if (nbt1 != null && nbt2 == null) + return false; Set keySet = nbt1.func_150296_c(); - for (Object obj : keySet) { - String key = (String) obj; - if (!nbt2.hasKey(key) || !(nbt1.getTag(key).equals(nbt2.getTag(key)))) return false; + String key = (String)obj; + if (!nbt2.hasKey(key) || !nbt1.getTag(key).equals(nbt2.getTag(key))) + return false; } - return true; } - + public static NBTTagCompound getNewCompound() { return new NBTTagCompound(); } diff --git a/Pistronics-Repo/src/main/java/letiu/pistronics/data/PTile.java b/Pistronics-Repo/src/main/java/letiu/pistronics/data/PTile.java index 76088f6..bfd8cbd 100644 --- a/Pistronics-Repo/src/main/java/letiu/pistronics/data/PTile.java +++ b/Pistronics-Repo/src/main/java/letiu/pistronics/data/PTile.java @@ -6,23 +6,22 @@ import net.minecraft.util.AxisAlignedBB; public abstract class PTile { - public BaseTile tileEntity; - + public abstract String getKey(); - - public void readFromNBT(NBTTagCompound tagCompound) {} - public void writeToNBT(NBTTagCompound tagCompound) {} + public void readFromNBT(NBTTagCompound tagCompound) {} + + public void writeToNBT(NBTTagCompound tagCompound) {} public void update() {} public void postLoad() {} - + public boolean hasInventory() { return false; } - + public NBTTagCompound getNBTForItem() { NBTTagCompound nbt = NBTUtil.getNewCompound(); writeToNBT(nbt); @@ -32,4 +31,4 @@ public NBTTagCompound getNBTForItem() { public AxisAlignedBB getRenderBoundingBox() { return null; } -} +} \ No newline at end of file diff --git a/Pistronics-Repo/src/main/java/letiu/pistronics/piston/ControllerData.java b/Pistronics-Repo/src/main/java/letiu/pistronics/piston/ControllerData.java new file mode 100644 index 0000000..695a4a8 --- /dev/null +++ b/Pistronics-Repo/src/main/java/letiu/pistronics/piston/ControllerData.java @@ -0,0 +1,14 @@ +package letiu.pistronics.piston; + +public class ControllerData { + public SystemController controller; + + public float lastValue; + + public String key; + + public void updateController() { + if (this.controller != null) + this.controller.update(this); + } +} \ No newline at end of file diff --git a/Pistronics-Repo/src/main/java/letiu/pistronics/piston/ControllerRegistry.java b/Pistronics-Repo/src/main/java/letiu/pistronics/piston/ControllerRegistry.java new file mode 100644 index 0000000..d7ab5e5 --- /dev/null +++ b/Pistronics-Repo/src/main/java/letiu/pistronics/piston/ControllerRegistry.java @@ -0,0 +1,43 @@ +package letiu.pistronics.piston; + +import java.util.HashMap; +import letiu.pistronics.util.BlockProxy; +import letiu.pistronics.util.Vector3; + +public class ControllerRegistry { + private static HashMap mapClient = new HashMap(); + + private static HashMap mapServer = new HashMap(); + + public static void register(SystemController ctr, BlockProxy root) { + HashMap map = (root.getWorld()).isRemote ? mapClient : mapServer; + Vector3 coords = root.getCoords(); + String key = coords.x + "x" + coords.y + "x" + coords.y; + for (; map.get(key) != null; key = key + "I"); + map.put(key, ctr); + ctr.setKey(key); + } + + public static void remove(String key) { + mapClient.remove(key); + mapServer.remove(key); + } + + public static SystemController find(String key) { + SystemController controller = mapServer.get(key); + if (controller == null) + controller = mapClient.get(key); + return controller; + } + + public static SystemController create(String key, MoveData moveData, boolean isRemote) { + HashMap map = isRemote ? mapClient : mapServer; + SystemController ctr = map.get(key); + if (ctr == null) { + ctr = new SystemController(moveData); + map.put(key, ctr); + ctr.setKey(key); + } + return ctr; + } +} \ No newline at end of file diff --git a/Pistronics-Repo/src/main/java/letiu/pistronics/piston/MoveData.java b/Pistronics-Repo/src/main/java/letiu/pistronics/piston/MoveData.java new file mode 100644 index 0000000..d669634 --- /dev/null +++ b/Pistronics-Repo/src/main/java/letiu/pistronics/piston/MoveData.java @@ -0,0 +1,95 @@ +package letiu.pistronics.piston; + +import letiu.pistronics.util.Vector3; +import letiu.pistronics.util.VectorUtil; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagCompound; + +public class MoveData { + public int rotateDir; + + public int moveDir; + + public float angle; + + public float progress; + + public float rotateSpeed; + + public float moveSpeed; + + public Vector3 rotatePoint; + + public MoveData(int moveDir, float moveSpeed) { + this.rotateDir = -1; + this.moveDir = -1; + this.moveDir = moveDir; + this.moveSpeed = moveSpeed; + } + + public MoveData(int rotateDir, float rotateSpeed, Vector3 rotatePoint) { + this.rotateDir = -1; + this.moveDir = -1; + this.rotateDir = rotateDir; + this.rotateSpeed = rotateSpeed; + this.rotatePoint = rotatePoint; + } + + public MoveData(NBTTagCompound nbt) { + this.rotateDir = -1; + this.moveDir = -1; + readFromNBT(nbt); + } + + public MoveData() { + this.rotateDir = -1; + this.moveDir = -1; + } + + public void update() { + if (!isDone()) + if (isRotating()) { + this.angle += this.rotateSpeed; + } else if (isMoving()) { + this.progress += this.moveSpeed; + } + } + + public boolean isDone() { + return (this.angle >= 90.0F || this.progress >= 1.0F); + } + + public boolean isMoving() { + return (this.moveDir != -1 && this.moveSpeed != 0.0F); + } + + public boolean isRotating() { + return (this.rotateDir != -1 && this.rotateSpeed != 0.0F); + } + + public float getValue() { + return isMoving() ? this.progress : this.angle; + } + + public void writeToNBT(NBTTagCompound nbt) { + nbt.setInteger("rotateDir", this.rotateDir); + nbt.setInteger("moveDir", this.moveDir); + nbt.setFloat("angle", this.angle); + nbt.setFloat("progress", this.progress); + nbt.setFloat("rotateSpeed", this.rotateSpeed); + nbt.setFloat("moveSpeed", this.moveSpeed); + if (this.rotatePoint != null) + nbt.setTag("rotatePoint", (NBTBase)VectorUtil.writeToNBT(this.rotatePoint)); + } + + public void readFromNBT(NBTTagCompound nbt) { + this.rotateDir = nbt.getInteger("rotateDir"); + this.moveDir = nbt.getInteger("moveDir"); + this.angle = nbt.getFloat("angle"); + this.rotateSpeed = nbt.getFloat("rotateSpeed"); + this.moveSpeed = nbt.getFloat("moveSpeed"); + this.progress = nbt.getFloat("progress"); + if (nbt.hasKey("rotatePoint")) + this.rotatePoint = VectorUtil.readFromNBT(nbt.getCompoundTag("rotatePoint")); + } +} \ No newline at end of file diff --git a/Pistronics-Repo/src/main/java/letiu/pistronics/piston/SystemController.java b/Pistronics-Repo/src/main/java/letiu/pistronics/piston/SystemController.java index 3100257..c413e31 100644 --- a/Pistronics-Repo/src/main/java/letiu/pistronics/piston/SystemController.java +++ b/Pistronics-Repo/src/main/java/letiu/pistronics/piston/SystemController.java @@ -1,29 +1,35 @@ package letiu.pistronics.piston; public class SystemController { + private MoveData moveData; - public SystemController() { - + private String key; + + public SystemController(MoveData moveData) { + this.moveData = moveData; + } + + public boolean update(ControllerData data) { + boolean result = false; + if (data.lastValue == this.moveData.getValue()) { + this.moveData.update(); + result = true; + } + data.lastValue = this.moveData.getValue(); + if (this.moveData.isDone()) + ControllerRegistry.remove(this.key); + return result; + } + + public void setKey(String key) { + this.key = key; + } + + public String getKey() { + return this.key; } - -// private ArrayList movers; -// -// public SystemController() { -// movers = new ArrayList(); -// } -// -// public void addMover(IMover mover) { -// movers.add(mover); -// } -// -// public void updateAll(float progress) { -// -// System.out.println("updating " + movers.size() + " Blocks."); -// -// for (IMover mover : movers) { -// mover.setProgress(progress); -// } -// } - + public MoveData getMoveData() { + return this.moveData; + } } diff --git a/Pistronics-Repo/src/main/java/letiu/pistronics/tiles/TileMotion.java b/Pistronics-Repo/src/main/java/letiu/pistronics/tiles/TileMotion.java index a363d53..aeb7d83 100644 --- a/Pistronics-Repo/src/main/java/letiu/pistronics/tiles/TileMotion.java +++ b/Pistronics-Repo/src/main/java/letiu/pistronics/tiles/TileMotion.java @@ -2,428 +2,397 @@ import java.util.Iterator; import java.util.List; - import letiu.modbase.util.BlockItemUtil; import letiu.modbase.util.NBTUtil; import letiu.modbase.util.WorldUtil; -import letiu.pistronics.blocks.BMotionblock; -import letiu.pistronics.blocks.BPartblock; import letiu.pistronics.data.PBlock; import letiu.pistronics.data.PTile; -import letiu.pistronics.data.TileData; +import letiu.pistronics.piston.ControllerData; +import letiu.pistronics.piston.ControllerRegistry; import letiu.pistronics.piston.ISpecialRotator; +import letiu.pistronics.piston.MoveData; +import letiu.pistronics.piston.SystemController; import letiu.pistronics.render.PRenderManager; import letiu.pistronics.render.PTileRenderer; +import letiu.pistronics.util.BlockProxy; import letiu.pistronics.util.RotateUtil; import letiu.pistronics.util.Vector3; -import letiu.pistronics.util.VectorUtil; import net.minecraft.entity.Entity; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.Facing; +import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; -import org.lwjgl.Sys; public class TileMotion extends TileElementHolder implements ISpecialRenderTile, IMover { - private int rotateDir = -1, moveDir = -1; - private float angle, progress; - private float rotateSpeed, moveSpeed; - - private Vector3 rotatePoint; - - public boolean remoteControl = true; - - public TileMotion() { - rotatePoint = new Vector3(0, 0, 0); -// data = new TempData(); -// data.p = 0.5F; -// System.out.println("TileMotion.TileMotion()"); - } - - @Override + public ControllerData ctrData = new ControllerData(); + + private NBTTagCompound tempNBTCompound = null; + public void update() { -// super.update(); // TODOe - - //if (!remoteControl) { -// System.out.println("TileMotion: local progress"); - if (rotateDir != -1 && rotateSpeed != 0) { - angle += rotateSpeed; - if (angle >= 90) { - loadBlock(); - postRotate(); - } - } - if (moveDir != -1 && moveSpeed != 0) { - progress += moveSpeed; - - pushEntities(); - - if (progress >= 1F) { - pushEntitiesFinal(); - loadBlock(); - postMove(); - //ktryToMoveOn(); - } + if (this.ctrData.controller == null) + this.ctrData.controller = new SystemController(new MoveData()); + + this.ctrData.updateController(); + MoveData moveData = this.ctrData.controller.getMoveData(); + + if (moveData.isMoving()) + pushEntities(); + + if (moveData.isDone()) + if (moveData.isMoving()) { + pushEntitiesFinal(); + loadBlock(); + postMove(); + } else if (moveData.isRotating()) { + loadBlock(); + postRotate(); } - //} -// System.out.println(data.p); -// if (progress2 >= 1) loadBlock(); - - - //this.remoteControl = false; } @Override - public void setProgress(float progress) { -// System.out.println("TileMotion.setProgress() " + tileEntity.getWorldObj().isRemote + " " + progress + " " + tileEntity.xCoord + "/" + tileEntity.yCoord + "/" + tileEntity.zCoord); -// this.progress2 = progress; -// this.remoteControl = true; -// this.data.p = progress2; - //System.out.println(tileEntity.getWorldObj().isRemote + " Setting progress to: " + progress); - } - + public void setProgress(float progress) {} + public AxisAlignedBB getBoxForPush(float pushSpace) { - - World world = tileEntity.getWorldObj(); - int x = tileEntity.xCoord; - int y = tileEntity.yCoord; - int z = tileEntity.zCoord; - - // get Box from Element // AxisAlignedBB box; - if (this.getPElement() instanceof BPartblock) { - box = AxisAlignedBB.getBoundingBox(x, y, z, x + 1, y + 1, z + 1); - } - else { - box = BlockItemUtil.getBoundingBox(world, x, y, z, element); - if (box == null) { - box = AxisAlignedBB.getBoundingBox(x, y, z, x + 1, y + 1, z + 1); - } + MoveData moveData = this.ctrData.controller.getMoveData(); + World world = this.tileEntity.getWorldObj(); + int x = this.tileEntity.xCoord; + int y = this.tileEntity.yCoord; + int z = this.tileEntity.zCoord; + if (getPElement() instanceof letiu.pistronics.blocks.BPartblock) { + box = AxisAlignedBB.getBoundingBox(x, y, z, (x + 1), (y + 1), (z + 1)); + } else { + box = BlockItemUtil.getBoundingBox(world, x, y, z, this.element); + if (box == null) + box = AxisAlignedBB.getBoundingBox(x, y, z, (x + 1), (y + 1), (z + 1)); } - - // expand Box // - switch (moveDir) { - case 0: box.maxY = y + 1; break; - case 1: box.minY = y; break; - case 2: box.maxZ = z + 1; break; - case 3: box.minZ = z; break; - case 4: box.maxX = x + 1; break; - case 5: box.minX = x; break; + switch (moveData.moveDir) { + case 0: + box.maxY = (y + 1); + break; + case 1: + box.minY = y; + break; + case 2: + box.maxZ = (z + 1); + break; + case 3: + box.minZ = z; + break; + case 4: + box.maxX = (x + 1); + break; + case 5: + box.minX = x; + break; } - - // offset depending on progress // - float antiProgress = 1F - (progress + pushSpace); - - return box.getOffsetBoundingBox((double)(antiProgress * (float)Facing.offsetsXForSide[moveDir]), (double)(antiProgress * (float)Facing.offsetsYForSide[moveDir]), (double)(antiProgress * (float)Facing.offsetsZForSide[moveDir])); + float antiProgress = 1.0F - moveData.progress + pushSpace; + return box.getOffsetBoundingBox((antiProgress * Facing.offsetsXForSide[moveData.moveDir]), (antiProgress * Facing.offsetsYForSide[moveData.moveDir]), (antiProgress * Facing.offsetsZForSide[moveData.moveDir])); } - - private void pushEntities() { - - World world = tileEntity.getWorldObj(); - int x = tileEntity.xCoord; - int y = tileEntity.yCoord; - int z = tileEntity.zCoord; - - float moveAmt = 1F * moveSpeed; - - - PBlock block = WorldUtil.getPBlock(world, x + Facing.offsetsXForSide[moveDir], y + Facing.offsetsYForSide[moveDir], z + Facing.offsetsZForSide[moveDir]); - - /** push Entities out of the Block */ - if (block != null && block instanceof BMotionblock) { - - List list = tileEntity.getWorldObj().getEntitiesWithinAABBExcludingEntity((Entity) null, AxisAlignedBB.getBoundingBox(x, y, z, x + 1, y + 1, z + 1)); - Iterator itr = list.iterator(); - - while (itr.hasNext()) { - - Entity entity = (Entity) itr.next(); - - double vX = 0.1D * (entity.posX - (x + 0.5D)); - double vY = 0.1D * (entity.posY - (y + 0.5D)); - double vZ = 0.1D * (entity.posZ - (z + 0.5D)); - - entity.motionX = vX; - entity.motionY = vY; - entity.motionZ = vZ; + + private void pushEntities() { + MoveData moveData = this.ctrData.controller.getMoveData(); + World world = this.tileEntity.getWorldObj(); + int x = this.tileEntity.xCoord; + int y = this.tileEntity.yCoord; + int z = this.tileEntity.zCoord; + float moveAmt = 1.0F * moveData.moveSpeed; + PBlock block = WorldUtil.getPBlock((IBlockAccess)world, x + Facing.offsetsXForSide[moveData.moveDir], y + Facing.offsetsYForSide[moveData.moveDir], z + Facing.offsetsZForSide[moveData.moveDir]); + if (block != null && block instanceof letiu.pistronics.blocks.BMotionblock) { + List list = this.tileEntity.getWorldObj().getEntitiesWithinAABBExcludingEntity((Entity)null, AxisAlignedBB.getBoundingBox(x, y, z, (x + 1), (y + 1), (z + 1))); + Iterator itr = list.iterator(); + while (itr.hasNext()) { + Entity entity = itr.next(); + double vX = 0.1D * (entity.posX - x + 0.5D); + double vY = 0.1D * (entity.posY - y + 0.5D); + double vZ = 0.1D * (entity.posZ - z + 0.5D); + entity.motionX = vX; + entity.motionY = vY; + entity.motionZ = vZ; + } + } else { + List list = this.tileEntity.getWorldObj().getEntitiesWithinAABBExcludingEntity((Entity)null, getBoxForPush(0.25F)); + Iterator itr = list.iterator(); + while (itr.hasNext()) { + Entity entity = itr.next(); + entity.moveEntity((moveAmt * Facing.offsetsXForSide[moveData.moveDir]), (moveAmt * Facing.offsetsYForSide[moveData.moveDir]), (moveAmt * Facing.offsetsZForSide[moveData.moveDir])); + switch (moveData.moveDir) { + case 0: + if (entity.motionY > 0.0D) + entity.motionY = 0.0D; + case 1: + if (entity.motionY < 0.0D) + entity.motionY = 0.0D; + case 2: + if (entity.motionZ > 0.0D) + entity.motionZ = 0.0D; + case 3: + if (entity.motionZ < 0.0D) + entity.motionZ = 0.0D; + case 4: + if (entity.motionX > 0.0D) + entity.motionX = 0.0D; + case 5: + if (entity.motionX < 0.0D) + entity.motionX = 0.0D; + } + } } } - /** push Entities in moveDir */ - else { - - List list = tileEntity.getWorldObj().getEntitiesWithinAABBExcludingEntity((Entity) null, getBoxForPush(0.25F)); - Iterator itr = list.iterator(); - + + private void pushEntitiesFinal() { + MoveData moveData = this.ctrData.controller.getMoveData(); + List list = this.tileEntity.getWorldObj().getEntitiesWithinAABBExcludingEntity((Entity)null, getBoxForPush(0.0F)); + Iterator itr = list.iterator(); while (itr.hasNext()) { - - Entity entity = (Entity) itr.next(); - entity.moveEntity((double)(moveAmt * (float)Facing.offsetsXForSide[moveDir]), (double)(moveAmt * (float)Facing.offsetsYForSide[moveDir]), (double)(moveAmt * (float)Facing.offsetsZForSide[moveDir])); - - // stop velocity against moveDir (e.g. gravity) // - switch(moveDir) { - case 0: if (entity.motionY > 0) entity.motionY = 0; break; - case 1: if (entity.motionY < 0) entity.motionY = 0; break; - case 2: if (entity.motionZ > 0) entity.motionZ = 0; break; - case 3: if (entity.motionZ < 0) entity.motionZ = 0; break; - case 4: if (entity.motionX > 0) entity.motionX = 0; break; - case 5: if (entity.motionX < 0) entity.motionX = 0; break; + Entity entity = itr.next(); + switch (moveData.moveDir) { + case 1: + entity.posY = Math.ceil(entity.posY); + entity.motionY = 0.25D; + case 2: + entity.motionZ = -0.25D; + case 3: + entity.motionZ = 0.25D; + case 4: + entity.motionX = -0.25D; + case 5: + entity.motionX = 0.25D; } } } - } - - private void pushEntitiesFinal() { - - List list = tileEntity.getWorldObj().getEntitiesWithinAABBExcludingEntity((Entity) null, getBoxForPush(0F)); - - Iterator itr = list.iterator(); - - while (itr.hasNext()) { - - Entity entity = (Entity) itr.next(); - - // Ensures no entities are left in the bounding box at the end // - switch(moveDir) { - //case 0: entity.posY = entity.posY - 1.0D; break; - case 1: entity.posY = Math.ceil(entity.posY); - entity.motionY = 0.25D; break; - case 2: entity.motionZ = -0.25D; break; - case 3: entity.motionZ = 0.25D; break; - case 4: entity.motionX = -0.25D; break; - case 5: entity.motionX = 0.25D; break; + + public boolean tryToMoveOn() { + MoveData moveData = this.ctrData.controller.getMoveData(); + int x = this.tileEntity.xCoord + Facing.offsetsXForSide[moveData.moveDir]; + int y = this.tileEntity.yCoord + Facing.offsetsYForSide[moveData.moveDir]; + int z = this.tileEntity.zCoord + Facing.offsetsZForSide[moveData.moveDir]; + PTile tile = WorldUtil.getPTile((IBlockAccess)this.tileEntity.getWorldObj(), x, y, z); + if (tile != null && tile instanceof TileMotion) { + moveData.progress = 0.0F; + NBTTagCompound nbt = new NBTTagCompound(); + writeToNBT(nbt); + tile.readFromNBT(nbt); + moveData.moveDir = -1; + this.element = null; + return true; } + return false; } - } - - public boolean tryToMoveOn() { - - int x = tileEntity.xCoord + Facing.offsetsXForSide[moveDir]; - int y = tileEntity.yCoord + Facing.offsetsYForSide[moveDir]; - int z = tileEntity.zCoord + Facing.offsetsZForSide[moveDir]; - - PTile tile = WorldUtil.getPTile(tileEntity.getWorldObj(), x, y, z); - - if (tile != null && tile instanceof TileMotion) { - this.progress = 0F; - NBTTagCompound nbt = new NBTTagCompound(); - this.writeToNBT(nbt); - tile.readFromNBT(nbt); - this.moveDir = -1; - this.element = null; - return true; + + public String getKey() { + return "tlMotion"; } - - return false; - } - - @Override - public String getKey() { - return TileData.key_motion; - } - @Override - public PTileRenderer getRenderer() { - return PRenderManager.motionRenderer; - } - - public int getRotateDir() { - return rotateDir; - } - - public int getMoveDir() { - return moveDir; - } - - public float getAngle() { - return angle; - } - - public float getProgress() { - return progress; - } - - public float getAngleForRender(float ticktime) { - if (ticktime > 1F) ticktime = 1F; - - return ((float) angle) + rotateSpeed * ticktime - 90F; - } - - public float getProgressForRender(float ticktime) { - if (ticktime > 1F) ticktime = 1F; - //return progress; - return ((float) progress) + moveSpeed * ticktime; - } + public PTileRenderer getRenderer() { + return PRenderManager.motionRenderer; + } - public float getRotateSpeed() { - return rotateSpeed; - } - - public float getMoveSpeed() { - return moveSpeed; - } - - public Vector3 getRotatePoint() { - return rotatePoint; - } - - public boolean isRotating() { - return rotateDir != -1 && rotateSpeed != 0F; - } - - public boolean isMoving() { - return moveDir != -1 && moveSpeed != 0F; - } - - public boolean isInMotion() { - return isMoving() || isRotating(); - } - - public void rotate(int rotateDir, float speed) { - this.rotateDir = rotateDir; - this.rotateSpeed = speed; - this.rotatePoint = new Vector3(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord); - } - - public void rotate(int rotateDir, float speed, Vector3 rotatePoint) { - this.rotateDir = rotateDir; - this.rotateSpeed = speed; - this.rotatePoint = rotatePoint; - } - - public void move(int moveDir, float speed) { - this.moveDir = moveDir; - this.moveSpeed = speed; - } - - public void loadBlock() { - - int x = tileEntity.xCoord, y = tileEntity.yCoord, z = tileEntity.zCoord; - World world = tileEntity.getWorldObj(); - - if (element != null) { - -// if (!world.isRemote && ItemReference.isFallingBlock(element)) { -// world.isRemote = true; -// WorldUtil.setBlock(world, x, y, z, element, elementMeta, 4); -// world.isRemote = false; -// } -// else { - WorldUtil.setBlock(world, x, y, z, element, elementMeta, 5); -// } - - if (elementTile != null) { - - - TileEntity tile = WorldUtil.getTileEntity(world, x, y, z); - -// elementTile.setWorldObj(world); -// elementTile.xCoord = x; -// elementTile.yCoord = y; -// elementTile.zCoord = z; -// - NBTTagCompound nbt = NBTUtil.getNewCompound(); - elementTile.writeToNBT(nbt); -// -// TileEntity.createAndLoadEntity(nbt); - - // TODO: FMP crash here! (no tile? �O�) - if (tile == null) { - elementTile.setWorldObj(world); - elementTile.xCoord = x; - elementTile.yCoord = y; - elementTile.zCoord = z; - WorldUtil.setTileEntity(world, x, y, z, elementTile); - WorldUtil.setBlock(world, x, y, z, element, elementMeta, 5); + public int getRotateDir() { + MoveData moveData = this.ctrData.controller.getMoveData(); + return moveData.rotateDir; + } + + public int getMoveDir() { + MoveData moveData = this.ctrData.controller.getMoveData(); + return moveData.moveDir; + } + + public float getAngle() { + MoveData moveData = this.ctrData.controller.getMoveData(); + return moveData.angle; + } + + public float getProgress() { + MoveData moveData = this.ctrData.controller.getMoveData(); + return moveData.progress; + } + + public float getAngleForRender(float ticktime) { + MoveData moveData = this.ctrData.controller.getMoveData(); + if (ticktime > 1.0F) + ticktime = 1.0F; + return moveData.angle + moveData.rotateSpeed * ticktime - 90.0F; + } + + public float getProgressForRender(float ticktime) { + MoveData moveData = this.ctrData.controller.getMoveData(); + if (ticktime > 1.0F) + ticktime = 1.0F; + return moveData.progress + moveData.moveSpeed * ticktime; + } + + public float getRotateSpeed() { + MoveData moveData = this.ctrData.controller.getMoveData(); + return moveData.rotateSpeed; + } + + public float getMoveSpeed() { + MoveData moveData = this.ctrData.controller.getMoveData(); + return moveData.moveSpeed; + } + + public Vector3 getRotatePoint() { + MoveData moveData = this.ctrData.controller.getMoveData(); + return moveData.rotatePoint; + } + + public boolean isRotating() { + MoveData moveData = this.ctrData.controller.getMoveData(); + return (moveData.rotateDir != -1 && moveData.rotateSpeed != 0.0F); + } + + public boolean isMoving() { + MoveData moveData = this.ctrData.controller.getMoveData(); + return (moveData.moveDir != -1 && moveData.moveSpeed != 0.0F); + } + + public boolean isInMotion() { + return (isMoving() || isRotating()); + } + + public void rotate(int rotateDir, float speed) { + rotate(rotateDir, speed, new Vector3(this.tileEntity.xCoord, this.tileEntity.yCoord, this.tileEntity.zCoord)); + } + + public void rotate(int rotateDir, float speed, Vector3 rotatePoint) { + if (this.ctrData.controller == null) { + MoveData moveData = new MoveData(rotateDir, speed, rotatePoint); + if (this.ctrData.key != null && !this.ctrData.key.equals("default")) { + this.ctrData.controller = ControllerRegistry.create(this.ctrData.key, moveData, (this.tileEntity.getWorldObj()).isRemote); + this.ctrData.key = this.ctrData.controller.getKey(); + } else { + SystemController ctr = new SystemController(moveData); + ControllerRegistry.register(ctr, new BlockProxy((TileEntity)this.tileEntity)); + this.ctrData.controller = ctr; + this.ctrData.key = ctr.getKey(); + } + } + } + + public void move(int moveDir, float speed) { + if (this.ctrData.controller == null) { + MoveData moveData = new MoveData(moveDir, speed); + if (this.ctrData.key != null && !this.ctrData.key.equals("default")) { + this.ctrData.controller = ControllerRegistry.create(this.ctrData.key, moveData, (this.tileEntity.getWorldObj()).isRemote); + this.ctrData.key = this.ctrData.controller.getKey(); + } else { + SystemController ctr = new SystemController(moveData); + ControllerRegistry.register(ctr, new BlockProxy((TileEntity)this.tileEntity)); + this.ctrData.controller = ctr; + this.ctrData.key = ctr.getKey(); } - - tile = WorldUtil.getTileEntity(world, x, y, z); - - if (tile != null) { - tile.readFromNBT(nbt); - tile.setWorldObj(world); - tile.xCoord = x; - tile.yCoord = y; - tile.zCoord = z; + } + } + + public void loadBlock() { + int x = this.tileEntity.xCoord, y = this.tileEntity.yCoord, z = this.tileEntity.zCoord; + World world = this.tileEntity.getWorldObj(); + if (this.element != null) { + WorldUtil.setBlock(world, x, y, z, this.element, this.elementMeta, 5); + if (this.elementTile != null) { + TileEntity tile = WorldUtil.getTileEntity((IBlockAccess)world, x, y, z); + NBTTagCompound nbt = NBTUtil.getNewCompound(); + this.elementTile.writeToNBT(nbt); + if (tile == null) { + this.elementTile.setWorldObj(world); + this.elementTile.xCoord = x; + this.elementTile.yCoord = y; + this.elementTile.zCoord = z; + WorldUtil.setTileEntity(world, x, y, z, this.elementTile); + WorldUtil.setBlock(world, x, y, z, this.element, this.elementMeta, 5); + } + tile = WorldUtil.getTileEntity((IBlockAccess)world, x, y, z); + if (tile != null) { + tile.readFromNBT(nbt); + tile.setWorldObj(world); + tile.xCoord = x; + tile.yCoord = y; + tile.zCoord = z; + } } + } else { + WorldUtil.setBlockToAir(world, x, y, z); } + WorldUtil.updateBlock(world, x, y, z); } - else { - WorldUtil.setBlockToAir(world, x, y, z); + + private void postRotate() { + MoveData moveData = this.ctrData.controller.getMoveData(); + int x = this.tileEntity.xCoord, y = this.tileEntity.yCoord, z = this.tileEntity.zCoord; + World world = this.tileEntity.getWorldObj(); + PBlock block = WorldUtil.getPBlock((IBlockAccess)world, x, y, z); + if (block instanceof ISpecialRotator) { + ((ISpecialRotator)block).postRotate(world, x, y, z, moveData.rotateDir, moveData.rotateSpeed, moveData.rotatePoint); + } else { + RotateUtil.rotateVanillaBlocks(world, x, y, z, this.elementMeta, moveData.rotateDir); + } } - - WorldUtil.updateBlock(world, x, y, z); - } - - private void postRotate() { - int x = tileEntity.xCoord, y = tileEntity.yCoord, z = tileEntity.zCoord; - World world = tileEntity.getWorldObj(); - - PBlock block = WorldUtil.getPBlock(world, x, y, z); - if (block instanceof ISpecialRotator) { - ((ISpecialRotator) block).postRotate(world, x, y, z, rotateDir, rotateSpeed, rotatePoint); + + private void postMove() { + WorldUtil.setBlockMeta(this.tileEntity.getWorldObj(), this.tileEntity.xCoord, this.tileEntity.yCoord, this.tileEntity.zCoord, this.elementMeta, 3); } - else { - RotateUtil.rotateVanillaBlocks(world, x, y, z, elementMeta, rotateDir); - } - } - private void postMove() { - WorldUtil.setBlockMeta(tileEntity.getWorldObj(), tileEntity.xCoord, - tileEntity.yCoord, tileEntity.zCoord, elementMeta, 3); - } - - @Override - public float getOffsetX(float ticktime) { - if (!isMoving()) return 0F; - return (float) Facing.offsetsXForSide[moveDir ^ 1] * (1 - getProgressForRender(ticktime)); - } + public float getOffsetX(float ticktime) { + MoveData moveData = this.ctrData.controller.getMoveData(); + if (!isMoving()) + return 0.0F; + return Facing.offsetsXForSide[moveData.moveDir ^ 0x1] * (1.0F - getProgressForRender(ticktime)); + } - @Override - public float getOffsetY(float ticktime) { - if (!isMoving()) return 0F; - return (float) Facing.offsetsYForSide[moveDir ^ 1] * (1 - getProgressForRender(ticktime)); - } + public float getOffsetY(float ticktime) { + MoveData moveData = this.ctrData.controller.getMoveData(); + if (!isMoving()) + return 0.0F; + return Facing.offsetsYForSide[moveData.moveDir ^ 0x1] * (1.0F - getProgressForRender(ticktime)); + } - @Override - public float getOffsetZ(float ticktime) { - if (!isMoving()) return 0F; - return (float) Facing.offsetsZForSide[moveDir ^ 1] * (1 - getProgressForRender(ticktime)); - } - - @Override - public void writeToNBT(NBTTagCompound tagCompound) { - super.writeToNBT(tagCompound); - - tagCompound.setInteger("rotateDir", rotateDir); - tagCompound.setInteger("moveDir", moveDir); - tagCompound.setFloat("angle", angle); - tagCompound.setFloat("progress", progress); - tagCompound.setFloat("rotateSpeed", rotateSpeed); - tagCompound.setFloat("moveSpeed", moveSpeed); - tagCompound.setBoolean("remote", remoteControl); - - tagCompound.setTag("rotatePoint", VectorUtil.writeToNBT(rotatePoint)); - } - - @Override - public void readFromNBT(NBTTagCompound tagCompound) { - super.readFromNBT(tagCompound); - - this.rotateDir = tagCompound.getInteger("rotateDir"); - this.moveDir = tagCompound.getInteger("moveDir"); - this.angle = tagCompound.getFloat("angle"); - this.rotateSpeed = tagCompound.getFloat("rotateSpeed"); - this.moveSpeed = tagCompound.getFloat("moveSpeed"); - this.remoteControl = tagCompound.getBoolean("remote"); - - this.rotatePoint = VectorUtil.readFromNBT(tagCompound.getCompoundTag("rotatePoint")); - - if (!isInMotion()) { - this.progress = tagCompound.getFloat("progress"); + public float getOffsetZ(float ticktime) { + MoveData moveData = this.ctrData.controller.getMoveData(); + if (!isMoving()) + return 0.0F; + return Facing.offsetsZForSide[moveData.moveDir ^ 0x1] * (1.0F - getProgressForRender(ticktime)); + } + + public void writeToNBT(NBTTagCompound tagCompound) { + super.writeToNBT(tagCompound); + if (this.ctrData.key == null && this.ctrData.controller != null) + this.ctrData.key = this.ctrData.controller.getKey(); + if (this.ctrData.key == null) + this.ctrData.key = "default"; + tagCompound.setString("ctrKey", this.ctrData.key); + if (this.ctrData.controller != null) { + MoveData moveData = this.ctrData.controller.getMoveData(); + moveData.writeToNBT(tagCompound); + } + } + + public void readFromNBT(NBTTagCompound tagCompound) { + super.readFromNBT(tagCompound); + this.ctrData.key = tagCompound.getString("ctrKey"); + if (this.ctrData.controller == null && !this.ctrData.key.equals("default")) { + MoveData moveData = new MoveData(tagCompound); + if (this.tileEntity != null && this.tileEntity.getWorldObj() != null) { + boolean isRemote = (this.tileEntity.getWorldObj()).isRemote; + this.ctrData.controller = ControllerRegistry.create(this.ctrData.key, moveData, isRemote); + } + } + this.tempNBTCompound = tagCompound; + } + + public void postLoad() { + super.postLoad(); + if (this.ctrData.controller == null && this.tempNBTCompound != null) { + MoveData moveData = new MoveData(this.tempNBTCompound); + if (this.tileEntity != null && this.tileEntity.getWorldObj() != null) { + boolean isRemote = (this.tileEntity.getWorldObj()).isRemote; + this.ctrData.controller = ControllerRegistry.create(this.ctrData.key, moveData, isRemote); + } + } } } -} diff --git a/Pistronics2-1.7.10-0.6.4-java/letiu/modbase/util/ItemReference.java b/Pistronics2-1.7.10-0.6.4-java/letiu/modbase/util/ItemReference.java index 708535d..c1a3e42 100644 --- a/Pistronics2-1.7.10-0.6.4-java/letiu/modbase/util/ItemReference.java +++ b/Pistronics2-1.7.10-0.6.4-java/letiu/modbase/util/ItemReference.java @@ -4,6 +4,7 @@ import letiu.pistronics.config.ConfigData; import letiu.pistronics.items.ItemSpade; import letiu.pistronics.util.BlockProxy; +import cpw.mods.fml.common.Loader; import net.minecraft.block.*; import net.minecraft.init.Blocks; import net.minecraft.init.Items; @@ -16,7 +17,10 @@ public class ItemReference { + public static boolean isTFCLoaded = Loader.isModLoaded("terrafirmacraftplus"); + public static final Item SLIME = Items.slime_ball; + public static final Block REDSTONE_TORCH = Blocks.redstone_torch; public static final Block REDSTONE_BLOCK = Blocks.redstone_block; @@ -41,10 +45,10 @@ public class ItemReference { public static final Item WHEAT_SEEDS = Items.wheat_seeds; public static final Item COMPARATOR = Items.comparator; public static final Item DIAMOND = Items.diamond; - - public static final Item BOW = Items.bow; - public static final Item ARROW = Items.arrow; - + + public static final Item BOW = TFCItems.bow; + public static final Item ARROW = TFCItems.arrow; + public static final Item ROTTEN_FLESH = Items.rotten_flesh; public static final Item POISONOUS_POTATO = Items.poisonous_potato; public static final Item SPIDER_EYE = Items.spider_eye; @@ -55,7 +59,7 @@ public class ItemReference { public static final Item MILK = Items.milk_bucket; public static final Item BOOK = Items.book; - + public static boolean isDye(ItemStack stack, int color) { if (stack == null) return false; switch (color) { @@ -86,11 +90,15 @@ public static int getStackDyeColor(ItemStack stack) { } return -1; } - + public static ItemStack getDye(int dmg) { - return new ItemStack(TFCItems.dye, 1, dmg); + if(isTFCLoaded) { + return new ItemStack(TFCItems.dye, 1, dmg); + } else { + return new ItemStack(Items.dye, 1, dmg); + } } - + public static boolean isHarvestTool(ItemStack stack) { if (stack == null) return false; Item item = stack.getItem(); diff --git a/Pistronics2-1.7.10-0.6.4-java/letiu/pistronics/recipes/PShapelessRecipe.java b/Pistronics2-1.7.10-0.6.4-java/letiu/pistronics/recipes/PShapelessRecipe.java index 82c4667..7e26448 100644 --- a/Pistronics2-1.7.10-0.6.4-java/letiu/pistronics/recipes/PShapelessRecipe.java +++ b/Pistronics2-1.7.10-0.6.4-java/letiu/pistronics/recipes/PShapelessRecipe.java @@ -63,6 +63,7 @@ public boolean matches(InventoryCrafting inv) { for (int k = 0; k < ingredients.size(); k++) { if (!foundIngredients[k] && CompareUtil.compare(ingredients.get(k), inv.getStackInSlot(i))) { foundIngredients[k] = foundMatch = true; + break; } } if (!foundMatch && (inv.getStackInSlot(i) != null)) return false; diff --git a/Pistronics2-1.7.10-0.6.4-java/letiu/pistronics/tiles/TileMotion.java b/Pistronics2-1.7.10-0.6.4-java/letiu/pistronics/tiles/TileMotion.java new file mode 100644 index 0000000..aeb7d83 --- /dev/null +++ b/Pistronics2-1.7.10-0.6.4-java/letiu/pistronics/tiles/TileMotion.java @@ -0,0 +1,398 @@ +package letiu.pistronics.tiles; + +import java.util.Iterator; +import java.util.List; +import letiu.modbase.util.BlockItemUtil; +import letiu.modbase.util.NBTUtil; +import letiu.modbase.util.WorldUtil; +import letiu.pistronics.data.PBlock; +import letiu.pistronics.data.PTile; +import letiu.pistronics.piston.ControllerData; +import letiu.pistronics.piston.ControllerRegistry; +import letiu.pistronics.piston.ISpecialRotator; +import letiu.pistronics.piston.MoveData; +import letiu.pistronics.piston.SystemController; +import letiu.pistronics.render.PRenderManager; +import letiu.pistronics.render.PTileRenderer; +import letiu.pistronics.util.BlockProxy; +import letiu.pistronics.util.RotateUtil; +import letiu.pistronics.util.Vector3; +import net.minecraft.entity.Entity; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.Facing; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; + +public class TileMotion extends TileElementHolder implements ISpecialRenderTile, IMover { + + public ControllerData ctrData = new ControllerData(); + + private NBTTagCompound tempNBTCompound = null; + + public void update() { + if (this.ctrData.controller == null) + this.ctrData.controller = new SystemController(new MoveData()); + + this.ctrData.updateController(); + MoveData moveData = this.ctrData.controller.getMoveData(); + + if (moveData.isMoving()) + pushEntities(); + + if (moveData.isDone()) + if (moveData.isMoving()) { + pushEntitiesFinal(); + loadBlock(); + postMove(); + } else if (moveData.isRotating()) { + loadBlock(); + postRotate(); + } + } + + @Override + public void setProgress(float progress) {} + + public AxisAlignedBB getBoxForPush(float pushSpace) { + AxisAlignedBB box; + MoveData moveData = this.ctrData.controller.getMoveData(); + World world = this.tileEntity.getWorldObj(); + int x = this.tileEntity.xCoord; + int y = this.tileEntity.yCoord; + int z = this.tileEntity.zCoord; + if (getPElement() instanceof letiu.pistronics.blocks.BPartblock) { + box = AxisAlignedBB.getBoundingBox(x, y, z, (x + 1), (y + 1), (z + 1)); + } else { + box = BlockItemUtil.getBoundingBox(world, x, y, z, this.element); + if (box == null) + box = AxisAlignedBB.getBoundingBox(x, y, z, (x + 1), (y + 1), (z + 1)); + } + switch (moveData.moveDir) { + case 0: + box.maxY = (y + 1); + break; + case 1: + box.minY = y; + break; + case 2: + box.maxZ = (z + 1); + break; + case 3: + box.minZ = z; + break; + case 4: + box.maxX = (x + 1); + break; + case 5: + box.minX = x; + break; + } + float antiProgress = 1.0F - moveData.progress + pushSpace; + return box.getOffsetBoundingBox((antiProgress * Facing.offsetsXForSide[moveData.moveDir]), (antiProgress * Facing.offsetsYForSide[moveData.moveDir]), (antiProgress * Facing.offsetsZForSide[moveData.moveDir])); + } + + private void pushEntities() { + MoveData moveData = this.ctrData.controller.getMoveData(); + World world = this.tileEntity.getWorldObj(); + int x = this.tileEntity.xCoord; + int y = this.tileEntity.yCoord; + int z = this.tileEntity.zCoord; + float moveAmt = 1.0F * moveData.moveSpeed; + PBlock block = WorldUtil.getPBlock((IBlockAccess)world, x + Facing.offsetsXForSide[moveData.moveDir], y + Facing.offsetsYForSide[moveData.moveDir], z + Facing.offsetsZForSide[moveData.moveDir]); + if (block != null && block instanceof letiu.pistronics.blocks.BMotionblock) { + List list = this.tileEntity.getWorldObj().getEntitiesWithinAABBExcludingEntity((Entity)null, AxisAlignedBB.getBoundingBox(x, y, z, (x + 1), (y + 1), (z + 1))); + Iterator itr = list.iterator(); + while (itr.hasNext()) { + Entity entity = itr.next(); + double vX = 0.1D * (entity.posX - x + 0.5D); + double vY = 0.1D * (entity.posY - y + 0.5D); + double vZ = 0.1D * (entity.posZ - z + 0.5D); + entity.motionX = vX; + entity.motionY = vY; + entity.motionZ = vZ; + } + } else { + List list = this.tileEntity.getWorldObj().getEntitiesWithinAABBExcludingEntity((Entity)null, getBoxForPush(0.25F)); + Iterator itr = list.iterator(); + while (itr.hasNext()) { + Entity entity = itr.next(); + entity.moveEntity((moveAmt * Facing.offsetsXForSide[moveData.moveDir]), (moveAmt * Facing.offsetsYForSide[moveData.moveDir]), (moveAmt * Facing.offsetsZForSide[moveData.moveDir])); + switch (moveData.moveDir) { + case 0: + if (entity.motionY > 0.0D) + entity.motionY = 0.0D; + case 1: + if (entity.motionY < 0.0D) + entity.motionY = 0.0D; + case 2: + if (entity.motionZ > 0.0D) + entity.motionZ = 0.0D; + case 3: + if (entity.motionZ < 0.0D) + entity.motionZ = 0.0D; + case 4: + if (entity.motionX > 0.0D) + entity.motionX = 0.0D; + case 5: + if (entity.motionX < 0.0D) + entity.motionX = 0.0D; + } + } + } + } + + private void pushEntitiesFinal() { + MoveData moveData = this.ctrData.controller.getMoveData(); + List list = this.tileEntity.getWorldObj().getEntitiesWithinAABBExcludingEntity((Entity)null, getBoxForPush(0.0F)); + Iterator itr = list.iterator(); + while (itr.hasNext()) { + Entity entity = itr.next(); + switch (moveData.moveDir) { + case 1: + entity.posY = Math.ceil(entity.posY); + entity.motionY = 0.25D; + case 2: + entity.motionZ = -0.25D; + case 3: + entity.motionZ = 0.25D; + case 4: + entity.motionX = -0.25D; + case 5: + entity.motionX = 0.25D; + } + } + } + + public boolean tryToMoveOn() { + MoveData moveData = this.ctrData.controller.getMoveData(); + int x = this.tileEntity.xCoord + Facing.offsetsXForSide[moveData.moveDir]; + int y = this.tileEntity.yCoord + Facing.offsetsYForSide[moveData.moveDir]; + int z = this.tileEntity.zCoord + Facing.offsetsZForSide[moveData.moveDir]; + PTile tile = WorldUtil.getPTile((IBlockAccess)this.tileEntity.getWorldObj(), x, y, z); + if (tile != null && tile instanceof TileMotion) { + moveData.progress = 0.0F; + NBTTagCompound nbt = new NBTTagCompound(); + writeToNBT(nbt); + tile.readFromNBT(nbt); + moveData.moveDir = -1; + this.element = null; + return true; + } + return false; + } + + public String getKey() { + return "tlMotion"; + } + + public PTileRenderer getRenderer() { + return PRenderManager.motionRenderer; + } + + public int getRotateDir() { + MoveData moveData = this.ctrData.controller.getMoveData(); + return moveData.rotateDir; + } + + public int getMoveDir() { + MoveData moveData = this.ctrData.controller.getMoveData(); + return moveData.moveDir; + } + + public float getAngle() { + MoveData moveData = this.ctrData.controller.getMoveData(); + return moveData.angle; + } + + public float getProgress() { + MoveData moveData = this.ctrData.controller.getMoveData(); + return moveData.progress; + } + + public float getAngleForRender(float ticktime) { + MoveData moveData = this.ctrData.controller.getMoveData(); + if (ticktime > 1.0F) + ticktime = 1.0F; + return moveData.angle + moveData.rotateSpeed * ticktime - 90.0F; + } + + public float getProgressForRender(float ticktime) { + MoveData moveData = this.ctrData.controller.getMoveData(); + if (ticktime > 1.0F) + ticktime = 1.0F; + return moveData.progress + moveData.moveSpeed * ticktime; + } + + public float getRotateSpeed() { + MoveData moveData = this.ctrData.controller.getMoveData(); + return moveData.rotateSpeed; + } + + public float getMoveSpeed() { + MoveData moveData = this.ctrData.controller.getMoveData(); + return moveData.moveSpeed; + } + + public Vector3 getRotatePoint() { + MoveData moveData = this.ctrData.controller.getMoveData(); + return moveData.rotatePoint; + } + + public boolean isRotating() { + MoveData moveData = this.ctrData.controller.getMoveData(); + return (moveData.rotateDir != -1 && moveData.rotateSpeed != 0.0F); + } + + public boolean isMoving() { + MoveData moveData = this.ctrData.controller.getMoveData(); + return (moveData.moveDir != -1 && moveData.moveSpeed != 0.0F); + } + + public boolean isInMotion() { + return (isMoving() || isRotating()); + } + + public void rotate(int rotateDir, float speed) { + rotate(rotateDir, speed, new Vector3(this.tileEntity.xCoord, this.tileEntity.yCoord, this.tileEntity.zCoord)); + } + + public void rotate(int rotateDir, float speed, Vector3 rotatePoint) { + if (this.ctrData.controller == null) { + MoveData moveData = new MoveData(rotateDir, speed, rotatePoint); + if (this.ctrData.key != null && !this.ctrData.key.equals("default")) { + this.ctrData.controller = ControllerRegistry.create(this.ctrData.key, moveData, (this.tileEntity.getWorldObj()).isRemote); + this.ctrData.key = this.ctrData.controller.getKey(); + } else { + SystemController ctr = new SystemController(moveData); + ControllerRegistry.register(ctr, new BlockProxy((TileEntity)this.tileEntity)); + this.ctrData.controller = ctr; + this.ctrData.key = ctr.getKey(); + } + } + } + + public void move(int moveDir, float speed) { + if (this.ctrData.controller == null) { + MoveData moveData = new MoveData(moveDir, speed); + if (this.ctrData.key != null && !this.ctrData.key.equals("default")) { + this.ctrData.controller = ControllerRegistry.create(this.ctrData.key, moveData, (this.tileEntity.getWorldObj()).isRemote); + this.ctrData.key = this.ctrData.controller.getKey(); + } else { + SystemController ctr = new SystemController(moveData); + ControllerRegistry.register(ctr, new BlockProxy((TileEntity)this.tileEntity)); + this.ctrData.controller = ctr; + this.ctrData.key = ctr.getKey(); + } + } + } + + public void loadBlock() { + int x = this.tileEntity.xCoord, y = this.tileEntity.yCoord, z = this.tileEntity.zCoord; + World world = this.tileEntity.getWorldObj(); + if (this.element != null) { + WorldUtil.setBlock(world, x, y, z, this.element, this.elementMeta, 5); + if (this.elementTile != null) { + TileEntity tile = WorldUtil.getTileEntity((IBlockAccess)world, x, y, z); + NBTTagCompound nbt = NBTUtil.getNewCompound(); + this.elementTile.writeToNBT(nbt); + if (tile == null) { + this.elementTile.setWorldObj(world); + this.elementTile.xCoord = x; + this.elementTile.yCoord = y; + this.elementTile.zCoord = z; + WorldUtil.setTileEntity(world, x, y, z, this.elementTile); + WorldUtil.setBlock(world, x, y, z, this.element, this.elementMeta, 5); + } + tile = WorldUtil.getTileEntity((IBlockAccess)world, x, y, z); + if (tile != null) { + tile.readFromNBT(nbt); + tile.setWorldObj(world); + tile.xCoord = x; + tile.yCoord = y; + tile.zCoord = z; + } + } + } else { + WorldUtil.setBlockToAir(world, x, y, z); + } + WorldUtil.updateBlock(world, x, y, z); + } + + private void postRotate() { + MoveData moveData = this.ctrData.controller.getMoveData(); + int x = this.tileEntity.xCoord, y = this.tileEntity.yCoord, z = this.tileEntity.zCoord; + World world = this.tileEntity.getWorldObj(); + PBlock block = WorldUtil.getPBlock((IBlockAccess)world, x, y, z); + if (block instanceof ISpecialRotator) { + ((ISpecialRotator)block).postRotate(world, x, y, z, moveData.rotateDir, moveData.rotateSpeed, moveData.rotatePoint); + } else { + RotateUtil.rotateVanillaBlocks(world, x, y, z, this.elementMeta, moveData.rotateDir); + } + } + + private void postMove() { + WorldUtil.setBlockMeta(this.tileEntity.getWorldObj(), this.tileEntity.xCoord, this.tileEntity.yCoord, this.tileEntity.zCoord, this.elementMeta, 3); + } + + public float getOffsetX(float ticktime) { + MoveData moveData = this.ctrData.controller.getMoveData(); + if (!isMoving()) + return 0.0F; + return Facing.offsetsXForSide[moveData.moveDir ^ 0x1] * (1.0F - getProgressForRender(ticktime)); + } + + public float getOffsetY(float ticktime) { + MoveData moveData = this.ctrData.controller.getMoveData(); + if (!isMoving()) + return 0.0F; + return Facing.offsetsYForSide[moveData.moveDir ^ 0x1] * (1.0F - getProgressForRender(ticktime)); + } + + public float getOffsetZ(float ticktime) { + MoveData moveData = this.ctrData.controller.getMoveData(); + if (!isMoving()) + return 0.0F; + return Facing.offsetsZForSide[moveData.moveDir ^ 0x1] * (1.0F - getProgressForRender(ticktime)); + } + + public void writeToNBT(NBTTagCompound tagCompound) { + super.writeToNBT(tagCompound); + if (this.ctrData.key == null && this.ctrData.controller != null) + this.ctrData.key = this.ctrData.controller.getKey(); + if (this.ctrData.key == null) + this.ctrData.key = "default"; + tagCompound.setString("ctrKey", this.ctrData.key); + if (this.ctrData.controller != null) { + MoveData moveData = this.ctrData.controller.getMoveData(); + moveData.writeToNBT(tagCompound); + } + } + + public void readFromNBT(NBTTagCompound tagCompound) { + super.readFromNBT(tagCompound); + this.ctrData.key = tagCompound.getString("ctrKey"); + if (this.ctrData.controller == null && !this.ctrData.key.equals("default")) { + MoveData moveData = new MoveData(tagCompound); + if (this.tileEntity != null && this.tileEntity.getWorldObj() != null) { + boolean isRemote = (this.tileEntity.getWorldObj()).isRemote; + this.ctrData.controller = ControllerRegistry.create(this.ctrData.key, moveData, isRemote); + } + } + this.tempNBTCompound = tagCompound; + } + + public void postLoad() { + super.postLoad(); + if (this.ctrData.controller == null && this.tempNBTCompound != null) { + MoveData moveData = new MoveData(this.tempNBTCompound); + if (this.tileEntity != null && this.tileEntity.getWorldObj() != null) { + boolean isRemote = (this.tileEntity.getWorldObj()).isRemote; + this.ctrData.controller = ControllerRegistry.create(this.ctrData.key, moveData, isRemote); + } + } + } + } + + diff --git a/Pistronics2-1.7.10-0.6.4/letiu/modbase/util/ItemReference.class b/Pistronics2-1.7.10-0.6.4/letiu/modbase/util/ItemReference.class index ea85def..c368998 100644 Binary files a/Pistronics2-1.7.10-0.6.4/letiu/modbase/util/ItemReference.class and b/Pistronics2-1.7.10-0.6.4/letiu/modbase/util/ItemReference.class differ diff --git a/Pistronics2-1.7.10-0.6.4/letiu/pistronics/recipes/PShapelessRecipe.class b/Pistronics2-1.7.10-0.6.4/letiu/pistronics/recipes/PShapelessRecipe.class index 8745e0e..1d107d2 100644 Binary files a/Pistronics2-1.7.10-0.6.4/letiu/pistronics/recipes/PShapelessRecipe.class and b/Pistronics2-1.7.10-0.6.4/letiu/pistronics/recipes/PShapelessRecipe.class differ diff --git a/Pistronics2-1.7.10-0.6.4/letiu/pistronics/tiles/TileMotion.class b/Pistronics2-1.7.10-0.6.4/letiu/pistronics/tiles/TileMotion.class new file mode 100644 index 0000000..1ec3ee9 Binary files /dev/null and b/Pistronics2-1.7.10-0.6.4/letiu/pistronics/tiles/TileMotion.class differ