Refactoring tile entities & gui, balancing conduit recipes.

master
Droog71 2020-08-13 20:01:19 -04:00
parent 0d9ec80c65
commit f23c7b547b
13 changed files with 232 additions and 418 deletions

View File

@ -21,8 +21,8 @@ public class BioGenGUI extends GuiContainer
public BioGenGUI(InventoryPlayer playerInv, IInventory bioGenInv)
{
super(new BioGenContainer(playerInv, bioGenInv));
this.playerInventory = playerInv;
this.tileBioGen = bioGenInv;
playerInventory = playerInv;
tileBioGen = bioGenInv;
}
/**
@ -31,9 +31,9 @@ public class BioGenGUI extends GuiContainer
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
this.drawDefaultBackground();
drawDefaultBackground();
super.drawScreen(mouseX, mouseY, partialTicks);
this.renderHoveredToolTip(mouseX, mouseY);
renderHoveredToolTip(mouseX, mouseY);
}
/**
@ -42,9 +42,9 @@ public class BioGenGUI extends GuiContainer
@Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
{
String s = this.tileBioGen.getName();
this.fontRenderer.drawString(s, this.xSize / 2 - this.fontRenderer.getStringWidth(s) / 2, 6, 4210752);
this.fontRenderer.drawString(this.playerInventory.getDisplayName().getUnformattedText(), 8, this.ySize - 96 + 2, 4210752);
String s = tileBioGen.getName();
fontRenderer.drawString(s, xSize / 2 - fontRenderer.getStringWidth(s) / 2, 6, 4210752);
fontRenderer.drawString(playerInventory.getDisplayName().getUnformattedText(), 8, ySize - 96 + 2, 4210752);
}
/**
@ -54,37 +54,30 @@ public class BioGenGUI extends GuiContainer
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY)
{
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(BIO_GEN_GUI_TEXTURES);
int i = (this.width - this.xSize) / 2;
int j = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(i, j, 0, 0, this.xSize, this.ySize);
mc.getTextureManager().bindTexture(BIO_GEN_GUI_TEXTURES);
int i = (width - xSize) / 2;
int j = (height - ySize) / 2;
drawTexturedModalRect(i, j, 0, 0, xSize, ySize);
if (BioGenTileEntity.isEnergized(this.tileBioGen))
if (BioGenTileEntity.isEnergized(tileBioGen))
{
int k = this.getPowerScaled(13);
this.drawTexturedModalRect(i + 56, j + 36 + 12 - k, 176, 12 - k, 14, k + 1);
int k = getPowerScaled(13);
drawTexturedModalRect(i + 56, j + 36 + 12 - k, 176, 12 - k, 14, k + 1);
}
int h = this.getBurnProgressScaled(16);
this.drawTexturedModalRect(i + 79, j + 34, 176, 14, 24, h + 1);
int h = getBurnProgressScaled(16);
drawTexturedModalRect(i + 79, j + 34, 176, 14, 24, h + 1);
}
private int getBurnProgressScaled(int pixels)
{
int i = this.tileBioGen.getField(2);
int j = this.tileBioGen.getField(3);
int i = tileBioGen.getField(2);
int j = tileBioGen.getField(3);
return j != 0 && i != 0 ? i * pixels / j : 16;
}
private int getPowerScaled(int pixels)
{
int i = this.tileBioGen.getField(1);
if (i == 0)
{
i = 200;
}
return this.tileBioGen.getField(0) * pixels / i;
return tileBioGen.getField(0) * pixels / tileBioGen.getField(1);
}
}

View File

@ -22,8 +22,8 @@ public class ExtruderGUI extends GuiContainer
public ExtruderGUI(InventoryPlayer playerInv, IInventory extruderInv)
{
super(new ExtruderContainer(playerInv, extruderInv));
this.playerInventory = playerInv;
this.tileExtruder = extruderInv;
playerInventory = playerInv;
tileExtruder = extruderInv;
}
/**
@ -32,9 +32,9 @@ public class ExtruderGUI extends GuiContainer
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
this.drawDefaultBackground();
drawDefaultBackground();
super.drawScreen(mouseX, mouseY, partialTicks);
this.renderHoveredToolTip(mouseX, mouseY);
renderHoveredToolTip(mouseX, mouseY);
}
/**
@ -43,9 +43,9 @@ public class ExtruderGUI extends GuiContainer
@Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
{
String s = this.tileExtruder.getName();
this.fontRenderer.drawString(s, this.xSize / 2 - this.fontRenderer.getStringWidth(s) / 2, 6, 4210752);
this.fontRenderer.drawString(this.playerInventory.getDisplayName().getUnformattedText(), 8, this.ySize - 96 + 2, 4210752);
String s = tileExtruder.getName();
fontRenderer.drawString(s, xSize / 2 - fontRenderer.getStringWidth(s) / 2, 6, 4210752);
fontRenderer.drawString(playerInventory.getDisplayName().getUnformattedText(), 8, ySize - 96 + 2, 4210752);
}
/**
@ -55,37 +55,30 @@ public class ExtruderGUI extends GuiContainer
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY)
{
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(EXTRUDER_GUI_TEXTURES);
int i = (this.width - this.xSize) / 2;
int j = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(i, j, 0, 0, this.xSize, this.ySize);
mc.getTextureManager().bindTexture(EXTRUDER_GUI_TEXTURES);
int i = (width - xSize) / 2;
int j = (height - ySize) / 2;
drawTexturedModalRect(i, j, 0, 0, xSize, ySize);
if (ExtruderTileEntity.isEnergized(this.tileExtruder))
if (ExtruderTileEntity.isEnergized(tileExtruder))
{
int k = this.getPowerScaled(13);
this.drawTexturedModalRect(i + 56, j + 36 + 12 - k, 176, 12 - k, 14, k + 1);
int k = getPowerScaled(13);
drawTexturedModalRect(i + 56, j + 36 + 12 - k, 176, 12 - k, 14, k + 1);
}
int l = this.getExtrustionProgressScaled(24);
this.drawTexturedModalRect(i + 79, j + 34, 176, 14, l + 1, 16);
int l = getExtrustionProgressScaled(24);
drawTexturedModalRect(i + 79, j + 34, 176, 14, l + 1, 16);
}
private int getExtrustionProgressScaled(int pixels)
{
int i = this.tileExtruder.getField(2);
int j = this.tileExtruder.getField(3);
int i = tileExtruder.getField(2);
int j = tileExtruder.getField(3);
return j != 0 && i != 0 ? i * pixels / j : 0;
}
private int getPowerScaled(int pixels)
{
int i = this.tileExtruder.getField(1);
if (i == 0)
{
i = 200;
}
return this.tileExtruder.getField(0) * pixels / i;
return tileExtruder.getField(0) * pixels / tileExtruder.getField(1);
}
}

View File

@ -22,8 +22,8 @@ public class FabricatorGUI extends GuiContainer
public FabricatorGUI(InventoryPlayer playerInv, IInventory fabricatorInv)
{
super(new FabricatorContainer(playerInv, fabricatorInv));
this.playerInventory = playerInv;
this.tileFabricator = fabricatorInv;
playerInventory = playerInv;
tileFabricator = fabricatorInv;
}
/**
@ -32,9 +32,9 @@ public class FabricatorGUI extends GuiContainer
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
this.drawDefaultBackground();
drawDefaultBackground();
super.drawScreen(mouseX, mouseY, partialTicks);
this.renderHoveredToolTip(mouseX, mouseY);
renderHoveredToolTip(mouseX, mouseY);
}
/**
@ -43,9 +43,9 @@ public class FabricatorGUI extends GuiContainer
@Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
{
String s = this.tileFabricator.getName();
this.fontRenderer.drawString(s, this.xSize / 2 - this.fontRenderer.getStringWidth(s) / 2, 6, 4210752);
this.fontRenderer.drawString(this.playerInventory.getDisplayName().getUnformattedText(), 8, this.ySize - 96 + 2, 4210752);
String s = tileFabricator.getName();
fontRenderer.drawString(s, xSize / 2 - fontRenderer.getStringWidth(s) / 2, 6, 4210752);
fontRenderer.drawString(playerInventory.getDisplayName().getUnformattedText(), 8, ySize - 96 + 2, 4210752);
}
/**
@ -55,37 +55,30 @@ public class FabricatorGUI extends GuiContainer
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY)
{
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(FABRICATOR_GUI_TEXTURES);
int i = (this.width - this.xSize) / 2;
int j = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(i, j, 0, 0, this.xSize, this.ySize);
mc.getTextureManager().bindTexture(FABRICATOR_GUI_TEXTURES);
int i = (width - xSize) / 2;
int j = (height - ySize) / 2;
drawTexturedModalRect(i, j, 0, 0, xSize, ySize);
if (FabricatorTileEntity.isEnergized(this.tileFabricator))
if (FabricatorTileEntity.isEnergized(tileFabricator))
{
int k = this.getPowerScaled(13);
this.drawTexturedModalRect(i + 56, j + 36 + 12 - k, 176, 12 - k, 14, k + 1);
int k = getPowerScaled(13);
drawTexturedModalRect(i + 56, j + 36 + 12 - k, 176, 12 - k, 14, k + 1);
}
int l = this.getFabricationProgressScaled(24);
this.drawTexturedModalRect(i + 79, j + 34, 176, 14, l + 1, 16);
int l = getFabricationProgressScaled(24);
drawTexturedModalRect(i + 79, j + 34, 176, 14, l + 1, 16);
}
private int getFabricationProgressScaled(int pixels)
{
int i = this.tileFabricator.getField(2);
int j = this.tileFabricator.getField(3);
int i = tileFabricator.getField(2);
int j = tileFabricator.getField(3);
return j != 0 && i != 0 ? i * pixels / j : 0;
}
private int getPowerScaled(int pixels)
{
int i = this.tileFabricator.getField(1);
if (i == 0)
{
i = 200;
}
return this.tileFabricator.getField(0) * pixels / i;
return tileFabricator.getField(0) * pixels / tileFabricator.getField(1);
}
}

View File

@ -22,8 +22,8 @@ public class LaunchPadGUI extends GuiContainer
public LaunchPadGUI(InventoryPlayer playerInv, IInventory launchpadInv)
{
super(new LaunchPadContainer(playerInv, launchpadInv));
this.playerInventory = playerInv;
this.tileLaunchPad = launchpadInv;
playerInventory = playerInv;
tileLaunchPad = launchpadInv;
}
/**
@ -32,9 +32,9 @@ public class LaunchPadGUI extends GuiContainer
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
this.drawDefaultBackground();
drawDefaultBackground();
super.drawScreen(mouseX, mouseY, partialTicks);
this.renderHoveredToolTip(mouseX, mouseY);
renderHoveredToolTip(mouseX, mouseY);
}
/**
@ -43,9 +43,9 @@ public class LaunchPadGUI extends GuiContainer
@Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
{
String s = this.tileLaunchPad.getName();
this.fontRenderer.drawString(s, this.xSize / 2 - this.fontRenderer.getStringWidth(s) / 2, 6, 4210752);
this.fontRenderer.drawString(this.playerInventory.getDisplayName().getUnformattedText(), 8, this.ySize - 96 + 2, 4210752);
String s = tileLaunchPad.getName();
fontRenderer.drawString(s, xSize / 2 - fontRenderer.getStringWidth(s) / 2, 6, 4210752);
fontRenderer.drawString(playerInventory.getDisplayName().getUnformattedText(), 8, ySize - 96 + 2, 4210752);
}
/**
@ -55,37 +55,30 @@ public class LaunchPadGUI extends GuiContainer
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY)
{
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(LAUNCHPAD_GUI_TEXTURES);
int i = (this.width - this.xSize) / 2;
int j = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(i, j, 0, 0, this.xSize, this.ySize);
mc.getTextureManager().bindTexture(LAUNCHPAD_GUI_TEXTURES);
int i = (width - xSize) / 2;
int j = (height - ySize) / 2;
drawTexturedModalRect(i, j, 0, 0, xSize, ySize);
if (LaunchPadTileEntity.isEnergized(this.tileLaunchPad))
if (LaunchPadTileEntity.isEnergized(tileLaunchPad))
{
int k = this.getPowerScaled(13);
this.drawTexturedModalRect(i + 56, j + 36 + 12 - k, 176, 12 - k, 14, k + 1);
int k = getPowerScaled(13);
drawTexturedModalRect(i + 56, j + 36 + 12 - k, 176, 12 - k, 14, k + 1);
}
int l = this.getLaunchProgressScaled(24);
this.drawTexturedModalRect(i + 79, j + 34, 176, 14, l + 1, 16);
int l = getLaunchProgressScaled(24);
drawTexturedModalRect(i + 79, j + 34, 176, 14, l + 1, 16);
}
private int getLaunchProgressScaled(int pixels)
{
int i = this.tileLaunchPad.getField(2);
int j = this.tileLaunchPad.getField(3);
int i = tileLaunchPad.getField(2);
int j = tileLaunchPad.getField(3);
return j != 0 && i != 0 ? i * pixels / j : 0;
}
private int getPowerScaled(int pixels)
{
int i = this.tileLaunchPad.getField(1);
if (i == 0)
{
i = 200;
}
return this.tileLaunchPad.getField(0) * pixels / i;
return tileLaunchPad.getField(0) * pixels / tileLaunchPad.getField(1);
}
}

View File

@ -22,8 +22,8 @@ public class PressGUI extends GuiContainer
public PressGUI(InventoryPlayer playerInv, IInventory pressInv)
{
super(new PressContainer(playerInv, pressInv));
this.playerInventory = playerInv;
this.tilePress = pressInv;
playerInventory = playerInv;
tilePress = pressInv;
}
/**
@ -32,9 +32,9 @@ public class PressGUI extends GuiContainer
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
this.drawDefaultBackground();
drawDefaultBackground();
super.drawScreen(mouseX, mouseY, partialTicks);
this.renderHoveredToolTip(mouseX, mouseY);
renderHoveredToolTip(mouseX, mouseY);
}
/**
@ -43,9 +43,9 @@ public class PressGUI extends GuiContainer
@Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
{
String s = this.tilePress.getName();
this.fontRenderer.drawString(s, this.xSize / 2 - this.fontRenderer.getStringWidth(s) / 2, 6, 4210752);
this.fontRenderer.drawString(this.playerInventory.getDisplayName().getUnformattedText(), 8, this.ySize - 96 + 2, 4210752);
String s = tilePress.getName();
fontRenderer.drawString(s, xSize / 2 - fontRenderer.getStringWidth(s) / 2, 6, 4210752);
fontRenderer.drawString(playerInventory.getDisplayName().getUnformattedText(), 8, ySize - 96 + 2, 4210752);
}
/**
@ -55,37 +55,30 @@ public class PressGUI extends GuiContainer
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY)
{
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(PRESS_GUI_TEXTURES);
int i = (this.width - this.xSize) / 2;
int j = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(i, j, 0, 0, this.xSize, this.ySize);
mc.getTextureManager().bindTexture(PRESS_GUI_TEXTURES);
int i = (width - xSize) / 2;
int j = (height - ySize) / 2;
drawTexturedModalRect(i, j, 0, 0, xSize, ySize);
if (PressTileEntity.isEnergized(this.tilePress))
if (PressTileEntity.isEnergized(tilePress))
{
int k = this.getPowerScaled(13);
this.drawTexturedModalRect(i + 56, j + 36 + 12 - k, 176, 12 - k, 14, k + 1);
int k = getPowerScaled(13);
drawTexturedModalRect(i + 56, j + 36 + 12 - k, 176, 12 - k, 14, k + 1);
}
int l = this.getPressProgressScaled(24);
this.drawTexturedModalRect(i + 79, j + 34, 176, 14, l + 1, 16);
int l = getPressProgressScaled(24);
drawTexturedModalRect(i + 79, j + 34, 176, 14, l + 1, 16);
}
private int getPressProgressScaled(int pixels)
{
int i = this.tilePress.getField(2);
int j = this.tilePress.getField(3);
int i = tilePress.getField(2);
int j = tilePress.getField(3);
return j != 0 && i != 0 ? i * pixels / j : 0;
}
private int getPowerScaled(int pixels)
{
int i = this.tilePress.getField(1);
if (i == 0)
{
i = 200;
}
return this.tilePress.getField(0) * pixels / i;
return tilePress.getField(0) * pixels / tilePress.getField(1);
}
}

View File

@ -22,8 +22,8 @@ public class ReplicatorGUI extends GuiContainer
public ReplicatorGUI(InventoryPlayer playerInv, IInventory replicatorInv)
{
super(new ReplicatorContainer(playerInv, replicatorInv));
this.playerInventory = playerInv;
this.tileReplicator = replicatorInv;
playerInventory = playerInv;
tileReplicator = replicatorInv;
}
/**
@ -32,9 +32,9 @@ public class ReplicatorGUI extends GuiContainer
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
this.drawDefaultBackground();
drawDefaultBackground();
super.drawScreen(mouseX, mouseY, partialTicks);
this.renderHoveredToolTip(mouseX, mouseY);
renderHoveredToolTip(mouseX, mouseY);
}
/**
@ -43,9 +43,9 @@ public class ReplicatorGUI extends GuiContainer
@Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
{
String s = this.tileReplicator.getName();
this.fontRenderer.drawString(s, this.xSize / 2 - this.fontRenderer.getStringWidth(s) / 2, 6, 4210752);
this.fontRenderer.drawString(this.playerInventory.getDisplayName().getUnformattedText(), 8, this.ySize - 96 + 2, 4210752);
String s = tileReplicator.getName();
fontRenderer.drawString(s, xSize / 2 - fontRenderer.getStringWidth(s) / 2, 6, 4210752);
fontRenderer.drawString(playerInventory.getDisplayName().getUnformattedText(), 8, ySize - 96 + 2, 4210752);
}
/**
@ -55,37 +55,30 @@ public class ReplicatorGUI extends GuiContainer
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY)
{
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(REPLICATOR_GUI_TEXTURES);
int i = (this.width - this.xSize) / 2;
int j = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(i, j, 0, 0, this.xSize, this.ySize);
mc.getTextureManager().bindTexture(REPLICATOR_GUI_TEXTURES);
int i = (width - xSize) / 2;
int j = (height - ySize) / 2;
drawTexturedModalRect(i, j, 0, 0, xSize, ySize);
if (ReplicatorTileEntity.isEnergized(this.tileReplicator))
if (ReplicatorTileEntity.isEnergized(tileReplicator))
{
int k = this.getPowerScaled(13);
this.drawTexturedModalRect(i + 56, j + 36 + 12 - k, 176, 12 - k, 14, k + 1);
int k = getPowerScaled(13);
drawTexturedModalRect(i + 56, j + 36 + 12 - k, 176, 12 - k, 14, k + 1);
}
int l = this.getReplicationProgressScaled(24);
this.drawTexturedModalRect(i + 79, j + 34, 176, 14, l + 1, 16);
int l = getReplicationProgressScaled(24);
drawTexturedModalRect(i + 79, j + 34, 176, 14, l + 1, 16);
}
private int getReplicationProgressScaled(int pixels)
{
int i = this.tileReplicator.getField(2);
int j = this.tileReplicator.getField(3);
int i = tileReplicator.getField(2);
int j = tileReplicator.getField(3);
return j != 0 && i != 0 ? i * pixels / j : 0;
}
private int getPowerScaled(int pixels)
{
int i = this.tileReplicator.getField(4);
if (i == 0)
{
i = 200;
}
return this.tileReplicator.getField(5) * pixels / i;
return tileReplicator.getField(5) * pixels / tileReplicator.getField(4);
}
}

View File

@ -8,9 +8,6 @@ import com.droog71.prospect.init.ProspectSounds;
import com.droog71.prospect.inventory.FabricatorContainer;
import com.droog71.prospect.items.Schematic;
import ic2.api.energy.prefab.BasicSink;
import net.minecraft.block.Block;
import net.minecraft.block.BlockChest;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.init.Items;
@ -22,16 +19,12 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityChest;
import net.minecraft.util.EntitySelectors;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable;
import net.minecraft.util.NonNullList;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.fml.common.Loader;
@ -468,62 +461,38 @@ public class FabricatorTileEntity extends TileEntity implements ITickable, ISide
// Returns an adjacent inventory containing the necessary ingredients for the current schematic
public IInventory getInventoryForCrafting(ItemStack[] stacks)
{
List<IInventory> invList = new ArrayList<IInventory>();
List<IInventory> inventoryList = new ArrayList<IInventory>();
BlockPos[] positions = {pos.add(0,1,0),pos.add(0,-1,0),pos.add(1,0,0),pos.add(-1,0,0),pos.add(0,0,1),pos.add(0,0,-1)};
for (BlockPos p : positions)
{
invList.add(getInventoryAtPosition(world,p.getX(),p.getY(),p.getZ()));
}
for (IInventory inventory : invList)
{
IInventory inventory = getInventoryAtPosition(p);
if (inventory != null)
{
if (canCraft(stacks,inventory))
{
return inventory;
}
{
inventoryList.add(inventory);
}
}
for (IInventory inventory : inventoryList)
{
if (canCraft(stacks,inventory))
{
return inventory;
}
}
return null;
}
// Returns IInventory instance at a given position
public static IInventory getInventoryAtPosition(World worldIn, double x, double y, double z)
public IInventory getInventoryAtPosition(BlockPos blockpos)
{
IInventory iinventory = null;
int i = MathHelper.floor(x);
int j = MathHelper.floor(y);
int k = MathHelper.floor(z);
BlockPos blockpos = new BlockPos(i, j, k);
net.minecraft.block.state.IBlockState state = worldIn.getBlockState(blockpos);
Block block = state.getBlock();
if (block.hasTileEntity(state))
TileEntity tileentity = world.getTileEntity(blockpos);
if (tileentity != null)
{
TileEntity tileentity = worldIn.getTileEntity(blockpos);
if (tileentity instanceof IInventory)
{
iinventory = (IInventory)tileentity;
if (iinventory instanceof TileEntityChest && block instanceof BlockChest)
{
iinventory = ((BlockChest)block).getContainer(worldIn, blockpos, true);
}
return (IInventory)tileentity;
}
}
if (iinventory == null)
{
List<Entity> list = worldIn.getEntitiesInAABBexcluding((Entity)null, new AxisAlignedBB(x - 0.5D, y - 0.5D, z - 0.5D, x + 0.5D, y + 0.5D, z + 0.5D), EntitySelectors.HAS_INVENTORY);
if (!list.isEmpty())
{
iinventory = (IInventory)list.get(worldIn.rand.nextInt(list.size()));
}
}
return iinventory;
return null;
}
/**

View File

@ -8,15 +8,11 @@ import com.droog71.prospect.forge_energy.ProspectEnergyStorage;
import com.droog71.prospect.init.ProspectBlocks;
import com.droog71.prospect.init.ProspectSounds;
import ic2.api.energy.prefab.BasicSink;
import net.minecraft.util.EntitySelectors;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.ITickable;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.energy.CapabilityEnergy;
@ -24,20 +20,33 @@ import net.minecraftforge.fluids.BlockFluidBase;
import net.minecraftforge.fluids.IFluidBlock;
import net.minecraftforge.fml.common.Loader;
import net.minecraft.block.Block;
import net.minecraft.block.BlockChest;
import net.minecraft.block.BlockLiquid;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityChest;
final class QuarryStorage
{
public IInventory inventory;
public ItemStack depositStack;
public int depositIndex;
public boolean combining;
public int amount;
public QuarryStorage(IInventory inventory, ItemStack depositStack, int depositIndex, boolean combining, int amount)
{
this.inventory = inventory;
this.depositStack = depositStack;
this.depositIndex = depositIndex;
this.combining = combining;
this.amount = amount;
}
}
public class QuarryTileEntity extends TileEntity implements ITickable
{
@ -47,14 +56,12 @@ public class QuarryTileEntity extends TileEntity implements ITickable
private int miningX = 100000000;
private int miningZ = 100000000;
private boolean quarryFinished;
private boolean overflow;
private IInventory currentInventory;
private int energyStored;
private boolean miningBlock;
private Object ic2EnergySink;
private ProspectEnergyStorage energyStorage = new ProspectEnergyStorage();
public List<BlockPos> quarryPositions = new ArrayList<BlockPos>();
@Override
public void onLoad()
{
@ -163,53 +170,19 @@ public class QuarryTileEntity extends TileEntity implements ITickable
// Puts mined blocks and items into adjacent storage
private void transferItemOut(ItemStack stack)
{
IInventory iinventory = getInventoryForTransfer();
if (iinventory != null)
{
if (!isInventoryFull(iinventory))
QuarryStorage quarryStorage = getQuarryStorage(stack);
if (quarryStorage != null)
{
if (quarryStorage.combining == true)
{
if (!isLiquid(stack))
{
int size = iinventory.getSizeInventory();
boolean flag = false;
for (int index = 0; index < size; ++index)
{
ItemStack itemstack = iinventory.getStackInSlot(index);
if (itemstack.isEmpty())
{
iinventory.setInventorySlotContents(index, stack);
stack = ItemStack.EMPTY;
flag = true;
}
else if (canCombine(itemstack, stack))
{
int i = stack.getMaxStackSize() - itemstack.getCount();
int j = Math.min(stack.getCount(), i);
stack.shrink(j);
itemstack.grow(j);
flag = j > 0;
}
}
if (flag)
{
overflow = false;
iinventory.markDirty();
}
else
{
overflow = true;
WorldServer w = (WorldServer) world;
EntityItem item = new EntityItem(w, pos.getX(), pos.getY(), pos.getZ(), stack);
w.spawnEntity(item);
}
}
stack.shrink(quarryStorage.amount);
quarryStorage.depositStack.grow(quarryStorage.amount);
}
else
else
{
WorldServer w = (WorldServer) world;
EntityItem item = new EntityItem(w, pos.getX(), pos.getY(), pos.getZ(), stack);
w.spawnEntity(item);
}
quarryStorage.inventory.setInventorySlotContents(quarryStorage.depositIndex, stack);
stack = ItemStack.EMPTY;
}
}
else
{
@ -253,138 +226,59 @@ public class QuarryTileEntity extends TileEntity implements ITickable
return ItemStack.areItemStackTagsEqual(stack1, stack2);
}
}
// Checks if given inventory is full
private boolean isInventoryFull(IInventory inventoryIn)
{
if (inventoryIn instanceof ISidedInventory)
{
return true;
}
else
{
int i = inventoryIn.getSizeInventory();
for (int j = 0; j < i; ++j)
{
ItemStack itemstack = inventoryIn.getStackInSlot(j);
if (itemstack.isEmpty() || itemstack.getCount() != itemstack.getMaxStackSize())
{
return false;
}
}
}
return true;
}
// Checks if given inventory has any empty slots
private boolean inventoryHasEmptySlot(IInventory inventoryIn)
{
if (inventoryIn instanceof ISidedInventory)
{
return false;
}
else
{
int i = inventoryIn.getSizeInventory();
for (int j = 0; j < i; ++j)
{
ItemStack itemstack = inventoryIn.getStackInSlot(j);
if (itemstack.isEmpty())
{
return true;
}
}
}
return false;
}
// The adjacent inventory the quarry will use to transfer items out
public IInventory getInventoryForTransfer()
public QuarryStorage getQuarryStorage(ItemStack stack)
{
List<IInventory> invList = new ArrayList<IInventory>();
BlockPos[] positions = {pos.add(0,1,0),pos.add(0,-1,0),pos.add(1,0,0),pos.add(-1,0,0),pos.add(0,0,1),pos.add(0,0,-1)};
for (BlockPos p : positions)
if (!isLiquid(stack))
{
invList.add(getInventoryAtPosition(world,p.getX(),p.getY(),p.getZ()));
}
for (IInventory inventory : invList)
{
if (inventory != null)
{
if (!isInventoryFull(inventory))
{
if (currentInventory != null)
{
if (overflow)
{
if (currentInventory != inventory)
{
if (inventoryHasEmptySlot(inventory))
{
currentInventory = inventory;
return inventory;
}
}
}
else
{
if (currentInventory == inventory)
{
currentInventory = inventory;
return inventory;
}
}
}
else
{
currentInventory = inventory;
return inventory;
}
}
}
BlockPos[] positions = {pos.add(0,1,0),pos.add(0,-1,0),pos.add(1,0,0),pos.add(-1,0,0),pos.add(0,0,1),pos.add(0,0,-1)};
List<IInventory> inventoryList = new ArrayList<IInventory>();
for (BlockPos p : positions)
{
IInventory inventory = getInventoryAtPosition(p);
if (inventory != null)
{
inventoryList.add(inventory);
}
}
for (IInventory inventory : inventoryList)
{
int size = inventory.getSizeInventory();
for (int index = 0; index < size; ++index)
{
ItemStack itemstack = inventory.getStackInSlot(index);
if (itemstack.isEmpty())
{
return new QuarryStorage(inventory, itemstack, index, false, 0);
}
else if (canCombine(itemstack, stack))
{
int i = stack.getMaxStackSize() - itemstack.getCount();
int j = Math.min(stack.getCount(), i);
if (j > 0)
{
return new QuarryStorage(inventory, itemstack, 0, true, j);
}
}
}
}
}
return null;
}
// Returns instance of IInventory at a given position
public static IInventory getInventoryAtPosition(World worldIn, double x, double y, double z)
// Returns IInventory instance at a given position
public IInventory getInventoryAtPosition(BlockPos blockpos)
{
IInventory iinventory = null;
int i = MathHelper.floor(x);
int j = MathHelper.floor(y);
int k = MathHelper.floor(z);
BlockPos blockpos = new BlockPos(i, j, k);
net.minecraft.block.state.IBlockState state = worldIn.getBlockState(blockpos);
Block block = state.getBlock();
if (block.hasTileEntity(state))
TileEntity tileentity = world.getTileEntity(blockpos);
if (tileentity != null)
{
TileEntity tileentity = worldIn.getTileEntity(blockpos);
if (tileentity instanceof IInventory)
{
iinventory = (IInventory)tileentity;
if (iinventory instanceof TileEntityChest && block instanceof BlockChest)
{
iinventory = ((BlockChest)block).getContainer(worldIn, blockpos, true);
}
return (IInventory)tileentity;
}
}
if (iinventory == null)
{
List<Entity> list = worldIn.getEntitiesInAABBexcluding((Entity)null, new AxisAlignedBB(x - 0.5D, y - 0.5D, z - 0.5D, x + 0.5D, y + 0.5D, z + 0.5D), EntitySelectors.HAS_INVENTORY);
if (!list.isEmpty())
{
iinventory = (IInventory)list.get(worldIn.rand.nextInt(list.size()));
}
}
return iinventory;
return null;
}
// Sets the starting position for the quarry
@ -498,7 +392,7 @@ public class QuarryTileEntity extends TileEntity implements ITickable
// Mines blocks, places quarry frames, tubes and drills
private void mineBlock(Block b, BlockPos p)
{
ItemStack stack = new ItemStack(Items.AIR);
ItemStack stack = ItemStack.EMPTY;
Item itemDropped = b.getItemDropped(b.getDefaultState(), new Random(), 0);
if (itemDropped != Item.getItemFromBlock(b))
{
@ -507,8 +401,9 @@ public class QuarryTileEntity extends TileEntity implements ITickable
else
{
stack = new ItemStack(Item.getItemFromBlock(b)); //All other blocks.
}
if (stack.getItem() != Items.AIR)
}
if (stack != ItemStack.EMPTY)
{
transferItemOut(stack); //Put the item collected in an adjacent storage container.
}
@ -549,14 +444,7 @@ public class QuarryTileEntity extends TileEntity implements ITickable
}
else
{
miningBlock = true; //A block will be removed at this position.
if (world.getBlockState(p).getBlock() != Blocks.AIR)
{
//Play sound and spawn particles at each block mined.
playMiningSound(p);
WorldServer w = (WorldServer) world;
w.spawnParticle(EnumParticleTypes.EXPLOSION_LARGE, p.getX(), p.getY(), p.getZ(), 1, 0, 0, 0, 1, null);
}
miningBlock = true; //A block will be removed at this position.
}
world.setBlockState(p, ProspectBlocks.quarry_drill.getDefaultState()); //Move the drill down to the next level.
world.getBlockState(p).getBlock().setHardness(1000.0f);
@ -564,6 +452,13 @@ public class QuarryTileEntity extends TileEntity implements ITickable
if (miningBlock == true)
{
//Remove the old drill block.
if (world.getBlockState(p).getBlock() != Blocks.AIR)
{
//Play sound and spawn particles at each block mined.
playMiningSound(p);
WorldServer w = (WorldServer) world;
w.spawnParticle(EnumParticleTypes.EXPLOSION_LARGE, p.getX(), p.getY(), p.getZ(), 1, 0, 0, 0, 1, null);
}
world.setBlockToAir(p.add(0,1,0));
miningBlock = false;
}
@ -574,34 +469,28 @@ public class QuarryTileEntity extends TileEntity implements ITickable
// Speed of quarry scales with the amount of power received.
private void increaseQuarryTimer()
{
if (getEnergyStored() >= 512)
if (useEnergy(512))
{
useEnergy(512);
quarryTimer += 32;
}
else if (getEnergyStored() >= 256)
else if (useEnergy(256))
{
useEnergy(256);
quarryTimer += 16;
}
else if (getEnergyStored() >= 128)
else if (useEnergy(128))
{
useEnergy(128);
quarryTimer += 8;
}
else if (getEnergyStored() >= 32)
else if (useEnergy(32))
{
useEnergy(32);
quarryTimer += 4;
}
else if (getEnergyStored() >= 5)
else if (useEnergy(5))
{
useEnergy(5);
quarryTimer += 2;
}
else if (getEnergyStored() >= 1)
else if (useEnergy(1))
{
useEnergy(1);
quarryTimer += 1;
}
}
@ -624,7 +513,6 @@ public class QuarryTileEntity extends TileEntity implements ITickable
soundTimer++;
if (soundTimer >= 60)
{
//Looping sound effect played at the quarry block.
world.playSound(null, pos, ProspectSounds.quarrySoundEvent, SoundCategory.BLOCKS, 1.0f, 1);
soundTimer = 0;
}

View File

@ -1,21 +1,20 @@
{
"type": "forge:ore_shaped",
"pattern": [
"AAA",
" ",
"AWA",
"AAA" ],
" " ],
"key": {
"W": {
"item": "prospect:in_ev_wire"
},
"A": {
"type": "forge:ore_dict",
"ore": "ingotAluminum"
"item": "prospect:aluminum_plate"
}
},
"result": {
"item": "prospect:ev_cable",
"data": 0
"count": 10
}
}

View File

@ -1,9 +1,9 @@
{
"type": "forge:ore_shaped",
"pattern": [
"AAA",
" ",
"AWA",
"AAA" ],
" " ],
"key": {
"W": {
"item": "prospect:in_hv_wire"
@ -14,7 +14,7 @@
},
"result": {
"item": "prospect:hv_cable",
"data": 0
"count": 10
}
}

View File

@ -1,9 +1,9 @@
{
"type": "forge:ore_shaped",
"pattern": [
"AAA",
" ",
"AWA",
"AAA" ],
" " ],
"key": {
"W": {
"item": "prospect:in_iv_wire"
@ -14,7 +14,7 @@
},
"result": {
"item": "prospect:iv_cable",
"data": 0
"count": 10
}
}

View File

@ -1,9 +1,9 @@
{
"type": "forge:ore_shaped",
"pattern": [
"AAA",
" ",
"AWA",
"AAA" ],
" " ],
"key": {
"W": {
"item": "prospect:in_lv_wire"
@ -14,7 +14,7 @@
},
"result": {
"item": "prospect:lv_cable",
"data": 0
"count": 10
}
}

View File

@ -1,9 +1,9 @@
{
"type": "forge:ore_shaped",
"pattern": [
"AAA",
" ",
"AWA",
"AAA" ],
" " ],
"key": {
"W": {
"item": "prospect:in_mv_wire"
@ -14,7 +14,7 @@
},
"result": {
"item": "prospect:mv_cable",
"data": 0
"count": 10
}
}