Miner done!

Woop-da-doop
This commit is contained in:
Ellpeck 2015-12-09 20:24:45 +01:00
parent 0280dc53a8
commit af9ba15c34
8 changed files with 256 additions and 46 deletions

View file

@ -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);
}
}
}

View file

@ -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);
}
}

View file

@ -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;

View file

@ -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));
}
}

View file

@ -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);

View file

@ -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<ItemStack> drops = new ArrayList<ItemStack>();
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;
}
}
}

View file

@ -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;
}
}

View file

@ -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"}]