diff --git a/buildnumber.txt b/buildnumber.txt index d58047831..7f707973a 100644 --- a/buildnumber.txt +++ b/buildnumber.txt @@ -1 +1 @@ -30 +31 diff --git a/info.txt b/info.txt index 0fc97c200..c55303c70 100644 --- a/info.txt +++ b/info.txt @@ -26,3 +26,4 @@ Minecraft 1.4.5 @ AssemblyLine_v0.1.8.28.jar AssemblyLine_v0.1.8.28_api.zip @ AssemblyLine_v0.1.8.29.jar AssemblyLine_v0.1.8.29_api.zip * AssemblyLine_v0.1.8.30.jar AssemblyLine_v0.1.8.30_api.zip +@ AssemblyLine_v0.1.8.31.jar AssemblyLine_v0.1.8.31_api.zip diff --git a/resources/assemblyline/language/en_US.properties b/resources/assemblyline/language/en_US.properties index 112b44a90..2f1315d38 100644 --- a/resources/assemblyline/language/en_US.properties +++ b/resources/assemblyline/language/en_US.properties @@ -4,7 +4,10 @@ # Blocks tile.crate.name=Crate tile.conveyorBelt.name=Conveyor Belt +tile.stamper.name=Filter Stamper tile.engineerTable.name=Engineer's Table +tile.armbot.name=Armbot # Items -# item.battery.name=Battery \ No newline at end of file +item.filter.name=Filter +item.blueprint.name=Blueprint \ No newline at end of file diff --git a/src/minecraft/assemblyline/client/ClientProxy.java b/src/minecraft/assemblyline/client/ClientProxy.java index 992f227d0..163cbcda9 100644 --- a/src/minecraft/assemblyline/client/ClientProxy.java +++ b/src/minecraft/assemblyline/client/ClientProxy.java @@ -1,10 +1,11 @@ package assemblyline.client; +import net.minecraft.client.gui.GuiScreen; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import net.minecraftforge.client.MinecraftForgeClient; -import assemblyline.client.gui.GuiSorter; +import assemblyline.client.gui.GuiRejector; import assemblyline.client.render.RenderConveyorBelt; import assemblyline.client.render.RenderCrate; import assemblyline.client.render.RenderHelper; @@ -47,14 +48,19 @@ public class ClientProxy extends CommonProxy { switch (ID) { - case 0: - return new GuiSorter(player.inventory, ((TileEntityRejector) tileEntity)); - case GUI_ARCHITECHT_TABLE: - return null; + case GUI_REJECTOR: + return new GuiRejector(player.inventory, ((TileEntityRejector) tileEntity)); + case GUI_STAMPER: + return new GuiRejector(player.inventory, ((TileEntityRejector) tileEntity)); } } return null; } + @Override + public boolean isCtrKeyDown() + { + return GuiScreen.isCtrlKeyDown(); + } } diff --git a/src/minecraft/assemblyline/client/gui/GuiSorter.java b/src/minecraft/assemblyline/client/gui/GuiRejector.java similarity index 92% rename from src/minecraft/assemblyline/client/gui/GuiSorter.java rename to src/minecraft/assemblyline/client/gui/GuiRejector.java index 79987ee63..47584c265 100644 --- a/src/minecraft/assemblyline/client/gui/GuiSorter.java +++ b/src/minecraft/assemblyline/client/gui/GuiRejector.java @@ -9,19 +9,19 @@ import org.lwjgl.input.Keyboard; import org.lwjgl.opengl.GL11; import assemblyline.common.AssemblyLine; -import assemblyline.common.machine.ContainerSorter; +import assemblyline.common.machine.ContainerRejector; import assemblyline.common.machine.TileEntityRejector; -public class GuiSorter extends GuiContainer +public class GuiRejector extends GuiContainer { private TileEntityRejector tileEntity; private int containerWidth; private int containerHeight; - public GuiSorter(InventoryPlayer par1InventoryPlayer, TileEntityRejector tileEntity) + public GuiRejector(InventoryPlayer par1InventoryPlayer, TileEntityRejector tileEntity) { - super(new ContainerSorter(par1InventoryPlayer, tileEntity)); + super(new ContainerRejector(par1InventoryPlayer, tileEntity)); this.tileEntity = tileEntity; } diff --git a/src/minecraft/assemblyline/client/gui/GuiStamper.java b/src/minecraft/assemblyline/client/gui/GuiStamper.java new file mode 100644 index 000000000..e500c82a0 --- /dev/null +++ b/src/minecraft/assemblyline/client/gui/GuiStamper.java @@ -0,0 +1,52 @@ +package assemblyline.client.gui; + +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.world.World; + +import org.lwjgl.opengl.GL11; + +import universalelectricity.core.vector.Vector3; +import assemblyline.common.AssemblyLine; +import assemblyline.common.machine.ContainerRejector; + +public class GuiStamper extends GuiContainer +{ + private int containerWidth; + private int containerHeight; + + public GuiStamper(InventoryPlayer par1InventoryPlayer, World worldObj, Vector3 position) + { + super(new ContainerRejector(par1InventoryPlayer, worldObj, position)); + } + + /** + * Draw the foreground layer for the GuiContainer (everything in front of the items) + */ + @Override + protected void drawGuiContainerForegroundLayer(int par1, int par2) + { + this.fontRenderer.drawString(AssemblyLine.translateLocal("assemblyline.gui.stamper"), 55, 6, 4210752); + } + + /** + * Draw the background layer for the GuiContainer (everything behind the items) + */ + @Override + protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) + { + int var4 = this.mc.renderEngine.getTexture(AssemblyLine.TEXTURE_PATH + "gui_ejector.png"); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + this.mc.renderEngine.bindTexture(var4); + containerWidth = (this.width - this.xSize) / 2; + containerHeight = (this.height - this.ySize) / 2; + this.drawTexturedModalRect(containerWidth, containerHeight, 0, 0, this.xSize, this.ySize); + + // GUI button changes + for (int i = 1; i < this.tileEntity.guiButtons.length; i++) + { + this.drawTexturedModalRect(containerWidth + 17 + i * 18, containerHeight + 17, 176, +(tileEntity.guiButtons[i] ? 12 : 0), 12, 12); + } + this.fontRenderer.drawString((tileEntity.guiButtons[0] ? "Inv" : "Other"), containerWidth + 108, containerHeight + 22, 4210752); + } +} diff --git a/src/minecraft/assemblyline/common/AssemblyLine.java b/src/minecraft/assemblyline/common/AssemblyLine.java index 9190ea307..3cc338852 100644 --- a/src/minecraft/assemblyline/common/AssemblyLine.java +++ b/src/minecraft/assemblyline/common/AssemblyLine.java @@ -16,6 +16,7 @@ import universalelectricity.prefab.UpdateNotifier; import universalelectricity.prefab.network.PacketManager; import assemblyline.common.block.BlockCrate; import assemblyline.common.block.BlockEngineerTable; +import assemblyline.common.block.BlockStamper; import assemblyline.common.block.ItemBlockCrate; import assemblyline.common.machine.BlockMulti; import assemblyline.common.machine.BlockMulti.MachineType; @@ -66,6 +67,10 @@ public class AssemblyLine public static Block blockMulti; public static Block blockEngineerTable; public static Block blockCrate; + public static Block blockStamper; + + public static final int ITEM_ID_PREFIX = 3030; + public static Item itemCrate; @PreInit public void preInit(FMLPreInitializationEvent event) @@ -78,13 +83,16 @@ public class AssemblyLine blockMulti = new BlockMulti(CONFIGURATION.getBlock("Machine", BLOCK_ID_PREFIX + 1).getInt()); blockEngineerTable = new BlockEngineerTable(CONFIGURATION.getBlock("Architect's Table", BLOCK_ID_PREFIX + 2).getInt()); blockCrate = new BlockCrate(CONFIGURATION.getBlock("Crate", BLOCK_ID_PREFIX + 3).getInt(), 0); + blockStamper = new BlockStamper(CONFIGURATION.getBlock("Stamper", BLOCK_ID_PREFIX + 4).getInt(), 0); + + itemCrate = new ItemFilter(CONFIGURATION.getBlock("Filter", ITEM_ID_PREFIX).getInt()); CONFIGURATION.save(); NetworkRegistry.instance().registerGuiHandler(this, this.proxy); GameRegistry.registerBlock(blockConveyorBelt, "Conveyor Belt"); GameRegistry.registerBlock(blockCrate, ItemBlockCrate.class, "Crate"); GameRegistry.registerBlock(blockMulti, ItemBlockMulti.class, "Machine"); - // GameRegistry.registerBlock(blockArchitectTable, "Engineer's Table"); + GameRegistry.registerBlock(blockEngineerTable, "Engineer's Table"); UpdateNotifier.INSTANCE.checkUpdate(NAME, VERSION, "http://calclavia.com/downloads/al/recommendedversion.txt"); @@ -93,13 +101,13 @@ public class AssemblyLine @Override public void onCrafting(EntityPlayer player, ItemStack itemStack, IInventory craftMatrix) { - System.out.println("TEST"); + System.out.println("TEST: " + craftMatrix.getSizeInventory()); } @Override public void onSmelting(EntityPlayer player, ItemStack item) { - + } }); proxy.preInit(); @@ -165,4 +173,10 @@ public class AssemblyLine UETab.setItemStack(new ItemStack(blockConveyorBelt)); } + + public static String translateLocal(String string) + { + // TODO Auto-generated method stub + return null; + } } \ No newline at end of file diff --git a/src/minecraft/assemblyline/common/CommonProxy.java b/src/minecraft/assemblyline/common/CommonProxy.java index b7be5a63b..339c64689 100644 --- a/src/minecraft/assemblyline/common/CommonProxy.java +++ b/src/minecraft/assemblyline/common/CommonProxy.java @@ -4,7 +4,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import assemblyline.common.block.TileEntityCrate; -import assemblyline.common.machine.ContainerSorter; +import assemblyline.common.machine.ContainerRejector; import assemblyline.common.machine.TileEntityManipulator; import assemblyline.common.machine.TileEntityRejector; import assemblyline.common.machine.belt.TileEntityConveyorBelt; @@ -13,7 +13,9 @@ import cpw.mods.fml.common.registry.GameRegistry; public class CommonProxy implements IGuiHandler { - public static final int GUI_ARCHITECHT_TABLE = 4; + public static final int GUI_REJECTOR = 0; + public static final int GUI_STAMPER = 1; + public static final int GUI_ARCHITECHT_TABLE = 2; public void preInit() { @@ -37,8 +39,10 @@ public class CommonProxy implements IGuiHandler { switch (ID) { - case 0: - return new ContainerSorter(player.inventory, ((TileEntityRejector) tileEntity)); + case GUI_REJECTOR: + return new ContainerRejector(player.inventory, ((TileEntityRejector) tileEntity)); + case GUI_STAMPER: + return new ContainerRejector(player.inventory, ((TileEntityRejector) tileEntity)); } } @@ -50,4 +54,9 @@ public class CommonProxy implements IGuiHandler { return null; } + + public boolean isCtrKeyDown() + { + return false; + } } diff --git a/src/minecraft/assemblyline/common/ItemFilter.java b/src/minecraft/assemblyline/common/ItemFilter.java index 1d663bf3f..055bbf5c8 100644 --- a/src/minecraft/assemblyline/common/ItemFilter.java +++ b/src/minecraft/assemblyline/common/ItemFilter.java @@ -1,15 +1,91 @@ package assemblyline.common; -import universalelectricity.prefab.UETab; +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import universalelectricity.prefab.UETab; public class ItemFilter extends Item { public ItemFilter(int id) { super(id); + this.setItemName("filter"); this.setIconIndex(Item.paper.getIconFromDamage(0)); this.setCreativeTab(UETab.INSTANCE); + this.setHasSubtypes(true); } + @Override + public void addInformation(ItemStack itemStack, EntityPlayer par2EntityPlayer, List list, boolean par4) + { + List filterItems = getFilters(itemStack); + + if (filterItems.size() > 0) + { + list.add("Filters:"); + + for (ItemStack filterItem : filterItems) + { + list.add(filterItem.getItemName()); + } + } + else + { + list.add("No filters"); + } + } + + /** + * Saves the list of items to filter out inside. + */ + public static void setFilters(ItemStack itemStack, List filterStacks) + { + if (itemStack.getTagCompound() == null) + { + itemStack.setTagCompound(new NBTTagCompound()); + } + + NBTTagList nbt = new NBTTagList(); + + for (int i = 0; i < filterStacks.size(); ++i) + { + if (filterStacks.get(i) != null) + { + NBTTagCompound newCompound = new NBTTagCompound(); + newCompound.setByte("Slot", (byte) i); + filterStacks.get(i).writeToNBT(newCompound); + nbt.appendTag(newCompound); + } + } + + itemStack.getTagCompound().setTag("Items", nbt); + } + + public static List getFilters(ItemStack itemStack) + { + List filterStacks = new ArrayList(); + + if (itemStack.getTagCompound() == null) + { + itemStack.setTagCompound(new NBTTagCompound()); + } + + NBTTagCompound nbt = itemStack.getTagCompound(); + NBTTagList tagList = nbt.getTagList("Items"); + + for (int i = 0; i < tagList.tagCount(); ++i) + { + NBTTagCompound var4 = (NBTTagCompound) tagList.tagAt(i); + byte var5 = var4.getByte("Slot"); + filterStacks.add(ItemStack.loadItemStackFromNBT(var4)); + } + + return filterStacks; + } } diff --git a/src/minecraft/assemblyline/common/ai/Task.java b/src/minecraft/assemblyline/common/ai/Task.java index 62f842c88..0d5f7b424 100644 --- a/src/minecraft/assemblyline/common/ai/Task.java +++ b/src/minecraft/assemblyline/common/ai/Task.java @@ -1,6 +1,6 @@ package assemblyline.common.ai; -import assemblyline.common.machine.crafter.TileEntityCraftingArm; +import assemblyline.common.machine.crafter.TileEntityArmbot; /** * An AI Task that is used by TileEntities with AI. @@ -11,9 +11,9 @@ import assemblyline.common.machine.crafter.TileEntityCraftingArm; public abstract class Task { protected int ticks; - protected TileEntityCraftingArm tileEntity; + protected TileEntityArmbot tileEntity; - public Task(TileEntityCraftingArm arm) + public Task(TileEntityArmbot arm) { this.tileEntity = arm; } diff --git a/src/minecraft/assemblyline/common/ai/TaskIdle.java b/src/minecraft/assemblyline/common/ai/TaskIdle.java index 1fee8ac92..deec16216 100644 --- a/src/minecraft/assemblyline/common/ai/TaskIdle.java +++ b/src/minecraft/assemblyline/common/ai/TaskIdle.java @@ -1,10 +1,10 @@ package assemblyline.common.ai; -import assemblyline.common.machine.crafter.TileEntityCraftingArm; +import assemblyline.common.machine.crafter.TileEntityArmbot; public class TaskIdle extends Task { - public TaskIdle(TileEntityCraftingArm arm) + public TaskIdle(TileEntityArmbot arm) { super(arm); } diff --git a/src/minecraft/assemblyline/common/block/BlockCrate.java b/src/minecraft/assemblyline/common/block/BlockCrate.java index 763bac5f5..b1755d044 100644 --- a/src/minecraft/assemblyline/common/block/BlockCrate.java +++ b/src/minecraft/assemblyline/common/block/BlockCrate.java @@ -1,5 +1,6 @@ package assemblyline.common.block; +import net.minecraft.client.gui.GuiScreen; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; @@ -31,40 +32,126 @@ public class BlockCrate extends BlockMachine * Placed the item the player is holding into the crate. */ @Override - public boolean onMachineActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9) + public boolean onMachineActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) { if (world.getBlockTileEntity(x, y, z) instanceof TileEntityCrate) { TileEntityCrate tileEntity = (TileEntityCrate) world.getBlockTileEntity(x, y, z); - ItemStack requestStack = player.getCurrentEquippedItem(); - if (requestStack != null) + if (side > 1 && hitY > 0.7) { - if (requestStack.isStackable()) - { - for (int i = 0; i < player.inventory.getSizeInventory(); i++) - { - ItemStack currentStack = player.inventory.getStackInSlot(i); + return this.insertAllItems(tileEntity, player); + } + else + { + return this.insertCurrentItem(tileEntity, player); + } - if (currentStack != null) - { - if (requestStack != currentStack && requestStack.isItemEqual(currentStack)) - { - player.inventory.setInventorySlotContents(i, this.putIn(tileEntity, currentStack)); - return true; - } - } - } + } - player.inventory.setInventorySlotContents(player.inventory.currentItem, this.putIn(tileEntity, requestStack)); - return true; - } + return false; + } + + /** + * Inserts a the itemStack the player is holding into the crate. + */ + public boolean insertCurrentItem(TileEntityCrate tileEntity, EntityPlayer player) + { + ItemStack currentStack = player.getCurrentEquippedItem(); + + if (currentStack != null) + { + if (currentStack.isStackable()) + { + player.inventory.setInventorySlotContents(player.inventory.currentItem, this.putIn(tileEntity, currentStack)); + return true; } } return false; } + /** + * Inserts all items of the same type this player has into the crate. + * + * @return + */ + public boolean insertAllItems(TileEntityCrate tileEntity, EntityPlayer player) + { + ItemStack requestStack = player.getCurrentEquippedItem(); + + if (requestStack != null) + { + if (requestStack.isStackable()) + { + for (int i = 0; i < player.inventory.getSizeInventory(); i++) + { + ItemStack currentStack = player.inventory.getStackInSlot(i); + + if (currentStack != null) + { + if (requestStack.isItemEqual(currentStack)) + { + player.inventory.setInventorySlotContents(i, this.putIn(tileEntity, currentStack)); + } + } + } + + return true; + } + } + + return false; + } + + /** + * Ejects and item out of the crate and spawn it under the player entity. + * + * @param tileEntity + * @param player + * @param maxStack - The maximum stack size to take out. Default should be 64. + * @return True on success + */ + public boolean ejectItems(TileEntityCrate tileEntity, EntityPlayer player, int maxStack) + { + World world = tileEntity.worldObj; + ItemStack containingStack = tileEntity.getStackInSlot(0); + + if (containingStack != null) + { + if (containingStack.stackSize > 0) + { + int amountToTake = Math.min(containingStack.stackSize, maxStack); + ItemStack dropStack = containingStack.copy(); + dropStack.stackSize = amountToTake; + + if (!world.isRemote) + { + EntityItem entityItem = new EntityItem(world, player.posX, player.posY, player.posZ, dropStack); + + float var13 = 0.05F; + entityItem.motionX = ((float) world.rand.nextGaussian() * var13); + entityItem.motionY = ((float) world.rand.nextGaussian() * var13 + 0.2F); + entityItem.motionZ = ((float) world.rand.nextGaussian() * var13); + entityItem.delayBeforeCanPickup = 0; + world.spawnEntityInWorld(entityItem); + } + + containingStack.stackSize -= amountToTake; + } + + if (containingStack.stackSize <= 0) + { + containingStack = null; + } + + tileEntity.setInventorySlotContents(0, containingStack); + + return true; + } + return false; + } + /** * Puts an itemStack into the crate. * @@ -110,45 +197,29 @@ public class BlockCrate extends BlockMachine * Drops the crate as a block that stores items within it. */ @Override - public boolean onSneakMachineActivated(World world, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ) + public boolean onSneakMachineActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) { - if (!world.isRemote && world.getBlockTileEntity(x, y, z) != null) + if (world.getBlockTileEntity(x, y, z) != null) { - if (par5EntityPlayer.getCurrentEquippedItem() == null) + TileEntityCrate tileEntity = (TileEntityCrate) world.getBlockTileEntity(x, y, z); + + if (player.getCurrentEquippedItem() == null) { - TileEntityCrate tileEntity = (TileEntityCrate) world.getBlockTileEntity(x, y, z); - ItemStack containingStack = tileEntity.getStackInSlot(0); - - if (containingStack != null) + /** + * Eject all items if clicked on the top 30% of the block. + */ + if (side > 1 && hitY > 0.7) { - if (containingStack.stackSize > 0) - { - int amountToTake = Math.min(containingStack.stackSize, 64); - ItemStack dropStack = containingStack.copy(); - dropStack.stackSize = amountToTake; - - EntityItem entityItem = new EntityItem(world, par5EntityPlayer.posX, par5EntityPlayer.posY, par5EntityPlayer.posZ, dropStack); - - float var13 = 0.05F; - entityItem.motionX = ((float) world.rand.nextGaussian() * var13); - entityItem.motionY = ((float) world.rand.nextGaussian() * var13 + 0.2F); - entityItem.motionZ = ((float) world.rand.nextGaussian() * var13); - entityItem.delayBeforeCanPickup = 0; - world.spawnEntityInWorld(entityItem); - - containingStack.stackSize -= amountToTake; - } - - if (containingStack.stackSize <= 0) - { - containingStack = null; - } - - tileEntity.setInventorySlotContents(0, containingStack); + return this.ejectItems(tileEntity, player, TileEntityCrate.MAX_LIMIT); + } + else + { + return this.ejectItems(tileEntity, player, 64); } } } - return true; + + return false; } @Override diff --git a/src/minecraft/assemblyline/common/block/BlockStamper.java b/src/minecraft/assemblyline/common/block/BlockStamper.java new file mode 100644 index 000000000..c97924ed1 --- /dev/null +++ b/src/minecraft/assemblyline/common/block/BlockStamper.java @@ -0,0 +1,43 @@ +package assemblyline.common.block; + +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; +import universalelectricity.prefab.UETab; + +public class BlockStamper extends Block +{ + public BlockStamper(int id, int texture) + { + super(id, Material.wood); + this.blockIndexInTexture = 59; + this.setBlockName("stamper"); + this.setCreativeTab(UETab.INSTANCE); + } + + /** + * Returns the block texture based on the side being looked at. Args: side + */ + public int getBlockTextureFromSide(int par1) + { + return Block.blockSteel.blockIndexInTexture; + } + + /** + * Called upon block activation (right click on the block.) + */ + public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9) + { + if (par1World.isRemote) + { + return true; + } + else + { + par5EntityPlayer.displayGUIWorkbench(par2, par3, par4); + return true; + } + } + +} diff --git a/src/minecraft/assemblyline/common/machine/ContainerSorter.java b/src/minecraft/assemblyline/common/machine/ContainerRejector.java similarity index 93% rename from src/minecraft/assemblyline/common/machine/ContainerSorter.java rename to src/minecraft/assemblyline/common/machine/ContainerRejector.java index 12140bb7b..78d5d5f9a 100644 --- a/src/minecraft/assemblyline/common/machine/ContainerSorter.java +++ b/src/minecraft/assemblyline/common/machine/ContainerRejector.java @@ -7,11 +7,11 @@ import net.minecraft.inventory.Slot; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -public class ContainerSorter extends Container +public class ContainerRejector extends Container { private TileEntityRejector tileEntity; - public ContainerSorter(InventoryPlayer par1InventoryPlayer, TileEntityRejector tileEntity) + public ContainerRejector(InventoryPlayer par1InventoryPlayer, TileEntityRejector tileEntity) { this.tileEntity = tileEntity; for (int i = 0; i < 4; i++) diff --git a/src/minecraft/assemblyline/common/machine/ContainerStamper.java b/src/minecraft/assemblyline/common/machine/ContainerStamper.java new file mode 100644 index 000000000..6cfc1506c --- /dev/null +++ b/src/minecraft/assemblyline/common/machine/ContainerStamper.java @@ -0,0 +1,98 @@ +package assemblyline.common.machine; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.Slot; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import universalelectricity.core.vector.Vector3; + +public class ContainerStamper extends Container +{ + private World worldObj; + private Vector3 position; + + public ContainerStamper(InventoryPlayer par1InventoryPlayer, World worldObj, Vector3 position) + { + this.worldObj = worldObj; + this.position = position; + + // Paper Input + this.addSlotToContainer(new Slot(par1InventoryPlayer, 0, 33, 34)); + // Item Stamp + this.addSlotToContainer(new Slot(par1InventoryPlayer, 1, 33 + 18, 34)); + // Output Filter + this.addSlotToContainer(new Slot(par1InventoryPlayer, 2, 33 + 36, 34)); + + int var3; + + for (var3 = 0; var3 < 3; ++var3) + { + for (int var4 = 0; var4 < 9; ++var4) + { + this.addSlotToContainer(new Slot(par1InventoryPlayer, var4 + var3 * 9 + 9, 8 + var4 * 18, 84 + var3 * 18)); + } + } + + for (var3 = 0; var3 < 9; ++var3) + { + this.addSlotToContainer(new Slot(par1InventoryPlayer, var3, 8 + var3 * 18, 142)); + } + } + + @Override + public void updateCraftingResults() + { + super.updateCraftingResults(); + System.out.println("WORK"); + } + + @Override + public boolean canInteractWith(EntityPlayer par1EntityPlayer) + { + return true; + } + + /** + * Called to transfer a stack from one inventory to the other eg. when shift clicking. + */ + @Override + public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par1) + { + ItemStack itemStack3 = null; + Slot itemStack = (Slot) this.inventorySlots.get(par1); + + if (itemStack != null && itemStack.getHasStack()) + { + ItemStack itemStack2 = itemStack.getStack(); + itemStack3 = itemStack2.copy(); + + if (par1 != 0) + { + if (itemStack2.itemID == Item.coal.shiftedIndex) + { + if (!this.mergeItemStack(itemStack2, 0, 1, false)) { return null; } + } + else if (par1 >= 30 && par1 < 37 && !this.mergeItemStack(itemStack2, 3, 30, false)) { return null; } + } + else if (!this.mergeItemStack(itemStack2, 3, 37, false)) { return null; } + + if (itemStack2.stackSize == 0) + { + itemStack.putStack((ItemStack) null); + } + else + { + itemStack.onSlotChanged(); + } + + if (itemStack2.stackSize == itemStack3.stackSize) { return null; } + + itemStack.onPickupFromSlot(par1EntityPlayer, itemStack2); + } + + return itemStack3; + } +} diff --git a/src/minecraft/assemblyline/common/machine/crafter/EntityCraftingArm.java b/src/minecraft/assemblyline/common/machine/crafter/EntityCraftingArm.java index 0baa4cc98..6a1e431e2 100644 --- a/src/minecraft/assemblyline/common/machine/crafter/EntityCraftingArm.java +++ b/src/minecraft/assemblyline/common/machine/crafter/EntityCraftingArm.java @@ -49,7 +49,7 @@ public class EntityCraftingArm extends Entity /** * TileEntity this arm is originating from */ - private TileEntityCraftingArm tileEntityCraftingArm; + private TileEntityArmbot tileEntityCraftingArm; /** * position that the arms claw is at diff --git a/src/minecraft/assemblyline/common/machine/crafter/TaskArmCollect.java b/src/minecraft/assemblyline/common/machine/crafter/TaskArmCollect.java index 9016a8e24..b732f7329 100644 --- a/src/minecraft/assemblyline/common/machine/crafter/TaskArmCollect.java +++ b/src/minecraft/assemblyline/common/machine/crafter/TaskArmCollect.java @@ -16,7 +16,7 @@ public class TaskArmCollect extends Task */ private EntityItem entityItem; - public TaskArmCollect(TileEntityCraftingArm arm, EntityItem entityItem) + public TaskArmCollect(TileEntityArmbot arm, EntityItem entityItem) { super(arm); this.entityItem = entityItem; diff --git a/src/minecraft/assemblyline/common/machine/crafter/TaskArmSearch.java b/src/minecraft/assemblyline/common/machine/crafter/TaskArmSearch.java index 4d0d679cd..d14629ece 100644 --- a/src/minecraft/assemblyline/common/machine/crafter/TaskArmSearch.java +++ b/src/minecraft/assemblyline/common/machine/crafter/TaskArmSearch.java @@ -25,7 +25,7 @@ public class TaskArmSearch extends Task private Entity foundEntity; - public TaskArmSearch(TileEntityCraftingArm arm, Class entityToInclude, double radius, float searchSpeed) + public TaskArmSearch(TileEntityArmbot arm, Class entityToInclude, double radius, float searchSpeed) { super(arm); this.entityToInclude = entityToInclude; diff --git a/src/minecraft/assemblyline/common/machine/crafter/TileEntityCraftingArm.java b/src/minecraft/assemblyline/common/machine/crafter/TileEntityArmbot.java similarity index 97% rename from src/minecraft/assemblyline/common/machine/crafter/TileEntityCraftingArm.java rename to src/minecraft/assemblyline/common/machine/crafter/TileEntityArmbot.java index d2947bae6..4a1207870 100644 --- a/src/minecraft/assemblyline/common/machine/crafter/TileEntityCraftingArm.java +++ b/src/minecraft/assemblyline/common/machine/crafter/TileEntityArmbot.java @@ -21,7 +21,7 @@ import assemblyline.common.ai.TaskManager; import com.google.common.io.ByteArrayDataInput; -public class TileEntityCraftingArm extends TileEntityElectricityReceiver implements IInventory, IPacketReceiver, IJouleStorage +public class TileEntityArmbot extends TileEntityElectricityReceiver implements IInventory, IPacketReceiver, IJouleStorage { /** * The items this container contains. diff --git a/src/minecraft/universalelectricity/prefab/modifier/IModifier.java b/src/minecraft/universalelectricity/prefab/modifier/IModifier.java new file mode 100644 index 000000000..dd0b49f44 --- /dev/null +++ b/src/minecraft/universalelectricity/prefab/modifier/IModifier.java @@ -0,0 +1,22 @@ +package universalelectricity.prefab.modifier; + +import net.minecraft.item.ItemStack; + +/** + * This must be applied to an item that acts as a modifier or an upgrade. + * + * @author Calclavia + * + */ +public interface IModifier +{ + /** + * @return - The name of the modifier. + */ + public String getName(ItemStack itemstack); + + /** + * @return - How much effect does this modifier have? + */ + public int getEffectiveness(ItemStack itemstack); +} diff --git a/src/minecraft/universalelectricity/prefab/modifier/SlotModifier.java b/src/minecraft/universalelectricity/prefab/modifier/SlotModifier.java new file mode 100644 index 000000000..f06b5b270 --- /dev/null +++ b/src/minecraft/universalelectricity/prefab/modifier/SlotModifier.java @@ -0,0 +1,29 @@ +package universalelectricity.prefab.modifier; + +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; + +/** + * This slot should be used by any container that contains an item that is a modifier. An example of + * this would be upgrade slots. + * + * @author Calclavia + * + */ +public class SlotModifier extends Slot +{ + public SlotModifier(IInventory par2IInventory, int par3, int par4, int par5) + { + super(par2IInventory, par3, par4, par5); + } + + /** + * Check if the stack is a valid item for this slot. Always true beside for the armor slots. + */ + @Override + public boolean isItemValid(ItemStack par1ItemStack) + { + return par1ItemStack.getItem() instanceof IModifier; + } +} diff --git a/src/minecraft/universalelectricity/prefab/ore/OreGenBase.java b/src/minecraft/universalelectricity/prefab/ore/OreGenBase.java new file mode 100644 index 000000000..6cf5389fc --- /dev/null +++ b/src/minecraft/universalelectricity/prefab/ore/OreGenBase.java @@ -0,0 +1,109 @@ +package universalelectricity.prefab.ore; + +import java.util.Random; + +import cpw.mods.fml.common.FMLLog; + +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import net.minecraft.world.chunk.IChunkProvider; +import net.minecraftforge.common.Configuration; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.oredict.OreDictionary; +import universalelectricity.core.UniversalElectricity; + +/** + * This class is used for storing ore generation data. If you are too lazy to generate your own + * ores, you can do {@link #OreGenerator.ORES_TO_GENERATE.add()} to add your ore to the list of ores + * to generate. + * + * @author Calclavia + * + */ +public abstract class OreGenBase +{ + public String name; + + public String oreDictionaryName; + + public boolean shouldGenerate; + + public int blockIndexTexture; + + public ItemStack oreStack; + + public int oreID; + + public int oreMeta; + + /** + * What harvest level does this machine need to be acquired? + */ + public int harvestLevel; + + /** + * The predefined tool classes are "pickaxe", "shovel", "axe". You can add others for custom + * tools. + */ + public String harvestTool; + + /** + * @param name - The name of the ore for display + * @param textureFile - The 16x16 png texture of your ore to override + * @param minGenerateLevel - The highest generation level of your ore + * @param maxGenerateLevel - The lowest generation level of your ore + * @param amountPerChunk - The amount of ores to generate per chunk + * @param amountPerBranch - The amount of ores to generate in a clutter. E.g coal generates with + * a lot of other coal next to it. How much do you want? + */ + public OreGenBase(String name, String oreDiectionaryName, ItemStack stack, String harvestTool, int harvestLevel) + { + if (stack != null) + { + + this.name = name; + this.shouldGenerate = false; + this.harvestTool = harvestTool; + this.harvestLevel = harvestLevel; + this.oreDictionaryName = oreDiectionaryName; + this.oreStack = stack; + this.oreID = stack.itemID; + this.oreMeta = stack.getItemDamage(); + + OreDictionary.registerOre(oreDictionaryName, stack); + MinecraftForge.setBlockHarvestLevel(Block.blocksList[stack.itemID], stack.getItemDamage(), harvestTool, harvestLevel); + } + else + { + FMLLog.severe("ItemStack is null while registering ore generation!"); + } + } + + public OreGenBase enable(Configuration config) + { + this.shouldGenerate = shouldGenerateOre(config, this.name); + return this; + } + + public OreGenBase enable() + { + this.enable(UniversalElectricity.CONFIGURATION); + return this; + } + + /** + * Checks the config file and see if Universal Electricity should generate this ore + */ + private static boolean shouldGenerateOre(Configuration configuration, String oreName) + { + configuration.load(); + boolean shouldGenerate = configuration.get("Ore Generation", "Generate " + oreName, true).getBoolean(true); + configuration.save(); + return shouldGenerate; + } + + public abstract void generate(World world, Random random, int varX, int varZ); + + public abstract boolean isOreGeneratedInWorld(World world, IChunkProvider chunkGenerator); +} diff --git a/src/minecraft/universalelectricity/prefab/ore/OreGenReplace.java b/src/minecraft/universalelectricity/prefab/ore/OreGenReplace.java new file mode 100644 index 000000000..410f06d75 --- /dev/null +++ b/src/minecraft/universalelectricity/prefab/ore/OreGenReplace.java @@ -0,0 +1,126 @@ +package universalelectricity.prefab.ore; + +import java.util.Random; + +import net.minecraft.item.ItemStack; +import net.minecraft.util.MathHelper; +import net.minecraft.world.World; +import net.minecraft.world.chunk.IChunkProvider; +import net.minecraft.world.gen.ChunkProviderEnd; +import net.minecraft.world.gen.ChunkProviderGenerate; +import net.minecraft.world.gen.ChunkProviderHell; + +/** + * This class is used for storing ore generation data. If you are too lazy to generate your own + * ores, you can do {@link #OreGenerator.ORES_TO_GENERATE.add()} to add your ore to the list of ores + * to generate. + * + * @author Calclavia + * + */ +public class OreGenReplace extends OreGenBase +{ + + public int minGenerateLevel; + public int maxGenerateLevel; + public int amountPerChunk; + public int amountPerBranch; + public int replaceID; + + public boolean generateSurface; + public boolean generateNether; + public boolean generateEnd; + + /** + * @param name - The name of the ore for display + * @param textureFile - The 16x16 png texture of your ore to override + * @param minGenerateLevel - The highest generation level of your ore + * @param maxGenerateLevel - The lowest generation level of your ore + * @param amountPerChunk - The amount of ores to generate per chunk + * @param amountPerBranch - The amount of ores to generate in a clutter. E.g coal generates with + * a lot of other coal next to it. How much do you want? + */ + public OreGenReplace(String name, String oreDiectionaryName, ItemStack stack, int replaceID, int minGenerateLevel, int maxGenerateLevel, int amountPerChunk, int amountPerBranch, String harvestTool, int harvestLevel) + { + super(name, oreDiectionaryName, stack, harvestTool, harvestLevel); + this.minGenerateLevel = minGenerateLevel; + this.maxGenerateLevel = maxGenerateLevel; + this.amountPerChunk = amountPerChunk; + this.amountPerBranch = amountPerBranch; + this.replaceID = replaceID; + } + + public void generate(World world, Random random, int varX, int varZ) + { + + for (int i = 0; i < this.amountPerChunk; i++) + { + int x = varX + random.nextInt(16); + int z = varZ + random.nextInt(16); + int y = random.nextInt(this.maxGenerateLevel - this.minGenerateLevel) + this.minGenerateLevel; + generateReplace(world, random, x, y, z); + } + } + + public boolean generateReplace(World par1World, Random par2Random, int par3, int par4, int par5) + { + float var6 = par2Random.nextFloat() * (float) Math.PI; + double var7 = (double) ((float) (par3 + 8) + MathHelper.sin(var6) * (float) this.amountPerBranch / 8.0F); + double var9 = (double) ((float) (par3 + 8) - MathHelper.sin(var6) * (float) this.amountPerBranch / 8.0F); + double var11 = (double) ((float) (par5 + 8) + MathHelper.cos(var6) * (float) this.amountPerBranch / 8.0F); + double var13 = (double) ((float) (par5 + 8) - MathHelper.cos(var6) * (float) this.amountPerBranch / 8.0F); + double var15 = (double) (par4 + par2Random.nextInt(3) - 2); + double var17 = (double) (par4 + par2Random.nextInt(3) - 2); + + for (int var19 = 0; var19 <= this.amountPerBranch; ++var19) + { + double var20 = var7 + (var9 - var7) * (double) var19 / (double) this.amountPerBranch; + double var22 = var15 + (var17 - var15) * (double) var19 / (double) this.amountPerBranch; + double var24 = var11 + (var13 - var11) * (double) var19 / (double) this.amountPerBranch; + double var26 = par2Random.nextDouble() * (double) this.amountPerBranch / 16.0D; + double var28 = (double) (MathHelper.sin((float) var19 * (float) Math.PI / (float) this.amountPerBranch) + 1.0F) * var26 + 1.0D; + double var30 = (double) (MathHelper.sin((float) var19 * (float) Math.PI / (float) this.amountPerBranch) + 1.0F) * var26 + 1.0D; + int var32 = MathHelper.floor_double(var20 - var28 / 2.0D); + int var33 = MathHelper.floor_double(var22 - var30 / 2.0D); + int var34 = MathHelper.floor_double(var24 - var28 / 2.0D); + int var35 = MathHelper.floor_double(var20 + var28 / 2.0D); + int var36 = MathHelper.floor_double(var22 + var30 / 2.0D); + int var37 = MathHelper.floor_double(var24 + var28 / 2.0D); + + for (int var38 = var32; var38 <= var35; ++var38) + { + double var39 = ((double) var38 + 0.5D - var20) / (var28 / 2.0D); + + if (var39 * var39 < 1.0D) + { + for (int var41 = var33; var41 <= var36; ++var41) + { + double var42 = ((double) var41 + 0.5D - var22) / (var30 / 2.0D); + + if (var39 * var39 + var42 * var42 < 1.0D) + { + for (int var44 = var34; var44 <= var37; ++var44) + { + double var45 = ((double) var44 + 0.5D - var24) / (var28 / 2.0D); + + int block = par1World.getBlockId(var38, var41, var44); + if (var39 * var39 + var42 * var42 + var45 * var45 < 1.0D && (this.replaceID == 0 || block == this.replaceID)) + { + par1World.setBlockAndMetadata(var38, var41, var44, this.oreID, this.oreMeta); + } + } + } + } + } + } + } + + return true; + } + + @Override + public boolean isOreGeneratedInWorld(World world, IChunkProvider chunkGenerator) + { + return ((this.generateSurface && chunkGenerator instanceof ChunkProviderGenerate) || (this.generateNether && chunkGenerator instanceof ChunkProviderHell) || (this.generateEnd && chunkGenerator instanceof ChunkProviderEnd)); + } +} diff --git a/src/minecraft/universalelectricity/prefab/ore/OreGenReplaceStone.java b/src/minecraft/universalelectricity/prefab/ore/OreGenReplaceStone.java new file mode 100644 index 000000000..1df9611d9 --- /dev/null +++ b/src/minecraft/universalelectricity/prefab/ore/OreGenReplaceStone.java @@ -0,0 +1,18 @@ +package universalelectricity.prefab.ore; + +import net.minecraft.item.ItemStack; + +public class OreGenReplaceStone extends OreGenReplace +{ + public OreGenReplaceStone(String name, String oreDiectionaryName, ItemStack stack, int replaceID, int minGenerateLevel, int maxGenerateLevel, int amountPerChunk, int amountPerBranch, String harvestTool, int harvestLevel) + { + super(name, oreDiectionaryName, stack, 1, minGenerateLevel, maxGenerateLevel, amountPerChunk, amountPerBranch, harvestTool, harvestLevel); + this.generateSurface = true; + } + + // A simplified version of the constructor + public OreGenReplaceStone(String name, String oreDiectionaryName, ItemStack stack, int replaceID, int maxGenerateLevel, int amountPerChunk, int amountPerBranch) + { + this(name, oreDiectionaryName, stack, 0, replaceID, maxGenerateLevel, amountPerChunk, amountPerBranch, "pickaxe", 1); + } +} \ No newline at end of file diff --git a/src/minecraft/universalelectricity/prefab/ore/OreGenerator.java b/src/minecraft/universalelectricity/prefab/ore/OreGenerator.java new file mode 100644 index 000000000..95e656014 --- /dev/null +++ b/src/minecraft/universalelectricity/prefab/ore/OreGenerator.java @@ -0,0 +1,75 @@ +package universalelectricity.prefab.ore; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +import net.minecraft.world.World; +import net.minecraft.world.chunk.IChunkProvider; +import cpw.mods.fml.common.IWorldGenerator; +import cpw.mods.fml.common.registry.GameRegistry; + +public class OreGenerator implements IWorldGenerator +{ + public static boolean isInitiated = false; + + /** + * Add your ore data to this list of ores for it to automatically generate! No hassle indeed! + */ + private static final List ORES_TO_GENERATE = new ArrayList(); + + /** + * Adds an ore to the ore generate list. Do this in pre-init. + */ + public static void addOre(OreGenBase data) + { + if (!isInitiated) + { + GameRegistry.registerWorldGenerator(new OreGenerator()); + } + + ORES_TO_GENERATE.add(data); + } + + /** + * Checks to see if this ore + * + * @param oreName + * @return + */ + public static boolean oreExists(String oreName) + { + for (OreGenBase ore : ORES_TO_GENERATE) + { + if (ore.oreDictionaryName == oreName) { return true; } + } + + return false; + } + + /** + * Removes an ore to the ore generate list. Do this in init. + */ + public static void removeOre(OreGenBase data) + { + ORES_TO_GENERATE.remove(data); + } + + @Override + public void generate(Random rand, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider) + { + chunkX = chunkX << 4; + chunkZ = chunkZ << 4; + + // Checks to make sure this is the normal + // world + for (OreGenBase oreData : ORES_TO_GENERATE) + { + if (oreData.shouldGenerate && oreData.isOreGeneratedInWorld(world, chunkGenerator)) + { + oreData.generate(world, rand, chunkX, chunkZ); + } + + } + } +} diff --git a/src/minecraft/universalelectricity/prefab/potion/CustomPotion.java b/src/minecraft/universalelectricity/prefab/potion/CustomPotion.java new file mode 100644 index 000000000..11f6c8653 --- /dev/null +++ b/src/minecraft/universalelectricity/prefab/potion/CustomPotion.java @@ -0,0 +1,37 @@ +package universalelectricity.prefab.potion; + +import net.minecraft.potion.Potion; +import cpw.mods.fml.common.registry.LanguageRegistry; + +public abstract class CustomPotion extends Potion +{ + /** + * Creates a new type of potion + * + * @param id - The ID of this potion. Make it greater than 20. + * @param isBadEffect - Is this potion a good potion or a bad one? + * @param color - The color of this potion. + * @param name - The name of this potion. + */ + public CustomPotion(int id, boolean isBadEffect, int color, String name) + { + super(id, isBadEffect, color); + this.setPotionName("potion." + name); + LanguageRegistry.instance().addStringLocalization(this.getName(), name); + } + + @Override + public Potion setIconIndex(int par1, int par2) + { + super.setIconIndex(par1, par2); + return this; + } + + /** + * You must register all your potion effects during mod initialization! + */ + public void register() + { + Potion.potionTypes[this.getId()] = this; + } +} diff --git a/src/minecraft/universalelectricity/prefab/potion/CustomPotionEffect.java b/src/minecraft/universalelectricity/prefab/potion/CustomPotionEffect.java new file mode 100644 index 000000000..788b623d4 --- /dev/null +++ b/src/minecraft/universalelectricity/prefab/potion/CustomPotionEffect.java @@ -0,0 +1,40 @@ +package universalelectricity.prefab.potion; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.item.ItemStack; +import net.minecraft.potion.Potion; +import net.minecraft.potion.PotionEffect; + +public class CustomPotionEffect extends PotionEffect +{ + public CustomPotionEffect(int potionID, int duration, int amplifier) + { + super(potionID, duration, amplifier); + } + + public CustomPotionEffect(Potion potion, int duration, int amplifier) + { + this(potion.getId(), duration, amplifier); + } + + /** + * Creates a potion effect with custom curable items. + * + * @param curativeItems - ItemStacks that can cure this potion effect + */ + public CustomPotionEffect(int potionID, int duration, int amplifier, List curativeItems) + { + super(potionID, duration, amplifier); + + if (curativeItems == null) + { + this.setCurativeItems(new ArrayList()); + } + else + { + this.setCurativeItems(curativeItems); + } + } +} diff --git a/src/minecraft/universalelectricity/prefab/repair/IRepairable.java b/src/minecraft/universalelectricity/prefab/repair/IRepairable.java new file mode 100644 index 000000000..f16be8251 --- /dev/null +++ b/src/minecraft/universalelectricity/prefab/repair/IRepairable.java @@ -0,0 +1,31 @@ +package universalelectricity.prefab.repair; + +import net.minecraft.entity.player.EntityPlayer; + +/** + * Applied to TileEntities/Machines that can be repaired. + * + * @author Calclavia + * + */ +public interface IRepairable +{ + /** + * Called when the machine is being repaired. + * + * @param itemStack - The repairing tool that the player is holding + * @param player - The player who is repairing this machine. + */ + public void onRepair(IToolRepair itemStack, EntityPlayer player); + + /** + * @return The maximum possible damage of this machine. + */ + public int getMaxDamage(); + + /** + * @return How damaged is this machine? + */ + public int getDamage(); + +} diff --git a/src/minecraft/universalelectricity/prefab/repair/IToolRepair.java b/src/minecraft/universalelectricity/prefab/repair/IToolRepair.java new file mode 100644 index 000000000..abc5ee529 --- /dev/null +++ b/src/minecraft/universalelectricity/prefab/repair/IToolRepair.java @@ -0,0 +1,19 @@ +package universalelectricity.prefab.repair; + +import net.minecraft.item.ItemStack; + +public interface IToolRepair +{ + /** + * A unique ID for mods to recognize what repair tool this is. + */ + public String getID(); + + /** + * How effective is this repairing tool? + * + * @param itemStack The ItemStack + * @return A effectiveness value. + */ + public int getEffectiveness(ItemStack itemStack); +} diff --git a/src/minecraft/universalelectricity/prefab/vector/Region2.java b/src/minecraft/universalelectricity/prefab/vector/Region2.java new file mode 100644 index 000000000..6d52a746c --- /dev/null +++ b/src/minecraft/universalelectricity/prefab/vector/Region2.java @@ -0,0 +1,36 @@ +package universalelectricity.prefab.vector; + +import universalelectricity.core.vector.Vector2; + +public class Region2 +{ + public Vector2 min; + public Vector2 max; + + public Region2() + { + this(new Vector2(), new Vector2()); + } + + public Region2(Vector2 min, Vector2 max) + { + this.min = min; + this.max = max; + } + + /** + * Checks if a point is located inside a region + */ + public boolean isIn(Vector2 point) + { + return (point.x > this.min.x && point.x < this.max.x) && (point.y > this.min.y && point.y < this.max.y); + } + + /** + * Returns whether the given region intersects with this one. + */ + public boolean isIn(Region2 region) + { + return region.max.x > this.min.x && region.min.x < this.max.x ? (region.max.y > this.min.y && region.min.y < this.max.y ? true : false) : false; + } +} diff --git a/src/minecraft/universalelectricity/prefab/vector/Region3.java b/src/minecraft/universalelectricity/prefab/vector/Region3.java new file mode 100644 index 000000000..278a984b2 --- /dev/null +++ b/src/minecraft/universalelectricity/prefab/vector/Region3.java @@ -0,0 +1,131 @@ +package universalelectricity.prefab.vector; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.entity.Entity; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.world.World; +import universalelectricity.core.vector.Vector3; + +/** + * A cubical region class. + * + * @author Calclavia + */ +public class Region3 +{ + public Vector3 min; + public Vector3 max; + + public Region3() + { + this(new Vector3(), new Vector3()); + } + + public Region3(Vector3 min, Vector3 max) + { + this.min = min; + this.max = max; + } + + public Region3(AxisAlignedBB aabb) + { + this.min = new Vector3(aabb.minX, aabb.minY, aabb.minZ); + this.max = new Vector3(aabb.maxX, aabb.maxY, aabb.maxZ); + } + + public AxisAlignedBB toAABB() + { + return AxisAlignedBB.getBoundingBox(this.min.x, this.min.y, this.min.z, this.max.x, this.max.y, this.max.z); + } + + public Region2 toRegion2() + { + return new Region2(this.min.toVector2(), this.max.toVector2()); + } + + /** + * Checks if a point is located inside a region + */ + public boolean isIn(Vector3 point) + { + return (point.x > this.min.x && point.x < this.max.x) && (point.y > this.min.y && point.y < this.max.y) && (point.z > this.min.z && point.z < this.max.z); + } + + /** + * Returns whether the given region intersects with this one. + */ + public boolean isIn(Region3 region) + { + return region.max.x > this.min.x && region.min.x < this.max.x ? (region.max.y > this.min.y && region.min.y < this.max.y ? region.max.z > this.min.z && region.min.z < this.max.z : false) : false; + } + + public void expand(Vector3 difference) + { + this.min.subtract(difference); + this.max.add(difference); + } + + /** + * @return List of vectors within this region. + */ + public List getVectors() + { + List vectors = new ArrayList(); + + for (int x = this.min.intX(); x < this.max.intX(); x++) + { + for (int y = this.min.intY(); x < this.max.intY(); y++) + { + for (int z = this.min.intZ(); x < this.max.intZ(); z++) + { + vectors.add(new Vector3(x, y, z)); + } + } + } + + return vectors; + } + + public List getVectors(Vector3 center, int radius) + { + List vectors = new ArrayList(); + + for (int x = this.min.intX(); x < this.max.intX(); x++) + { + for (int y = this.min.intY(); x < this.max.intY(); y++) + { + for (int z = this.min.intZ(); x < this.max.intZ(); z++) + { + Vector3 vector3 = new Vector3(x, y, z); + + if (center.distanceTo(vector3) <= radius) + { + vectors.add(vector3); + } + } + } + } + + return vectors; + } + + /** + * Returns all entities in this region. + */ + public List getEntities(World world, Class entityClass) + { + return world.getEntitiesWithinAABB(entityClass, this.toAABB()); + } + + public List getEntitiesExlude(World world, Entity entity) + { + return world.getEntitiesWithinAABBExcludingEntity(entity, this.toAABB()); + } + + public List getEntities(World world) + { + return this.getEntities(world, Entity.class); + } +}