From af9ba15c341997f9af94db3ddb659bbb43075d23 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Wed, 9 Dec 2015 20:24:45 +0100 Subject: [PATCH] Miner done! Woop-da-doop --- .../actuallyadditions/blocks/BlockMiner.java | 15 ++- .../inventory/ContainerMiner.java | 99 +++++++++++++++++++ .../inventory/GuiHandler.java | 7 +- .../inventory/gui/GuiMiner.java | 82 +++++++++++++++ .../tile/TileEntityInventoryBase.java | 5 - .../tile/TileEntityMiner.java | 88 +++++++++++------ .../tile/TileEntityPhantomface.java | 5 + .../assets/actuallyadditions/lang/en_US.lang | 1 + 8 files changed, 256 insertions(+), 46 deletions(-) create mode 100644 src/main/java/ellpeck/actuallyadditions/inventory/ContainerMiner.java create mode 100644 src/main/java/ellpeck/actuallyadditions/inventory/gui/GuiMiner.java diff --git a/src/main/java/ellpeck/actuallyadditions/blocks/BlockMiner.java b/src/main/java/ellpeck/actuallyadditions/blocks/BlockMiner.java index 771068be5..e07163163 100644 --- a/src/main/java/ellpeck/actuallyadditions/blocks/BlockMiner.java +++ b/src/main/java/ellpeck/actuallyadditions/blocks/BlockMiner.java @@ -12,7 +12,9 @@ package ellpeck.actuallyadditions.blocks; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import ellpeck.actuallyadditions.ActuallyAdditions; import ellpeck.actuallyadditions.blocks.base.BlockContainerBase; +import ellpeck.actuallyadditions.inventory.GuiHandler; import ellpeck.actuallyadditions.tile.TileEntityMiner; import ellpeck.actuallyadditions.util.ModUtil; import net.minecraft.block.Block; @@ -83,17 +85,12 @@ public class BlockMiner extends BlockContainerBase{ if(tile != null && tile instanceof TileEntityMiner){ if(player.isSneaking()){ player.addChatComponentMessage(new ChatComponentText(((TileEntityMiner)tile).storage.getEnergyStored()+"/"+((TileEntityMiner)tile).storage.getMaxEnergyStored()+" RF")); - player.addChatComponentMessage(new ChatComponentText("Mining at Y = "+((TileEntityMiner)tile).layerAt+".")); + + String info = ((TileEntityMiner)tile).layerAt <= 0 ? "Done Mining!" : "Mining at Y = "+((TileEntityMiner)tile).layerAt+"."; + player.addChatComponentMessage(new ChatComponentText(info)); } else{ - if(!((TileEntityMiner)tile).onlyMineOres){ - player.addChatComponentMessage(new ChatComponentText("Now only mining Ores")); - ((TileEntityMiner)tile).onlyMineOres = true; - } - else{ - player.addChatComponentMessage(new ChatComponentText("Now mining everything")); - ((TileEntityMiner)tile).onlyMineOres = false; - } + player.openGui(ActuallyAdditions.instance, GuiHandler.GuiTypes.MINER.ordinal(), world, x, y, z); } } } diff --git a/src/main/java/ellpeck/actuallyadditions/inventory/ContainerMiner.java b/src/main/java/ellpeck/actuallyadditions/inventory/ContainerMiner.java new file mode 100644 index 000000000..e2c0cbc32 --- /dev/null +++ b/src/main/java/ellpeck/actuallyadditions/inventory/ContainerMiner.java @@ -0,0 +1,99 @@ +/* + * This file ("ContainerMiner.java") is part of the Actually Additions Mod for Minecraft. + * It is created and owned by Ellpeck and distributed + * under the Actually Additions License to be found at + * http://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md + * View the source code at https://github.com/Ellpeck/ActuallyAdditions + * + * © 2015 Ellpeck + */ + +package ellpeck.actuallyadditions.inventory; + +import ellpeck.actuallyadditions.tile.TileEntityBase; +import ellpeck.actuallyadditions.tile.TileEntityMiner; +import invtweaks.api.container.InventoryContainer; +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.ItemStack; + +@InventoryContainer +public class ContainerMiner extends Container{ + + private TileEntityMiner miner; + + public ContainerMiner(InventoryPlayer inventory, TileEntityBase tile){ + this.miner = (TileEntityMiner)tile; + + for(int i = 0; i < 3; i++){ + for(int j = 0; j < 3; j++){ + this.addSlotToContainer(new Slot(this.miner, j+i*3, 62+j*18, 21+i*18)); + } + } + + for(int i = 0; i < 3; i++){ + for(int j = 0; j < 9; j++){ + this.addSlotToContainer(new Slot(inventory, j+i*9+9, 8+j*18, 97+i*18)); + } + } + for(int i = 0; i < 9; i++){ + this.addSlotToContainer(new Slot(inventory, i, 8+i*18, 155)); + } + } + + @Override + public ItemStack transferStackInSlot(EntityPlayer player, int slot){ + final int inventoryStart = 9; + final int inventoryEnd = inventoryStart+26; + final int hotbarStart = inventoryEnd+1; + final int hotbarEnd = hotbarStart+8; + + Slot theSlot = (Slot)this.inventorySlots.get(slot); + + if(theSlot != null && theSlot.getHasStack()){ + ItemStack newStack = theSlot.getStack(); + ItemStack currentStack = newStack.copy(); + + //Other Slots in Inventory excluded + if(slot >= inventoryStart){ + //Shift from Inventory + if(!this.mergeItemStack(newStack, 0, 9, false)){ + // + if(slot >= inventoryStart && slot <= inventoryEnd){ + if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)){ + return null; + } + } + else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)){ + return null; + } + } + } + else if(!this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false)){ + return null; + } + + if(newStack.stackSize == 0){ + theSlot.putStack(null); + } + else{ + theSlot.onSlotChanged(); + } + + if(newStack.stackSize == currentStack.stackSize){ + return null; + } + theSlot.onPickupFromSlot(player, newStack); + + return currentStack; + } + return null; + } + + @Override + public boolean canInteractWith(EntityPlayer player){ + return this.miner.isUseableByPlayer(player); + } +} \ No newline at end of file diff --git a/src/main/java/ellpeck/actuallyadditions/inventory/GuiHandler.java b/src/main/java/ellpeck/actuallyadditions/inventory/GuiHandler.java index 055e576b0..77b8a7ab0 100644 --- a/src/main/java/ellpeck/actuallyadditions/inventory/GuiHandler.java +++ b/src/main/java/ellpeck/actuallyadditions/inventory/GuiHandler.java @@ -85,6 +85,8 @@ public class GuiHandler implements IGuiHandler{ return new ContainerDirectionalBreaker(entityPlayer.inventory, tile); case RANGED_COLLECTOR: return new ContainerRangedCollector(entityPlayer.inventory, tile); + case MINER: + return new ContainerMiner(entityPlayer.inventory, tile); default: return null; } @@ -151,6 +153,8 @@ public class GuiHandler implements IGuiHandler{ return new GuiDirectionalBreaker(entityPlayer.inventory, tile); case RANGED_COLLECTOR: return new GuiRangedCollector(entityPlayer.inventory, tile, x, y, z, world); + case MINER: + return new GuiMiner(entityPlayer.inventory, tile); default: return null; } @@ -183,7 +187,8 @@ public class GuiHandler implements IGuiHandler{ BOOK(false), BOOK_STAND, DIRECTIONAL_BREAKER, - RANGED_COLLECTOR; + RANGED_COLLECTOR, + MINER; public boolean checkTileEntity; diff --git a/src/main/java/ellpeck/actuallyadditions/inventory/gui/GuiMiner.java b/src/main/java/ellpeck/actuallyadditions/inventory/gui/GuiMiner.java new file mode 100644 index 000000000..c5d5cb244 --- /dev/null +++ b/src/main/java/ellpeck/actuallyadditions/inventory/gui/GuiMiner.java @@ -0,0 +1,82 @@ +/* + * This file ("GuiMiner.java") is part of the Actually Additions Mod for Minecraft. + * It is created and owned by Ellpeck and distributed + * under the Actually Additions License to be found at + * http://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md + * View the source code at https://github.com/Ellpeck/ActuallyAdditions + * + * © 2015 Ellpeck + */ + +package ellpeck.actuallyadditions.inventory.gui; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import ellpeck.actuallyadditions.inventory.ContainerMiner; +import ellpeck.actuallyadditions.network.PacketHandler; +import ellpeck.actuallyadditions.network.gui.PacketGuiButton; +import ellpeck.actuallyadditions.tile.TileEntityBase; +import ellpeck.actuallyadditions.tile.TileEntityMiner; +import ellpeck.actuallyadditions.util.AssetUtil; +import ellpeck.actuallyadditions.util.StringUtil; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.opengl.GL11; + +@SideOnly(Side.CLIENT) +public class GuiMiner extends GuiContainer{ + + private static final ResourceLocation resLoc = AssetUtil.getGuiLocation("guiBreaker"); + private TileEntityMiner miner; + + public GuiMiner(InventoryPlayer inventory, TileEntityBase tile){ + super(new ContainerMiner(inventory, tile)); + this.miner = (TileEntityMiner)tile; + this.xSize = 176; + this.ySize = 93+86; + } + + @Override + public void drawScreen(int x, int y, float f){ + super.drawScreen(x, y, f); + } + + @Override + public void drawGuiContainerForegroundLayer(int x, int y){ + AssetUtil.displayNameString(this.fontRendererObj, xSize, -10, this.miner.getInventoryName()); + } + + @Override + public void drawGuiContainerBackgroundLayer(float f, int x, int y){ + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + + this.mc.getTextureManager().bindTexture(AssetUtil.GUI_INVENTORY_LOCATION); + this.drawTexturedModalRect(this.guiLeft, this.guiTop+93, 0, 0, 176, 86); + + this.mc.getTextureManager().bindTexture(resLoc); + this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, 176, 93); + + String mining = this.miner.onlyMineOres ? "Only Mining Ores" : "Mining Everything"; + this.fontRendererObj.drawString(mining, this.guiLeft+this.xSize/2-fontRendererObj.getStringWidth(mining)/2, guiTop+8, StringUtil.DECIMAL_COLOR_GRAY_TEXT); + } + + @SuppressWarnings("unchecked") + @Override + public void initGui(){ + super.initGui(); + + GuiButton buttonMode = new GuiButton(0, guiLeft+xSize/2-51, guiTop+75, 50, 20, "Mode"); + this.buttonList.add(buttonMode); + + GuiButton buttonReset = new GuiButton(1, guiLeft+xSize/2+1, guiTop+75, 50, 20, "Reset"); + this.buttonList.add(buttonReset); + } + + @Override + public void actionPerformed(GuiButton button){ + PacketHandler.theNetwork.sendToServer(new PacketGuiButton(miner.xCoord, miner.yCoord, miner.zCoord, miner.getWorldObj(), button.id, Minecraft.getMinecraft().thePlayer)); + } +} \ No newline at end of file diff --git a/src/main/java/ellpeck/actuallyadditions/tile/TileEntityInventoryBase.java b/src/main/java/ellpeck/actuallyadditions/tile/TileEntityInventoryBase.java index 4a17d9704..08945b55e 100644 --- a/src/main/java/ellpeck/actuallyadditions/tile/TileEntityInventoryBase.java +++ b/src/main/java/ellpeck/actuallyadditions/tile/TileEntityInventoryBase.java @@ -99,11 +99,6 @@ public abstract class TileEntityInventoryBase extends TileEntityBase implements return player.getDistanceSq(xCoord+0.5D, yCoord+0.5D, zCoord+0.5D) <= 64; } - @Override - public boolean isItemValidForSlot(int i, ItemStack stack){ - return false; - } - @Override public ItemStack getStackInSlotOnClosing(int i){ return getStackInSlot(i); diff --git a/src/main/java/ellpeck/actuallyadditions/tile/TileEntityMiner.java b/src/main/java/ellpeck/actuallyadditions/tile/TileEntityMiner.java index c94a9a3c6..5bc3e1b95 100644 --- a/src/main/java/ellpeck/actuallyadditions/tile/TileEntityMiner.java +++ b/src/main/java/ellpeck/actuallyadditions/tile/TileEntityMiner.java @@ -15,49 +15,52 @@ import cofh.api.energy.IEnergyReceiver; import cpw.mods.fml.common.network.NetworkRegistry; import ellpeck.actuallyadditions.network.PacketHandler; import ellpeck.actuallyadditions.network.PacketParticle; +import ellpeck.actuallyadditions.network.gui.IButtonReactor; import ellpeck.actuallyadditions.util.WorldUtil; import net.minecraft.block.Block; -import net.minecraft.inventory.IInventory; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.oredict.OreDictionary; import java.util.ArrayList; -public class TileEntityMiner extends TileEntityBase implements IEnergyReceiver{ +public class TileEntityMiner extends TileEntityInventoryBase implements IEnergyReceiver, IButtonReactor{ public EnergyStorage storage = new EnergyStorage(1000000); - public static final int ENERGY_USE_PER_BLOCK = 300; + public static final int ENERGY_USE_PER_BLOCK = 500; - public int layerAt; + public int layerAt = -1; public boolean onlyMineOres; + public TileEntityMiner(){ + super(9, "miner"); + } + @Override public void updateEntity(){ super.updateEntity(); if(!this.worldObj.isRemote){ - if(this.ticksElapsed%350 == 0){ - if(this.layerAt <= 0){ + if(!this.isRedstonePowered && this.ticksElapsed%5 == 0){ + if(this.layerAt == -1){ this.layerAt = this.yCoord-1; } - if(this.mine(3)){ - this.layerAt--; + if(this.layerAt > 0){ + if(this.mine(TileEntityPhantomface.upgradeRange(2, worldObj, xCoord, yCoord, zCoord))){ + this.layerAt--; + } } } } } private boolean mine(int range){ - TileEntity tileAbove = worldObj.getTileEntity(xCoord, yCoord+1, zCoord); - boolean shouldContinueMining = true; - boolean mined = false; - for(int anX = -range; anX <= range; anX++){ for(int aZ = -range; aZ <= range; aZ++){ - if(this.storage.getEnergyStored() >= ENERGY_USE_PER_BLOCK){ + int actualUse = ENERGY_USE_PER_BLOCK*(this.onlyMineOres ? 3 : 1); + if(this.storage.getEnergyStored() >= actualUse){ int x = this.xCoord+anX; int z = this.zCoord+aZ; int y = this.layerAt; @@ -65,33 +68,30 @@ public class TileEntityMiner extends TileEntityBase implements IEnergyReceiver{ Block block = this.worldObj.getBlock(x, y, z); int meta = this.worldObj.getBlockMetadata(x, y, z); if(block != null && !block.isAir(this.worldObj, x, y, z)){ - if(block.getHarvestLevel(meta) <= 3F && block.getHarvestLevel(meta) >= 0F && this.isMinable(block, meta)){ + if(block.getHarvestLevel(meta) <= 3F && block.getBlockHardness(this.worldObj, x, y, z) >= 0F && this.isMinable(block, meta)){ ArrayList drops = new ArrayList(); drops.addAll(block.getDrops(worldObj, x, y, z, meta, 0)); - if(tileAbove instanceof IInventory && WorldUtil.addToInventory((IInventory)tileAbove, drops, ForgeDirection.DOWN, false)){ + if(WorldUtil.addToInventory(this, drops, ForgeDirection.UNKNOWN, false)){ worldObj.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(block)+(meta << 12)); worldObj.setBlockToAir(x, y, z); - WorldUtil.addToInventory((IInventory)tileAbove, drops, ForgeDirection.DOWN, true); - tileAbove.markDirty(); + WorldUtil.addToInventory(this, drops, ForgeDirection.UNKNOWN, true); + this.markDirty(); - this.storage.extractEnergy(ENERGY_USE_PER_BLOCK, false); - mined = true; - } - else{ - shouldContinueMining = false; + this.storage.extractEnergy(actualUse, false); + this.shootParticles(x, y, z); } + return false; } } } + else{ + return false; + } } } - if(mined){ - this.shootParticles(); - } - - return shouldContinueMining; + return true; } private boolean isMinable(Block block, int meta){ @@ -102,7 +102,7 @@ public class TileEntityMiner extends TileEntityBase implements IEnergyReceiver{ int[] ids = OreDictionary.getOreIDs(new ItemStack(block, 1, meta)); for(int id : ids){ String name = OreDictionary.getOreName(id); - if(name.substring(0, 3).equals("ore")){ + if(name.startsWith("ore") || name.startsWith("denseore")){ return true; } } @@ -110,8 +110,8 @@ public class TileEntityMiner extends TileEntityBase implements IEnergyReceiver{ } } - private void shootParticles(){ - PacketHandler.theNetwork.sendToAllAround(new PacketParticle(xCoord, yCoord, zCoord, xCoord, this.layerAt, zCoord, new float[]{62F/255F, 163F/255F, 74F/255F}, 5, 2.5F), new NetworkRegistry.TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 128)); + private void shootParticles(int endX, int endY, int endZ){ + PacketHandler.theNetwork.sendToAllAround(new PacketParticle(xCoord, yCoord, zCoord, endX, endY, endZ, new float[]{62F/255F, 163F/255F, 74F/255F}, 5, 1.0F), new NetworkRegistry.TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 96)); } @Override @@ -149,4 +149,30 @@ public class TileEntityMiner extends TileEntityBase implements IEnergyReceiver{ public boolean canConnectEnergy(ForgeDirection from){ return true; } + + @Override + public boolean canInsertItem(int slot, ItemStack stack, int side){ + return this.isItemValidForSlot(slot, stack); + } + + @Override + public boolean canExtractItem(int slot, ItemStack stack, int side){ + return true; + } + + @Override + public boolean isItemValidForSlot(int slot, ItemStack stack){ + return false; + } + + @Override + public void onButtonPressed(int buttonID, EntityPlayer player){ + if(buttonID == 0){ + this.onlyMineOres = !this.onlyMineOres; + this.sendUpdate(); + } + else if(buttonID == 1){ + this.layerAt = -1; + } + } } diff --git a/src/main/java/ellpeck/actuallyadditions/tile/TileEntityPhantomface.java b/src/main/java/ellpeck/actuallyadditions/tile/TileEntityPhantomface.java index 790845df0..ccb0a55b7 100644 --- a/src/main/java/ellpeck/actuallyadditions/tile/TileEntityPhantomface.java +++ b/src/main/java/ellpeck/actuallyadditions/tile/TileEntityPhantomface.java @@ -167,4 +167,9 @@ public class TileEntityPhantomface extends TileEntityInventoryBase implements IP public boolean canExtractItem(int slot, ItemStack stack, int side){ return false; } + + @Override + public boolean isItemValidForSlot(int slot, ItemStack stack){ + return false; + } } diff --git a/src/main/resources/assets/actuallyadditions/lang/en_US.lang b/src/main/resources/assets/actuallyadditions/lang/en_US.lang index e300c7a97..ae6c87c53 100644 --- a/src/main/resources/assets/actuallyadditions/lang/en_US.lang +++ b/src/main/resources/assets/actuallyadditions/lang/en_US.lang @@ -399,6 +399,7 @@ container.actuallyadditions.xpSolidifier.name=Experience Solidifier container.actuallyadditions.cloud.name=Smiley Cloud container.actuallyadditions.directionalBreaker.name=Long-Range Breaker container.actuallyadditions.rangedCollector.name=Ranged Collector +container.actuallyadditions.miner.name=Vertical Digger #Update Information info.actuallyadditions.update.generic=[{"text":"There is an Update for "},{"text":"Actually Additions ","color":"dark_green"},{"text":"available!","color":"none"}]