From 3fe4e3bfed69231d28bea98bbb7191a687ccc60e Mon Sep 17 00:00:00 2001 From: dmillerw Date: Sat, 12 Apr 2014 18:31:37 -0700 Subject: [PATCH] Addition of creative engine --- .../assets/buildcraft/lang/en_US.lang | 1 + common/buildcraft/energy/BlockEngine.java | 89 +++++++------- common/buildcraft/energy/EnergyProxy.java | 1 + .../buildcraft/energy/EnergyProxyClient.java | 1 + common/buildcraft/energy/ItemEngine.java | 23 ++-- common/buildcraft/energy/TileEngine.java | 17 +-- .../buildcraft/energy/TileEngineCreative.java | 109 ++++++++++++++++++ 7 files changed, 183 insertions(+), 58 deletions(-) create mode 100644 common/buildcraft/energy/TileEngineCreative.java diff --git a/buildcraft_resources/assets/buildcraft/lang/en_US.lang b/buildcraft_resources/assets/buildcraft/lang/en_US.lang index 0501f224..a509c7dc 100755 --- a/buildcraft_resources/assets/buildcraft/lang/en_US.lang +++ b/buildcraft_resources/assets/buildcraft/lang/en_US.lang @@ -180,6 +180,7 @@ tile.blockFuel.name=Fuel tile.blockHopper.name=Chute tile.blockOil.name=Oil tile.builderBlock.name=Builder +tile.engineCreative.name=Creative Engine tile.engineIron.name=Combustion Engine tile.engineStone.name=Stirling Engine tile.engineWood.name=Redstone Engine diff --git a/common/buildcraft/energy/BlockEngine.java b/common/buildcraft/energy/BlockEngine.java index f64a9c94..652dd7bb 100644 --- a/common/buildcraft/energy/BlockEngine.java +++ b/common/buildcraft/energy/BlockEngine.java @@ -8,44 +8,44 @@ */ package buildcraft.energy; -import java.util.List; -import java.util.Random; - +import buildcraft.BuildCraftCore; +import buildcraft.core.BlockBuildCraft; +import buildcraft.core.CreativeTabBuildCraft; +import buildcraft.core.ICustomHighlight; +import buildcraft.core.IItemPipe; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.IIcon; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.util.Vec3; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; -import buildcraft.BuildCraftCore; -import buildcraft.core.BlockBuildCraft; -import buildcraft.core.CreativeTabBuildCraft; -import buildcraft.core.IItemPipe; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import net.minecraft.util.MovingObjectPosition; -import buildcraft.core.ICustomHighlight; -import net.minecraft.util.AxisAlignedBB; -import net.minecraft.entity.Entity; -import net.minecraft.util.Vec3; + +import java.util.List; +import java.util.Random; import static net.minecraft.util.AxisAlignedBB.getBoundingBox; public class BlockEngine extends BlockBuildCraft implements ICustomHighlight { private static final AxisAlignedBB[][] boxes = { - {getBoundingBox(0.0, 0.5, 0.0, 1.0, 1.0, 1.0), getBoundingBox(0.25, 0.0, 0.25, 0.75, 0.5, 0.75)},// -Y - {getBoundingBox(0.0, 0.0, 0.0, 1.0, 0.5, 1.0), getBoundingBox(0.25, 0.5, 0.25, 0.75, 1.0, 0.75)},// +Y - {getBoundingBox(0.0, 0.0, 0.5, 1.0, 1.0, 1.0), getBoundingBox(0.25, 0.25, 0.0, 0.75, 0.75, 0.5)},// -Z - {getBoundingBox(0.0, 0.0, 0.0, 1.0, 1.0, 0.5), getBoundingBox(0.25, 0.25, 0.5, 0.75, 0.75, 1.0)},// +Z - {getBoundingBox(0.5, 0.0, 0.0, 1.0, 1.0, 1.0), getBoundingBox(0.0, 0.25, 0.25, 0.5, 0.75, 0.75)},// -X - {getBoundingBox(0.0, 0.0, 0.0, 0.5, 1.0, 1.0), getBoundingBox(0.5, 0.25, 0.25, 1.0, 0.75, 0.75)} // +X + {getBoundingBox(0.0, 0.5, 0.0, 1.0, 1.0, 1.0), getBoundingBox(0.25, 0.0, 0.25, 0.75, 0.5, 0.75)},// -Y + {getBoundingBox(0.0, 0.0, 0.0, 1.0, 0.5, 1.0), getBoundingBox(0.25, 0.5, 0.25, 0.75, 1.0, 0.75)},// +Y + {getBoundingBox(0.0, 0.0, 0.5, 1.0, 1.0, 1.0), getBoundingBox(0.25, 0.25, 0.0, 0.75, 0.75, 0.5)},// -Z + {getBoundingBox(0.0, 0.0, 0.0, 1.0, 1.0, 0.5), getBoundingBox(0.25, 0.25, 0.5, 0.75, 0.75, 1.0)},// +Z + {getBoundingBox(0.5, 0.0, 0.0, 1.0, 1.0, 1.0), getBoundingBox(0.0, 0.25, 0.25, 0.5, 0.75, 0.75)},// -X + {getBoundingBox(0.0, 0.0, 0.0, 0.5, 1.0, 1.0), getBoundingBox(0.5, 0.25, 0.25, 1.0, 0.75, 0.75)} // +X }; private static IIcon woodTexture; @@ -82,12 +82,17 @@ public class BlockEngine extends BlockBuildCraft implements ICustomHighlight { @Override public TileEntity createTileEntity(World world, int metadata) { - if (metadata == 1) { - return new TileEngineStone(); - } else if (metadata == 2) { - return new TileEngineIron(); - } else { - return new TileEngineWood(); + switch (metadata) { + case 0: + return new TileEngineWood(); + case 1: + return new TileEngineStone(); + case 2: + return new TileEngineIron(); + case 3: + return new TileEngineCreative(); + default: + return new TileEngineWood(); } } @@ -118,10 +123,11 @@ public class BlockEngine extends BlockBuildCraft implements ICustomHighlight { TileEngine tile = (TileEngine) world.getTileEntity(i, j, k); + // REMOVED DUE TO CREATIVE ENGINE REQUIREMENTS - dmillerw // Drop through if the player is sneaking - if (player.isSneaking()) { - return false; - } +// if (player.isSneaking()) { +// return false; +// } // Do not open guis when having a pipe in hand if (player.getCurrentEquippedItem() != null) { @@ -141,11 +147,11 @@ public class BlockEngine extends BlockBuildCraft implements ICustomHighlight { @SuppressWarnings("unchecked") public void addCollisionBoxesToList(World wrd, int x, int y, int z, AxisAlignedBB mask, List list, Entity ent) { TileEntity tile = wrd.getTileEntity(x, y, z); - if (tile instanceof TileEngine){ - AxisAlignedBB[] aabbs = boxes[((TileEngine)tile).orientation.ordinal()]; + if (tile instanceof TileEngine) { + AxisAlignedBB[] aabbs = boxes[((TileEngine) tile).orientation.ordinal()]; for (AxisAlignedBB aabb : aabbs) { aabb = aabb.getOffsetBoundingBox(x, y, z); - if (mask.intersectsWith(aabb)){ + if (mask.intersectsWith(aabb)) { list.add(aabb); } } @@ -158,7 +164,7 @@ public class BlockEngine extends BlockBuildCraft implements ICustomHighlight { public AxisAlignedBB[] getBoxes(World wrd, int x, int y, int z, EntityPlayer player) { TileEntity tile = wrd.getTileEntity(x, y, z); if (tile instanceof TileEngine) { - return boxes[((TileEngine)tile).orientation.ordinal()]; + return boxes[((TileEngine) tile).orientation.ordinal()]; } else { return new AxisAlignedBB[]{AxisAlignedBB.getAABBPool().getAABB(0.0, 0.0, 0.0, 1.0, 1.0, 1.0)}; } @@ -172,12 +178,12 @@ public class BlockEngine extends BlockBuildCraft implements ICustomHighlight { @Override public MovingObjectPosition collisionRayTrace(World wrd, int x, int y, int z, Vec3 origin, Vec3 direction) { TileEntity tile = wrd.getTileEntity(x, y, z); - if (tile instanceof TileEngine){ - AxisAlignedBB[] aabbs = boxes[((TileEngine)tile).orientation.ordinal()]; + if (tile instanceof TileEngine) { + AxisAlignedBB[] aabbs = boxes[((TileEngine) tile).orientation.ordinal()]; MovingObjectPosition closest = null; - for(AxisAlignedBB aabb : aabbs){ + for (AxisAlignedBB aabb : aabbs) { MovingObjectPosition mop = aabb.getOffsetBoundingBox(x, y, z).calculateIntercept(origin, direction); - if(mop != null){ + if (mop != null) { if (closest != null && mop.hitVec.distanceTo(origin) < closest.hitVec.distanceTo(origin)) { closest = mop; } else { @@ -185,7 +191,7 @@ public class BlockEngine extends BlockBuildCraft implements ICustomHighlight { } } } - if (closest != null){ + if (closest != null) { closest.blockX = x; closest.blockY = y; closest.blockZ = z; @@ -236,10 +242,11 @@ public class BlockEngine extends BlockBuildCraft implements ICustomHighlight { @Override public void getSubBlocks(Item item, CreativeTabs par2CreativeTabs, List itemList) { if (par2CreativeTabs == CreativeTabBuildCraft.TIER_1.get()) { - itemList.add(new ItemStack(this, 1, 0)); - itemList.add(new ItemStack(this, 1, 1)); + itemList.add(new ItemStack(this, 1, 0)); // WOOD + itemList.add(new ItemStack(this, 1, 1)); // STONE } else { - itemList.add(new ItemStack(this, 1, 2)); + itemList.add(new ItemStack(this, 1, 2)); // IRON + itemList.add(new ItemStack(this, 1, 3)); // CREATIVE } } diff --git a/common/buildcraft/energy/EnergyProxy.java b/common/buildcraft/energy/EnergyProxy.java index 12ecaa94..916b4663 100644 --- a/common/buildcraft/energy/EnergyProxy.java +++ b/common/buildcraft/energy/EnergyProxy.java @@ -20,6 +20,7 @@ public class EnergyProxy { GameRegistry.registerTileEntity(TileEngineWood.class, "net.minecraft.src.buildcraft.energy.TileEngineWood"); GameRegistry.registerTileEntity(TileEngineStone.class, "net.minecraft.src.buildcraft.energy.TileEngineStone"); GameRegistry.registerTileEntity(TileEngineIron.class, "net.minecraft.src.buildcraft.energy.TileEngineIron"); + GameRegistry.registerTileEntity(TileEngineCreative.class, "net.minecraft.src.buildcraft.energy.TileEngineCreative"); } public void registerBlockRenderers() { diff --git a/common/buildcraft/energy/EnergyProxyClient.java b/common/buildcraft/energy/EnergyProxyClient.java index eaac7b17..3b52dcc6 100644 --- a/common/buildcraft/energy/EnergyProxyClient.java +++ b/common/buildcraft/energy/EnergyProxyClient.java @@ -34,5 +34,6 @@ public class EnergyProxyClient extends EnergyProxy { RenderingEntityBlocks.blockByEntityRenders.put(new EntityRenderIndex(BuildCraftEnergy.engineBlock, 0), new RenderEngine(TileEngine.WOOD_TEXTURE)); RenderingEntityBlocks.blockByEntityRenders.put(new EntityRenderIndex(BuildCraftEnergy.engineBlock, 1), new RenderEngine(TileEngine.STONE_TEXTURE)); RenderingEntityBlocks.blockByEntityRenders.put(new EntityRenderIndex(BuildCraftEnergy.engineBlock, 2), new RenderEngine(TileEngine.IRON_TEXTURE)); + RenderingEntityBlocks.blockByEntityRenders.put(new EntityRenderIndex(BuildCraftEnergy.engineBlock, 3), new RenderEngine(TileEngine.CREATIVE_TEXTURE)); } } diff --git a/common/buildcraft/energy/ItemEngine.java b/common/buildcraft/energy/ItemEngine.java index 9c081ffa..577a77df 100644 --- a/common/buildcraft/energy/ItemEngine.java +++ b/common/buildcraft/energy/ItemEngine.java @@ -8,11 +8,11 @@ */ package buildcraft.energy; +import buildcraft.core.CreativeTabBuildCraft; +import buildcraft.core.ItemBlockBuildCraft; import net.minecraft.block.Block; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.ItemStack; -import buildcraft.core.CreativeTabBuildCraft; -import buildcraft.core.ItemBlockBuildCraft; public class ItemEngine extends ItemBlockBuildCraft { @@ -29,17 +29,22 @@ public class ItemEngine extends ItemBlockBuildCraft { @Override public String getUnlocalizedName(ItemStack itemstack) { - if (itemstack.getItemDamage() == 0) { - return "tile.engineWood"; - } else if (itemstack.getItemDamage() == 1) { - return "tile.engineStone"; - } else { - return "tile.engineIron"; + switch (itemstack.getItemDamage()) { + case 0: + return "tile.engineWood"; + case 1: + return "tile.engineStone"; + case 2: + return "tile.engineIron"; + case 3: + return "tile.engineCreative"; + default: + return "tile.engineWood"; } } @Override public CreativeTabs[] getCreativeTabs() { - return new CreativeTabs[] { CreativeTabBuildCraft.TIER_1.get(), CreativeTabBuildCraft.TIER_2.get() }; + return new CreativeTabs[]{CreativeTabBuildCraft.TIER_1.get(), CreativeTabBuildCraft.TIER_2.get()}; } } diff --git a/common/buildcraft/energy/TileEngine.java b/common/buildcraft/energy/TileEngine.java index f7feb20c..242bbba1 100644 --- a/common/buildcraft/energy/TileEngine.java +++ b/common/buildcraft/energy/TileEngine.java @@ -8,14 +8,6 @@ */ package buildcraft.energy; -import java.util.LinkedList; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.ICrafting; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.common.util.ForgeDirection; import buildcraft.BuildCraftEnergy; import buildcraft.api.gates.IOverrideDefaultTriggers; import buildcraft.api.gates.ITrigger; @@ -34,12 +26,21 @@ import buildcraft.core.TileBuffer; import buildcraft.core.TileBuildCraft; import buildcraft.core.network.NetworkData; import buildcraft.energy.gui.ContainerEngine; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.ICrafting; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.common.util.ForgeDirection; + +import java.util.LinkedList; public abstract class TileEngine extends TileBuildCraft implements IPowerReceptor, IPowerEmitter, IOverrideDefaultTriggers, IPipeConnection { public static final ResourceLocation WOOD_TEXTURE = new ResourceLocation(DefaultProps.TEXTURE_PATH_BLOCKS + "/base_wood.png"); public static final ResourceLocation STONE_TEXTURE = new ResourceLocation(DefaultProps.TEXTURE_PATH_BLOCKS + "/base_stone.png"); public static final ResourceLocation IRON_TEXTURE = new ResourceLocation(DefaultProps.TEXTURE_PATH_BLOCKS + "/base_iron.png"); + public static final ResourceLocation CREATIVE_TEXTURE = new ResourceLocation(DefaultProps.TEXTURE_PATH_BLOCKS + "/base_iron.png"); public enum EnergyStage { BLUE, GREEN, YELLOW, RED, OVERHEAT; diff --git a/common/buildcraft/energy/TileEngineCreative.java b/common/buildcraft/energy/TileEngineCreative.java new file mode 100644 index 00000000..8e7fc905 --- /dev/null +++ b/common/buildcraft/energy/TileEngineCreative.java @@ -0,0 +1,109 @@ +package buildcraft.energy; + +import buildcraft.api.tools.IToolWrench; +import buildcraft.core.utils.StringUtils; +import buildcraft.transport.pipes.PipePowerIron; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.common.util.ForgeDirection; + +public class TileEngineCreative extends TileEngine { + + private PipePowerIron.PowerMode powerMode = PipePowerIron.PowerMode.M2; + + @Override + public ResourceLocation getTextureFile() { + return CREATIVE_TEXTURE; + } + + @Override + protected EnergyStage computeEnergyStage() { + return EnergyStage.RED; + } + + @Override + public boolean onBlockActivated(EntityPlayer player, ForgeDirection side) { + Item equipped = player.getCurrentEquippedItem() != null ? player.getCurrentEquippedItem().getItem() : null; + + if (equipped instanceof IToolWrench && ((IToolWrench) equipped).canWrench(player, xCoord, yCoord, zCoord)) { + powerMode = powerMode.getNext(); + energy = 0; + + if (!getWorld().isRemote) { + player.addChatMessage(new ChatComponentText(String.format(StringUtils.localize("chat.pipe.power.iron.mode"), powerMode.maxPower))); + } + + ((IToolWrench) equipped).wrenchUsed(player, xCoord, yCoord, zCoord); + return true; + } + + return false; + } + + @Override + public void readFromNBT(NBTTagCompound data) { + super.readFromNBT(data); + + powerMode = PipePowerIron.PowerMode.fromId(data.getByte("mode")); + } + + @Override + public void writeToNBT(NBTTagCompound data) { + super.writeToNBT(data); + + data.setByte("mode", (byte) powerMode.ordinal()); + } + + @Override + public float getPistonSpeed() { + return 0.02F * (powerMode.ordinal() + 1); + } + + @Override + public void engineUpdate() { + super.engineUpdate(); + + if (isRedstonePowered) { + addEnergy(getCurrentOutput()); + } + } + + @Override + public boolean isBurning() { + return isRedstonePowered; + } + + @Override + public int getScaledBurnTime(int scale) { + return 0; + } + + @Override + public double maxEnergyReceived() { + return getCurrentOutput(); + } + + @Override + public double maxEnergyExtracted() { + return getCurrentOutput(); + } + + @Override + public double getMaxEnergy() { + return getCurrentOutput(); + } + + @Override + public double getCurrentOutput() { + return powerMode.maxPower; + } + + @Override + public float explosionRange() { + return 0; + } + +}