Upgrade rework, now with 3463% more caching!

(it was slow and needed a redo)
This commit is contained in:
BallOfEnergy 2024-10-14 22:00:39 -05:00
parent 42e200ac7a
commit e38ce02ccf
31 changed files with 1634 additions and 1506 deletions

View File

@ -1,50 +0,0 @@
package com.hbm.inventory;
import java.util.HashMap;
import com.hbm.interfaces.Untested;
import com.hbm.items.machine.ItemMachineUpgrade;
import com.hbm.items.machine.ItemMachineUpgrade.UpgradeType;
import net.minecraft.item.ItemStack;
public class UpgradeManager {
private static HashMap<UpgradeType, Integer> upgrades = new HashMap();
private static UpgradeType mutexType = null;
@Untested
public static void eval(ItemStack[] slots, int start, int end) {
upgrades.clear();
for(int i = start; i <= end; i++) {
if(slots[i] != null && slots[i].getItem() instanceof ItemMachineUpgrade) {
ItemMachineUpgrade item = (ItemMachineUpgrade) slots[i].getItem();
if(item.type.mutex) {
if(mutexType == null || mutexType.ordinal() < item.type.ordinal()) {
mutexType = item.type;
}
} else {
Integer up = upgrades.get(item.type);
int upgrade = (up == null ? 0 : up);
upgrade += item.tier;
upgrades.put(item.type, upgrade);
}
}
}
}
public static int getLevel(UpgradeType type) {
Integer up = upgrades.get(type);
return up == null ? 0 : up;
}
public static UpgradeType getMinerMutex() {
return mutexType;
}
}

View File

@ -0,0 +1,80 @@
package com.hbm.inventory;
import com.hbm.items.machine.ItemMachineUpgrade;
import com.hbm.items.machine.ItemMachineUpgrade.UpgradeType;
import com.hbm.tileentity.IUpgradeInfoProvider;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import java.util.Arrays;
import java.util.HashMap;
/*
Steps for use:
1. TE implements IUpgradeInfoProvider
2. TE creates a new instance of UpgradeManagerNT
3. Upgrades and their levels can then be pulled from there.
*/
/**
* Upgrade system, now with caching!
* @author BallOfEnergy1
*/
public class UpgradeManagerNT {
public ItemStack[] cachedSlots;
private UpgradeType mutexType;
public HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
public void checkSlots(TileEntity te, ItemStack[] slots, int start, int end) {
if(!(te instanceof IUpgradeInfoProvider) || slots == null)
return;
ItemStack[] upgradeSlots = Arrays.copyOfRange(slots, start, end + 1);
if(Arrays.equals(upgradeSlots, cachedSlots))
return;
cachedSlots = upgradeSlots.clone();
upgrades.clear();
for (int i = 0; i <= end - start; i++) {
if(upgradeSlots[i] != null && upgradeSlots[i].getItem() instanceof ItemMachineUpgrade) {
ItemMachineUpgrade item = (ItemMachineUpgrade) upgradeSlots[i].getItem();
IUpgradeInfoProvider upgradable = (IUpgradeInfoProvider) te;
if(upgradable.getValidUpgrades() == null)
return;
if (upgradable.getValidUpgrades().containsKey(item.type)) { // Check if upgrade can even be accepted by the machine.
if (item.type.mutex) {
if (mutexType == null) {
upgrades.put(item.type, 1);
mutexType = item.type;
} else if(item.type.ordinal() > mutexType.ordinal()) {
upgrades.remove(mutexType);
upgrades.put(item.type, 1);
mutexType = item.type;
}
} else {
Integer levelBefore = upgrades.get(item.type);
int upgradeLevel = (levelBefore == null ? 0 : levelBefore);
upgradeLevel += item.tier;
// Add additional check to make sure it doesn't go over the max.
upgrades.put(item.type, Math.min(upgradeLevel, upgradable.getValidUpgrades().get(item.type)));
}
}
}
}
}
public Integer getLevel(UpgradeType type) {
return upgrades.getOrDefault(type, 0);
}
}

View File

@ -40,36 +40,36 @@ public abstract class GuiInfoContainer extends GuiContainer implements INEIGuiHa
public GuiInfoContainer(Container p_i1072_1_) { public GuiInfoContainer(Container p_i1072_1_) {
super(p_i1072_1_); super(p_i1072_1_);
} }
public void drawElectricityInfo(GuiInfoContainer gui, int mouseX, int mouseY, int x, int y, int width, int height, long power, long maxPower) { public void drawElectricityInfo(GuiInfoContainer gui, int mouseX, int mouseY, int x, int y, int width, int height, long power, long maxPower) {
if(x <= mouseX && x + width > mouseX && y < mouseY && y + height >= mouseY) if(x <= mouseX && x + width > mouseX && y < mouseY && y + height >= mouseY)
gui.drawInfo(new String[] { BobMathUtil.getShortNumber(power) + "/" + BobMathUtil.getShortNumber(maxPower) + "HE" }, mouseX, mouseY); gui.drawInfo(new String[] { BobMathUtil.getShortNumber(power) + "/" + BobMathUtil.getShortNumber(maxPower) + "HE" }, mouseX, mouseY);
} }
public void drawCustomInfoStat(int mouseX, int mouseY, int x, int y, int width, int height, int tPosX, int tPosY, String... text) { drawCustomInfoStat(mouseX, mouseY, x, y, width, height, tPosX, tPosY, Arrays.asList(text)); } public void drawCustomInfoStat(int mouseX, int mouseY, int x, int y, int width, int height, int tPosX, int tPosY, String... text) { drawCustomInfoStat(mouseX, mouseY, x, y, width, height, tPosX, tPosY, Arrays.asList(text)); }
public void drawCustomInfoStat(int mouseX, int mouseY, int x, int y, int width, int height, int tPosX, int tPosY, List text) { public void drawCustomInfoStat(int mouseX, int mouseY, int x, int y, int width, int height, int tPosX, int tPosY, List text) {
if(x <= mouseX && x + width > mouseX && y < mouseY && y + height >= mouseY) if(x <= mouseX && x + width > mouseX && y < mouseY && y + height >= mouseY)
this.func_146283_a(text, tPosX, tPosY); this.func_146283_a(text, tPosX, tPosY);
} }
public void drawInfo(String[] text, int x, int y) { public void drawInfo(String[] text, int x, int y) {
this.func_146283_a(Arrays.asList(text), x, y); this.func_146283_a(Arrays.asList(text), x, y);
} }
/** Automatically grabs upgrade info out of the tile entity if it's a IUpgradeInfoProvider and crams the available info into a list for display. Automation, yeah! */ /** Automatically grabs upgrade info out of the tile entity if it's a IUpgradeInfoProvider and crams the available info into a list for display. Automation, yeah! */
public List<String> getUpgradeInfo(TileEntity tile) { public List<String> getUpgradeInfo(TileEntity tile) {
List<String> lines = new ArrayList(); List<String> lines = new ArrayList();
if(tile instanceof IUpgradeInfoProvider) { if(tile instanceof IUpgradeInfoProvider) {
IUpgradeInfoProvider provider = (IUpgradeInfoProvider) tile; IUpgradeInfoProvider provider = (IUpgradeInfoProvider) tile;
lines.add(I18nUtil.resolveKey("upgrade.gui.title")); lines.add(I18nUtil.resolveKey("upgrade.gui.title"));
for(UpgradeType type : UpgradeType.values()) { for(UpgradeType type : UpgradeType.values()) {
if(provider.canProvideInfo(type, 0, false)) { if(provider.canProvideInfo(type, 0, false)) {
int maxLevel = provider.getMaxLevel(type); int maxLevel = provider.getValidUpgrades().get(type);
switch(type) { switch(type) {
case SPEED: lines.add(I18nUtil.resolveKey("upgrade.gui.speed", maxLevel)); break; case SPEED: lines.add(I18nUtil.resolveKey("upgrade.gui.speed", maxLevel)); break;
case POWER: lines.add(I18nUtil.resolveKey("upgrade.gui.power", maxLevel)); break; case POWER: lines.add(I18nUtil.resolveKey("upgrade.gui.power", maxLevel)); break;
@ -81,20 +81,20 @@ public abstract class GuiInfoContainer extends GuiContainer implements INEIGuiHa
} }
} }
} }
return lines; return lines;
} }
@Deprecated @Deprecated
public void drawCustomInfo(GuiInfoContainer gui, int mouseX, int mouseY, int x, int y, int width, int height, String[] text) { public void drawCustomInfo(GuiInfoContainer gui, int mouseX, int mouseY, int x, int y, int width, int height, String[] text) {
if(x <= mouseX && x + width > mouseX && y < mouseY && y + height >= mouseY) if(x <= mouseX && x + width > mouseX && y < mouseY && y + height >= mouseY)
this.func_146283_a(Arrays.asList(text), mouseX, mouseY); this.func_146283_a(Arrays.asList(text), mouseX, mouseY);
} }
public void drawInfoPanel(int x, int y, int width, int height, int type) { public void drawInfoPanel(int x, int y, int width, int height, int type) {
Minecraft.getMinecraft().getTextureManager().bindTexture(guiUtil); Minecraft.getMinecraft().getTextureManager().bindTexture(guiUtil);
switch(type) { switch(type) {
case 0: drawTexturedModalRect(x, y, 0, 0, 8, 8); break; //Small blue I case 0: drawTexturedModalRect(x, y, 0, 0, 8, 8); break; //Small blue I
case 1: drawTexturedModalRect(x, y, 0, 8, 8, 8); break; //Small green I case 1: drawTexturedModalRect(x, y, 0, 8, 8, 8); break; //Small green I
@ -110,7 +110,7 @@ public abstract class GuiInfoContainer extends GuiContainer implements INEIGuiHa
case 11: drawTexturedModalRect(x, y, 24, 32, 16, 16); break; //Large grey * case 11: drawTexturedModalRect(x, y, 24, 32, 16, 16); break; //Large grey *
} }
} }
protected boolean isMouseOverSlot(Slot slot, int x, int y) { protected boolean isMouseOverSlot(Slot slot, int x, int y) {
return this.func_146978_c(slot.xDisplayPosition, slot.yDisplayPosition, 16, 16, x, y); return this.func_146978_c(slot.xDisplayPosition, slot.yDisplayPosition, 16, 16, x, y);
} }
@ -130,32 +130,32 @@ public abstract class GuiInfoContainer extends GuiContainer implements INEIGuiHa
return null; return null;
} }
protected boolean checkClick(int x, int y, int left, int top, int sizeX, int sizeY) { protected boolean checkClick(int x, int y, int left, int top, int sizeX, int sizeY) {
return guiLeft + left <= x && guiLeft + left + sizeX > x && guiTop + top < y && guiTop + top + sizeY >= y; return guiLeft + left <= x && guiLeft + left + sizeX > x && guiTop + top < y && guiTop + top + sizeY >= y;
} }
/* Getters for external use of the GUI's rect rendering, such as NumberDisplay */ /* Getters for external use of the GUI's rect rendering, such as NumberDisplay */
public int getGuiTop() { public int getGuiTop() {
return this.guiTop; return this.guiTop;
} }
public int getGuiLeft() { public int getGuiLeft() {
return this.guiLeft; return this.guiLeft;
} }
public float getZLevel() { public float getZLevel() {
return this.zLevel; return this.zLevel;
} }
public void setZLevel(float level) { public void setZLevel(float level) {
this.zLevel = level; this.zLevel = level;
} }
public RenderItem getItemRenderer() { public RenderItem getItemRenderer() {
return this.itemRender; return this.itemRender;
} }
public FontRenderer getFontRenderer() { public FontRenderer getFontRenderer() {
return this.fontRendererObj; return this.fontRendererObj;
} }
@ -175,7 +175,7 @@ public abstract class GuiInfoContainer extends GuiContainer implements INEIGuiHa
} }
protected void drawStackText(List lines, int x, int y, FontRenderer font) { protected void drawStackText(List lines, int x, int y, FontRenderer font) {
if(!lines.isEmpty()) { if(!lines.isEmpty()) {
GL11.glDisable(GL12.GL_RESCALE_NORMAL); GL11.glDisable(GL12.GL_RESCALE_NORMAL);
RenderHelper.disableStandardItemLighting(); RenderHelper.disableStandardItemLighting();
@ -189,11 +189,11 @@ public abstract class GuiInfoContainer extends GuiContainer implements INEIGuiHa
while(iterator.hasNext()) { while(iterator.hasNext()) {
Object[] line = (Object[]) iterator.next(); Object[] line = (Object[]) iterator.next();
int lineWidth = 0; int lineWidth = 0;
boolean hasStack = false; boolean hasStack = false;
for(Object o : line) { for(Object o : line) {
if(o instanceof String) { if(o instanceof String) {
lineWidth += font.getStringWidth((String) o); lineWidth += font.getStringWidth((String) o);
} else { } else {
@ -201,7 +201,7 @@ public abstract class GuiInfoContainer extends GuiContainer implements INEIGuiHa
hasStack = true; hasStack = true;
} }
} }
if(hasStack) { if(hasStack) {
height += 18; height += 18;
} else { } else {
@ -243,19 +243,19 @@ public abstract class GuiInfoContainer extends GuiContainer implements INEIGuiHa
this.drawGradientRect(minX - 3, minY + height + 2, minX + longestline + 3, minY + height + 3, color1, color1); this.drawGradientRect(minX - 3, minY + height + 2, minX + longestline + 3, minY + height + 3, color1, color1);
for(int index = 0; index < lines.size(); ++index) { for(int index = 0; index < lines.size(); ++index) {
Object[] line = (Object[]) lines.get(index); Object[] line = (Object[]) lines.get(index);
int indent = 0; int indent = 0;
boolean hasStack = false; boolean hasStack = false;
for(Object o : line) { for(Object o : line) {
if(!(o instanceof String)) { if(!(o instanceof String)) {
hasStack = true; hasStack = true;
} }
} }
for(Object o : line) { for(Object o : line) {
if(o instanceof String) { if(o instanceof String) {
font.drawStringWithShadow((String) o, minX + indent, minY + (hasStack ? 4 : 0), -1); font.drawStringWithShadow((String) o, minX + indent, minY + (hasStack ? 4 : 0), -1);
indent += font.getStringWidth((String) o) + 2; indent += font.getStringWidth((String) o) + 2;
@ -301,7 +301,7 @@ public abstract class GuiInfoContainer extends GuiContainer implements INEIGuiHa
if(inventorySlots instanceof ContainerBase) { if(inventorySlots instanceof ContainerBase) {
NBTTagCompound tag = new NBTTagCompound(); NBTTagCompound tag = new NBTTagCompound();
tag.setInteger("slot", slot.slotNumber); tag.setInteger("slot", slot.slotNumber);
NBTTagCompound item = new NBTTagCompound(); NBTTagCompound item = new NBTTagCompound();
stack.writeToNBT(item); stack.writeToNBT(item);
tag.setTag("stack", item); tag.setTag("stack", item);

View File

@ -1,5 +1,6 @@
package com.hbm.tileentity; package com.hbm.tileentity;
import java.util.HashMap;
import java.util.List; import java.util.List;
import com.hbm.items.machine.ItemMachineUpgrade.UpgradeType; import com.hbm.items.machine.ItemMachineUpgrade.UpgradeType;
@ -13,8 +14,8 @@ public interface IUpgradeInfoProvider {
/** If any of the automated display stuff should be applied for this upgrade. A level of 0 is used by the GUI's indicator, as opposed to the item tooltips */ /** If any of the automated display stuff should be applied for this upgrade. A level of 0 is used by the GUI's indicator, as opposed to the item tooltips */
public boolean canProvideInfo(UpgradeType type, int level, boolean extendedInfo); public boolean canProvideInfo(UpgradeType type, int level, boolean extendedInfo);
public void provideInfo(UpgradeType type, int level, List<String> info, boolean extendedInfo); public void provideInfo(UpgradeType type, int level, List<String> info, boolean extendedInfo);
public int getMaxLevel(UpgradeType type); public HashMap<UpgradeType, Integer> getValidUpgrades();
public static String getStandardLabel(Block block) { public static String getStandardLabel(Block block) {
return EnumChatFormatting.GREEN.YELLOW + ">>> " + I18nUtil.resolveKey(block.getUnlocalizedName() + ".name") + " <<<"; return EnumChatFormatting.GREEN.YELLOW + ">>> " + I18nUtil.resolveKey(block.getUnlocalizedName() + ".name") + " <<<";
} }

View File

@ -1,12 +1,13 @@
package com.hbm.tileentity.machine; package com.hbm.tileentity.machine;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import com.hbm.blocks.BlockDummyable; import com.hbm.blocks.BlockDummyable;
import com.hbm.blocks.ModBlocks; import com.hbm.blocks.ModBlocks;
import com.hbm.interfaces.IControlReceiver; import com.hbm.interfaces.IControlReceiver;
import com.hbm.inventory.UpgradeManager; import com.hbm.inventory.UpgradeManagerNT;
import com.hbm.inventory.container.ContainerElectrolyserFluid; import com.hbm.inventory.container.ContainerElectrolyserFluid;
import com.hbm.inventory.container.ContainerElectrolyserMetal; import com.hbm.inventory.container.ContainerElectrolyserMetal;
import com.hbm.inventory.fluid.Fluids; import com.hbm.inventory.fluid.Fluids;
@ -49,14 +50,14 @@ import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityElectrolyser extends TileEntityMachineBase implements IEnergyReceiverMK2, IFluidStandardTransceiver, IControlReceiver, IGUIProvider, IUpgradeInfoProvider, IFluidCopiable, IMetalCopiable { public class TileEntityElectrolyser extends TileEntityMachineBase implements IEnergyReceiverMK2, IFluidStandardTransceiver, IControlReceiver, IGUIProvider, IUpgradeInfoProvider, IFluidCopiable, IMetalCopiable {
public long power; public long power;
public static final long maxPower = 20000000; public static final long maxPower = 20000000;
public static final int usageOreBase = 10_000; public static final int usageOreBase = 10_000;
public static final int usageFluidBase = 10_000; public static final int usageFluidBase = 10_000;
public int usageOre; public int usageOre;
public int usageFluid; public int usageFluid;
public int progressFluid; public int progressFluid;
public int processFluidTime = 100; public int processFluidTime = 100;
public int progressOre; public int progressOre;
@ -68,6 +69,8 @@ public class TileEntityElectrolyser extends TileEntityMachineBase implements IEn
public FluidTank[] tanks; public FluidTank[] tanks;
public UpgradeManagerNT upgradeManager = new UpgradeManagerNT();
public TileEntityElectrolyser() { public TileEntityElectrolyser() {
//0: Battery //0: Battery
//1-2: Upgrades //1-2: Upgrades
@ -129,9 +132,9 @@ public class TileEntityElectrolyser extends TileEntityMachineBase implements IEn
} }
} }
UpgradeManager.eval(slots, 1, 2); upgradeManager.checkSlots(this, slots, 1, 2);
int speedLevel = Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 3); int speedLevel = upgradeManager.getLevel(UpgradeType.SPEED);
int powerLevel = Math.min(UpgradeManager.getLevel(UpgradeType.POWER), 3); int powerLevel = upgradeManager.getLevel(UpgradeType.POWER);
usageOre = usageOreBase - usageOreBase * powerLevel / 4; usageOre = usageOreBase - usageOreBase * powerLevel / 4;
usageFluid = usageFluidBase - usageFluidBase * powerLevel / 4; usageFluid = usageFluidBase - usageFluidBase * powerLevel / 4;
@ -390,19 +393,19 @@ public class TileEntityElectrolyser extends TileEntityMachineBase implements IEn
public int getDurationMetal() { public int getDurationMetal() {
ElectrolysisMetalRecipe result = ElectrolyserMetalRecipes.getRecipe(slots[14]); ElectrolysisMetalRecipe result = ElectrolyserMetalRecipes.getRecipe(slots[14]);
int base = result != null ? result.duration : 600; int base = result != null ? result.duration : 600;
int speed = Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 3) - Math.min(UpgradeManager.getLevel(UpgradeType.POWER), 1); int speed = upgradeManager.getLevel(UpgradeType.SPEED) - upgradeManager.getLevel(UpgradeType.POWER);
return (int) Math.ceil((base * Math.max(1F - 0.25F * speed, 0.2))); return (int) Math.ceil((base * Math.max(1F - 0.25F * speed, 0.2)));
} }
public int getDurationFluid() { public int getDurationFluid() {
ElectrolysisRecipe result = ElectrolyserFluidRecipes.getRecipe(tanks[0].getTankType()); ElectrolysisRecipe result = ElectrolyserFluidRecipes.getRecipe(tanks[0].getTankType());
int base = result != null ? result.duration : 100; int base = result != null ? result.duration : 100;
int speed = Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 3) - Math.min(UpgradeManager.getLevel(UpgradeType.POWER), 1); int speed = upgradeManager.getLevel(UpgradeType.SPEED) - upgradeManager.getLevel(UpgradeType.POWER);
return (int) Math.ceil((base * Math.max(1F - 0.25F * speed, 0.2))); return (int) Math.ceil((base * Math.max(1F - 0.25F * speed, 0.2)));
} }
public int getCycleCount() { public int getCycleCount() {
int speed = UpgradeManager.getLevel(UpgradeType.OVERDRIVE); int speed = upgradeManager.getLevel(UpgradeType.OVERDRIVE);
return Math.min(1 + speed * 2, 7); return Math.min(1 + speed * 2, 7);
} }
@ -513,7 +516,7 @@ public class TileEntityElectrolyser extends TileEntityMachineBase implements IEn
@Override @Override
public void receiveControl(NBTTagCompound data) { } public void receiveControl(NBTTagCompound data) { }
@Override @Override
public void receiveControl(EntityPlayer player, NBTTagCompound data) { public void receiveControl(EntityPlayer player, NBTTagCompound data) {
@ -548,11 +551,12 @@ public class TileEntityElectrolyser extends TileEntityMachineBase implements IEn
} }
@Override @Override
public int getMaxLevel(UpgradeType type) { public HashMap<UpgradeType, Integer> getValidUpgrades() {
if(type == UpgradeType.SPEED) return 3; HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
if(type == UpgradeType.POWER) return 3; upgrades.put(UpgradeType.SPEED, 3);
if(type == UpgradeType.OVERDRIVE) return 3; upgrades.put(UpgradeType.POWER, 3);
return 0; upgrades.put(UpgradeType.OVERDRIVE, 3);
return upgrades;
} }
@Override @Override

View File

@ -1,11 +1,12 @@
package com.hbm.tileentity.machine; package com.hbm.tileentity.machine;
import java.util.HashMap;
import java.util.List; import java.util.List;
import com.hbm.blocks.ModBlocks; import com.hbm.blocks.ModBlocks;
import com.hbm.handler.pollution.PollutionHandler; import com.hbm.handler.pollution.PollutionHandler;
import com.hbm.handler.pollution.PollutionHandler.PollutionType; import com.hbm.handler.pollution.PollutionHandler.PollutionType;
import com.hbm.inventory.UpgradeManager; import com.hbm.inventory.UpgradeManagerNT;
import com.hbm.inventory.container.ContainerFurnaceIron; import com.hbm.inventory.container.ContainerFurnaceIron;
import com.hbm.inventory.gui.GUIFurnaceIron; import com.hbm.inventory.gui.GUIFurnaceIron;
import com.hbm.items.machine.ItemMachineUpgrade.UpgradeType; import com.hbm.items.machine.ItemMachineUpgrade.UpgradeType;
@ -29,7 +30,7 @@ import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityFurnaceIron extends TileEntityMachineBase implements IGUIProvider, IUpgradeInfoProvider { public class TileEntityFurnaceIron extends TileEntityMachineBase implements IGUIProvider, IUpgradeInfoProvider {
public int maxBurnTime; public int maxBurnTime;
public int burnTime; public int burnTime;
public boolean wasOn = false; public boolean wasOn = false;
@ -37,12 +38,14 @@ public class TileEntityFurnaceIron extends TileEntityMachineBase implements IGUI
public int progress; public int progress;
public int processingTime; public int processingTime;
public static final int baseTime = 160; public static final int baseTime = 160;
public ModuleBurnTime burnModule; public ModuleBurnTime burnModule;
public UpgradeManagerNT upgradeManager = new UpgradeManagerNT();
public TileEntityFurnaceIron() { public TileEntityFurnaceIron() {
super(5); super(5);
burnModule = new ModuleBurnTime() burnModule = new ModuleBurnTime()
.setLigniteTimeMod(1.25) .setLigniteTimeMod(1.25)
.setCoalTimeMod(1.25) .setCoalTimeMod(1.25)
@ -59,21 +62,21 @@ public class TileEntityFurnaceIron extends TileEntityMachineBase implements IGUI
@Override @Override
public void updateEntity() { public void updateEntity() {
if(!worldObj.isRemote) { if(!worldObj.isRemote) {
UpgradeManager.eval(slots, 4, 4); upgradeManager.checkSlots(this, slots, 4, 4);
this.processingTime = baseTime - ((baseTime / 2) * Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 3) / 3); this.processingTime = baseTime - ((baseTime / 2) * upgradeManager.getLevel(UpgradeType.SPEED) / 3);
wasOn = false; wasOn = false;
if(burnTime <= 0) { if(burnTime <= 0) {
for(int i = 1; i < 3; i++) { for(int i = 1; i < 3; i++) {
if(slots[i] != null) { if(slots[i] != null) {
int fuel = burnModule.getBurnTime(slots[i]); int fuel = burnModule.getBurnTime(slots[i]);
if(fuel > 0) { if(fuel > 0) {
this.maxBurnTime = this.burnTime = fuel; this.maxBurnTime = this.burnTime = fuel;
slots[i].stackSize--; slots[i].stackSize--;
@ -81,33 +84,33 @@ public class TileEntityFurnaceIron extends TileEntityMachineBase implements IGUI
if(slots[i].stackSize == 0) { if(slots[i].stackSize == 0) {
slots[i] = slots[i].getItem().getContainerItem(slots[i]); slots[i] = slots[i].getItem().getContainerItem(slots[i]);
} }
break; break;
} }
} }
} }
} }
if(canSmelt()) { if(canSmelt()) {
wasOn = true; wasOn = true;
this.progress++; this.progress++;
this.burnTime--; this.burnTime--;
if(this.progress % 15 == 0 && !this.muffled) { if(this.progress % 15 == 0 && !this.muffled) {
worldObj.playSoundEffect(xCoord, yCoord, zCoord, "fire.fire", 1.0F, 0.5F + worldObj.rand.nextFloat() * 0.5F); worldObj.playSoundEffect(xCoord, yCoord, zCoord, "fire.fire", 1.0F, 0.5F + worldObj.rand.nextFloat() * 0.5F);
} }
if(this.progress >= this.processingTime) { if(this.progress >= this.processingTime) {
ItemStack result = FurnaceRecipes.smelting().getSmeltingResult(slots[0]); ItemStack result = FurnaceRecipes.smelting().getSmeltingResult(slots[0]);
if(slots[3] == null) { if(slots[3] == null) {
slots[3] = result.copy(); slots[3] = result.copy();
} else { } else {
slots[3].stackSize += result.stackSize; slots[3].stackSize += result.stackSize;
} }
this.decrStackSize(0, 1); this.decrStackSize(0, 1);
this.progress = 0; this.progress = 0;
this.markDirty(); this.markDirty();
} }
@ -118,14 +121,14 @@ public class TileEntityFurnaceIron extends TileEntityMachineBase implements IGUI
this.networkPackNT(50); this.networkPackNT(50);
} else { } else {
if(this.progress > 0) { if(this.progress > 0) {
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10); ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10);
ForgeDirection rot = dir.getRotation(ForgeDirection.UP); ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
double offset = this.progress % 2 == 0 ? 1 : 0.5; double offset = this.progress % 2 == 0 ? 1 : 0.5;
worldObj.spawnParticle("smoke", xCoord + 0.5 - dir.offsetX * offset - rot.offsetX * 0.1875, yCoord + 2, zCoord + 0.5 - dir.offsetZ * offset - rot.offsetZ * 0.1875, 0.0, 0.01, 0.0); worldObj.spawnParticle("smoke", xCoord + 0.5 - dir.offsetX * offset - rot.offsetX * 0.1875, yCoord + 2, zCoord + 0.5 - dir.offsetZ * offset - rot.offsetZ * 0.1875, 0.0, 0.01, 0.0);
if(this.progress % 5 == 0) { if(this.progress % 5 == 0) {
double rand = worldObj.rand.nextDouble(); double rand = worldObj.rand.nextDouble();
worldObj.spawnParticle("flame", xCoord + 0.5 + dir.offsetX * 0.25 + rot.offsetX * rand, yCoord + 0.25 + worldObj.rand.nextDouble() * 0.25, zCoord + 0.5 + dir.offsetZ * 0.25 + rot.offsetZ * rand, 0.0, 0.0, 0.0); worldObj.spawnParticle("flame", xCoord + 0.5 + dir.offsetX * 0.25 + rot.offsetX * rand, yCoord + 0.25 + worldObj.rand.nextDouble() * 0.25, zCoord + 0.5 + dir.offsetZ * 0.25 + rot.offsetZ * rand, 0.0, 0.0, 0.0);
@ -155,21 +158,21 @@ public class TileEntityFurnaceIron extends TileEntityMachineBase implements IGUI
} }
public boolean canSmelt() { public boolean canSmelt() {
if(this.burnTime <= 0) return false; if(this.burnTime <= 0) return false;
if(slots[0] == null) return false; if(slots[0] == null) return false;
ItemStack result = FurnaceRecipes.smelting().getSmeltingResult(slots[0]); ItemStack result = FurnaceRecipes.smelting().getSmeltingResult(slots[0]);
if(result == null) return false; if(result == null) return false;
if(slots[3] == null) return true; if(slots[3] == null) return true;
if(!result.isItemEqual(slots[3])) return false; if(!result.isItemEqual(slots[3])) return false;
if(result.stackSize + slots[3].stackSize > slots[3].getMaxStackSize()) return false; if(result.stackSize + slots[3].stackSize > slots[3].getMaxStackSize()) return false;
return true; return true;
} }
@Override @Override
public int[] getAccessibleSlotsFromSide(int meta) { public int[] getAccessibleSlotsFromSide(int meta) {
return new int[] { 0, 1, 2, 3 }; return new int[] { 0, 1, 2, 3 };
@ -177,13 +180,13 @@ public class TileEntityFurnaceIron extends TileEntityMachineBase implements IGUI
@Override @Override
public boolean isItemValidForSlot(int i, ItemStack itemStack) { public boolean isItemValidForSlot(int i, ItemStack itemStack) {
if(i == 0) if(i == 0)
return FurnaceRecipes.smelting().getSmeltingResult(itemStack) != null; return FurnaceRecipes.smelting().getSmeltingResult(itemStack) != null;
if(i < 3) if(i < 3)
return burnModule.getBurnTime(itemStack) > 0; return burnModule.getBurnTime(itemStack) > 0;
return false; return false;
} }
@ -191,7 +194,7 @@ public class TileEntityFurnaceIron extends TileEntityMachineBase implements IGUI
public boolean canExtractItem(int i, ItemStack itemStack, int j) { public boolean canExtractItem(int i, ItemStack itemStack, int j) {
return i == 3; return i == 3;
} }
@Override @Override
public void readFromNBT(NBTTagCompound nbt) { public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt); super.readFromNBT(nbt);
@ -200,7 +203,7 @@ public class TileEntityFurnaceIron extends TileEntityMachineBase implements IGUI
this.burnTime = nbt.getInteger("burnTime"); this.burnTime = nbt.getInteger("burnTime");
this.progress = nbt.getInteger("progress"); this.progress = nbt.getInteger("progress");
} }
@Override @Override
public void writeToNBT(NBTTagCompound nbt) { public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt); super.writeToNBT(nbt);
@ -220,12 +223,12 @@ public class TileEntityFurnaceIron extends TileEntityMachineBase implements IGUI
public Object provideGUI(int ID, EntityPlayer player, World world, int x, int y, int z) { public Object provideGUI(int ID, EntityPlayer player, World world, int x, int y, int z) {
return new GUIFurnaceIron(player.inventory, this); return new GUIFurnaceIron(player.inventory, this);
} }
AxisAlignedBB bb = null; AxisAlignedBB bb = null;
@Override @Override
public AxisAlignedBB getRenderBoundingBox() { public AxisAlignedBB getRenderBoundingBox() {
if(bb == null) { if(bb == null) {
bb = AxisAlignedBB.getBoundingBox( bb = AxisAlignedBB.getBoundingBox(
xCoord - 1, xCoord - 1,
@ -236,10 +239,10 @@ public class TileEntityFurnaceIron extends TileEntityMachineBase implements IGUI
zCoord + 2 zCoord + 2
); );
} }
return bb; return bb;
} }
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public double getMaxRenderDistanceSquared() { public double getMaxRenderDistanceSquared() {
@ -260,8 +263,9 @@ public class TileEntityFurnaceIron extends TileEntityMachineBase implements IGUI
} }
@Override @Override
public int getMaxLevel(UpgradeType type) { public HashMap<UpgradeType, Integer> getValidUpgrades() {
if(type == UpgradeType.SPEED) return 3; HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
return 0; upgrades.put(UpgradeType.SPEED, 3);
return upgrades;
} }
} }

View File

@ -1,13 +1,14 @@
package com.hbm.tileentity.machine; package com.hbm.tileentity.machine;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import com.hbm.blocks.ModBlocks; import com.hbm.blocks.ModBlocks;
import com.hbm.handler.pollution.PollutionHandler; import com.hbm.handler.pollution.PollutionHandler;
import com.hbm.handler.pollution.PollutionHandler.PollutionType; import com.hbm.handler.pollution.PollutionHandler.PollutionType;
import com.hbm.interfaces.IControlReceiver; import com.hbm.interfaces.IControlReceiver;
import com.hbm.inventory.UpgradeManager; import com.hbm.inventory.UpgradeManagerNT;
import com.hbm.inventory.container.ContainerMachineArcFurnaceLarge; import com.hbm.inventory.container.ContainerMachineArcFurnaceLarge;
import com.hbm.inventory.gui.GUIMachineArcFurnaceLarge; import com.hbm.inventory.gui.GUIMachineArcFurnaceLarge;
import com.hbm.inventory.material.MaterialShapes; import com.hbm.inventory.material.MaterialShapes;
@ -47,7 +48,7 @@ import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityMachineArcFurnaceLarge extends TileEntityMachineBase implements IEnergyReceiverMK2, IControlReceiver, IGUIProvider, IUpgradeInfoProvider { public class TileEntityMachineArcFurnaceLarge extends TileEntityMachineBase implements IEnergyReceiverMK2, IControlReceiver, IGUIProvider, IUpgradeInfoProvider {
public long power; public long power;
public static final long maxPower = 2_500_000; public static final long maxPower = 2_500_000;
public boolean liquidMode = false; public boolean liquidMode = false;
@ -56,25 +57,27 @@ public class TileEntityMachineArcFurnaceLarge extends TileEntityMachineBase impl
public boolean hasMaterial; public boolean hasMaterial;
public int delay; public int delay;
public int upgrade; public int upgrade;
public float lid; public float lid;
public float prevLid; public float prevLid;
public int approachNum; public int approachNum;
public float syncLid; public float syncLid;
private AudioWrapper audioLid; private AudioWrapper audioLid;
private AudioWrapper audioProgress; private AudioWrapper audioProgress;
public UpgradeManagerNT upgradeManager = new UpgradeManagerNT();
public byte[] electrodes = new byte[3]; public byte[] electrodes = new byte[3];
public static final byte ELECTRODE_NONE = 0; public static final byte ELECTRODE_NONE = 0;
public static final byte ELECTRODE_FRESH = 1; public static final byte ELECTRODE_FRESH = 1;
public static final byte ELECTRODE_USED = 2; public static final byte ELECTRODE_USED = 2;
public static final byte ELECTRODE_DEPLETED = 3; public static final byte ELECTRODE_DEPLETED = 3;
public int getMaxInputSize() { public int getMaxInputSize() {
return upgrade == 0 ? 1 : upgrade == 1 ? 4 : upgrade == 2 ? 8 : 16; return upgrade == 0 ? 1 : upgrade == 1 ? 4 : upgrade == 2 ? 8 : 16;
} }
public static final int maxLiquid = MaterialShapes.BLOCK.q(128); public static final int maxLiquid = MaterialShapes.BLOCK.q(128);
public List<MaterialStack> liquids = new ArrayList(); public List<MaterialStack> liquids = new ArrayList();
@ -90,7 +93,7 @@ public class TileEntityMachineArcFurnaceLarge extends TileEntityMachineBase impl
@Override @Override
public void setInventorySlotContents(int i, ItemStack stack) { public void setInventorySlotContents(int i, ItemStack stack) {
super.setInventorySlotContents(i, stack); super.setInventorySlotContents(i, stack);
if(stack != null && stack.getItem() instanceof ItemMachineUpgrade && i == 4) { if(stack != null && stack.getItem() instanceof ItemMachineUpgrade && i == 4) {
worldObj.playSoundEffect(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5, "hbm:item.upgradePlug", 1.0F, 1.0F); worldObj.playSoundEffect(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5, "hbm:item.upgradePlug", 1.0F, 1.0F);
} }
@ -98,31 +101,31 @@ public class TileEntityMachineArcFurnaceLarge extends TileEntityMachineBase impl
@Override @Override
public void updateEntity() { public void updateEntity() {
UpgradeManager.eval(slots, 4, 4); upgradeManager.checkSlots(this, slots, 4, 4);
this.upgrade = Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 3); this.upgrade = upgradeManager.getLevel(UpgradeType.SPEED);
if(!worldObj.isRemote) { if(!worldObj.isRemote) {
this.power = Library.chargeTEFromItems(slots, 3, power, maxPower); this.power = Library.chargeTEFromItems(slots, 3, power, maxPower);
this.isProgressing = false; this.isProgressing = false;
for(DirPos pos : getConPos()) this.trySubscribe(worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); for(DirPos pos : getConPos()) this.trySubscribe(worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
if(power > 0) { if(power > 0) {
boolean ingredients = this.hasIngredients(); boolean ingredients = this.hasIngredients();
boolean electrodes = this.hasElectrodes(); boolean electrodes = this.hasElectrodes();
int consumption = (int) (1_000 * Math.pow(5, upgrade)); int consumption = (int) (1_000 * Math.pow(5, upgrade));
if(ingredients && electrodes && delay <= 0 && this.liquids.isEmpty()) { if(ingredients && electrodes && delay <= 0 && this.liquids.isEmpty()) {
if(lid > 0) { if(lid > 0) {
lid -= 1F / (60F / (upgrade * 0.5 + 1)); lid -= 1F / (60F / (upgrade * 0.5 + 1));
if(lid < 0) lid = 0; if(lid < 0) lid = 0;
this.progress = 0; this.progress = 0;
} else { } else {
if(power >= consumption) { if(power >= consumption) {
int duration = 400 / (upgrade * 2 + 1); int duration = 400 / (upgrade * 2 + 1);
this.progress += 1F / duration; this.progress += 1F / duration;
@ -145,18 +148,18 @@ public class TileEntityMachineArcFurnaceLarge extends TileEntityMachineBase impl
if(lid > 1) lid = 1; if(lid > 1) lid = 1;
} }
} }
hasMaterial = ingredients; hasMaterial = ingredients;
} }
this.decideElectrodeState(); this.decideElectrodeState();
if(!hasMaterial) hasMaterial = this.hasIngredients(); if(!hasMaterial) hasMaterial = this.hasIngredients();
if(!this.liquids.isEmpty() && this.lid > 0F) { if(!this.liquids.isEmpty() && this.lid > 0F) {
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10); ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10);
Vec3 impact = Vec3.createVectorHelper(0, 0, 0); Vec3 impact = Vec3.createVectorHelper(0, 0, 0);
MaterialStack didPour = CrucibleUtil.pourFullStack(worldObj, xCoord + 0.5D + dir.offsetX * 2.875D, yCoord + 1.25D, zCoord + 0.5D + dir.offsetZ * 2.875D, 6, true, this.liquids, MaterialShapes.INGOT.q(1), impact); MaterialStack didPour = CrucibleUtil.pourFullStack(worldObj, xCoord + 0.5D + dir.offsetX * 2.875D, yCoord + 1.25D, zCoord + 0.5D + dir.offsetZ * 2.875D, 6, true, this.liquids, MaterialShapes.INGOT.q(1), impact);
@ -171,21 +174,21 @@ public class TileEntityMachineArcFurnaceLarge extends TileEntityMachineBase impl
PacketDispatcher.wrapper.sendToAllAround(new AuxParticlePacketNT(data, xCoord + 0.5D + dir.offsetX * 2.875D, yCoord + 1, zCoord + 0.5D + dir.offsetZ * 2.875D), new TargetPoint(worldObj.provider.dimensionId, xCoord + 0.5, yCoord + 1, zCoord + 0.5, 50)); PacketDispatcher.wrapper.sendToAllAround(new AuxParticlePacketNT(data, xCoord + 0.5D + dir.offsetX * 2.875D, yCoord + 1, zCoord + 0.5D + dir.offsetZ * 2.875D), new TargetPoint(worldObj.provider.dimensionId, xCoord + 0.5, yCoord + 1, zCoord + 0.5, 50));
} }
} }
this.liquids.removeIf(o -> o.amount <= 0); this.liquids.removeIf(o -> o.amount <= 0);
this.networkPackNT(150); this.networkPackNT(150);
} else { } else {
this.prevLid = this.lid; this.prevLid = this.lid;
if(this.approachNum > 0) { if(this.approachNum > 0) {
this.lid = this.lid + ((this.syncLid - this.lid) / (float) this.approachNum); this.lid = this.lid + ((this.syncLid - this.lid) / (float) this.approachNum);
--this.approachNum; --this.approachNum;
} else { } else {
this.lid = this.syncLid; this.lid = this.syncLid;
} }
if(this.lid != this.prevLid) { if(this.lid != this.prevLid) {
if(this.audioLid == null || !this.audioLid.isPlaying()) { if(this.audioLid == null || !this.audioLid.isPlaying()) {
this.audioLid = MainRegistry.proxy.getLoopedSound("hbm:door.wgh_start", xCoord, yCoord, zCoord, this.getVolume(0.75F), 15F, 1.0F, 5); this.audioLid = MainRegistry.proxy.getLoopedSound("hbm:door.wgh_start", xCoord, yCoord, zCoord, this.getVolume(0.75F), 15F, 1.0F, 5);
@ -198,11 +201,11 @@ public class TileEntityMachineArcFurnaceLarge extends TileEntityMachineBase impl
this.audioLid = null; this.audioLid = null;
} }
} }
if((lid == 1 || lid == 0) && lid != prevLid && !(this.prevLid == 0 && this.lid == 1)) { if((lid == 1 || lid == 0) && lid != prevLid && !(this.prevLid == 0 && this.lid == 1)) {
MainRegistry.proxy.playSoundClient(xCoord, yCoord, zCoord, "hbm:door.wgh_stop", this.getVolume(1), 1F); MainRegistry.proxy.playSoundClient(xCoord, yCoord, zCoord, "hbm:door.wgh_stop", this.getVolume(1), 1F);
} }
if(this.isProgressing) { if(this.isProgressing) {
if(this.audioProgress == null || !this.audioProgress.isPlaying()) { if(this.audioProgress == null || !this.audioProgress.isPlaying()) {
this.audioProgress = MainRegistry.proxy.getLoopedSound("hbm:block.electricHum", xCoord, yCoord, zCoord, this.getVolume(1.5F), 15F, 0.75F, 5); this.audioProgress = MainRegistry.proxy.getLoopedSound("hbm:block.electricHum", xCoord, yCoord, zCoord, this.getVolume(1.5F), 15F, 0.75F, 5);
@ -216,7 +219,7 @@ public class TileEntityMachineArcFurnaceLarge extends TileEntityMachineBase impl
this.audioProgress = null; this.audioProgress = null;
} }
} }
if(this.lid != this.prevLid && this.lid > this.prevLid && !(this.prevLid == 0 && this.lid == 1) && MainRegistry.proxy.me().getDistance(xCoord + 0.5, yCoord + 4, zCoord + 0.5) < 50) { if(this.lid != this.prevLid && this.lid > this.prevLid && !(this.prevLid == 0 && this.lid == 1) && MainRegistry.proxy.me().getDistance(xCoord + 0.5, yCoord + 4, zCoord + 0.5) < 50) {
NBTTagCompound data = new NBTTagCompound(); NBTTagCompound data = new NBTTagCompound();
data.setString("type", "tower"); data.setString("type", "tower");
@ -233,7 +236,7 @@ public class TileEntityMachineArcFurnaceLarge extends TileEntityMachineBase impl
data.setFloat("strafe", 0.05F); data.setFloat("strafe", 0.05F);
for(int i = 0; i < 3; i++) MainRegistry.proxy.effectNT(data); for(int i = 0; i < 3; i++) MainRegistry.proxy.effectNT(data);
} }
if(this.lid != this.prevLid && this.lid < this.prevLid && this.lid > 0.5F && this.hasMaterial && MainRegistry.proxy.me().getDistance(xCoord + 0.5, yCoord + 4, zCoord + 0.5) < 50) { if(this.lid != this.prevLid && this.lid < this.prevLid && this.lid > 0.5F && this.hasMaterial && MainRegistry.proxy.me().getDistance(xCoord + 0.5, yCoord + 4, zCoord + 0.5) < 50) {
/*NBTTagCompound data = new NBTTagCompound(); /*NBTTagCompound data = new NBTTagCompound();
data.setString("type", "tower"); data.setString("type", "tower");
@ -249,7 +252,7 @@ public class TileEntityMachineArcFurnaceLarge extends TileEntityMachineBase impl
data.setInteger("color", 0x808080); data.setInteger("color", 0x808080);
data.setFloat("strafe", 0.15F); data.setFloat("strafe", 0.15F);
MainRegistry.proxy.effectNT(data);*/ MainRegistry.proxy.effectNT(data);*/
if(worldObj.rand.nextInt(5) == 0) { if(worldObj.rand.nextInt(5) == 0) {
NBTTagCompound flame = new NBTTagCompound(); NBTTagCompound flame = new NBTTagCompound();
flame.setString("type", "rbmkflame"); flame.setString("type", "rbmkflame");
@ -262,10 +265,10 @@ public class TileEntityMachineArcFurnaceLarge extends TileEntityMachineBase impl
} }
} }
} }
public void decideElectrodeState() { public void decideElectrodeState() {
for(int i = 0; i < 3; i++) { for(int i = 0; i < 3; i++) {
if(slots[i] != null) { if(slots[i] != null) {
if(slots[i].getItem() == ModItems.arc_electrode_burnt) { this.electrodes[i] = this.ELECTRODE_DEPLETED; continue; } if(slots[i].getItem() == ModItems.arc_electrode_burnt) { this.electrodes[i] = this.ELECTRODE_DEPLETED; continue; }
if(slots[i].getItem() == ModItems.arc_electrode) { if(slots[i].getItem() == ModItems.arc_electrode) {
@ -277,26 +280,26 @@ public class TileEntityMachineArcFurnaceLarge extends TileEntityMachineBase impl
this.electrodes[i] = this.ELECTRODE_NONE; this.electrodes[i] = this.ELECTRODE_NONE;
} }
} }
public void process() { public void process() {
for(int i = 5; i < 25; i++) { for(int i = 5; i < 25; i++) {
if(slots[i] == null) continue; if(slots[i] == null) continue;
ArcFurnaceRecipe recipe = ArcFurnaceRecipes.getOutput(slots[i], this.liquidMode); ArcFurnaceRecipe recipe = ArcFurnaceRecipes.getOutput(slots[i], this.liquidMode);
if(recipe == null) continue; if(recipe == null) continue;
if(!liquidMode && recipe.solidOutput != null) { if(!liquidMode && recipe.solidOutput != null) {
int amount = slots[i].stackSize; int amount = slots[i].stackSize;
slots[i] = recipe.solidOutput.copy(); slots[i] = recipe.solidOutput.copy();
slots[i].stackSize *= amount; slots[i].stackSize *= amount;
} }
if(liquidMode && recipe.fluidOutput != null) { if(liquidMode && recipe.fluidOutput != null) {
while(slots[i] != null && slots[i].stackSize > 0) { while(slots[i] != null && slots[i].stackSize > 0) {
int liquid = this.getStackAmount(liquids); int liquid = this.getStackAmount(liquids);
int toAdd = this.getStackAmount(recipe.fluidOutput); int toAdd = this.getStackAmount(recipe.fluidOutput);
if(liquid + toAdd <= this.maxLiquid) { if(liquid + toAdd <= this.maxLiquid) {
this.decrStackSize(i, 1); this.decrStackSize(i, 1);
for(MaterialStack stack : recipe.fluidOutput) { for(MaterialStack stack : recipe.fluidOutput) {
@ -308,16 +311,16 @@ public class TileEntityMachineArcFurnaceLarge extends TileEntityMachineBase impl
} }
} }
} }
for(int i = 0; i < 3; i++) { for(int i = 0; i < 3; i++) {
if(ItemArcElectrode.damage(slots[i])) { if(ItemArcElectrode.damage(slots[i])) {
slots[i] = new ItemStack(ModItems.arc_electrode_burnt, 1, slots[i].getItemDamage()); slots[i] = new ItemStack(ModItems.arc_electrode_burnt, 1, slots[i].getItemDamage());
} }
} }
} }
public boolean hasIngredients() { public boolean hasIngredients() {
for(int i = 5; i < 25; i++) { for(int i = 5; i < 25; i++) {
if(slots[i] == null) continue; if(slots[i] == null) continue;
ArcFurnaceRecipe recipe = ArcFurnaceRecipes.getOutput(slots[i], this.liquidMode); ArcFurnaceRecipe recipe = ArcFurnaceRecipes.getOutput(slots[i], this.liquidMode);
@ -325,10 +328,10 @@ public class TileEntityMachineArcFurnaceLarge extends TileEntityMachineBase impl
if(liquidMode && recipe.fluidOutput != null) return true; if(liquidMode && recipe.fluidOutput != null) return true;
if(!liquidMode && recipe.solidOutput != null) return true; if(!liquidMode && recipe.solidOutput != null) return true;
} }
return false; return false;
} }
public boolean hasElectrodes() { public boolean hasElectrodes() {
for(int i = 0; i < 3; i++) { for(int i = 0; i < 3; i++) {
if(slots[i] == null || slots[i].getItem() != ModItems.arc_electrode) return false; if(slots[i] == null || slots[i].getItem() != ModItems.arc_electrode) return false;
@ -384,35 +387,35 @@ public class TileEntityMachineArcFurnaceLarge extends TileEntityMachineBase impl
if(slot > 4) return lid > 0 && ArcFurnaceRecipes.getOutput(stack, this.liquidMode) == null; if(slot > 4) return lid > 0 && ArcFurnaceRecipes.getOutput(stack, this.liquidMode) == null;
return false; return false;
} }
public void addToStack(MaterialStack matStack) { public void addToStack(MaterialStack matStack) {
for(MaterialStack mat : liquids) { for(MaterialStack mat : liquids) {
if(mat.material == matStack.material) { if(mat.material == matStack.material) {
mat.amount += matStack.amount; mat.amount += matStack.amount;
return; return;
} }
} }
liquids.add(matStack.copy()); liquids.add(matStack.copy());
} }
public static int getStackAmount(List<MaterialStack> stack) { public static int getStackAmount(List<MaterialStack> stack) {
int amount = 0; int amount = 0;
for(MaterialStack mat : stack) amount += mat.amount; for(MaterialStack mat : stack) amount += mat.amount;
return amount; return amount;
} }
public static int getStackAmount(MaterialStack[] stack) { public static int getStackAmount(MaterialStack[] stack) {
int amount = 0; int amount = 0;
for(MaterialStack mat : stack) amount += mat.amount; for(MaterialStack mat : stack) amount += mat.amount;
return amount; return amount;
} }
protected DirPos[] getConPos() { protected DirPos[] getConPos() {
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10); ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10);
ForgeDirection rot = dir.getRotation(ForgeDirection.UP); ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
return new DirPos[] { return new DirPos[] {
new DirPos(xCoord + dir.offsetX * 3 + rot.offsetX, yCoord, zCoord + dir.offsetZ * 3 + rot.offsetZ, dir), new DirPos(xCoord + dir.offsetX * 3 + rot.offsetX, yCoord, zCoord + dir.offsetZ * 3 + rot.offsetZ, dir),
new DirPos(xCoord + dir.offsetX * 3 - rot.offsetX, yCoord, zCoord + dir.offsetZ * 3 - rot.offsetZ, dir), new DirPos(xCoord + dir.offsetX * 3 - rot.offsetX, yCoord, zCoord + dir.offsetZ * 3 - rot.offsetZ, dir),
@ -432,17 +435,17 @@ public class TileEntityMachineArcFurnaceLarge extends TileEntityMachineBase impl
buf.writeBoolean(isProgressing); buf.writeBoolean(isProgressing);
buf.writeBoolean(liquidMode); buf.writeBoolean(liquidMode);
buf.writeBoolean(hasMaterial); buf.writeBoolean(hasMaterial);
for(int i = 0; i < 3; i++) buf.writeByte(electrodes[i]); for(int i = 0; i < 3; i++) buf.writeByte(electrodes[i]);
buf.writeShort(liquids.size()); buf.writeShort(liquids.size());
for(MaterialStack mat : liquids) { for(MaterialStack mat : liquids) {
buf.writeInt(mat.material.id); buf.writeInt(mat.material.id);
buf.writeInt(mat.amount); buf.writeInt(mat.amount);
} }
} }
@Override @Override
public void deserialize(ByteBuf buf) { public void deserialize(ByteBuf buf) {
super.deserialize(buf); super.deserialize(buf);
@ -452,32 +455,32 @@ public class TileEntityMachineArcFurnaceLarge extends TileEntityMachineBase impl
this.isProgressing = buf.readBoolean(); this.isProgressing = buf.readBoolean();
this.liquidMode = buf.readBoolean(); this.liquidMode = buf.readBoolean();
this.hasMaterial = buf.readBoolean(); this.hasMaterial = buf.readBoolean();
for(int i = 0; i < 3; i++) electrodes[i] = buf.readByte(); for(int i = 0; i < 3; i++) electrodes[i] = buf.readByte();
int mats = buf.readShort(); int mats = buf.readShort();
this.liquids.clear(); this.liquids.clear();
for(int i = 0; i < mats; i++) { for(int i = 0; i < mats; i++) {
liquids.add(new MaterialStack(Mats.matById.get(buf.readInt()), buf.readInt())); liquids.add(new MaterialStack(Mats.matById.get(buf.readInt()), buf.readInt()));
} }
if(syncLid != 0 && syncLid != 1) this.approachNum = 2; if(syncLid != 0 && syncLid != 1) this.approachNum = 2;
} }
@Override @Override
public void readFromNBT(NBTTagCompound nbt) { public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt); super.readFromNBT(nbt);
this.power = nbt.getLong("power"); this.power = nbt.getLong("power");
this.liquidMode = nbt.getBoolean("liquidMode"); this.liquidMode = nbt.getBoolean("liquidMode");
this.progress = nbt.getFloat("progress"); this.progress = nbt.getFloat("progress");
this.lid = nbt.getFloat("lid"); this.lid = nbt.getFloat("lid");
this.delay = nbt.getInteger("delay"); this.delay = nbt.getInteger("delay");
int count = nbt.getShort("count"); int count = nbt.getShort("count");
liquids.clear(); liquids.clear();
for(int i = 0; i < count; i++) { for(int i = 0; i < count; i++) {
liquids.add(new MaterialStack(Mats.matById.get(nbt.getInteger("m" + i)), nbt.getInteger("a" + i))); liquids.add(new MaterialStack(Mats.matById.get(nbt.getInteger("m" + i)), nbt.getInteger("a" + i)));
} }
@ -491,7 +494,7 @@ public class TileEntityMachineArcFurnaceLarge extends TileEntityMachineBase impl
nbt.setFloat("progress", progress); nbt.setFloat("progress", progress);
nbt.setFloat("lid", lid); nbt.setFloat("lid", lid);
nbt.setInteger("delay", delay); nbt.setInteger("delay", delay);
int count = liquids.size(); int count = liquids.size();
nbt.setShort("count", (short) count); nbt.setShort("count", (short) count);
for(int i = 0; i < count; i++) { for(int i = 0; i < count; i++) {
@ -515,12 +518,12 @@ public class TileEntityMachineArcFurnaceLarge extends TileEntityMachineBase impl
public long getMaxPower() { public long getMaxPower() {
return maxPower; return maxPower;
} }
AxisAlignedBB bb = null; AxisAlignedBB bb = null;
@Override @Override
public AxisAlignedBB getRenderBoundingBox() { public AxisAlignedBB getRenderBoundingBox() {
if(bb == null) { if(bb == null) {
bb = AxisAlignedBB.getBoundingBox( bb = AxisAlignedBB.getBoundingBox(
xCoord - 3, xCoord - 3,
@ -531,10 +534,10 @@ public class TileEntityMachineArcFurnaceLarge extends TileEntityMachineBase impl
zCoord + 4 zCoord + 4
); );
} }
return bb; return bb;
} }
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public double getMaxRenderDistanceSquared() { public double getMaxRenderDistanceSquared() {
@ -580,8 +583,10 @@ public class TileEntityMachineArcFurnaceLarge extends TileEntityMachineBase impl
} }
@Override @Override
public int getMaxLevel(UpgradeType type) { public HashMap<UpgradeType, Integer> getValidUpgrades() {
if(type == UpgradeType.SPEED) return 3; HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
return 0; upgrades.put(UpgradeType.SPEED, 3);
return upgrades;
} }
} }

View File

@ -1,10 +1,11 @@
package com.hbm.tileentity.machine; package com.hbm.tileentity.machine;
import java.util.HashMap;
import java.util.List; import java.util.List;
import com.hbm.inventory.RecipesCommon.AStack; import com.hbm.inventory.RecipesCommon.AStack;
import com.hbm.blocks.ModBlocks; import com.hbm.blocks.ModBlocks;
import com.hbm.inventory.UpgradeManager; import com.hbm.inventory.UpgradeManagerNT;
import com.hbm.inventory.container.ContainerMachineArcWelder; import com.hbm.inventory.container.ContainerMachineArcWelder;
import com.hbm.inventory.fluid.Fluids; import com.hbm.inventory.fluid.Fluids;
import com.hbm.inventory.fluid.tank.FluidTank; import com.hbm.inventory.fluid.tank.FluidTank;
@ -38,17 +39,19 @@ import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityMachineArcWelder extends TileEntityMachineBase implements IEnergyReceiverMK2, IFluidStandardReceiver, IConditionalInvAccess, IGUIProvider, IUpgradeInfoProvider, IFluidCopiable { public class TileEntityMachineArcWelder extends TileEntityMachineBase implements IEnergyReceiverMK2, IFluidStandardReceiver, IConditionalInvAccess, IGUIProvider, IUpgradeInfoProvider, IFluidCopiable {
public long power; public long power;
public long maxPower = 2_000; public long maxPower = 2_000;
public long consumption; public long consumption;
public int progress; public int progress;
public int processTime = 1; public int processTime = 1;
public FluidTank tank; public FluidTank tank;
public ItemStack display; public ItemStack display;
public UpgradeManagerNT upgradeManager = new UpgradeManagerNT();
public TileEntityMachineArcWelder() { public TileEntityMachineArcWelder() {
super(8); super(8);
this.tank = new FluidTank(Fluids.NONE, 24_000); this.tank = new FluidTank(Fluids.NONE, 24_000);
@ -62,7 +65,7 @@ public class TileEntityMachineArcWelder extends TileEntityMachineBase implements
@Override @Override
public void setInventorySlotContents(int i, ItemStack stack) { public void setInventorySlotContents(int i, ItemStack stack) {
super.setInventorySlotContents(i, stack); super.setInventorySlotContents(i, stack);
if(stack != null && stack.getItem() instanceof ItemMachineUpgrade && i >= 6 && i <= 7) { if(stack != null && stack.getItem() instanceof ItemMachineUpgrade && i >= 6 && i <= 7) {
worldObj.playSoundEffect(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5, "hbm:item.upgradePlug", 1.0F, 1.0F); worldObj.playSoundEffect(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5, "hbm:item.upgradePlug", 1.0F, 1.0F);
} }
@ -70,48 +73,48 @@ public class TileEntityMachineArcWelder extends TileEntityMachineBase implements
@Override @Override
public void updateEntity() { public void updateEntity() {
if(!worldObj.isRemote) { if(!worldObj.isRemote) {
this.power = Library.chargeTEFromItems(slots, 4, this.getPower(), this.getMaxPower()); this.power = Library.chargeTEFromItems(slots, 4, this.getPower(), this.getMaxPower());
this.tank.setType(5, slots); this.tank.setType(5, slots);
if(worldObj.getTotalWorldTime() % 20 == 0) { if(worldObj.getTotalWorldTime() % 20 == 0) {
for(DirPos pos : getConPos()) { for(DirPos pos : getConPos()) {
this.trySubscribe(worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); this.trySubscribe(worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
if(tank.getTankType() != Fluids.NONE) this.trySubscribe(tank.getTankType(), worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); if(tank.getTankType() != Fluids.NONE) this.trySubscribe(tank.getTankType(), worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
} }
} }
ArcWelderRecipe recipe = ArcWelderRecipes.getRecipe(slots[0], slots[1], slots[2]); ArcWelderRecipe recipe = ArcWelderRecipes.getRecipe(slots[0], slots[1], slots[2]);
long intendedMaxPower; long intendedMaxPower;
UpgradeManager.eval(slots, 6, 7); upgradeManager.checkSlots(this, slots, 6, 7);
int redLevel = Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 3); int redLevel = upgradeManager.getLevel(UpgradeType.SPEED);
int blueLevel = Math.min(UpgradeManager.getLevel(UpgradeType.POWER), 3); int blueLevel = upgradeManager.getLevel(UpgradeType.POWER);
if(recipe != null) { if(recipe != null) {
this.processTime = recipe.duration - (recipe.duration * redLevel / 6) + (recipe.duration * blueLevel / 3); this.processTime = recipe.duration - (recipe.duration * redLevel / 6) + (recipe.duration * blueLevel / 3);
this.consumption = recipe.consumption + (recipe.consumption * redLevel) - (recipe.consumption * blueLevel / 6); this.consumption = recipe.consumption + (recipe.consumption * redLevel) - (recipe.consumption * blueLevel / 6);
intendedMaxPower = recipe.consumption * 20; intendedMaxPower = recipe.consumption * 20;
if(canProcess(recipe)) { if(canProcess(recipe)) {
this.progress++; this.progress++;
this.power -= this.consumption; this.power -= this.consumption;
if(progress >= processTime) { if(progress >= processTime) {
this.progress = 0; this.progress = 0;
this.consumeItems(recipe); this.consumeItems(recipe);
if(slots[3] == null) { if(slots[3] == null) {
slots[3] = recipe.output.copy(); slots[3] = recipe.output.copy();
} else { } else {
slots[3].stackSize += recipe.output.stackSize; slots[3].stackSize += recipe.output.stackSize;
} }
this.markDirty(); this.markDirty();
} }
if(worldObj.getTotalWorldTime() % 2 == 0) { if(worldObj.getTotalWorldTime() % 2 == 0) {
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10); ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10);
NBTTagCompound dPart = new NBTTagCompound(); NBTTagCompound dPart = new NBTTagCompound();
@ -119,23 +122,23 @@ public class TileEntityMachineArcWelder extends TileEntityMachineBase implements
dPart.setByte("count", (byte) 5); dPart.setByte("count", (byte) 5);
PacketDispatcher.wrapper.sendToAllAround(new AuxParticlePacketNT(dPart, xCoord + 0.5 - dir.offsetX * 0.5, yCoord + 1.25, zCoord + 0.5 - dir.offsetZ * 0.5), new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 25)); PacketDispatcher.wrapper.sendToAllAround(new AuxParticlePacketNT(dPart, xCoord + 0.5 - dir.offsetX * 0.5, yCoord + 1.25, zCoord + 0.5 - dir.offsetZ * 0.5), new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 25));
} }
} else { } else {
this.progress = 0; this.progress = 0;
} }
} else { } else {
this.progress = 0; this.progress = 0;
this.consumption = 100; this.consumption = 100;
intendedMaxPower = 2000; intendedMaxPower = 2000;
} }
this.maxPower = Math.max(intendedMaxPower, power); this.maxPower = Math.max(intendedMaxPower, power);
this.networkPackNT(25); this.networkPackNT(25);
} }
} }
@Override @Override
public void serialize(ByteBuf buf) { public void serialize(ByteBuf buf) {
super.serialize(buf); super.serialize(buf);
@ -144,11 +147,11 @@ public class TileEntityMachineArcWelder extends TileEntityMachineBase implements
buf.writeLong(consumption); buf.writeLong(consumption);
buf.writeInt(progress); buf.writeInt(progress);
buf.writeInt(processTime); buf.writeInt(processTime);
tank.serialize(buf); tank.serialize(buf);
ArcWelderRecipe recipe = ArcWelderRecipes.getRecipe(slots[0], slots[1], slots[2]); ArcWelderRecipe recipe = ArcWelderRecipes.getRecipe(slots[0], slots[1], slots[2]);
if(recipe != null) { if(recipe != null) {
buf.writeBoolean(true); buf.writeBoolean(true);
buf.writeInt(Item.getIdFromItem(recipe.output.getItem())); buf.writeInt(Item.getIdFromItem(recipe.output.getItem()));
@ -156,7 +159,7 @@ public class TileEntityMachineArcWelder extends TileEntityMachineBase implements
} else } else
buf.writeBoolean(false); buf.writeBoolean(false);
} }
@Override @Override
public void deserialize(ByteBuf buf) { public void deserialize(ByteBuf buf) {
super.deserialize(buf); super.deserialize(buf);
@ -165,37 +168,37 @@ public class TileEntityMachineArcWelder extends TileEntityMachineBase implements
consumption = buf.readLong(); consumption = buf.readLong();
progress = buf.readInt(); progress = buf.readInt();
processTime = buf.readInt(); processTime = buf.readInt();
tank.deserialize(buf); tank.deserialize(buf);
if(buf.readBoolean()) { if(buf.readBoolean()) {
this.display = new ItemStack(Item.getItemById(buf.readInt()), 1, buf.readInt()); this.display = new ItemStack(Item.getItemById(buf.readInt()), 1, buf.readInt());
} else } else
this.display = null; this.display = null;
} }
public boolean canProcess(ArcWelderRecipe recipe) { public boolean canProcess(ArcWelderRecipe recipe) {
if(this.power < this.consumption) return false; if(this.power < this.consumption) return false;
if(recipe.fluid != null) { if(recipe.fluid != null) {
if(this.tank.getTankType() != recipe.fluid.type) return false; if(this.tank.getTankType() != recipe.fluid.type) return false;
if(this.tank.getFill() < recipe.fluid.fill) return false; if(this.tank.getFill() < recipe.fluid.fill) return false;
} }
if(slots[3] != null) { if(slots[3] != null) {
if(slots[3].getItem() != recipe.output.getItem()) return false; if(slots[3].getItem() != recipe.output.getItem()) return false;
if(slots[3].getItemDamage() != recipe.output.getItemDamage()) return false; if(slots[3].getItemDamage() != recipe.output.getItemDamage()) return false;
if(slots[3].stackSize + recipe.output.stackSize > slots[3].getMaxStackSize()) return false; if(slots[3].stackSize + recipe.output.stackSize > slots[3].getMaxStackSize()) return false;
} }
return true; return true;
} }
public void consumeItems(ArcWelderRecipe recipe) { public void consumeItems(ArcWelderRecipe recipe) {
for(AStack aStack : recipe.ingredients) { for(AStack aStack : recipe.ingredients) {
for(int i = 0; i < 3; i++) { for(int i = 0; i < 3; i++) {
ItemStack stack = slots[i]; ItemStack stack = slots[i];
if(aStack.matchesRecipe(stack, true) && stack.stackSize >= aStack.stacksize) { if(aStack.matchesRecipe(stack, true) && stack.stackSize >= aStack.stacksize) {
@ -204,17 +207,17 @@ public class TileEntityMachineArcWelder extends TileEntityMachineBase implements
} }
} }
} }
if(recipe.fluid != null) { if(recipe.fluid != null) {
this.tank.setFill(tank.getFill() - recipe.fluid.fill); this.tank.setFill(tank.getFill() - recipe.fluid.fill);
} }
} }
protected DirPos[] getConPos() { protected DirPos[] getConPos() {
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10); ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10);
ForgeDirection rot = dir.getRotation(ForgeDirection.UP); ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
return new DirPos[] { return new DirPos[] {
new DirPos(xCoord + dir.offsetX, yCoord, zCoord + dir.offsetZ, dir), new DirPos(xCoord + dir.offsetX, yCoord, zCoord + dir.offsetZ, dir),
new DirPos(xCoord + dir.offsetX + rot.offsetX, yCoord, zCoord + dir.offsetZ + rot.offsetZ, dir), new DirPos(xCoord + dir.offsetX + rot.offsetX, yCoord, zCoord + dir.offsetZ + rot.offsetZ, dir),
@ -228,7 +231,7 @@ public class TileEntityMachineArcWelder extends TileEntityMachineBase implements
new DirPos(xCoord - dir.offsetX - rot.offsetX * 2, yCoord, zCoord - dir.offsetZ - rot.offsetZ * 2, rot.getOpposite()) new DirPos(xCoord - dir.offsetX - rot.offsetX * 2, yCoord, zCoord - dir.offsetZ - rot.offsetZ * 2, rot.getOpposite())
}; };
} }
@Override @Override
public void readFromNBT(NBTTagCompound nbt) { public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt); super.readFromNBT(nbt);
@ -239,7 +242,7 @@ public class TileEntityMachineArcWelder extends TileEntityMachineBase implements
this.processTime = nbt.getInteger("processTime"); this.processTime = nbt.getInteger("processTime");
tank.readFromNBT(nbt, "t"); tank.readFromNBT(nbt, "t");
} }
@Override @Override
public void writeToNBT(NBTTagCompound nbt) { public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt); super.writeToNBT(nbt);
@ -312,19 +315,19 @@ public class TileEntityMachineArcWelder extends TileEntityMachineBase implements
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10); ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10);
ForgeDirection rot = dir.getRotation(ForgeDirection.UP); ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
BlockPos core = new BlockPos(xCoord, yCoord, zCoord); BlockPos core = new BlockPos(xCoord, yCoord, zCoord);
//Red //Red
if(pos.equals(core.clone().offset(rot)) || pos.equals(core.clone().offset(rot.getOpposite()).offset(dir.getOpposite()))) if(pos.equals(core.clone().offset(rot)) || pos.equals(core.clone().offset(rot.getOpposite()).offset(dir.getOpposite())))
return new int[] { 0, 3 }; return new int[] { 0, 3 };
//Yellow //Yellow
if(pos.equals(core.clone().offset(dir.getOpposite()))) if(pos.equals(core.clone().offset(dir.getOpposite())))
return new int[] { 1, 3 }; return new int[] { 1, 3 };
//Green //Green
if(pos.equals(core.clone().offset(rot.getOpposite())) || pos.equals(core.clone().offset(rot).offset(dir.getOpposite()))) if(pos.equals(core.clone().offset(rot.getOpposite())) || pos.equals(core.clone().offset(rot).offset(dir.getOpposite())))
return new int[] { 2, 3 }; return new int[] { 2, 3 };
return new int[] { }; return new int[] { };
} }
@ -338,12 +341,12 @@ public class TileEntityMachineArcWelder extends TileEntityMachineBase implements
public Object provideGUI(int ID, EntityPlayer player, World world, int x, int y, int z) { public Object provideGUI(int ID, EntityPlayer player, World world, int x, int y, int z) {
return new GUIMachineArcWelder(player.inventory, this); return new GUIMachineArcWelder(player.inventory, this);
} }
AxisAlignedBB bb = null; AxisAlignedBB bb = null;
@Override @Override
public AxisAlignedBB getRenderBoundingBox() { public AxisAlignedBB getRenderBoundingBox() {
if(bb == null) { if(bb == null) {
bb = AxisAlignedBB.getBoundingBox( bb = AxisAlignedBB.getBoundingBox(
xCoord - 1, xCoord - 1,
@ -354,10 +357,10 @@ public class TileEntityMachineArcWelder extends TileEntityMachineBase implements
zCoord + 2 zCoord + 2
); );
} }
return bb; return bb;
} }
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public double getMaxRenderDistanceSquared() { public double getMaxRenderDistanceSquared() {
@ -383,10 +386,11 @@ public class TileEntityMachineArcWelder extends TileEntityMachineBase implements
} }
@Override @Override
public int getMaxLevel(UpgradeType type) { public HashMap<UpgradeType, Integer> getValidUpgrades() {
if(type == UpgradeType.SPEED) return 3; HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
if(type == UpgradeType.POWER) return 3; upgrades.put(UpgradeType.SPEED, 3);
return 0; upgrades.put(UpgradeType.POWER, 3);
return upgrades;
} }
@Override @Override

View File

@ -1,12 +1,13 @@
package com.hbm.tileentity.machine; package com.hbm.tileentity.machine;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
import com.hbm.blocks.BlockDummyable; import com.hbm.blocks.BlockDummyable;
import com.hbm.blocks.ModBlocks; import com.hbm.blocks.ModBlocks;
import com.hbm.handler.MultiblockHandlerXR; import com.hbm.handler.MultiblockHandlerXR;
import com.hbm.inventory.UpgradeManager; import com.hbm.inventory.UpgradeManagerNT;
import com.hbm.inventory.container.ContainerMachineAssembler; import com.hbm.inventory.container.ContainerMachineAssembler;
import com.hbm.inventory.gui.GUIMachineAssembler; import com.hbm.inventory.gui.GUIMachineAssembler;
import com.hbm.items.machine.ItemMachineUpgrade.UpgradeType; import com.hbm.items.machine.ItemMachineUpgrade.UpgradeType;
@ -31,11 +32,13 @@ import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityMachineAssembler extends TileEntityMachineAssemblerBase implements IUpgradeInfoProvider { public class TileEntityMachineAssembler extends TileEntityMachineAssemblerBase implements IUpgradeInfoProvider {
public int recipe = -1; public int recipe = -1;
public UpgradeManagerNT upgradeManager = new UpgradeManagerNT();
Random rand = new Random(); Random rand = new Random();
public TileEntityMachineAssembler() { public TileEntityMachineAssembler() {
super(18); super(18);
} }
@ -50,19 +53,19 @@ public class TileEntityMachineAssembler extends TileEntityMachineAssemblerBase i
if(i == 0) if(i == 0)
if(itemStack.getItem() instanceof IBatteryItem) if(itemStack.getItem() instanceof IBatteryItem)
return true; return true;
if(i == 1) if(i == 1)
return true; return true;
return false; return false;
} }
@Override @Override
public void updateEntity() { public void updateEntity() {
super.updateEntity(); super.updateEntity();
if(!worldObj.isRemote) { if(!worldObj.isRemote) {
//meta below 12 means that it's an old multiblock configuration //meta below 12 means that it's an old multiblock configuration
if(this.getBlockMetadata() < 12) { if(this.getBlockMetadata() < 12) {
int meta = this.getBlockMetadata(); int meta = this.getBlockMetadata();
@ -83,18 +86,18 @@ public class TileEntityMachineAssembler extends TileEntityMachineAssemblerBase i
worldObj.getTileEntity(xCoord, yCoord, zCoord).readFromNBT(data); worldObj.getTileEntity(xCoord, yCoord, zCoord).readFromNBT(data);
return; return;
} }
this.updateConnections(); this.updateConnections();
this.consumption = 100; this.consumption = 100;
this.speed = 100; this.speed = 100;
UpgradeManager.eval(slots, 1, 3);
int speedLevel = Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 3); upgradeManager.checkSlots(this, slots, 1, 3);
int powerLevel = Math.min(UpgradeManager.getLevel(UpgradeType.POWER), 3);
int overLevel = UpgradeManager.getLevel(UpgradeType.OVERDRIVE); int speedLevel = upgradeManager.getLevel(UpgradeType.SPEED);
int powerLevel = upgradeManager.getLevel(UpgradeType.POWER);
int overLevel = upgradeManager.getLevel(UpgradeType.OVERDRIVE);
speed -= speedLevel * 25; speed -= speedLevel * 25;
consumption += speedLevel * 300; consumption += speedLevel * 300;
speed += powerLevel * 5; speed += powerLevel * 5;
@ -107,14 +110,14 @@ public class TileEntityMachineAssembler extends TileEntityMachineAssemblerBase i
ComparableStack comp = ItemAssemblyTemplate.readType(slots[4]); ComparableStack comp = ItemAssemblyTemplate.readType(slots[4]);
rec = AssemblerRecipes.recipeList.indexOf(comp); rec = AssemblerRecipes.recipeList.indexOf(comp);
}*/ }*/
this.networkPackNT(150); this.networkPackNT(150);
} else { } else {
float volume = this.getVolume(2F); float volume = this.getVolume(2F);
if(isProgressing && volume > 0) { if(isProgressing && volume > 0) {
if(audio == null) { if(audio == null) {
audio = this.createAudioLoop(); audio = this.createAudioLoop();
audio.updateVolume(volume); audio.updateVolume(volume);
@ -123,9 +126,9 @@ public class TileEntityMachineAssembler extends TileEntityMachineAssemblerBase i
audio = rebootAudio(audio); audio = rebootAudio(audio);
audio.updateVolume(volume); audio.updateVolume(volume);
} }
} else { } else {
if(audio != null) { if(audio != null) {
audio.stopSound(); audio.stopSound();
audio = null; audio = null;
@ -133,7 +136,7 @@ public class TileEntityMachineAssembler extends TileEntityMachineAssemblerBase i
} }
} }
} }
@Override @Override
public void serialize(ByteBuf buf) { public void serialize(ByteBuf buf) {
super.serialize(buf); super.serialize(buf);
@ -142,11 +145,11 @@ public class TileEntityMachineAssembler extends TileEntityMachineAssemblerBase i
buf.writeInt(progress[i]); buf.writeInt(progress[i]);
buf.writeInt(maxProgress[i]); buf.writeInt(maxProgress[i]);
} }
buf.writeBoolean(isProgressing); buf.writeBoolean(isProgressing);
buf.writeInt(recipe); buf.writeInt(recipe);
} }
@Override @Override
public void deserialize(ByteBuf buf) { public void deserialize(ByteBuf buf) {
super.deserialize(buf); super.deserialize(buf);
@ -155,28 +158,28 @@ public class TileEntityMachineAssembler extends TileEntityMachineAssemblerBase i
progress[i] = buf.readInt(); progress[i] = buf.readInt();
maxProgress[i] = buf.readInt(); maxProgress[i] = buf.readInt();
} }
isProgressing = buf.readBoolean(); isProgressing = buf.readBoolean();
recipe = buf.readInt(); recipe = buf.readInt();
} }
@Override @Override
public AudioWrapper createAudioLoop() { public AudioWrapper createAudioLoop() {
return MainRegistry.proxy.getLoopedSound("hbm:block.assemblerOperate", xCoord, yCoord, zCoord, 1.0F, 10F, 1.0F); return MainRegistry.proxy.getLoopedSound("hbm:block.assemblerOperate", xCoord, yCoord, zCoord, 1.0F, 10F, 1.0F);
} }
private void updateConnections() { private void updateConnections() {
for(DirPos pos : getConPos()) { for(DirPos pos : getConPos()) {
this.trySubscribe(worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); this.trySubscribe(worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
} }
} }
public DirPos[] getConPos() { public DirPos[] getConPos() {
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset).getOpposite(); ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset).getOpposite();
ForgeDirection rot = dir.getRotation(ForgeDirection.DOWN); ForgeDirection rot = dir.getRotation(ForgeDirection.DOWN);
return new DirPos[] { return new DirPos[] {
new DirPos(xCoord + rot.offsetX * 3, yCoord, zCoord + rot.offsetZ * 3, rot), new DirPos(xCoord + rot.offsetX * 3, yCoord, zCoord + rot.offsetZ * 3, rot),
new DirPos(xCoord - rot.offsetX * 2, yCoord, zCoord - rot.offsetZ * 2, rot.getOpposite()), new DirPos(xCoord - rot.offsetX * 2, yCoord, zCoord - rot.offsetZ * 2, rot.getOpposite()),
@ -204,7 +207,7 @@ public class TileEntityMachineAssembler extends TileEntityMachineAssemblerBase i
audio = null; audio = null;
} }
} }
private AudioWrapper audio; private AudioWrapper audio;
@Override @Override
@ -244,12 +247,12 @@ public class TileEntityMachineAssembler extends TileEntityMachineAssemblerBase i
public long getMaxPower() { public long getMaxPower() {
return 100_000; return 100_000;
} }
@Override @Override
public AxisAlignedBB getRenderBoundingBox() { public AxisAlignedBB getRenderBoundingBox() {
return AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 1, zCoord + 1).expand(2, 1, 2); return AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 1, zCoord + 1).expand(2, 1, 2);
} }
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public double getMaxRenderDistanceSquared() { public double getMaxRenderDistanceSquared() {
@ -289,10 +292,11 @@ public class TileEntityMachineAssembler extends TileEntityMachineAssemblerBase i
} }
@Override @Override
public int getMaxLevel(UpgradeType type) { public HashMap<UpgradeType, Integer> getValidUpgrades() {
if(type == UpgradeType.SPEED) return 3; HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
if(type == UpgradeType.POWER) return 3; upgrades.put(UpgradeType.SPEED, 3);
if(type == UpgradeType.OVERDRIVE) return 9; upgrades.put(UpgradeType.POWER, 3);
return 0; upgrades.put(UpgradeType.OVERDRIVE, 3);
return upgrades;
} }
} }

View File

@ -1,11 +1,12 @@
package com.hbm.tileentity.machine; package com.hbm.tileentity.machine;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
import com.hbm.blocks.BlockDummyable; import com.hbm.blocks.BlockDummyable;
import com.hbm.blocks.ModBlocks; import com.hbm.blocks.ModBlocks;
import com.hbm.inventory.UpgradeManager; import com.hbm.inventory.UpgradeManagerNT;
import com.hbm.inventory.container.ContainerAssemfac; import com.hbm.inventory.container.ContainerAssemfac;
import com.hbm.inventory.fluid.Fluids; import com.hbm.inventory.fluid.Fluids;
import com.hbm.inventory.fluid.tank.FluidTank; import com.hbm.inventory.fluid.tank.FluidTank;
@ -31,15 +32,17 @@ import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityMachineAssemfac extends TileEntityMachineAssemblerBase implements IFluidStandardTransceiver, IUpgradeInfoProvider, IFluidCopiable { public class TileEntityMachineAssemfac extends TileEntityMachineAssemblerBase implements IFluidStandardTransceiver, IUpgradeInfoProvider, IFluidCopiable {
public AssemblerArm[] arms; public AssemblerArm[] arms;
public FluidTank water; public FluidTank water;
public FluidTank steam; public FluidTank steam;
public UpgradeManagerNT upgradeManager = new UpgradeManagerNT();
public TileEntityMachineAssemfac() { public TileEntityMachineAssemfac() {
super(14 * 8 + 4 + 1); //8 assembler groups with 14 slots, 4 upgrade slots, 1 battery slot super(14 * 8 + 4 + 1); //8 assembler groups with 14 slots, 4 upgrade slots, 1 battery slot
arms = new AssemblerArm[6]; arms = new AssemblerArm[6];
for(int i = 0; i < arms.length; i++) { for(int i = 0; i < arms.length; i++) {
arms[i] = new AssemblerArm(i % 3 == 1 ? 1 : 0); //the second of every group of three becomes a welder arms[i] = new AssemblerArm(i % 3 == 1 ? 1 : 0); //the second of every group of three becomes a welder
@ -57,7 +60,7 @@ public class TileEntityMachineAssemfac extends TileEntityMachineAssemblerBase im
@Override @Override
public void setInventorySlotContents(int i, ItemStack stack) { public void setInventorySlotContents(int i, ItemStack stack) {
super.setInventorySlotContents(i, stack); super.setInventorySlotContents(i, stack);
if(stack != null && i >= 1 && i <= 4 && stack.getItem() instanceof ItemMachineUpgrade) { if(stack != null && i >= 1 && i <= 4 && stack.getItem() instanceof ItemMachineUpgrade) {
worldObj.playSoundEffect(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5, "hbm:item.upgradePlug", 1.0F, 1.0F); worldObj.playSoundEffect(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5, "hbm:item.upgradePlug", 1.0F, 1.0F);
} }
@ -66,37 +69,37 @@ public class TileEntityMachineAssemfac extends TileEntityMachineAssemblerBase im
@Override @Override
public void updateEntity() { public void updateEntity() {
super.updateEntity(); super.updateEntity();
if(!worldObj.isRemote) { if(!worldObj.isRemote) {
if(worldObj.getTotalWorldTime() % 20 == 0) { if(worldObj.getTotalWorldTime() % 20 == 0) {
this.updateConnections(); this.updateConnections();
} }
this.speed = 100; this.speed = 100;
this.consumption = 100; this.consumption = 100;
UpgradeManager.eval(slots, 1, 4);
int speedLevel = Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 6); upgradeManager.checkSlots(this, slots, 1, 4);
int powerLevel = Math.min(UpgradeManager.getLevel(UpgradeType.POWER), 3);
int overLevel = UpgradeManager.getLevel(UpgradeType.OVERDRIVE); int speedLevel = upgradeManager.getLevel(UpgradeType.SPEED);
int powerLevel = upgradeManager.getLevel(UpgradeType.POWER);
int overLevel = upgradeManager.getLevel(UpgradeType.OVERDRIVE);
this.speed -= speedLevel * 15; this.speed -= speedLevel * 15;
this.consumption += speedLevel * 300; this.consumption += speedLevel * 300;
this.speed += powerLevel * 5; this.speed += powerLevel * 5;
this.consumption -= powerLevel * 30; this.consumption -= powerLevel * 30;
this.speed /= (overLevel + 1); this.speed /= (overLevel + 1);
this.consumption *= (overLevel + 1); this.consumption *= (overLevel + 1);
for(DirPos pos : getConPos()) { for(DirPos pos : getConPos()) {
this.sendFluid(steam, worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); this.sendFluid(steam, worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
} }
this.networkPackNT(150); this.networkPackNT(150);
} else { } else {
for(AssemblerArm arm : arms) { for(AssemblerArm arm : arms) {
arm.updateInterp(); arm.updateInterp();
if(isProgressing) { if(isProgressing) {
@ -105,7 +108,7 @@ public class TileEntityMachineAssemfac extends TileEntityMachineAssemblerBase im
} }
} }
} }
@Override @Override
public void serialize(ByteBuf buf) { public void serialize(ByteBuf buf) {
super.serialize(buf); super.serialize(buf);
@ -118,7 +121,7 @@ public class TileEntityMachineAssemfac extends TileEntityMachineAssemblerBase im
water.serialize(buf); water.serialize(buf);
steam.serialize(buf); steam.serialize(buf);
} }
@Override @Override
public void deserialize(ByteBuf buf) { public void deserialize(ByteBuf buf) {
super.deserialize(buf); super.deserialize(buf);
@ -131,7 +134,7 @@ public class TileEntityMachineAssemfac extends TileEntityMachineAssemblerBase im
water.deserialize(buf); water.deserialize(buf);
steam.deserialize(buf); steam.deserialize(buf);
} }
private int getWaterRequired() { private int getWaterRequired() {
return 1000 / this.speed; return 1000 / this.speed;
} }
@ -147,19 +150,19 @@ public class TileEntityMachineAssemfac extends TileEntityMachineAssemblerBase im
this.water.setFill(this.water.getFill() - getWaterRequired()); this.water.setFill(this.water.getFill() - getWaterRequired());
this.steam.setFill(this.steam.getFill() + getWaterRequired()); this.steam.setFill(this.steam.getFill() + getWaterRequired());
} }
private void updateConnections() { private void updateConnections() {
for(DirPos pos : getConPos()) { for(DirPos pos : getConPos()) {
this.trySubscribe(worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); this.trySubscribe(worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
this.trySubscribe(water.getTankType(), worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); this.trySubscribe(water.getTankType(), worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
} }
} }
public DirPos[] getConPos() { public DirPos[] getConPos() {
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset); ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset);
ForgeDirection rot = dir.getRotation(ForgeDirection.UP); ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
return new DirPos[] { return new DirPos[] {
new DirPos(xCoord - dir.offsetX * 3 + rot.offsetX * 5, yCoord, zCoord - dir.offsetZ * 3 + rot.offsetZ * 5, rot), new DirPos(xCoord - dir.offsetX * 3 + rot.offsetX * 5, yCoord, zCoord - dir.offsetZ * 3 + rot.offsetZ * 5, rot),
new DirPos(xCoord + dir.offsetX * 2 + rot.offsetX * 5, yCoord, zCoord + dir.offsetZ * 2 + rot.offsetZ * 5, rot), new DirPos(xCoord + dir.offsetX * 2 + rot.offsetX * 5, yCoord, zCoord + dir.offsetZ * 2 + rot.offsetZ * 5, rot),
@ -171,22 +174,22 @@ public class TileEntityMachineAssemfac extends TileEntityMachineAssemblerBase im
new DirPos(xCoord + dir.offsetX * 4 - rot.offsetX * 2, yCoord, zCoord + dir.offsetZ * 4 - rot.offsetZ * 2, dir) new DirPos(xCoord + dir.offsetX * 4 - rot.offsetX * 2, yCoord, zCoord + dir.offsetZ * 4 - rot.offsetZ * 2, dir)
}; };
} }
public static class AssemblerArm { public static class AssemblerArm {
public double[] angles = new double[4]; public double[] angles = new double[4];
public double[] prevAngles = new double[4]; public double[] prevAngles = new double[4];
public double[] targetAngles = new double[4]; public double[] targetAngles = new double[4];
public double[] speed = new double[4]; public double[] speed = new double[4];
Random rand = new Random(); Random rand = new Random();
int actionMode; int actionMode;
ArmActionState state; ArmActionState state;
int actionDelay = 0; int actionDelay = 0;
public AssemblerArm(int actionMode) { public AssemblerArm(int actionMode) {
this.actionMode = actionMode; this.actionMode = actionMode;
if(this.actionMode == 0) { if(this.actionMode == 0) {
speed[0] = 15; //Pivot speed[0] = 15; //Pivot
speed[1] = 15; //Arm speed[1] = 15; //Arm
@ -198,19 +201,19 @@ public class TileEntityMachineAssemfac extends TileEntityMachineAssemblerBase im
speed[2] = 1; //Piston speed[2] = 1; //Piston
speed[3] = 0.125; //Striker speed[3] = 0.125; //Striker
} }
state = ArmActionState.ASSUME_POSITION; state = ArmActionState.ASSUME_POSITION;
chooseNewArmPoistion(); chooseNewArmPoistion();
actionDelay = rand.nextInt(20); actionDelay = rand.nextInt(20);
} }
public void updateArm() { public void updateArm() {
if(actionDelay > 0) { if(actionDelay > 0) {
actionDelay--; actionDelay--;
return; return;
} }
switch(state) { switch(state) {
//Move. If done moving, set a delay and progress to EXTEND //Move. If done moving, set a delay and progress to EXTEND
case ASSUME_POSITION: case ASSUME_POSITION:
@ -254,12 +257,12 @@ public class TileEntityMachineAssemfac extends TileEntityMachineAssemblerBase im
state = ArmActionState.ASSUME_POSITION; state = ArmActionState.ASSUME_POSITION;
} }
break; break;
} }
} }
public void chooseNewArmPoistion() { public void chooseNewArmPoistion() {
if(this.actionMode == 0) { if(this.actionMode == 0) {
targetAngles[0] = -rand.nextInt(50); //Pivot targetAngles[0] = -rand.nextInt(50); //Pivot
targetAngles[1] = -targetAngles[0]; //Arm targetAngles[1] = -targetAngles[0]; //Arm
@ -270,45 +273,45 @@ public class TileEntityMachineAssemfac extends TileEntityMachineAssemblerBase im
targetAngles[2] = rand.nextInt(10) + 10; //Piston targetAngles[2] = rand.nextInt(10) + 10; //Piston
} }
} }
private void updateInterp() { private void updateInterp() {
for(int i = 0; i < angles.length; i++) { for(int i = 0; i < angles.length; i++) {
prevAngles[i] = angles[i]; prevAngles[i] = angles[i];
} }
} }
/** /**
* @return True when it has finished moving * @return True when it has finished moving
*/ */
private boolean move() { private boolean move() {
boolean didMove = false; boolean didMove = false;
for(int i = 0; i < angles.length; i++) { for(int i = 0; i < angles.length; i++) {
if(angles[i] == targetAngles[i]) if(angles[i] == targetAngles[i])
continue; continue;
didMove = true; didMove = true;
double angle = angles[i]; double angle = angles[i];
double target = targetAngles[i]; double target = targetAngles[i];
double turn = speed[i]; double turn = speed[i];
double delta = Math.abs(angle - target); double delta = Math.abs(angle - target);
if(delta <= turn) { if(delta <= turn) {
angles[i] = targetAngles[i]; angles[i] = targetAngles[i];
continue; continue;
} }
if(angle < target) { if(angle < target) {
angles[i] += turn; angles[i] += turn;
} else { } else {
angles[i] -= turn; angles[i] -= turn;
} }
} }
return !didMove; return !didMove;
} }
public static enum ArmActionState { public static enum ArmActionState {
ASSUME_POSITION, ASSUME_POSITION,
EXTEND_STRIKER, EXTEND_STRIKER,
@ -316,12 +319,12 @@ public class TileEntityMachineAssemfac extends TileEntityMachineAssemblerBase im
RETRACT_STRIKER RETRACT_STRIKER
} }
} }
AxisAlignedBB bb = null; AxisAlignedBB bb = null;
@Override @Override
public AxisAlignedBB getRenderBoundingBox() { public AxisAlignedBB getRenderBoundingBox() {
if(bb == null) { if(bb == null) {
bb = AxisAlignedBB.getBoundingBox( bb = AxisAlignedBB.getBoundingBox(
xCoord - 5, xCoord - 5,
@ -332,10 +335,10 @@ public class TileEntityMachineAssemfac extends TileEntityMachineAssemblerBase im
zCoord + 5 zCoord + 5
); );
} }
return bb; return bb;
} }
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public double getMaxRenderDistanceSquared() { public double getMaxRenderDistanceSquared() {
@ -364,42 +367,42 @@ public class TileEntityMachineAssemfac extends TileEntityMachineAssemblerBase im
DirPos[] inpos; DirPos[] inpos;
DirPos[] outpos; DirPos[] outpos;
@Override @Override
public DirPos[] getInputPositions() { public DirPos[] getInputPositions() {
if(inpos != null) if(inpos != null)
return inpos; return inpos;
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset); ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset);
ForgeDirection rot = dir.getRotation(ForgeDirection.UP); ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
inpos = new DirPos[] { inpos = new DirPos[] {
new DirPos(xCoord + dir.offsetX * 4 - rot.offsetX * 1, yCoord, zCoord + dir.offsetZ * 4 - rot.offsetZ * 1, dir), new DirPos(xCoord + dir.offsetX * 4 - rot.offsetX * 1, yCoord, zCoord + dir.offsetZ * 4 - rot.offsetZ * 1, dir),
new DirPos(xCoord - dir.offsetX * 5 + rot.offsetX * 2, yCoord, zCoord - dir.offsetZ * 5 + rot.offsetZ * 2, dir.getOpposite()), new DirPos(xCoord - dir.offsetX * 5 + rot.offsetX * 2, yCoord, zCoord - dir.offsetZ * 5 + rot.offsetZ * 2, dir.getOpposite()),
new DirPos(xCoord - dir.offsetX * 2 - rot.offsetX * 4, yCoord, zCoord - dir.offsetZ * 2 - rot.offsetZ * 4, rot.getOpposite()), new DirPos(xCoord - dir.offsetX * 2 - rot.offsetX * 4, yCoord, zCoord - dir.offsetZ * 2 - rot.offsetZ * 4, rot.getOpposite()),
new DirPos(xCoord + dir.offsetX * 1 + rot.offsetX * 5, yCoord, zCoord + dir.offsetZ * 1 + rot.offsetZ * 5, rot) new DirPos(xCoord + dir.offsetX * 1 + rot.offsetX * 5, yCoord, zCoord + dir.offsetZ * 1 + rot.offsetZ * 5, rot)
}; };
return inpos; return inpos;
} }
@Override @Override
public DirPos[] getOutputPositions() { public DirPos[] getOutputPositions() {
if(outpos != null) if(outpos != null)
return outpos; return outpos;
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset); ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset);
ForgeDirection rot = dir.getRotation(ForgeDirection.UP); ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
outpos = new DirPos[] { outpos = new DirPos[] {
new DirPos(xCoord + dir.offsetX * 4 + rot.offsetX * 2, yCoord, zCoord + dir.offsetZ * 4 + rot.offsetZ * 2, dir), new DirPos(xCoord + dir.offsetX * 4 + rot.offsetX * 2, yCoord, zCoord + dir.offsetZ * 4 + rot.offsetZ * 2, dir),
new DirPos(xCoord - dir.offsetX * 5 - rot.offsetX * 1, yCoord, zCoord - dir.offsetZ * 5 - rot.offsetZ * 1, dir.getOpposite()), new DirPos(xCoord - dir.offsetX * 5 - rot.offsetX * 1, yCoord, zCoord - dir.offsetZ * 5 - rot.offsetZ * 1, dir.getOpposite()),
new DirPos(xCoord + dir.offsetX * 1 - rot.offsetX * 4, yCoord, zCoord + dir.offsetZ * 1 - rot.offsetZ * 4, rot.getOpposite()), new DirPos(xCoord + dir.offsetX * 1 - rot.offsetX * 4, yCoord, zCoord + dir.offsetZ * 1 - rot.offsetZ * 4, rot.getOpposite()),
new DirPos(xCoord - dir.offsetX * 2 + rot.offsetX * 5, yCoord, zCoord - dir.offsetZ * 2 + rot.offsetZ * 5, rot) new DirPos(xCoord - dir.offsetX * 2 + rot.offsetX * 5, yCoord, zCoord - dir.offsetZ * 2 + rot.offsetZ * 5, rot)
}; };
return outpos; return outpos;
} }
@ -456,11 +459,12 @@ public class TileEntityMachineAssemfac extends TileEntityMachineAssemblerBase im
} }
@Override @Override
public int getMaxLevel(UpgradeType type) { public HashMap<UpgradeType, Integer> getValidUpgrades() {
if(type == UpgradeType.SPEED) return 6; HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
if(type == UpgradeType.POWER) return 3; upgrades.put(UpgradeType.SPEED, 6);
if(type == UpgradeType.OVERDRIVE) return 12; upgrades.put(UpgradeType.POWER, 3);
return 0; upgrades.put(UpgradeType.OVERDRIVE, 12);
return upgrades;
} }
@Override @Override

View File

@ -1,12 +1,13 @@
package com.hbm.tileentity.machine; package com.hbm.tileentity.machine;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap;
import java.util.List; import java.util.List;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.stream.JsonWriter; import com.google.gson.stream.JsonWriter;
import com.hbm.blocks.ModBlocks; import com.hbm.blocks.ModBlocks;
import com.hbm.inventory.UpgradeManager; import com.hbm.inventory.UpgradeManagerNT;
import com.hbm.inventory.container.ContainerCentrifuge; import com.hbm.inventory.container.ContainerCentrifuge;
import com.hbm.inventory.gui.GUIMachineCentrifuge; import com.hbm.inventory.gui.GUIMachineCentrifuge;
import com.hbm.inventory.recipes.CentrifugeRecipes; import com.hbm.inventory.recipes.CentrifugeRecipes;
@ -38,12 +39,12 @@ import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityMachineCentrifuge extends TileEntityMachineBase implements IEnergyReceiverMK2, IGUIProvider, IUpgradeInfoProvider, IInfoProviderEC, IConfigurableMachine{ public class TileEntityMachineCentrifuge extends TileEntityMachineBase implements IEnergyReceiverMK2, IGUIProvider, IUpgradeInfoProvider, IInfoProviderEC, IConfigurableMachine{
public int progress; public int progress;
public long power; public long power;
public boolean isProgressing; public boolean isProgressing;
private int audioDuration = 0; private int audioDuration = 0;
private AudioWrapper audio; private AudioWrapper audio;
//configurable values //configurable values
@ -51,6 +52,8 @@ public class TileEntityMachineCentrifuge extends TileEntityMachineBase implement
public static int processingSpeed = 200; public static int processingSpeed = 200;
public static int baseConsumption = 200; public static int baseConsumption = 200;
public UpgradeManagerNT upgradeManager = new UpgradeManagerNT();
public String getConfigName() { public String getConfigName() {
return "centrifuge"; return "centrifuge";
} }
@ -70,7 +73,7 @@ public class TileEntityMachineCentrifuge extends TileEntityMachineBase implement
/* /*
* So why do we do this now? You have a funny mekanism/thermal/whatever pipe and you want to output stuff from a side * So why do we do this now? You have a funny mekanism/thermal/whatever pipe and you want to output stuff from a side
* that isn't the bottom, what do? Answer: make all slots accessible from all sides and regulate in/output in the * that isn't the bottom, what do? Answer: make all slots accessible from all sides and regulate in/output in the
* dedicated methods. Duh. * dedicated methods. Duh.
*/ */
private static final int[] slot_io = new int[] { 0, 2, 3, 4, 5 }; private static final int[] slot_io = new int[] { 0, 2, 3, 4, 5 };
@ -78,11 +81,11 @@ public class TileEntityMachineCentrifuge extends TileEntityMachineBase implement
public TileEntityMachineCentrifuge() { public TileEntityMachineCentrifuge() {
super(8); super(8);
} }
public String getName() { public String getName() {
return "container.centrifuge"; return "container.centrifuge";
} }
@Override @Override
public boolean isItemValidForSlot(int i, ItemStack itemStack) { public boolean isItemValidForSlot(int i, ItemStack itemStack) {
return i == 0; return i == 0;
@ -126,7 +129,7 @@ public class TileEntityMachineCentrifuge extends TileEntityMachineBase implement
return false; return false;
} }
ItemStack[] out = CentrifugeRecipes.getOutput(slots[0]); ItemStack[] out = CentrifugeRecipes.getOutput(slots[0]);
if(out == null) { if(out == null) {
return false; return false;
} }
@ -175,7 +178,7 @@ public class TileEntityMachineCentrifuge extends TileEntityMachineBase implement
public boolean isProcessing() { public boolean isProcessing() {
return this.progress > 0; return this.progress > 0;
} }
@Override @Override
public void updateEntity() { public void updateEntity() {
@ -184,18 +187,18 @@ public class TileEntityMachineCentrifuge extends TileEntityMachineBase implement
for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) this.trySubscribe(worldObj, xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ, dir); for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) this.trySubscribe(worldObj, xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ, dir);
power = Library.chargeTEFromItems(slots, 1, power, maxPower); power = Library.chargeTEFromItems(slots, 1, power, maxPower);
int consumption = baseConsumption; int consumption = baseConsumption;
int speed = 1; int speed = 1;
UpgradeManager.eval(slots, 6, 7); upgradeManager.checkSlots(this, slots, 6, 7);
speed += Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 3); speed += upgradeManager.getLevel(UpgradeType.SPEED);
consumption += Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 3) * baseConsumption; consumption += upgradeManager.getLevel(UpgradeType.SPEED) * baseConsumption;
speed *= (1 + Math.min(UpgradeManager.getLevel(UpgradeType.OVERDRIVE), 3) * 5); speed *= (1 + upgradeManager.getLevel(UpgradeType.OVERDRIVE) * 5);
consumption += Math.min(UpgradeManager.getLevel(UpgradeType.OVERDRIVE), 3) * baseConsumption * 50; consumption += upgradeManager.getLevel(UpgradeType.OVERDRIVE) * baseConsumption * 50;
consumption /= (1 + Math.min(UpgradeManager.getLevel(UpgradeType.POWER), 3)); consumption /= (1 + upgradeManager.getLevel(UpgradeType.POWER));
if(hasPower() && isProcessing()) { if(hasPower() && isProcessing()) {
this.power -= consumption; this.power -= consumption;
@ -221,20 +224,20 @@ public class TileEntityMachineCentrifuge extends TileEntityMachineBase implement
} else { } else {
progress = 0; progress = 0;
} }
this.networkPackNT(50); this.networkPackNT(50);
} else { } else {
if(isProgressing) { if(isProgressing) {
audioDuration += 2; audioDuration += 2;
} else { } else {
audioDuration -= 3; audioDuration -= 3;
} }
audioDuration = MathHelper.clamp_int(audioDuration, 0, 60); audioDuration = MathHelper.clamp_int(audioDuration, 0, 60);
if(audioDuration > 10) { if(audioDuration > 10) {
if(audio == null) { if(audio == null) {
audio = createAudioLoop(); audio = createAudioLoop();
audio.startSound(); audio.startSound();
@ -244,9 +247,9 @@ public class TileEntityMachineCentrifuge extends TileEntityMachineBase implement
audio.updateVolume(getVolume(1F)); audio.updateVolume(getVolume(1F));
audio.updatePitch((audioDuration - 10) / 100F + 0.5F); audio.updatePitch((audioDuration - 10) / 100F + 0.5F);
} else { } else {
if(audio != null) { if(audio != null) {
audio.stopSound(); audio.stopSound();
audio = null; audio = null;
@ -254,7 +257,7 @@ public class TileEntityMachineCentrifuge extends TileEntityMachineBase implement
} }
} }
} }
@Override @Override
public void serialize(ByteBuf buf) { public void serialize(ByteBuf buf) {
super.serialize(buf); super.serialize(buf);
@ -262,7 +265,7 @@ public class TileEntityMachineCentrifuge extends TileEntityMachineBase implement
buf.writeInt(progress); buf.writeInt(progress);
buf.writeBoolean(isProgressing); buf.writeBoolean(isProgressing);
} }
@Override @Override
public void deserialize(ByteBuf buf) { public void deserialize(ByteBuf buf) {
super.deserialize(buf); super.deserialize(buf);
@ -295,12 +298,12 @@ public class TileEntityMachineCentrifuge extends TileEntityMachineBase implement
audio = null; audio = null;
} }
} }
AxisAlignedBB bb = null; AxisAlignedBB bb = null;
@Override @Override
public AxisAlignedBB getRenderBoundingBox() { public AxisAlignedBB getRenderBoundingBox() {
if(bb == null) { if(bb == null) {
bb = AxisAlignedBB.getBoundingBox( bb = AxisAlignedBB.getBoundingBox(
xCoord, xCoord,
@ -311,7 +314,7 @@ public class TileEntityMachineCentrifuge extends TileEntityMachineBase implement
zCoord + 1 zCoord + 1
); );
} }
return bb; return bb;
} }
@ -369,11 +372,12 @@ public class TileEntityMachineCentrifuge extends TileEntityMachineBase implement
} }
@Override @Override
public int getMaxLevel(UpgradeType type) { public HashMap<UpgradeType, Integer> getValidUpgrades() {
if(type == UpgradeType.SPEED) return 3; HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
if(type == UpgradeType.POWER) return 3; upgrades.put(UpgradeType.SPEED, 3);
if(type == UpgradeType.OVERDRIVE) return 3; upgrades.put(UpgradeType.POWER, 3);
return 0; upgrades.put(UpgradeType.OVERDRIVE, 3);
return upgrades;
} }
@Override @Override
@ -381,4 +385,4 @@ public class TileEntityMachineCentrifuge extends TileEntityMachineBase implement
data.setBoolean(CompatEnergyControl.B_ACTIVE, this.progress > 0); data.setBoolean(CompatEnergyControl.B_ACTIVE, this.progress > 0);
data.setInteger(CompatEnergyControl.B_ACTIVE, this.progress); data.setInteger(CompatEnergyControl.B_ACTIVE, this.progress);
} }
} }

View File

@ -1,12 +1,13 @@
package com.hbm.tileentity.machine; package com.hbm.tileentity.machine;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
import com.hbm.blocks.BlockDummyable; import com.hbm.blocks.BlockDummyable;
import com.hbm.blocks.ModBlocks; import com.hbm.blocks.ModBlocks;
import com.hbm.inventory.UpgradeManager; import com.hbm.inventory.UpgradeManagerNT;
import com.hbm.inventory.container.ContainerChemfac; import com.hbm.inventory.container.ContainerChemfac;
import com.hbm.inventory.fluid.Fluids; import com.hbm.inventory.fluid.Fluids;
import com.hbm.inventory.fluid.tank.FluidTank; import com.hbm.inventory.fluid.tank.FluidTank;
@ -33,7 +34,7 @@ import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityMachineChemfac extends TileEntityMachineChemplantBase implements IUpgradeInfoProvider, IFluidCopiable { public class TileEntityMachineChemfac extends TileEntityMachineChemplantBase implements IUpgradeInfoProvider, IFluidCopiable {
float rotSpeed; float rotSpeed;
public float rot; public float rot;
public float prevRot; public float prevRot;
@ -41,6 +42,8 @@ public class TileEntityMachineChemfac extends TileEntityMachineChemplantBase imp
public FluidTank water; public FluidTank water;
public FluidTank steam; public FluidTank steam;
public UpgradeManagerNT upgradeManager = new UpgradeManagerNT();
public TileEntityMachineChemfac() { public TileEntityMachineChemfac() {
super(77); super(77);
@ -51,7 +54,7 @@ public class TileEntityMachineChemfac extends TileEntityMachineChemplantBase imp
@Override @Override
public void setInventorySlotContents(int i, ItemStack stack) { public void setInventorySlotContents(int i, ItemStack stack) {
super.setInventorySlotContents(i, stack); super.setInventorySlotContents(i, stack);
if(stack != null && i >= 1 && i <= 4 && stack.getItem() instanceof ItemMachineUpgrade) { if(stack != null && i >= 1 && i <= 4 && stack.getItem() instanceof ItemMachineUpgrade) {
worldObj.playSoundEffect(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5, "hbm:item.upgradePlug", 1.0F, 1.0F); worldObj.playSoundEffect(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5, "hbm:item.upgradePlug", 1.0F, 1.0F);
} }
@ -60,14 +63,14 @@ public class TileEntityMachineChemfac extends TileEntityMachineChemplantBase imp
@Override @Override
public void updateEntity() { public void updateEntity() {
super.updateEntity(); super.updateEntity();
if(!worldObj.isRemote) { if(!worldObj.isRemote) {
if(worldObj.getTotalWorldTime() % 60 == 0) { if(worldObj.getTotalWorldTime() % 60 == 0) {
for(DirPos pos : getConPos()) { for(DirPos pos : getConPos()) {
this.trySubscribe(worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); this.trySubscribe(worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
for(FluidTank tank : inTanks()) { for(FluidTank tank : inTanks()) {
if(tank.getTankType() != Fluids.NONE) { if(tank.getTankType() != Fluids.NONE) {
this.trySubscribe(tank.getTankType(), worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); this.trySubscribe(tank.getTankType(), worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
@ -75,77 +78,77 @@ public class TileEntityMachineChemfac extends TileEntityMachineChemplantBase imp
} }
} }
} }
for(DirPos pos : getConPos()) for(FluidTank tank : outTanks()) { for(DirPos pos : getConPos()) for(FluidTank tank : outTanks()) {
if(tank.getTankType() != Fluids.NONE && tank.getFill() > 0) { if(tank.getTankType() != Fluids.NONE && tank.getFill() > 0) {
this.sendFluid(tank, worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); this.sendFluid(tank, worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
} }
} }
this.speed = 100; this.speed = 100;
this.consumption = 100; this.consumption = 100;
UpgradeManager.eval(slots, 1, 4);
int speedLevel = Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 6); upgradeManager.checkSlots(this, slots, 1, 4);
int powerLevel = Math.min(UpgradeManager.getLevel(UpgradeType.POWER), 3);
int overLevel = UpgradeManager.getLevel(UpgradeType.OVERDRIVE); int speedLevel = upgradeManager.getLevel(UpgradeType.SPEED);
int powerLevel = upgradeManager.getLevel(UpgradeType.POWER);
int overLevel = upgradeManager.getLevel(UpgradeType.OVERDRIVE);
this.speed -= speedLevel * 15; this.speed -= speedLevel * 15;
this.consumption += speedLevel * 300; this.consumption += speedLevel * 300;
this.speed += powerLevel * 5; this.speed += powerLevel * 5;
this.consumption -= powerLevel * 20; this.consumption -= powerLevel * 20;
this.speed /= (overLevel + 1); this.speed /= (overLevel + 1);
this.consumption *= (overLevel + 1); this.consumption *= (overLevel + 1);
if(this.speed <= 0) { if(this.speed <= 0) {
this.speed = 1; this.speed = 1;
} }
this.networkPackNT(150); this.networkPackNT(150);
} else { } else {
float maxSpeed = 30F; float maxSpeed = 30F;
if(isProgressing) { if(isProgressing) {
rotSpeed += 0.1; rotSpeed += 0.1;
if(rotSpeed > maxSpeed) if(rotSpeed > maxSpeed)
rotSpeed = maxSpeed; rotSpeed = maxSpeed;
if(rotSpeed == maxSpeed && this.worldObj.getTotalWorldTime() % 5 == 0) { if(rotSpeed == maxSpeed && this.worldObj.getTotalWorldTime() % 5 == 0) {
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset).getOpposite(); ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset).getOpposite();
ForgeDirection rot = dir.getRotation(ForgeDirection.UP); ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
Random rand = worldObj.rand; Random rand = worldObj.rand;
double x = xCoord + 0.5 - rot.offsetX * 0.5; double x = xCoord + 0.5 - rot.offsetX * 0.5;
double y = yCoord + 3; double y = yCoord + 3;
double z = zCoord + 0.5 - rot.offsetZ * 0.5; double z = zCoord + 0.5 - rot.offsetZ * 0.5;
worldObj.spawnParticle("cloud", x + dir.offsetX * 1.5 + rand.nextGaussian() * 0.15, y, z + dir.offsetZ * 1.5 + rand.nextGaussian() * 0.15, 0.0, 0.15, 0.0); worldObj.spawnParticle("cloud", x + dir.offsetX * 1.5 + rand.nextGaussian() * 0.15, y, z + dir.offsetZ * 1.5 + rand.nextGaussian() * 0.15, 0.0, 0.15, 0.0);
worldObj.spawnParticle("cloud", x - dir.offsetX * 0.5 + rand.nextGaussian() * 0.15, y, z - dir.offsetZ * 0.5 + rand.nextGaussian() * 0.15, 0.0, 0.15, 0.0); worldObj.spawnParticle("cloud", x - dir.offsetX * 0.5 + rand.nextGaussian() * 0.15, y, z - dir.offsetZ * 0.5 + rand.nextGaussian() * 0.15, 0.0, 0.15, 0.0);
} }
} else { } else {
rotSpeed -= 0.1; rotSpeed -= 0.1;
if(rotSpeed < 0) if(rotSpeed < 0)
rotSpeed = 0; rotSpeed = 0;
} }
prevRot = rot; prevRot = rot;
rot += rotSpeed; rot += rotSpeed;
if(rot >= 360) { if(rot >= 360) {
rot -= 360; rot -= 360;
prevRot -= 360; prevRot -= 360;
} }
} }
} }
@Override @Override
public void serialize(ByteBuf buf) { public void serialize(ByteBuf buf) {
super.serialize(buf); super.serialize(buf);
@ -154,15 +157,15 @@ public class TileEntityMachineChemfac extends TileEntityMachineChemplantBase imp
buf.writeInt(progress[i]); buf.writeInt(progress[i]);
buf.writeInt(maxProgress[i]); buf.writeInt(maxProgress[i]);
} }
buf.writeBoolean(isProgressing); buf.writeBoolean(isProgressing);
for(int i = 0; i < tanks.length; i++) tanks[i].serialize(buf); for(int i = 0; i < tanks.length; i++) tanks[i].serialize(buf);
water.serialize(buf); water.serialize(buf);
steam.serialize(buf); steam.serialize(buf);
} }
@Override @Override
public void deserialize(ByteBuf buf) { public void deserialize(ByteBuf buf) {
super.deserialize(buf); super.deserialize(buf);
@ -171,15 +174,15 @@ public class TileEntityMachineChemfac extends TileEntityMachineChemplantBase imp
progress[i] = buf.readInt(); progress[i] = buf.readInt();
maxProgress[i] = buf.readInt(); maxProgress[i] = buf.readInt();
} }
isProgressing = buf.readBoolean(); isProgressing = buf.readBoolean();
for(int i = 0; i < tanks.length; i++) tanks[i].deserialize(buf); for(int i = 0; i < tanks.length; i++) tanks[i].deserialize(buf);
water.deserialize(buf); water.deserialize(buf);
steam.deserialize(buf); steam.deserialize(buf);
} }
private int getWaterRequired() { private int getWaterRequired() {
return 1000 / this.speed; return 1000 / this.speed;
} }
@ -201,19 +204,19 @@ public class TileEntityMachineChemfac extends TileEntityMachineChemplantBase imp
public long getMaxPower() { public long getMaxPower() {
return 10_000_000; return 10_000_000;
} }
protected List<DirPos> conPos; protected List<DirPos> conPos;
protected List<DirPos> getConPos() { protected List<DirPos> getConPos() {
if(conPos != null && !conPos.isEmpty()) if(conPos != null && !conPos.isEmpty())
return conPos; return conPos;
conPos = new ArrayList(); conPos = new ArrayList();
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset).getOpposite(); ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset).getOpposite();
ForgeDirection rot = dir.getRotation(ForgeDirection.DOWN); ForgeDirection rot = dir.getRotation(ForgeDirection.DOWN);
for(int i = 0; i < 6; i++) { for(int i = 0; i < 6; i++) {
conPos.add(new DirPos(xCoord + dir.offsetX * (3 - i) + rot.offsetX * 3, yCoord + 4, zCoord + dir.offsetZ * (3 - i) + rot.offsetZ * 3, Library.POS_Y)); conPos.add(new DirPos(xCoord + dir.offsetX * (3 - i) + rot.offsetX * 3, yCoord + 4, zCoord + dir.offsetZ * (3 - i) + rot.offsetZ * 3, Library.POS_Y));
conPos.add(new DirPos(xCoord + dir.offsetX * (3 - i) - rot.offsetX * 2, yCoord + 4, zCoord + dir.offsetZ * (3 - i) - rot.offsetZ * 2, Library.POS_Y)); conPos.add(new DirPos(xCoord + dir.offsetX * (3 - i) - rot.offsetX * 2, yCoord + 4, zCoord + dir.offsetZ * (3 - i) - rot.offsetZ * 2, Library.POS_Y));
@ -223,7 +226,7 @@ public class TileEntityMachineChemfac extends TileEntityMachineChemplantBase imp
conPos.add(new DirPos(xCoord + dir.offsetX * (3 - i) - rot.offsetX * 4, yCoord + 1 + j, zCoord + dir.offsetZ * (3 - i) - rot.offsetZ * 4, rot.getOpposite())); conPos.add(new DirPos(xCoord + dir.offsetX * (3 - i) - rot.offsetX * 4, yCoord + 1 + j, zCoord + dir.offsetZ * (3 - i) - rot.offsetZ * 4, rot.getOpposite()));
} }
} }
return conPos; return conPos;
} }
@ -249,52 +252,52 @@ public class TileEntityMachineChemfac extends TileEntityMachineChemplantBase imp
DirPos[] inpos; DirPos[] inpos;
DirPos[] outpos; DirPos[] outpos;
@Override @Override
public DirPos[] getInputPositions() { public DirPos[] getInputPositions() {
if(inpos != null) if(inpos != null)
return inpos; return inpos;
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset); ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset);
ForgeDirection rot = dir.getRotation(ForgeDirection.UP); ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
inpos = new DirPos[] { inpos = new DirPos[] {
new DirPos(xCoord + dir.offsetX * 4 - rot.offsetX * 1, yCoord, zCoord + dir.offsetZ * 4 - rot.offsetZ * 1, dir), new DirPos(xCoord + dir.offsetX * 4 - rot.offsetX * 1, yCoord, zCoord + dir.offsetZ * 4 - rot.offsetZ * 1, dir),
new DirPos(xCoord - dir.offsetX * 5 + rot.offsetX * 2, yCoord, zCoord - dir.offsetZ * 5 + rot.offsetZ * 2, dir.getOpposite()), new DirPos(xCoord - dir.offsetX * 5 + rot.offsetX * 2, yCoord, zCoord - dir.offsetZ * 5 + rot.offsetZ * 2, dir.getOpposite()),
new DirPos(xCoord - dir.offsetX * 2 - rot.offsetX * 4, yCoord, zCoord - dir.offsetZ * 2 - rot.offsetZ * 4, rot.getOpposite()), new DirPos(xCoord - dir.offsetX * 2 - rot.offsetX * 4, yCoord, zCoord - dir.offsetZ * 2 - rot.offsetZ * 4, rot.getOpposite()),
new DirPos(xCoord + dir.offsetX * 1 + rot.offsetX * 5, yCoord, zCoord + dir.offsetZ * 1 + rot.offsetZ * 5, rot) new DirPos(xCoord + dir.offsetX * 1 + rot.offsetX * 5, yCoord, zCoord + dir.offsetZ * 1 + rot.offsetZ * 5, rot)
}; };
return inpos; return inpos;
} }
@Override @Override
public DirPos[] getOutputPositions() { public DirPos[] getOutputPositions() {
if(outpos != null) if(outpos != null)
return outpos; return outpos;
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset); ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset);
ForgeDirection rot = dir.getRotation(ForgeDirection.UP); ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
outpos = new DirPos[] { outpos = new DirPos[] {
new DirPos(xCoord + dir.offsetX * 4 + rot.offsetX * 2, yCoord, zCoord + dir.offsetZ * 4 + rot.offsetZ * 2, dir), new DirPos(xCoord + dir.offsetX * 4 + rot.offsetX * 2, yCoord, zCoord + dir.offsetZ * 4 + rot.offsetZ * 2, dir),
new DirPos(xCoord - dir.offsetX * 5 - rot.offsetX * 1, yCoord, zCoord - dir.offsetZ * 5 - rot.offsetZ * 1, dir.getOpposite()), new DirPos(xCoord - dir.offsetX * 5 - rot.offsetX * 1, yCoord, zCoord - dir.offsetZ * 5 - rot.offsetZ * 1, dir.getOpposite()),
new DirPos(xCoord + dir.offsetX * 1 - rot.offsetX * 4, yCoord, zCoord + dir.offsetZ * 1 - rot.offsetZ * 4, rot.getOpposite()), new DirPos(xCoord + dir.offsetX * 1 - rot.offsetX * 4, yCoord, zCoord + dir.offsetZ * 1 - rot.offsetZ * 4, rot.getOpposite()),
new DirPos(xCoord - dir.offsetX * 2 + rot.offsetX * 5, yCoord, zCoord - dir.offsetZ * 2 + rot.offsetZ * 5, rot) new DirPos(xCoord - dir.offsetX * 2 + rot.offsetX * 5, yCoord, zCoord - dir.offsetZ * 2 + rot.offsetZ * 5, rot)
}; };
return outpos; return outpos;
} }
@Override @Override
public void readFromNBT(NBTTagCompound nbt) { public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt); super.readFromNBT(nbt);
water.readFromNBT(nbt, "w"); water.readFromNBT(nbt, "w");
steam.readFromNBT(nbt, "s"); steam.readFromNBT(nbt, "s");
} }
@Override @Override
public void writeToNBT(NBTTagCompound nbt) { public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt); super.writeToNBT(nbt);
@ -309,27 +312,27 @@ public class TileEntityMachineChemfac extends TileEntityMachineChemplantBase imp
@Override @Override
protected List<FluidTank> inTanks() { protected List<FluidTank> inTanks() {
List<FluidTank> inTanks = super.inTanks(); List<FluidTank> inTanks = super.inTanks();
inTanks.add(water); inTanks.add(water);
return inTanks; return inTanks;
} }
@Override @Override
protected List<FluidTank> outTanks() { protected List<FluidTank> outTanks() {
List<FluidTank> outTanks = super.outTanks(); List<FluidTank> outTanks = super.outTanks();
outTanks.add(steam); outTanks.add(steam);
return outTanks; return outTanks;
} }
AxisAlignedBB bb = null; AxisAlignedBB bb = null;
@Override @Override
public AxisAlignedBB getRenderBoundingBox() { public AxisAlignedBB getRenderBoundingBox() {
if(bb == null) { if(bb == null) {
bb = AxisAlignedBB.getBoundingBox( bb = AxisAlignedBB.getBoundingBox(
xCoord - 5, xCoord - 5,
@ -340,10 +343,10 @@ public class TileEntityMachineChemfac extends TileEntityMachineChemplantBase imp
zCoord + 5 zCoord + 5
); );
} }
return bb; return bb;
} }
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public double getMaxRenderDistanceSquared() { public double getMaxRenderDistanceSquared() {
@ -383,11 +386,12 @@ public class TileEntityMachineChemfac extends TileEntityMachineChemplantBase imp
} }
@Override @Override
public int getMaxLevel(UpgradeType type) { public HashMap<UpgradeType, Integer> getValidUpgrades() {
if(type == UpgradeType.SPEED) return 6; HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
if(type == UpgradeType.POWER) return 3; upgrades.put(UpgradeType.SPEED, 6);
if(type == UpgradeType.OVERDRIVE) return 12; upgrades.put(UpgradeType.POWER, 3);
return 0; upgrades.put(UpgradeType.OVERDRIVE, 12);
return upgrades;
} }
@Override @Override

View File

@ -1,11 +1,12 @@
package com.hbm.tileentity.machine; package com.hbm.tileentity.machine;
import java.util.HashMap;
import java.util.List; import java.util.List;
import com.hbm.blocks.BlockDummyable; import com.hbm.blocks.BlockDummyable;
import com.hbm.blocks.ModBlocks; import com.hbm.blocks.ModBlocks;
import com.hbm.inventory.RecipesCommon.AStack; import com.hbm.inventory.RecipesCommon.AStack;
import com.hbm.inventory.UpgradeManager; import com.hbm.inventory.UpgradeManagerNT;
import com.hbm.inventory.container.ContainerMachineChemplant; import com.hbm.inventory.container.ContainerMachineChemplant;
import com.hbm.inventory.fluid.Fluids; import com.hbm.inventory.fluid.Fluids;
import com.hbm.inventory.fluid.tank.FluidTank; import com.hbm.inventory.fluid.tank.FluidTank;
@ -49,15 +50,17 @@ public class TileEntityMachineChemplant extends TileEntityMachineBase implements
public int progress; public int progress;
public int maxProgress = 100; public int maxProgress = 100;
public boolean isProgressing; public boolean isProgressing;
private AudioWrapper audio; private AudioWrapper audio;
public FluidTank[] tanks; public FluidTank[] tanks;
//upgraded stats //upgraded stats
int consumption = 100; int consumption = 100;
int speed = 100; int speed = 100;
public UpgradeManagerNT upgradeManager = new UpgradeManagerNT();
public TileEntityMachineChemplant() { public TileEntityMachineChemplant() {
super(21); super(21);
/* /*
@ -71,7 +74,7 @@ public class TileEntityMachineChemplant extends TileEntityMachineBase implements
* 17-18 FIn In * 17-18 FIn In
* 19-20 FIn Out * 19-20 FIn Out
*/ */
tanks = new FluidTank[4]; tanks = new FluidTank[4];
for(int i = 0; i < 4; i++) { for(int i = 0; i < 4; i++) {
tanks[i] = new FluidTank(Fluids.NONE, 24_000); tanks[i] = new FluidTank(Fluids.NONE, 24_000);
@ -82,7 +85,7 @@ public class TileEntityMachineChemplant extends TileEntityMachineBase implements
public String getName() { public String getName() {
return "container.chemplant"; return "container.chemplant";
} }
// last successful load // last successful load
int lsl0 = 0; int lsl0 = 0;
int lsl1 = 0; int lsl1 = 0;
@ -91,23 +94,23 @@ public class TileEntityMachineChemplant extends TileEntityMachineBase implements
@Override @Override
public void updateEntity() { public void updateEntity() {
if(!worldObj.isRemote) { if(!worldObj.isRemote) {
this.speed = 100; this.speed = 100;
this.consumption = 100; this.consumption = 100;
this.isProgressing = false; this.isProgressing = false;
this.power = Library.chargeTEFromItems(slots, 0, power, maxPower); this.power = Library.chargeTEFromItems(slots, 0, power, maxPower);
int fluidDelay = 40; int fluidDelay = 40;
if(lsu0 >= fluidDelay && tanks[0].loadTank(17, 19, slots)) lsl0 = 0; if(lsu0 >= fluidDelay && tanks[0].loadTank(17, 19, slots)) lsl0 = 0;
if(lsu1 >= fluidDelay && tanks[1].loadTank(18, 20, slots)) lsl1 = 0; if(lsu1 >= fluidDelay && tanks[1].loadTank(18, 20, slots)) lsl1 = 0;
if(lsl0 >= fluidDelay && slots[17] != null && !FluidTank.noDualUnload.contains(slots[17].getItem())) if(tanks[0].unloadTank(17, 19, slots)) lsu0 = 0; if(lsl0 >= fluidDelay && slots[17] != null && !FluidTank.noDualUnload.contains(slots[17].getItem())) if(tanks[0].unloadTank(17, 19, slots)) lsu0 = 0;
if(lsl1 >= fluidDelay && slots[18] != null && !FluidTank.noDualUnload.contains(slots[18].getItem())) if(tanks[1].unloadTank(18, 20, slots)) lsu1 = 0; if(lsl1 >= fluidDelay && slots[18] != null && !FluidTank.noDualUnload.contains(slots[18].getItem())) if(tanks[1].unloadTank(18, 20, slots)) lsu1 = 0;
tanks[2].unloadTank(9, 11, slots); tanks[2].unloadTank(9, 11, slots);
tanks[3].unloadTank(10, 12, slots); tanks[3].unloadTank(10, 12, slots);
@ -115,48 +118,48 @@ public class TileEntityMachineChemplant extends TileEntityMachineBase implements
if(lsl1 < fluidDelay) lsl1++; if(lsl1 < fluidDelay) lsl1++;
if(lsu0 < fluidDelay) lsu0++; if(lsu0 < fluidDelay) lsu0++;
if(lsu1 < fluidDelay) lsu1++; if(lsu1 < fluidDelay) lsu1++;
loadItems(); loadItems();
unloadItems(); unloadItems();
if(worldObj.getTotalWorldTime() % 20 == 0) { if(worldObj.getTotalWorldTime() % 20 == 0) {
this.updateConnections(); this.updateConnections();
} }
for(DirPos pos : getConPos()) { for(DirPos pos : getConPos()) {
if(tanks[2].getFill() > 0) this.sendFluid(tanks[2], worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); if(tanks[2].getFill() > 0) this.sendFluid(tanks[2], worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
if(tanks[3].getFill() > 0) this.sendFluid(tanks[3], worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); if(tanks[3].getFill() > 0) this.sendFluid(tanks[3], worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
} }
UpgradeManager.eval(slots, 1, 3);
int speedLevel = Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 3); upgradeManager.checkSlots(this, slots, 1, 3);
int powerLevel = Math.min(UpgradeManager.getLevel(UpgradeType.POWER), 3);
int overLevel = UpgradeManager.getLevel(UpgradeType.OVERDRIVE); int speedLevel = upgradeManager.getLevel(UpgradeType.SPEED);
int powerLevel = upgradeManager.getLevel(UpgradeType.POWER);
int overLevel = upgradeManager.getLevel(UpgradeType.OVERDRIVE);
this.speed -= speedLevel * 25; this.speed -= speedLevel * 25;
this.consumption += speedLevel * 300; this.consumption += speedLevel * 300;
this.speed += powerLevel * 5; this.speed += powerLevel * 5;
this.consumption -= powerLevel * 20; this.consumption -= powerLevel * 20;
this.speed /= (overLevel + 1); this.speed /= (overLevel + 1);
this.consumption *= (overLevel + 1); this.consumption *= (overLevel + 1);
if(this.speed <= 0) { if(this.speed <= 0) {
this.speed = 1; this.speed = 1;
} }
if(!canProcess()) { if(!canProcess()) {
this.progress = 0; this.progress = 0;
} else { } else {
isProgressing = true; isProgressing = true;
process(); process();
} }
this.networkPackNT(150); this.networkPackNT(150);
} else { } else {
if(isProgressing && this.worldObj.getTotalWorldTime() % 3 == 0) { if(isProgressing && this.worldObj.getTotalWorldTime() % 3 == 0) {
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset).getOpposite(); ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset).getOpposite();
ForgeDirection rot = dir.getRotation(ForgeDirection.UP); ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
double x = xCoord + 0.5 + dir.offsetX * 1.125 + rot.offsetX * 0.125; double x = xCoord + 0.5 + dir.offsetX * 1.125 + rot.offsetX * 0.125;
@ -164,11 +167,11 @@ public class TileEntityMachineChemplant extends TileEntityMachineBase implements
double z = zCoord + 0.5 + dir.offsetZ * 1.125 + rot.offsetZ * 0.125; double z = zCoord + 0.5 + dir.offsetZ * 1.125 + rot.offsetZ * 0.125;
worldObj.spawnParticle("cloud", x, y, z, 0.0, 0.1, 0.0); worldObj.spawnParticle("cloud", x, y, z, 0.0, 0.1, 0.0);
} }
float volume = this.getVolume(1F); float volume = this.getVolume(1F);
if(isProgressing && volume > 0) { if(isProgressing && volume > 0) {
if(audio == null) { if(audio == null) {
audio = this.createAudioLoop(); audio = this.createAudioLoop();
audio.updateVolume(volume); audio.updateVolume(volume);
@ -177,9 +180,9 @@ public class TileEntityMachineChemplant extends TileEntityMachineBase implements
audio = rebootAudio(audio); audio = rebootAudio(audio);
audio.updateVolume(volume); audio.updateVolume(volume);
} }
} else { } else {
if(audio != null) { if(audio != null) {
audio.stopSound(); audio.stopSound();
audio = null; audio = null;
@ -199,7 +202,7 @@ public class TileEntityMachineChemplant extends TileEntityMachineBase implements
for(int i = 0; i < tanks.length; i++) for(int i = 0; i < tanks.length; i++)
tanks[i].serialize(buf); tanks[i].serialize(buf);
} }
@Override @Override
public void deserialize(ByteBuf buf) { public void deserialize(ByteBuf buf) {
super.deserialize(buf); super.deserialize(buf);
@ -211,7 +214,7 @@ public class TileEntityMachineChemplant extends TileEntityMachineBase implements
for(int i = 0; i < tanks.length; i++) for(int i = 0; i < tanks.length; i++)
tanks[i].deserialize(buf); tanks[i].deserialize(buf);
} }
@Override @Override
public AudioWrapper createAudioLoop() { public AudioWrapper createAudioLoop() {
return MainRegistry.proxy.getLoopedSound("hbm:block.chemplantOperate", xCoord, yCoord, zCoord, 1.0F, 10F, 1.0F); return MainRegistry.proxy.getLoopedSound("hbm:block.chemplantOperate", xCoord, yCoord, zCoord, 1.0F, 10F, 1.0F);
@ -236,21 +239,21 @@ public class TileEntityMachineChemplant extends TileEntityMachineBase implements
audio = null; audio = null;
} }
} }
private void updateConnections() { private void updateConnections() {
for(DirPos pos : getConPos()) { for(DirPos pos : getConPos()) {
this.trySubscribe(worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); this.trySubscribe(worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
this.trySubscribe(tanks[0].getTankType(), worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); this.trySubscribe(tanks[0].getTankType(), worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
this.trySubscribe(tanks[1].getTankType(), worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); this.trySubscribe(tanks[1].getTankType(), worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
} }
} }
public DirPos[] getConPos() { public DirPos[] getConPos() {
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset).getOpposite(); ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset).getOpposite();
ForgeDirection rot = dir.getRotation(ForgeDirection.DOWN); ForgeDirection rot = dir.getRotation(ForgeDirection.DOWN);
return new DirPos[] { return new DirPos[] {
new DirPos(xCoord + rot.offsetX * 3, yCoord, zCoord + rot.offsetZ * 3, rot), new DirPos(xCoord + rot.offsetX * 3, yCoord, zCoord + rot.offsetZ * 3, rot),
new DirPos(xCoord - rot.offsetX * 2, yCoord, zCoord - rot.offsetZ * 2, rot.getOpposite()), new DirPos(xCoord - rot.offsetX * 2, yCoord, zCoord - rot.offsetZ * 2, rot.getOpposite()),
@ -258,69 +261,69 @@ public class TileEntityMachineChemplant extends TileEntityMachineBase implements
new DirPos(xCoord - rot.offsetX * 2 + dir.offsetX, yCoord, zCoord - rot.offsetZ * 2 + dir.offsetZ, rot.getOpposite()) new DirPos(xCoord - rot.offsetX * 2 + dir.offsetX, yCoord, zCoord - rot.offsetZ * 2 + dir.offsetZ, rot.getOpposite())
}; };
} }
private boolean canProcess() { private boolean canProcess() {
if(slots[4] == null || slots[4].getItem() != ModItems.chemistry_template) if(slots[4] == null || slots[4].getItem() != ModItems.chemistry_template)
return false; return false;
ChemRecipe recipe = ChemplantRecipes.indexMapping.get(slots[4].getItemDamage()); ChemRecipe recipe = ChemplantRecipes.indexMapping.get(slots[4].getItemDamage());
if(recipe == null) if(recipe == null)
return false; return false;
setupTanks(recipe); setupTanks(recipe);
if(this.power < this.consumption) return false; if(this.power < this.consumption) return false;
if(!hasRequiredFluids(recipe)) return false; if(!hasRequiredFluids(recipe)) return false;
if(!hasSpaceForFluids(recipe)) return false; if(!hasSpaceForFluids(recipe)) return false;
if(!hasRequiredItems(recipe)) return false; if(!hasRequiredItems(recipe)) return false;
if(!hasSpaceForItems(recipe)) return false; if(!hasSpaceForItems(recipe)) return false;
return true; return true;
} }
private void setupTanks(ChemRecipe recipe) { private void setupTanks(ChemRecipe recipe) {
if(recipe.inputFluids[0] != null) tanks[0].withPressure(recipe.inputFluids[0].pressure).setTankType(recipe.inputFluids[0].type); else tanks[0].setTankType(Fluids.NONE); if(recipe.inputFluids[0] != null) tanks[0].withPressure(recipe.inputFluids[0].pressure).setTankType(recipe.inputFluids[0].type); else tanks[0].setTankType(Fluids.NONE);
if(recipe.inputFluids[1] != null) tanks[1].withPressure(recipe.inputFluids[1].pressure).setTankType(recipe.inputFluids[1].type); else tanks[1].setTankType(Fluids.NONE); if(recipe.inputFluids[1] != null) tanks[1].withPressure(recipe.inputFluids[1].pressure).setTankType(recipe.inputFluids[1].type); else tanks[1].setTankType(Fluids.NONE);
if(recipe.outputFluids[0] != null) tanks[2].withPressure(recipe.outputFluids[0].pressure).setTankType(recipe.outputFluids[0].type); else tanks[2].setTankType(Fluids.NONE); if(recipe.outputFluids[0] != null) tanks[2].withPressure(recipe.outputFluids[0].pressure).setTankType(recipe.outputFluids[0].type); else tanks[2].setTankType(Fluids.NONE);
if(recipe.outputFluids[1] != null) tanks[3].withPressure(recipe.outputFluids[1].pressure).setTankType(recipe.outputFluids[1].type); else tanks[3].setTankType(Fluids.NONE); if(recipe.outputFluids[1] != null) tanks[3].withPressure(recipe.outputFluids[1].pressure).setTankType(recipe.outputFluids[1].type); else tanks[3].setTankType(Fluids.NONE);
} }
private boolean hasRequiredFluids(ChemRecipe recipe) { private boolean hasRequiredFluids(ChemRecipe recipe) {
if(recipe.inputFluids[0] != null && tanks[0].getFill() < recipe.inputFluids[0].fill) return false; if(recipe.inputFluids[0] != null && tanks[0].getFill() < recipe.inputFluids[0].fill) return false;
if(recipe.inputFluids[1] != null && tanks[1].getFill() < recipe.inputFluids[1].fill) return false; if(recipe.inputFluids[1] != null && tanks[1].getFill() < recipe.inputFluids[1].fill) return false;
return true; return true;
} }
private boolean hasSpaceForFluids(ChemRecipe recipe) { private boolean hasSpaceForFluids(ChemRecipe recipe) {
if(recipe.outputFluids[0] != null && tanks[2].getFill() + recipe.outputFluids[0].fill > tanks[2].getMaxFill()) return false; if(recipe.outputFluids[0] != null && tanks[2].getFill() + recipe.outputFluids[0].fill > tanks[2].getMaxFill()) return false;
if(recipe.outputFluids[1] != null && tanks[3].getFill() + recipe.outputFluids[1].fill > tanks[3].getMaxFill()) return false; if(recipe.outputFluids[1] != null && tanks[3].getFill() + recipe.outputFluids[1].fill > tanks[3].getMaxFill()) return false;
return true; return true;
} }
private boolean hasRequiredItems(ChemRecipe recipe) { private boolean hasRequiredItems(ChemRecipe recipe) {
return InventoryUtil.doesArrayHaveIngredients(slots, 13, 16, recipe.inputs); return InventoryUtil.doesArrayHaveIngredients(slots, 13, 16, recipe.inputs);
} }
private boolean hasSpaceForItems(ChemRecipe recipe) { private boolean hasSpaceForItems(ChemRecipe recipe) {
return InventoryUtil.doesArrayHaveSpace(slots, 5, 8, recipe.outputs); return InventoryUtil.doesArrayHaveSpace(slots, 5, 8, recipe.outputs);
} }
private void process() { private void process() {
this.power -= this.consumption; this.power -= this.consumption;
this.progress++; this.progress++;
if(slots[0] != null && slots[0].getItem() == ModItems.meteorite_sword_machined) if(slots[0] != null && slots[0].getItem() == ModItems.meteorite_sword_machined)
slots[0] = new ItemStack(ModItems.meteorite_sword_treated); //fisfndmoivndlmgindgifgjfdnblfm slots[0] = new ItemStack(ModItems.meteorite_sword_treated); //fisfndmoivndlmgindgifgjfdnblfm
ChemRecipe recipe = ChemplantRecipes.indexMapping.get(slots[4].getItemDamage()); ChemRecipe recipe = ChemplantRecipes.indexMapping.get(slots[4].getItemDamage());
this.maxProgress = recipe.getDuration() * this.speed / 100; this.maxProgress = recipe.getDuration() * this.speed / 100;
if(maxProgress <= 0) maxProgress = 1; if(maxProgress <= 0) maxProgress = 1;
if(this.progress >= this.maxProgress) { if(this.progress >= this.maxProgress) {
consumeFluids(recipe); consumeFluids(recipe);
produceFluids(recipe); produceFluids(recipe);
@ -330,81 +333,81 @@ public class TileEntityMachineChemplant extends TileEntityMachineBase implements
this.markDirty(); this.markDirty();
} }
} }
private void consumeFluids(ChemRecipe recipe) { private void consumeFluids(ChemRecipe recipe) {
if(recipe.inputFluids[0] != null) tanks[0].setFill(tanks[0].getFill() - recipe.inputFluids[0].fill); if(recipe.inputFluids[0] != null) tanks[0].setFill(tanks[0].getFill() - recipe.inputFluids[0].fill);
if(recipe.inputFluids[1] != null) tanks[1].setFill(tanks[1].getFill() - recipe.inputFluids[1].fill); if(recipe.inputFluids[1] != null) tanks[1].setFill(tanks[1].getFill() - recipe.inputFluids[1].fill);
} }
private void produceFluids(ChemRecipe recipe) { private void produceFluids(ChemRecipe recipe) {
if(recipe.outputFluids[0] != null) tanks[2].setFill(tanks[2].getFill() + recipe.outputFluids[0].fill); if(recipe.outputFluids[0] != null) tanks[2].setFill(tanks[2].getFill() + recipe.outputFluids[0].fill);
if(recipe.outputFluids[1] != null) tanks[3].setFill(tanks[3].getFill() + recipe.outputFluids[1].fill); if(recipe.outputFluids[1] != null) tanks[3].setFill(tanks[3].getFill() + recipe.outputFluids[1].fill);
} }
private void consumeItems(ChemRecipe recipe) { private void consumeItems(ChemRecipe recipe) {
for(AStack in : recipe.inputs) { for(AStack in : recipe.inputs) {
if(in != null) if(in != null)
InventoryUtil.tryConsumeAStack(slots, 13, 16, in); InventoryUtil.tryConsumeAStack(slots, 13, 16, in);
} }
} }
private void produceItems(ChemRecipe recipe) { private void produceItems(ChemRecipe recipe) {
for(ItemStack out : recipe.outputs) { for(ItemStack out : recipe.outputs) {
if(out != null) if(out != null)
InventoryUtil.tryAddItemToInventory(slots, 5, 8, out.copy()); InventoryUtil.tryAddItemToInventory(slots, 5, 8, out.copy());
} }
} }
//TODO: move this into a util class //TODO: move this into a util class
private void loadItems() { private void loadItems() {
if(slots[4] == null || slots[4].getItem() != ModItems.chemistry_template) if(slots[4] == null || slots[4].getItem() != ModItems.chemistry_template)
return; return;
ChemRecipe recipe = ChemplantRecipes.indexMapping.get(slots[4].getItemDamage()); ChemRecipe recipe = ChemplantRecipes.indexMapping.get(slots[4].getItemDamage());
if(recipe != null) { if(recipe != null) {
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset).getOpposite(); ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset).getOpposite();
int x = xCoord - dir.offsetX * 2; int x = xCoord - dir.offsetX * 2;
int z = zCoord - dir.offsetZ * 2; int z = zCoord - dir.offsetZ * 2;
TileEntity te = worldObj.getTileEntity(x, yCoord, z); TileEntity te = worldObj.getTileEntity(x, yCoord, z);
if(te instanceof IInventory) { if(te instanceof IInventory) {
IInventory inv = (IInventory) te; IInventory inv = (IInventory) te;
ISidedInventory sided = inv instanceof ISidedInventory ? (ISidedInventory) inv : null; ISidedInventory sided = inv instanceof ISidedInventory ? (ISidedInventory) inv : null;
int[] access = sided != null ? sided.getAccessibleSlotsFromSide(dir.ordinal()) : null; int[] access = sided != null ? sided.getAccessibleSlotsFromSide(dir.ordinal()) : null;
for(AStack ingredient : recipe.inputs) { for(AStack ingredient : recipe.inputs) {
outer: outer:
while(!InventoryUtil.doesArrayHaveIngredients(slots, 13, 16, ingredient)) { while(!InventoryUtil.doesArrayHaveIngredients(slots, 13, 16, ingredient)) {
boolean found = false; boolean found = false;
for(int i = 0; i < (access != null ? access.length : inv.getSizeInventory()); i++) { for(int i = 0; i < (access != null ? access.length : inv.getSizeInventory()); i++) {
int slot = access != null ? access[i] : i; int slot = access != null ? access[i] : i;
ItemStack stack = inv.getStackInSlot(slot); ItemStack stack = inv.getStackInSlot(slot);
if(ingredient.matchesRecipe(stack, true) && (sided == null || sided.canExtractItem(slot, stack, 0))) { if(ingredient.matchesRecipe(stack, true) && (sided == null || sided.canExtractItem(slot, stack, 0))) {
for(int j = 13; j <= 16; j++) { for(int j = 13; j <= 16; j++) {
if(slots[j] != null && slots[j].stackSize < slots[j].getMaxStackSize() & InventoryUtil.doesStackDataMatch(slots[j], stack)) { if(slots[j] != null && slots[j].stackSize < slots[j].getMaxStackSize() & InventoryUtil.doesStackDataMatch(slots[j], stack)) {
inv.decrStackSize(slot, 1); inv.decrStackSize(slot, 1);
slots[j].stackSize++; slots[j].stackSize++;
continue outer; continue outer;
} }
} }
for(int j = 13; j <= 16; j++) { for(int j = 13; j <= 16; j++) {
if(slots[j] == null) { if(slots[j] == null) {
slots[j] = stack.copy(); slots[j] = stack.copy();
slots[j].stackSize = 1; slots[j].stackSize = 1;
@ -421,43 +424,43 @@ public class TileEntityMachineChemplant extends TileEntityMachineBase implements
} }
} }
} }
private void unloadItems() { private void unloadItems() {
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset).getOpposite(); ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset).getOpposite();
ForgeDirection rot = dir.getRotation(ForgeDirection.DOWN); ForgeDirection rot = dir.getRotation(ForgeDirection.DOWN);
int x = xCoord + dir.offsetX * 3 + rot.offsetX; int x = xCoord + dir.offsetX * 3 + rot.offsetX;
int z = zCoord + dir.offsetZ * 3 + rot.offsetZ; int z = zCoord + dir.offsetZ * 3 + rot.offsetZ;
TileEntity te = worldObj.getTileEntity(x, yCoord, z); TileEntity te = worldObj.getTileEntity(x, yCoord, z);
if(te instanceof IInventory) { if(te instanceof IInventory) {
IInventory inv = (IInventory) te; IInventory inv = (IInventory) te;
ISidedInventory sided = inv instanceof ISidedInventory ? (ISidedInventory) inv : null; ISidedInventory sided = inv instanceof ISidedInventory ? (ISidedInventory) inv : null;
int[] access = sided != null ? sided.getAccessibleSlotsFromSide(dir.ordinal()) : null; int[] access = sided != null ? sided.getAccessibleSlotsFromSide(dir.ordinal()) : null;
boolean shouldOutput = true; boolean shouldOutput = true;
while(shouldOutput) { while(shouldOutput) {
shouldOutput = false; shouldOutput = false;
outer: outer:
for(int i = 5; i <= 8; i++) { for(int i = 5; i <= 8; i++) {
ItemStack out = slots[i]; ItemStack out = slots[i];
if(out != null) { if(out != null) {
for(int j = 0; j < (access != null ? access.length : inv.getSizeInventory()); j++) { for(int j = 0; j < (access != null ? access.length : inv.getSizeInventory()); j++) {
int slot = access != null ? access[j] : j; int slot = access != null ? access[j] : j;
if(!inv.isItemValidForSlot(slot, out)) if(!inv.isItemValidForSlot(slot, out))
continue; continue;
ItemStack target = inv.getStackInSlot(slot); ItemStack target = inv.getStackInSlot(slot);
if(InventoryUtil.doesStackDataMatch(out, target) && target.stackSize < Math.min(target.getMaxStackSize(), inv.getInventoryStackLimit())) { if(InventoryUtil.doesStackDataMatch(out, target) && target.stackSize < Math.min(target.getMaxStackSize(), inv.getInventoryStackLimit())) {
int toDec = Math.min(out.stackSize, Math.min(target.getMaxStackSize(), inv.getInventoryStackLimit()) - target.stackSize); int toDec = Math.min(out.stackSize, Math.min(target.getMaxStackSize(), inv.getInventoryStackLimit()) - target.stackSize);
this.decrStackSize(i, toDec); this.decrStackSize(i, toDec);
@ -466,14 +469,14 @@ public class TileEntityMachineChemplant extends TileEntityMachineBase implements
break outer; break outer;
} }
} }
for(int j = 0; j < (access != null ? access.length : inv.getSizeInventory()); j++) { for(int j = 0; j < (access != null ? access.length : inv.getSizeInventory()); j++) {
int slot = access != null ? access[j] : j; int slot = access != null ? access[j] : j;
if(!inv.isItemValidForSlot(slot, out)) if(!inv.isItemValidForSlot(slot, out))
continue; continue;
if(inv.getStackInSlot(slot) == null && (sided != null ? sided.canInsertItem(slot, out, dir.ordinal()) : inv.isItemValidForSlot(slot, out))) { if(inv.getStackInSlot(slot) == null && (sided != null ? sided.canInsertItem(slot, out, dir.ordinal()) : inv.isItemValidForSlot(slot, out))) {
ItemStack copy = out.copy(); ItemStack copy = out.copy();
copy.stackSize = 1; copy.stackSize = 1;
@ -503,36 +506,36 @@ public class TileEntityMachineChemplant extends TileEntityMachineBase implements
public long getMaxPower() { public long getMaxPower() {
return maxPower; return maxPower;
} }
@Override @Override
public void readFromNBT(NBTTagCompound nbt) { public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt); super.readFromNBT(nbt);
this.power = nbt.getLong("power"); this.power = nbt.getLong("power");
this.progress = nbt.getInteger("progress"); this.progress = nbt.getInteger("progress");
for(int i = 0; i < tanks.length; i++) { for(int i = 0; i < tanks.length; i++) {
tanks[i].readFromNBT(nbt, "t" + i); tanks[i].readFromNBT(nbt, "t" + i);
} }
} }
@Override @Override
public void writeToNBT(NBTTagCompound nbt) { public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt); super.writeToNBT(nbt);
nbt.setLong("power", power); nbt.setLong("power", power);
nbt.setInteger("progress", progress); nbt.setInteger("progress", progress);
for(int i = 0; i < tanks.length; i++) { for(int i = 0; i < tanks.length; i++) {
tanks[i].writeToNBT(nbt, "t" + i); tanks[i].writeToNBT(nbt, "t" + i);
} }
} }
AxisAlignedBB bb = null; AxisAlignedBB bb = null;
@Override @Override
public AxisAlignedBB getRenderBoundingBox() { public AxisAlignedBB getRenderBoundingBox() {
if(bb == null) { if(bb == null) {
bb = AxisAlignedBB.getBoundingBox( bb = AxisAlignedBB.getBoundingBox(
xCoord - 2, xCoord - 2,
@ -543,10 +546,10 @@ public class TileEntityMachineChemplant extends TileEntityMachineBase implements
zCoord + 3 zCoord + 3
); );
} }
return bb; return bb;
} }
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public double getMaxRenderDistanceSquared() { public double getMaxRenderDistanceSquared() {
@ -601,10 +604,11 @@ public class TileEntityMachineChemplant extends TileEntityMachineBase implements
} }
@Override @Override
public int getMaxLevel(UpgradeType type) { public HashMap<UpgradeType, Integer> getValidUpgrades() {
if(type == UpgradeType.SPEED) return 3; HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
if(type == UpgradeType.POWER) return 3; upgrades.put(UpgradeType.SPEED, 3);
if(type == UpgradeType.OVERDRIVE) return 9; upgrades.put(UpgradeType.POWER, 3);
return 0; upgrades.put(UpgradeType.OVERDRIVE, 9);
return upgrades;
} }
} }

View File

@ -1,11 +1,12 @@
package com.hbm.tileentity.machine; package com.hbm.tileentity.machine;
import java.util.HashMap;
import java.util.List; import java.util.List;
import com.hbm.blocks.BlockDummyable; import com.hbm.blocks.BlockDummyable;
import com.hbm.blocks.ModBlocks; import com.hbm.blocks.ModBlocks;
import com.hbm.interfaces.IControlReceiver; import com.hbm.interfaces.IControlReceiver;
import com.hbm.inventory.UpgradeManager; import com.hbm.inventory.UpgradeManagerNT;
import com.hbm.inventory.container.ContainerCompressor; import com.hbm.inventory.container.ContainerCompressor;
import com.hbm.inventory.fluid.Fluids; import com.hbm.inventory.fluid.Fluids;
import com.hbm.inventory.fluid.tank.FluidTank; import com.hbm.inventory.fluid.tank.FluidTank;
@ -15,10 +16,7 @@ import com.hbm.inventory.recipes.CompressorRecipes.CompressorRecipe;
import com.hbm.items.machine.ItemMachineUpgrade.UpgradeType; import com.hbm.items.machine.ItemMachineUpgrade.UpgradeType;
import com.hbm.lib.Library; import com.hbm.lib.Library;
import com.hbm.main.MainRegistry; import com.hbm.main.MainRegistry;
import com.hbm.tileentity.IFluidCopiable; import com.hbm.tileentity.*;
import com.hbm.tileentity.IGUIProvider;
import com.hbm.tileentity.IUpgradeInfoProvider;
import com.hbm.tileentity.TileEntityMachineBase;
import com.hbm.util.BobMathUtil; import com.hbm.util.BobMathUtil;
import com.hbm.util.I18nUtil; import com.hbm.util.I18nUtil;
import com.hbm.util.Tuple.Pair; import com.hbm.util.Tuple.Pair;
@ -39,7 +37,7 @@ import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityMachineCompressor extends TileEntityMachineBase implements IGUIProvider, IControlReceiver, IEnergyReceiverMK2, IFluidStandardTransceiver, IUpgradeInfoProvider, IFluidCopiable { public class TileEntityMachineCompressor extends TileEntityMachineBase implements IGUIProvider, IControlReceiver, IEnergyReceiverMK2, IFluidStandardTransceiver, IUpgradeInfoProvider, IFluidCopiable {
public FluidTank[] tanks; public FluidTank[] tanks;
public long power; public long power;
public static final long maxPower = 100_000; public static final long maxPower = 100_000;
@ -49,13 +47,15 @@ public class TileEntityMachineCompressor extends TileEntityMachineBase implement
public static final int processTimeBase = 100; public static final int processTimeBase = 100;
public int powerRequirement; public int powerRequirement;
public static final int powerRequirementBase = 2_500; public static final int powerRequirementBase = 2_500;
public float fanSpin; public float fanSpin;
public float prevFanSpin; public float prevFanSpin;
public float piston; public float piston;
public float prevPiston; public float prevPiston;
public boolean pistonDir; public boolean pistonDir;
public UpgradeManagerNT upgradeManager = new UpgradeManagerNT();
public TileEntityMachineCompressor() { public TileEntityMachineCompressor() {
super(4); super(4);
this.tanks = new FluidTank[2]; this.tanks = new FluidTank[2];
@ -70,23 +70,23 @@ public class TileEntityMachineCompressor extends TileEntityMachineBase implement
@Override @Override
public void updateEntity() { public void updateEntity() {
if(!worldObj.isRemote) { if(!worldObj.isRemote) {
if(worldObj.getTotalWorldTime() % 20 == 0) { if(worldObj.getTotalWorldTime() % 20 == 0) {
this.updateConnections(); this.updateConnections();
} }
this.power = Library.chargeTEFromItems(slots, 1, power, maxPower); this.power = Library.chargeTEFromItems(slots, 1, power, maxPower);
this.tanks[0].setType(0, slots); this.tanks[0].setType(0, slots);
this.setupTanks(); this.setupTanks();
UpgradeManager.eval(slots, 1, 3);
int speedLevel = Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 3); upgradeManager.checkSlots(this, slots, 1, 3);
int powerLevel = Math.min(UpgradeManager.getLevel(UpgradeType.POWER), 3);
int overLevel = UpgradeManager.getLevel(UpgradeType.OVERDRIVE); int speedLevel = upgradeManager.getLevel(UpgradeType.SPEED);
int powerLevel = upgradeManager.getLevel(UpgradeType.POWER);
int overLevel = upgradeManager.getLevel(UpgradeType.OVERDRIVE);
CompressorRecipe rec = CompressorRecipes.recipes.get(new Pair(tanks[0].getTankType(), tanks[0].getPressure())); CompressorRecipe rec = CompressorRecipes.recipes.get(new Pair(tanks[0].getTankType(), tanks[0].getPressure()));
int timeBase = this.processTimeBase; int timeBase = this.processTimeBase;
if(rec != null) timeBase = rec.duration; if(rec != null) timeBase = rec.duration;
@ -98,44 +98,44 @@ public class TileEntityMachineCompressor extends TileEntityMachineBase implement
this.powerRequirement = this.powerRequirementBase / (powerLevel + 1); this.powerRequirement = this.powerRequirementBase / (powerLevel + 1);
this.processTime = this.processTime / (overLevel + 1); this.processTime = this.processTime / (overLevel + 1);
this.powerRequirement = this.powerRequirement * ((overLevel * 2) + 1); this.powerRequirement = this.powerRequirement * ((overLevel * 2) + 1);
if(processTime <= 0) processTime = 1; if(processTime <= 0) processTime = 1;
if(canProcess()) { if(canProcess()) {
this.progress++; this.progress++;
this.isOn = true; this.isOn = true;
this.power -= powerRequirement; this.power -= powerRequirement;
if(progress >= this.processTime) { if(progress >= this.processTime) {
progress = 0; progress = 0;
this.process(); this.process();
this.markChanged(); this.markChanged();
} }
} else { } else {
this.progress = 0; this.progress = 0;
this.isOn = false; this.isOn = false;
} }
for(DirPos pos : getConPos()) { for(DirPos pos : getConPos()) {
this.sendFluid(tanks[1], worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); this.sendFluid(tanks[1], worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
} }
this.networkPackNT(100); this.networkPackNT(100);
} else { } else {
this.prevFanSpin = this.fanSpin; this.prevFanSpin = this.fanSpin;
this.prevPiston = this.piston; this.prevPiston = this.piston;
if(this.isOn) { if(this.isOn) {
this.fanSpin += 15; this.fanSpin += 15;
if(this.fanSpin >= 360) { if(this.fanSpin >= 360) {
this.prevFanSpin -= 360; this.prevFanSpin -= 360;
this.fanSpin -= 360; this.fanSpin -= 360;
} }
if(this.pistonDir) { if(this.pistonDir) {
this.piston -= randSpeed; this.piston -= randSpeed;
if(this.piston <= 0) { if(this.piston <= 0) {
@ -149,12 +149,12 @@ public class TileEntityMachineCompressor extends TileEntityMachineBase implement
this.pistonDir = !this.pistonDir; this.pistonDir = !this.pistonDir;
} }
} }
this.piston = MathHelper.clamp_float(this.piston, 0F, 1F); this.piston = MathHelper.clamp_float(this.piston, 0F, 1F);
} }
} }
} }
private float randSpeed = 0.1F; private float randSpeed = 0.1F;
@Override @Override
@ -180,42 +180,42 @@ public class TileEntityMachineCompressor extends TileEntityMachineBase implement
tanks[1].deserialize(buf); tanks[1].deserialize(buf);
this.isOn = buf.readBoolean(); this.isOn = buf.readBoolean();
} }
private void updateConnections() { private void updateConnections() {
for(DirPos pos : getConPos()) { for(DirPos pos : getConPos()) {
this.trySubscribe(worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); this.trySubscribe(worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
this.trySubscribe(tanks[0].getTankType(), worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); this.trySubscribe(tanks[0].getTankType(), worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
} }
} }
public DirPos[] getConPos() { public DirPos[] getConPos() {
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset); ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset);
ForgeDirection rot = dir.getRotation(ForgeDirection.UP); ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
return new DirPos[] { return new DirPos[] {
new DirPos(xCoord + rot.offsetX * 2, yCoord, zCoord + rot.offsetZ * 2, rot), new DirPos(xCoord + rot.offsetX * 2, yCoord, zCoord + rot.offsetZ * 2, rot),
new DirPos(xCoord - rot.offsetX * 2, yCoord, zCoord - rot.offsetZ * 2, rot.getOpposite()), new DirPos(xCoord - rot.offsetX * 2, yCoord, zCoord - rot.offsetZ * 2, rot.getOpposite()),
new DirPos(xCoord - dir.offsetX * 2, yCoord, zCoord - dir.offsetZ * 2, dir.getOpposite()), new DirPos(xCoord - dir.offsetX * 2, yCoord, zCoord - dir.offsetZ * 2, dir.getOpposite()),
}; };
} }
public boolean canProcess() { public boolean canProcess() {
if(this.power <= powerRequirement) return false; if(this.power <= powerRequirement) return false;
CompressorRecipe recipe = CompressorRecipes.recipes.get(new Pair(tanks[0].getTankType(), tanks[0].getPressure())); CompressorRecipe recipe = CompressorRecipes.recipes.get(new Pair(tanks[0].getTankType(), tanks[0].getPressure()));
if(recipe == null) { if(recipe == null) {
return tanks[0].getFill() >= 1000 && tanks[1].getFill() + 1000 <= tanks[1].getMaxFill(); return tanks[0].getFill() >= 1000 && tanks[1].getFill() + 1000 <= tanks[1].getMaxFill();
} }
return tanks[0].getFill() > recipe.inputAmount && tanks[1].getFill() + recipe.output.fill <= tanks[1].getMaxFill(); return tanks[0].getFill() > recipe.inputAmount && tanks[1].getFill() + recipe.output.fill <= tanks[1].getMaxFill();
} }
public void process() { public void process() {
CompressorRecipe recipe = CompressorRecipes.recipes.get(new Pair(tanks[0].getTankType(), tanks[0].getPressure())); CompressorRecipe recipe = CompressorRecipes.recipes.get(new Pair(tanks[0].getTankType(), tanks[0].getPressure()));
if(recipe == null) { if(recipe == null) {
tanks[0].setFill(tanks[0].getFill() - 1_000); tanks[0].setFill(tanks[0].getFill() - 1_000);
tanks[1].setFill(tanks[1].getFill() + 1_000); tanks[1].setFill(tanks[1].getFill() + 1_000);
@ -224,18 +224,18 @@ public class TileEntityMachineCompressor extends TileEntityMachineBase implement
tanks[1].setFill(tanks[1].getFill() + recipe.output.fill); tanks[1].setFill(tanks[1].getFill() + recipe.output.fill);
} }
} }
protected void setupTanks() { protected void setupTanks() {
CompressorRecipe recipe = CompressorRecipes.recipes.get(new Pair(tanks[0].getTankType(), tanks[0].getPressure())); CompressorRecipe recipe = CompressorRecipes.recipes.get(new Pair(tanks[0].getTankType(), tanks[0].getPressure()));
if(recipe == null) { if(recipe == null) {
tanks[1].withPressure(tanks[0].getPressure() + 1).setTankType(tanks[0].getTankType()); tanks[1].withPressure(tanks[0].getPressure() + 1).setTankType(tanks[0].getTankType());
} else { } else {
tanks[1].withPressure(recipe.output.pressure).setTankType(recipe.output.type); tanks[1].withPressure(recipe.output.pressure).setTankType(recipe.output.type);
} }
} }
@Override @Override
public void readFromNBT(NBTTagCompound nbt) { public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt); super.readFromNBT(nbt);
@ -244,7 +244,7 @@ public class TileEntityMachineCompressor extends TileEntityMachineBase implement
tanks[0].readFromNBT(nbt, "0"); tanks[0].readFromNBT(nbt, "0");
tanks[1].readFromNBT(nbt, "1"); tanks[1].readFromNBT(nbt, "1");
} }
@Override @Override
public void writeToNBT(NBTTagCompound nbt) { public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt); super.writeToNBT(nbt);
@ -273,18 +273,18 @@ public class TileEntityMachineCompressor extends TileEntityMachineBase implement
@Override @Override
public void receiveControl(NBTTagCompound data) { public void receiveControl(NBTTagCompound data) {
int compression = data.getInteger("compression"); int compression = data.getInteger("compression");
if(compression != tanks[0].getPressure()) { if(compression != tanks[0].getPressure()) {
tanks[0].withPressure(compression); tanks[0].withPressure(compression);
CompressorRecipe recipe = CompressorRecipes.recipes.get(new Pair(tanks[0].getTankType(), compression)); CompressorRecipe recipe = CompressorRecipes.recipes.get(new Pair(tanks[0].getTankType(), compression));
if(recipe == null) { if(recipe == null) {
tanks[1].withPressure(compression + 1); tanks[1].withPressure(compression + 1);
} else { } else {
tanks[1].withPressure(recipe.output.pressure).setTankType(recipe.output.type); tanks[1].withPressure(recipe.output.pressure).setTankType(recipe.output.type);
} }
this.markChanged(); this.markChanged();
} }
} }
@ -318,12 +318,12 @@ public class TileEntityMachineCompressor extends TileEntityMachineBase implement
public FluidTank[] getReceivingTanks() { public FluidTank[] getReceivingTanks() {
return new FluidTank[] {tanks[0]}; return new FluidTank[] {tanks[0]};
} }
AxisAlignedBB bb = null; AxisAlignedBB bb = null;
@Override @Override
public AxisAlignedBB getRenderBoundingBox() { public AxisAlignedBB getRenderBoundingBox() {
if(bb == null) { if(bb == null) {
bb = AxisAlignedBB.getBoundingBox( bb = AxisAlignedBB.getBoundingBox(
xCoord - 2, xCoord - 2,
@ -334,10 +334,10 @@ public class TileEntityMachineCompressor extends TileEntityMachineBase implement
zCoord + 3 zCoord + 3
); );
} }
return bb; return bb;
} }
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public double getMaxRenderDistanceSquared() { public double getMaxRenderDistanceSquared() {
@ -365,11 +365,12 @@ public class TileEntityMachineCompressor extends TileEntityMachineBase implement
} }
@Override @Override
public int getMaxLevel(UpgradeType type) { public HashMap<UpgradeType, Integer> getValidUpgrades() {
if(type == UpgradeType.SPEED) return 3; HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
if(type == UpgradeType.POWER) return 3; upgrades.put(UpgradeType.SPEED, 3);
if(type == UpgradeType.OVERDRIVE) return 9; upgrades.put(UpgradeType.POWER, 3);
return 0; upgrades.put(UpgradeType.OVERDRIVE, 9);
return upgrades;
} }
@Override @Override

View File

@ -1,10 +1,11 @@
package com.hbm.tileentity.machine; package com.hbm.tileentity.machine;
import java.util.HashMap;
import java.util.List; import java.util.List;
import com.hbm.blocks.ModBlocks; import com.hbm.blocks.ModBlocks;
import com.hbm.extprop.HbmPlayerProps; import com.hbm.extprop.HbmPlayerProps;
import com.hbm.inventory.UpgradeManager; import com.hbm.inventory.UpgradeManagerNT;
import com.hbm.inventory.container.ContainerCrystallizer; import com.hbm.inventory.container.ContainerCrystallizer;
import com.hbm.inventory.fluid.Fluids; import com.hbm.inventory.fluid.Fluids;
import com.hbm.inventory.fluid.tank.FluidTank; import com.hbm.inventory.fluid.tank.FluidTank;
@ -15,10 +16,7 @@ import com.hbm.items.machine.ItemMachineUpgrade;
import com.hbm.items.machine.ItemMachineUpgrade.UpgradeType; import com.hbm.items.machine.ItemMachineUpgrade.UpgradeType;
import com.hbm.lib.Library; import com.hbm.lib.Library;
import com.hbm.main.MainRegistry; import com.hbm.main.MainRegistry;
import com.hbm.tileentity.IFluidCopiable; import com.hbm.tileentity.*;
import com.hbm.tileentity.IGUIProvider;
import com.hbm.tileentity.IUpgradeInfoProvider;
import com.hbm.tileentity.TileEntityMachineBase;
import com.hbm.util.BobMathUtil; import com.hbm.util.BobMathUtil;
import com.hbm.util.I18nUtil; import com.hbm.util.I18nUtil;
import com.hbm.util.fauxpointtwelve.DirPos; import com.hbm.util.fauxpointtwelve.DirPos;
@ -40,19 +38,21 @@ import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityMachineCrystallizer extends TileEntityMachineBase implements IEnergyReceiverMK2, IFluidStandardReceiver, IGUIProvider, IUpgradeInfoProvider, IFluidCopiable { public class TileEntityMachineCrystallizer extends TileEntityMachineBase implements IEnergyReceiverMK2, IFluidStandardReceiver, IGUIProvider, IUpgradeInfoProvider, IFluidCopiable {
public long power; public long power;
public static final long maxPower = 1000000; public static final long maxPower = 1000000;
public static final int demand = 1000; public static final int demand = 1000;
public short progress; public short progress;
public short duration = 600; public short duration = 600;
public boolean isOn; public boolean isOn;
public float angle; public float angle;
public float prevAngle; public float prevAngle;
public FluidTank tank; public FluidTank tank;
public UpgradeManagerNT upgradeManager = new UpgradeManagerNT();
public TileEntityMachineCrystallizer() { public TileEntityMachineCrystallizer() {
super(8); super(8);
tank = new FluidTank(Fluids.PEROXIDE, 8000); tank = new FluidTank(Fluids.PEROXIDE, 8000);
@ -65,76 +65,76 @@ public class TileEntityMachineCrystallizer extends TileEntityMachineBase impleme
@Override @Override
public void updateEntity() { public void updateEntity() {
if(!worldObj.isRemote) { if(!worldObj.isRemote) {
this.isOn = false; this.isOn = false;
this.updateConnections(); this.updateConnections();
power = Library.chargeTEFromItems(slots, 1, power, maxPower); power = Library.chargeTEFromItems(slots, 1, power, maxPower);
tank.setType(7, slots); tank.setType(7, slots);
tank.loadTank(3, 4, slots); tank.loadTank(3, 4, slots);
UpgradeManager.eval(slots, 5, 6); upgradeManager.checkSlots(this, slots, 5, 6);
for(int i = 0; i < getCycleCount(); i++) { for(int i = 0; i < getCycleCount(); i++) {
if(canProcess()) { if(canProcess()) {
progress++; progress++;
power -= getPowerRequired(); power -= getPowerRequired();
isOn = true; isOn = true;
if(progress > getDuration()) { if(progress > getDuration()) {
progress = 0; progress = 0;
processItem(); processItem();
this.markDirty(); this.markDirty();
} }
} else { } else {
progress = 0; progress = 0;
} }
} }
this.networkPackNT(25); this.networkPackNT(25);
} else { } else {
prevAngle = angle; prevAngle = angle;
if(isOn) { if(isOn) {
angle += 5F * this.getCycleCount(); angle += 5F * this.getCycleCount();
if(angle >= 360) { if(angle >= 360) {
angle -= 360; angle -= 360;
prevAngle -= 360; prevAngle -= 360;
} }
if(worldObj.rand.nextInt(20) == 0 && MainRegistry.proxy.me().getDistance(xCoord + 0.5, yCoord + 6, zCoord + 0.5) < 50) { if(worldObj.rand.nextInt(20) == 0 && MainRegistry.proxy.me().getDistance(xCoord + 0.5, yCoord + 6, zCoord + 0.5) < 50) {
worldObj.spawnParticle("cloud", xCoord + worldObj.rand.nextDouble(), yCoord + 6.5D, zCoord + worldObj.rand.nextDouble(), 0.0, 0.1, 0.0); worldObj.spawnParticle("cloud", xCoord + worldObj.rand.nextDouble(), yCoord + 6.5D, zCoord + worldObj.rand.nextDouble(), 0.0, 0.1, 0.0);
} }
} }
} }
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10); ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10);
ForgeDirection rot = dir.getRotation(ForgeDirection.UP); ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
List<EntityPlayer> players = worldObj.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(xCoord + 0.25, yCoord + 1, zCoord + 0.25, xCoord + 0.75, yCoord + 6, zCoord + 0.75).offset(rot.offsetX * 1.5, 0, rot.offsetZ * 1.5)); List<EntityPlayer> players = worldObj.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(xCoord + 0.25, yCoord + 1, zCoord + 0.25, xCoord + 0.75, yCoord + 6, zCoord + 0.75).offset(rot.offsetX * 1.5, 0, rot.offsetZ * 1.5));
for(EntityPlayer player : players) { for(EntityPlayer player : players) {
HbmPlayerProps props = HbmPlayerProps.getData(player); HbmPlayerProps props = HbmPlayerProps.getData(player);
props.isOnLadder = true; props.isOnLadder = true;
} }
} }
private void updateConnections() { private void updateConnections() {
for(DirPos pos : getConPos()) { for(DirPos pos : getConPos()) {
this.trySubscribe(worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); this.trySubscribe(worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
this.trySubscribe(tank.getTankType(), worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); this.trySubscribe(tank.getTankType(), worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
} }
} }
protected DirPos[] getConPos() { protected DirPos[] getConPos() {
return new DirPos[] { return new DirPos[] {
@ -148,7 +148,7 @@ public class TileEntityMachineCrystallizer extends TileEntityMachineBase impleme
new DirPos(xCoord - 1, yCoord, zCoord - 2, Library.NEG_Z) new DirPos(xCoord - 1, yCoord, zCoord - 2, Library.NEG_Z)
}; };
} }
@Override @Override
public void serialize(ByteBuf buf) { public void serialize(ByteBuf buf) {
super.serialize(buf); super.serialize(buf);
@ -158,7 +158,7 @@ public class TileEntityMachineCrystallizer extends TileEntityMachineBase impleme
buf.writeBoolean(isOn); buf.writeBoolean(isOn);
tank.serialize(buf); tank.serialize(buf);
} }
@Override @Override
public void deserialize(ByteBuf buf) { public void deserialize(ByteBuf buf) {
super.deserialize(buf); super.deserialize(buf);
@ -168,103 +168,103 @@ public class TileEntityMachineCrystallizer extends TileEntityMachineBase impleme
isOn = buf.readBoolean(); isOn = buf.readBoolean();
tank.deserialize(buf); tank.deserialize(buf);
} }
private void processItem() { private void processItem() {
CrystallizerRecipe result = CrystallizerRecipes.getOutput(slots[0], tank.getTankType()); CrystallizerRecipe result = CrystallizerRecipes.getOutput(slots[0], tank.getTankType());
if(result == null) //never happens but you can't be sure enough if(result == null) //never happens but you can't be sure enough
return; return;
ItemStack stack = result.output.copy(); ItemStack stack = result.output.copy();
if(slots[2] == null) if(slots[2] == null)
slots[2] = stack; slots[2] = stack;
else if(slots[2].stackSize + stack.stackSize <= slots[2].getMaxStackSize()) else if(slots[2].stackSize + stack.stackSize <= slots[2].getMaxStackSize())
slots[2].stackSize += stack.stackSize; slots[2].stackSize += stack.stackSize;
tank.setFill(tank.getFill() - getRequiredAcid(result.acidAmount)); tank.setFill(tank.getFill() - getRequiredAcid(result.acidAmount));
float freeChance = this.getFreeChance(); float freeChance = this.getFreeChance();
if(freeChance == 0 || freeChance < worldObj.rand.nextFloat()) if(freeChance == 0 || freeChance < worldObj.rand.nextFloat())
this.decrStackSize(0, result.itemAmount); this.decrStackSize(0, result.itemAmount);
} }
private boolean canProcess() { private boolean canProcess() {
//Is there no input? //Is there no input?
if(slots[0] == null) if(slots[0] == null)
return false; return false;
if(power < getPowerRequired()) if(power < getPowerRequired())
return false; return false;
CrystallizerRecipe result = CrystallizerRecipes.getOutput(slots[0], tank.getTankType()); CrystallizerRecipe result = CrystallizerRecipes.getOutput(slots[0], tank.getTankType());
//Or output? //Or output?
if(result == null) if(result == null)
return false; return false;
//Not enough of the input item? //Not enough of the input item?
if(slots[0].stackSize < result.itemAmount) if(slots[0].stackSize < result.itemAmount)
return false; return false;
if(tank.getFill() < getRequiredAcid(result.acidAmount)) return false; if(tank.getFill() < getRequiredAcid(result.acidAmount)) return false;
ItemStack stack = result.output.copy(); ItemStack stack = result.output.copy();
//Does the output not match? //Does the output not match?
if(slots[2] != null && (slots[2].getItem() != stack.getItem() || slots[2].getItemDamage() != stack.getItemDamage())) if(slots[2] != null && (slots[2].getItem() != stack.getItem() || slots[2].getItemDamage() != stack.getItemDamage()))
return false; return false;
//Or is the output slot already full? //Or is the output slot already full?
if(slots[2] != null && slots[2].stackSize + stack.stackSize > slots[2].getMaxStackSize()) if(slots[2] != null && slots[2].stackSize + stack.stackSize > slots[2].getMaxStackSize())
return false; return false;
return true; return true;
} }
public int getRequiredAcid(int base) { public int getRequiredAcid(int base) {
int efficiency = Math.min(UpgradeManager.getLevel(UpgradeType.EFFECT), 3); int efficiency = upgradeManager.getLevel(UpgradeType.EFFECT);
if(efficiency > 0) { if(efficiency > 0) {
return base * (efficiency + 2); return base * (efficiency + 2);
} }
return base; return base;
} }
public float getFreeChance() { public float getFreeChance() {
int efficiency = Math.min(UpgradeManager.getLevel(UpgradeType.EFFECT), 3); int efficiency = upgradeManager.getLevel(UpgradeType.EFFECT);
if(efficiency > 0) { if(efficiency > 0) {
return Math.min(efficiency * 0.05F, 0.15F); return Math.min(efficiency * 0.05F, 0.15F);
} }
return 0; return 0;
} }
public short getDuration() { public short getDuration() {
CrystallizerRecipe result = CrystallizerRecipes.getOutput(slots[0], tank.getTankType()); CrystallizerRecipe result = CrystallizerRecipes.getOutput(slots[0], tank.getTankType());
int base = result != null ? result.duration : 600; int base = result != null ? result.duration : 600;
int speed = Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 3); int speed = upgradeManager.getLevel(UpgradeType.SPEED);
if(speed > 0) { if(speed > 0) {
return (short) Math.ceil((base * Math.max(1F - 0.25F * speed, 0.25F))); return (short) Math.ceil((base * Math.max(1F - 0.25F * speed, 0.25F)));
} }
return (short) base; return (short) base;
} }
public int getPowerRequired() { public int getPowerRequired() {
int speed = Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 3); int speed = upgradeManager.getLevel(UpgradeType.SPEED);
return (int) (demand + Math.min(speed * 1000, 3000)); return (int) (demand + Math.min(speed * 1000, 3000));
} }
public float getCycleCount() { public float getCycleCount() {
int speed = UpgradeManager.getLevel(UpgradeType.OVERDRIVE); int speed = upgradeManager.getLevel(UpgradeType.OVERDRIVE);
return Math.min(1 + speed * 2, 7); return Math.min(1 + speed * 2, 7);
} }
public long getPowerScaled(int i) { public long getPowerScaled(int i) {
return (power * i) / maxPower; return (power * i) / maxPower;
} }
public int getProgressScaled(int i) { public int getProgressScaled(int i) {
return (progress * i) / duration; return (progress * i) / duration;
} }
@ -283,34 +283,34 @@ public class TileEntityMachineCrystallizer extends TileEntityMachineBase impleme
public long getMaxPower() { public long getMaxPower() {
return maxPower; return maxPower;
} }
@Override @Override
public void readFromNBT(NBTTagCompound nbt) { public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt); super.readFromNBT(nbt);
power = nbt.getLong("power"); power = nbt.getLong("power");
tank.readFromNBT(nbt, "tank"); tank.readFromNBT(nbt, "tank");
} }
@Override @Override
public void writeToNBT(NBTTagCompound nbt) { public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt); super.writeToNBT(nbt);
nbt.setLong("power", power); nbt.setLong("power", power);
tank.writeToNBT(nbt, "tank"); tank.writeToNBT(nbt, "tank");
} }
@Override @Override
public boolean isItemValidForSlot(int i, ItemStack itemStack) { public boolean isItemValidForSlot(int i, ItemStack itemStack) {
CrystallizerRecipe recipe = CrystallizerRecipes.getOutput(itemStack, tank.getTankType()); CrystallizerRecipe recipe = CrystallizerRecipes.getOutput(itemStack, tank.getTankType());
if(i == 0 && recipe != null) { if(i == 0 && recipe != null) {
return true; return true;
} }
if(i == 1 && itemStack.getItem() instanceof IBatteryItem) if(i == 1 && itemStack.getItem() instanceof IBatteryItem)
return true; return true;
return false; return false;
} }
@ -321,15 +321,15 @@ public class TileEntityMachineCrystallizer extends TileEntityMachineBase impleme
@Override @Override
public int[] getAccessibleSlotsFromSide(int side) { public int[] getAccessibleSlotsFromSide(int side) {
return side == 0 ? new int[] { 2 } : new int[] { 0, 2 }; return side == 0 ? new int[] { 2 } : new int[] { 0, 2 };
} }
@Override @Override
public AxisAlignedBB getRenderBoundingBox() { public AxisAlignedBB getRenderBoundingBox() {
return TileEntity.INFINITE_EXTENT_AABB; return TileEntity.INFINITE_EXTENT_AABB;
} }
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public double getMaxRenderDistanceSquared() { public double getMaxRenderDistanceSquared() {
@ -339,7 +339,7 @@ public class TileEntityMachineCrystallizer extends TileEntityMachineBase impleme
@Override @Override
public void setInventorySlotContents(int i, ItemStack stack) { public void setInventorySlotContents(int i, ItemStack stack) {
super.setInventorySlotContents(i, stack); super.setInventorySlotContents(i, stack);
if(stack != null && i >= 5 && i <= 6 && stack.getItem() instanceof ItemMachineUpgrade) { if(stack != null && i >= 5 && i <= 6 && stack.getItem() instanceof ItemMachineUpgrade) {
worldObj.playSoundEffect(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5, "hbm:item.upgradePlug", 1.0F, 1.0F); worldObj.playSoundEffect(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5, "hbm:item.upgradePlug", 1.0F, 1.0F);
} }
@ -388,11 +388,12 @@ public class TileEntityMachineCrystallizer extends TileEntityMachineBase impleme
} }
@Override @Override
public int getMaxLevel(UpgradeType type) { public HashMap<UpgradeType, Integer> getValidUpgrades() {
if(type == UpgradeType.SPEED) return 3; HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
if(type == UpgradeType.EFFECT) return 3; upgrades.put(UpgradeType.SPEED, 3);
if(type == UpgradeType.OVERDRIVE) return 3; upgrades.put(UpgradeType.EFFECT, 3);
return 0; upgrades.put(UpgradeType.OVERDRIVE, 3);
return upgrades;
} }
@Override @Override

View File

@ -1,10 +1,11 @@
package com.hbm.tileentity.machine; package com.hbm.tileentity.machine;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
import com.hbm.blocks.ModBlocks; import com.hbm.blocks.ModBlocks;
import com.hbm.inventory.UpgradeManager; import com.hbm.inventory.UpgradeManagerNT;
import com.hbm.inventory.RecipesCommon.AStack; import com.hbm.inventory.RecipesCommon.AStack;
import com.hbm.inventory.RecipesCommon.ComparableStack; import com.hbm.inventory.RecipesCommon.ComparableStack;
import com.hbm.inventory.container.ContainerMachineCyclotron; import com.hbm.inventory.container.ContainerMachineCyclotron;
@ -39,21 +40,23 @@ import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityMachineCyclotron extends TileEntityMachineBase implements IEnergyReceiverMK2, IFluidStandardTransceiver, IGUIProvider, IConditionalInvAccess, IUpgradeInfoProvider, IInfoProviderEC, IFluidCopiable { public class TileEntityMachineCyclotron extends TileEntityMachineBase implements IEnergyReceiverMK2, IFluidStandardTransceiver, IGUIProvider, IConditionalInvAccess, IUpgradeInfoProvider, IInfoProviderEC, IFluidCopiable {
public long power; public long power;
public static final long maxPower = 100000000; public static final long maxPower = 100000000;
public static int consumption = 1_000_000; public static int consumption = 1_000_000;
private byte plugs; private byte plugs;
public int progress; public int progress;
public static final int duration = 690; public static final int duration = 690;
public FluidTank[] tanks; public FluidTank[] tanks;
public UpgradeManagerNT upgradeManager = new UpgradeManagerNT();
public TileEntityMachineCyclotron() { public TileEntityMachineCyclotron() {
super(12); super(12);
this.tanks = new FluidTank[3]; this.tanks = new FluidTank[3];
this.tanks[0] = new FluidTank(Fluids.WATER, 32000); this.tanks[0] = new FluidTank(Fluids.WATER, 32000);
this.tanks[1] = new FluidTank(Fluids.SPENTSTEAM, 32000); this.tanks[1] = new FluidTank(Fluids.SPENTSTEAM, 32000);
@ -67,67 +70,67 @@ public class TileEntityMachineCyclotron extends TileEntityMachineBase implements
@Override @Override
public void updateEntity() { public void updateEntity() {
if(!worldObj.isRemote) { if(!worldObj.isRemote) {
this.updateConnections(); this.updateConnections();
this.power = Library.chargeTEFromItems(slots, 9, power, maxPower); this.power = Library.chargeTEFromItems(slots, 9, power, maxPower);
UpgradeManager.eval(slots, 10, 11); upgradeManager.checkSlots(this, slots, 10, 11);
if(canProcess()) { if(canProcess()) {
progress += getSpeed(); progress += getSpeed();
power -= getConsumption(); power -= getConsumption();
int convert = getCoolantConsumption(); int convert = getCoolantConsumption();
tanks[0].setFill(tanks[0].getFill() - convert); tanks[0].setFill(tanks[0].getFill() - convert);
tanks[1].setFill(tanks[1].getFill() + convert); tanks[1].setFill(tanks[1].getFill() + convert);
if(progress >= duration) { if(progress >= duration) {
process(); process();
progress = 0; progress = 0;
this.markDirty(); this.markDirty();
} }
} else { } else {
progress = 0; progress = 0;
} }
this.sendFluid(); this.sendFluid();
this.networkPackNT(25); this.networkPackNT(25);
} }
} }
@Override @Override
public void serialize(ByteBuf buf) { public void serialize(ByteBuf buf) {
super.serialize(buf); super.serialize(buf);
buf.writeLong(power); buf.writeLong(power);
buf.writeInt(progress); buf.writeInt(progress);
buf.writeByte(plugs); buf.writeByte(plugs);
for(int i = 0; i < 3; i++) for(int i = 0; i < 3; i++)
tanks[i].serialize(buf); tanks[i].serialize(buf);
} }
@Override @Override
public void deserialize(ByteBuf buf) { public void deserialize(ByteBuf buf) {
super.deserialize(buf); super.deserialize(buf);
power = buf.readLong(); power = buf.readLong();
progress = buf.readInt(); progress = buf.readInt();
plugs = buf.readByte(); plugs = buf.readByte();
for(int i = 0; i < 3; i++) for(int i = 0; i < 3; i++)
tanks[i].deserialize(buf); tanks[i].deserialize(buf);
} }
private void updateConnections() { private void updateConnections() {
for(DirPos pos : getConPos()) { for(DirPos pos : getConPos()) {
this.trySubscribe(worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); this.trySubscribe(worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
this.trySubscribe(tanks[0].getTankType(), worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); this.trySubscribe(tanks[0].getTankType(), worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
} }
} }
private void sendFluid() { private void sendFluid() {
for(int i = 1; i < 3; i++) { for(int i = 1; i < 3; i++) {
if(tanks[i].getFill() > 0) { if(tanks[i].getFill() > 0) {
@ -137,7 +140,7 @@ public class TileEntityMachineCyclotron extends TileEntityMachineBase implements
} }
} }
} }
public DirPos[] getConPos() { public DirPos[] getConPos() {
return new DirPos[] { return new DirPos[] {
new DirPos(xCoord + 3, yCoord, zCoord + 1, Library.POS_X), new DirPos(xCoord + 3, yCoord, zCoord + 1, Library.POS_X),
@ -150,93 +153,93 @@ public class TileEntityMachineCyclotron extends TileEntityMachineBase implements
new DirPos(xCoord - 1, yCoord, zCoord - 3, Library.NEG_Z) new DirPos(xCoord - 1, yCoord, zCoord - 3, Library.NEG_Z)
}; };
} }
public boolean canProcess() { public boolean canProcess() {
if(power < getConsumption()) if(power < getConsumption())
return false; return false;
int convert = getCoolantConsumption(); int convert = getCoolantConsumption();
if(tanks[0].getFill() < convert) if(tanks[0].getFill() < convert)
return false; return false;
if(tanks[1].getFill() + convert > tanks[1].getMaxFill()) if(tanks[1].getFill() + convert > tanks[1].getMaxFill())
return false; return false;
for(int i = 0; i < 3; i++) { for(int i = 0; i < 3; i++) {
Object[] res = CyclotronRecipes.getOutput(slots[i + 3], slots[i]); Object[] res = CyclotronRecipes.getOutput(slots[i + 3], slots[i]);
if(res == null) if(res == null)
continue; continue;
ItemStack out = (ItemStack)res[0]; ItemStack out = (ItemStack)res[0];
if(out == null) if(out == null)
continue; continue;
if(slots[i + 6] == null) if(slots[i + 6] == null)
return true; return true;
if(slots[i + 6].getItem() == out.getItem() && slots[i + 6].getItemDamage() == out.getItemDamage() && slots[i + 6].stackSize < out.getMaxStackSize()) if(slots[i + 6].getItem() == out.getItem() && slots[i + 6].getItemDamage() == out.getItemDamage() && slots[i + 6].stackSize < out.getMaxStackSize())
return true; return true;
} }
return false; return false;
} }
public void process() { public void process() {
for(int i = 0; i < 3; i++) { for(int i = 0; i < 3; i++) {
Object[] res = CyclotronRecipes.getOutput(slots[i + 3], slots[i]); Object[] res = CyclotronRecipes.getOutput(slots[i + 3], slots[i]);
if(res == null) if(res == null)
continue; continue;
ItemStack out = (ItemStack)res[0]; ItemStack out = (ItemStack)res[0];
if(out == null) if(out == null)
continue; continue;
if(slots[i + 6] == null) { if(slots[i + 6] == null) {
this.decrStackSize(i, 1); this.decrStackSize(i, 1);
this.decrStackSize(i + 3, 1); this.decrStackSize(i + 3, 1);
slots[i + 6] = out; slots[i + 6] = out;
this.tanks[2].setFill(this.tanks[2].getFill() + (Integer)res[1]); this.tanks[2].setFill(this.tanks[2].getFill() + (Integer)res[1]);
continue; continue;
} }
if(slots[i + 6].getItem() == out.getItem() && slots[i + 6].getItemDamage() == out.getItemDamage() && slots[i + 6].stackSize < out.getMaxStackSize()) { if(slots[i + 6].getItem() == out.getItem() && slots[i + 6].getItemDamage() == out.getItemDamage() && slots[i + 6].stackSize < out.getMaxStackSize()) {
this.decrStackSize(i, 1); this.decrStackSize(i, 1);
this.decrStackSize(i + 3, 1); this.decrStackSize(i + 3, 1);
slots[i + 6].stackSize++; slots[i + 6].stackSize++;
this.tanks[2].setFill(this.tanks[2].getFill() + (Integer)res[1]); this.tanks[2].setFill(this.tanks[2].getFill() + (Integer)res[1]);
} }
} }
if(this.tanks[2].getFill() > this.tanks[2].getMaxFill()) if(this.tanks[2].getFill() > this.tanks[2].getMaxFill())
this.tanks[2].setFill(this.tanks[2].getMaxFill()); this.tanks[2].setFill(this.tanks[2].getMaxFill());
} }
public int getSpeed() { public int getSpeed() {
return Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 3) + 1; return upgradeManager.getLevel(UpgradeType.SPEED) + 1;
} }
public int getConsumption() { public int getConsumption() {
int efficiency = Math.min(UpgradeManager.getLevel(UpgradeType.POWER), 3); int efficiency = upgradeManager.getLevel(UpgradeType.POWER);
return consumption - 100_000 * efficiency; return consumption - 100_000 * efficiency;
} }
public int getCoolantConsumption() { public int getCoolantConsumption() {
int efficiency = Math.min(UpgradeManager.getLevel(UpgradeType.EFFECT), 3); int efficiency = upgradeManager.getLevel(UpgradeType.EFFECT);
//half a small tower's worth //half a small tower's worth
return 500 / (efficiency + 1) * getSpeed(); return 500 / (efficiency + 1) * getSpeed();
} }
@ -248,67 +251,67 @@ public class TileEntityMachineCyclotron extends TileEntityMachineBase implements
public int getProgressScaled(int i) { public int getProgressScaled(int i) {
return (progress * i) / duration; return (progress * i) / duration;
} }
@Override @Override
public AxisAlignedBB getRenderBoundingBox() { public AxisAlignedBB getRenderBoundingBox() {
return AxisAlignedBB.getBoundingBox(xCoord - 2, yCoord, zCoord - 2, xCoord + 3, yCoord + 4, zCoord + 3); return AxisAlignedBB.getBoundingBox(xCoord - 2, yCoord, zCoord - 2, xCoord + 3, yCoord + 4, zCoord + 3);
} }
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public double getMaxRenderDistanceSquared() { public double getMaxRenderDistanceSquared() {
return 65536.0D; return 65536.0D;
} }
@Override @Override
public void readFromNBT(NBTTagCompound nbt) { public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt); super.readFromNBT(nbt);
for(int i = 0; i < 3; i++) for(int i = 0; i < 3; i++)
tanks[i].readFromNBT(nbt, "t" + i); tanks[i].readFromNBT(nbt, "t" + i);
this.progress = nbt.getInteger("progress"); this.progress = nbt.getInteger("progress");
this.power = nbt.getLong("power"); this.power = nbt.getLong("power");
this.plugs = nbt.getByte("plugs"); this.plugs = nbt.getByte("plugs");
} }
@Override @Override
public void writeToNBT(NBTTagCompound nbt) { public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt); super.writeToNBT(nbt);
for(int i = 0; i < 3; i++) for(int i = 0; i < 3; i++)
tanks[i].writeToNBT(nbt, "t" + i); tanks[i].writeToNBT(nbt, "t" + i);
nbt.setInteger("progress", progress); nbt.setInteger("progress", progress);
nbt.setLong("power", power); nbt.setLong("power", power);
nbt.setByte("plugs", plugs); nbt.setByte("plugs", plugs);
} }
public void setPlug(int index) { public void setPlug(int index) {
this.plugs |= (1 << index); this.plugs |= (1 << index);
this.markDirty(); this.markDirty();
} }
public boolean getPlug(int index) { public boolean getPlug(int index) {
return (this.plugs & (1 << index)) > 0; return (this.plugs & (1 << index)) > 0;
} }
public static Item getItemForPlug(int i) { public static Item getItemForPlug(int i) {
switch(i) { switch(i) {
case 0: return ModItems.powder_balefire; case 0: return ModItems.powder_balefire;
case 1: return ModItems.book_of_; case 1: return ModItems.book_of_;
case 2: return ModItems.diamond_gavel; case 2: return ModItems.diamond_gavel;
case 3: return ModItems.coin_maskman; case 3: return ModItems.coin_maskman;
} }
return null; return null;
} }
@Override @Override
public void setInventorySlotContents(int i, ItemStack stack) { public void setInventorySlotContents(int i, ItemStack stack) {
super.setInventorySlotContents(i, stack); super.setInventorySlotContents(i, stack);
if(stack != null && i >= 14 && i <= 15 && stack.getItem() instanceof ItemMachineUpgrade) if(stack != null && i >= 14 && i <= 15 && stack.getItem() instanceof ItemMachineUpgrade)
worldObj.playSoundEffect(xCoord + 0.5, yCoord + 1.5, zCoord + 0.5, "hbm:item.upgradePlug", 1.5F, 1.0F); worldObj.playSoundEffect(xCoord + 0.5, yCoord + 1.5, zCoord + 0.5, "hbm:item.upgradePlug", 1.5F, 1.0F);
} }
@ -356,7 +359,7 @@ public class TileEntityMachineCyclotron extends TileEntityMachineBase implements
@Override @Override
public boolean isItemValidForSlot(int x, int y, int z, int slot, ItemStack stack) { public boolean isItemValidForSlot(int x, int y, int z, int slot, ItemStack stack) {
if(slot < 3) { if(slot < 3) {
for(Entry<Pair<ComparableStack, AStack>, Pair<ItemStack, Integer>> entry : CyclotronRecipes.recipes.entrySet()) { for(Entry<Pair<ComparableStack, AStack>, Pair<ItemStack, Integer>> entry : CyclotronRecipes.recipes.entrySet()) {
if(entry.getKey().getKey().matchesRecipe(stack, true)) return true; if(entry.getKey().getKey().matchesRecipe(stack, true)) return true;
@ -367,7 +370,7 @@ public class TileEntityMachineCyclotron extends TileEntityMachineBase implements
if(entry.getKey().getValue().matchesRecipe(stack, true)) return true; if(entry.getKey().getValue().matchesRecipe(stack, true)) return true;
} }
} }
return false; return false;
} }
@ -383,7 +386,7 @@ public class TileEntityMachineCyclotron extends TileEntityMachineBase implements
@Override @Override
public int[] getAccessibleSlotsFromSide(int x, int y, int z, int side) { public int[] getAccessibleSlotsFromSide(int x, int y, int z, int side) {
for(int i = 2; i < 6; i++) { for(int i = 2; i < 6; i++) {
ForgeDirection dir = ForgeDirection.getOrientation(i); ForgeDirection dir = ForgeDirection.getOrientation(i);
ForgeDirection rot = dir.getRotation(ForgeDirection.UP); ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
@ -392,7 +395,7 @@ public class TileEntityMachineCyclotron extends TileEntityMachineBase implements
if(x == xCoord + dir.offsetX * 2 && z == zCoord + dir.offsetZ * 2) return new int[] {1, 4, 6, 7, 8}; if(x == xCoord + dir.offsetX * 2 && z == zCoord + dir.offsetZ * 2) return new int[] {1, 4, 6, 7, 8};
if(x == xCoord + dir.offsetX * 2 - rot.offsetX && z == zCoord + dir.offsetZ * 2 - rot.offsetZ) return new int[] {2, 5, 6, 7, 8}; if(x == xCoord + dir.offsetX * 2 - rot.offsetX && z == zCoord + dir.offsetZ * 2 - rot.offsetZ) return new int[] {2, 5, 6, 7, 8};
} }
return new int[] {6, 7, 8}; return new int[] {6, 7, 8};
} }
@ -417,11 +420,12 @@ public class TileEntityMachineCyclotron extends TileEntityMachineBase implements
} }
@Override @Override
public int getMaxLevel(UpgradeType type) { public HashMap<UpgradeType, Integer> getValidUpgrades() {
if(type == UpgradeType.SPEED) return 3; HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
if(type == UpgradeType.POWER) return 3; upgrades.put(UpgradeType.SPEED, 3);
if(type == UpgradeType.EFFECT) return 3; upgrades.put(UpgradeType.POWER, 3);
return 0; upgrades.put(UpgradeType.EFFECT, 3);
return upgrades;
} }
@Override @Override

View File

@ -1,9 +1,10 @@
package com.hbm.tileentity.machine; package com.hbm.tileentity.machine;
import java.util.HashMap;
import java.util.List; import java.util.List;
import com.hbm.blocks.ModBlocks; import com.hbm.blocks.ModBlocks;
import com.hbm.inventory.UpgradeManager; import com.hbm.inventory.UpgradeManagerNT;
import com.hbm.inventory.container.ContainerMachineEPress; import com.hbm.inventory.container.ContainerMachineEPress;
import com.hbm.inventory.gui.GUIMachineEPress; import com.hbm.inventory.gui.GUIMachineEPress;
import com.hbm.inventory.recipes.PressRecipes; import com.hbm.inventory.recipes.PressRecipes;
@ -44,9 +45,11 @@ public class TileEntityMachineEPress extends TileEntityMachineBase implements IE
public final static int maxPress = 200; public final static int maxPress = 200;
boolean isRetracting = false; boolean isRetracting = false;
private int delay; private int delay;
public ItemStack syncStack; public ItemStack syncStack;
public UpgradeManagerNT upgradeManager = new UpgradeManagerNT();
public TileEntityMachineEPress() { public TileEntityMachineEPress() {
super(5); super(5);
} }
@ -55,39 +58,39 @@ public class TileEntityMachineEPress extends TileEntityMachineBase implements IE
public String getName() { public String getName() {
return "container.epress"; return "container.epress";
} }
@Override @Override
public void updateEntity() { public void updateEntity() {
if(!worldObj.isRemote) { if(!worldObj.isRemote) {
this.updateConnections(); this.updateConnections();
power = Library.chargeTEFromItems(slots, 0, power, maxPower); power = Library.chargeTEFromItems(slots, 0, power, maxPower);
boolean canProcess = this.canProcess(); boolean canProcess = this.canProcess();
if((canProcess || this.isRetracting || this.delay > 0) && power >= 100) { if((canProcess || this.isRetracting || this.delay > 0) && power >= 100) {
power -= 100; power -= 100;
if(delay <= 0) { if(delay <= 0) {
UpgradeManager.eval(slots, 4, 4); upgradeManager.checkSlots(this, slots, 4, 4);
int speed = 1 + Math.min(3, UpgradeManager.getLevel(UpgradeType.SPEED)); int speed = 1 + upgradeManager.getLevel(UpgradeType.SPEED);
int stampSpeed = this.isRetracting ? 20 : 45; int stampSpeed = this.isRetracting ? 20 : 45;
stampSpeed *= (1D + (double) speed / 4D); stampSpeed *= (1D + (double) speed / 4D);
if(this.isRetracting) { if(this.isRetracting) {
this.press -= stampSpeed; this.press -= stampSpeed;
if(this.press <= 0) { if(this.press <= 0) {
this.isRetracting = false; this.isRetracting = false;
this.delay = 5 - speed + 1; this.delay = 5 - speed + 1;
} }
} else if(canProcess) { } else if(canProcess) {
this.press += stampSpeed; this.press += stampSpeed;
if(this.press >= this.maxPress) { if(this.press >= this.maxPress) {
this.worldObj.playSoundEffect(this.xCoord, this.yCoord, this.zCoord, "hbm:block.pressOperate", getVolume(1.5F), 1.0F); this.worldObj.playSoundEffect(this.xCoord, this.yCoord, this.zCoord, "hbm:block.pressOperate", getVolume(1.5F), 1.0F);
ItemStack output = PressRecipes.getOutput(slots[2], slots[1]); ItemStack output = PressRecipes.getOutput(slots[2], slots[1]);
@ -97,17 +100,17 @@ public class TileEntityMachineEPress extends TileEntityMachineBase implements IE
slots[3].stackSize += output.stackSize; slots[3].stackSize += output.stackSize;
} }
this.decrStackSize(2, 1); this.decrStackSize(2, 1);
if(slots[1].getMaxDamage() != 0) { if(slots[1].getMaxDamage() != 0) {
slots[1].setItemDamage(slots[1].getItemDamage() + 1); slots[1].setItemDamage(slots[1].getItemDamage() + 1);
if(slots[1].getItemDamage() >= slots[1].getMaxDamage()) { if(slots[1].getItemDamage() >= slots[1].getMaxDamage()) {
slots[1] = null; slots[1] = null;
} }
} }
this.isRetracting = true; this.isRetracting = true;
this.delay = 5 - speed + 1; this.delay = 5 - speed + 1;
this.markDirty(); this.markDirty();
} }
} else if(this.press > 0){ } else if(this.press > 0){
@ -117,14 +120,14 @@ public class TileEntityMachineEPress extends TileEntityMachineBase implements IE
delay--; delay--;
} }
} }
this.networkPackNT(50); this.networkPackNT(50);
} else { } else {
// approach-based interpolation, GO! // approach-based interpolation, GO!
this.lastPress = this.renderPress; this.lastPress = this.renderPress;
if(this.turnProgress > 0) { if(this.turnProgress > 0) {
this.renderPress = this.renderPress + ((this.syncPress - this.renderPress) / (double) this.turnProgress); this.renderPress = this.renderPress + ((this.syncPress - this.renderPress) / (double) this.turnProgress);
--this.turnProgress; --this.turnProgress;
@ -156,35 +159,35 @@ public class TileEntityMachineEPress extends TileEntityMachineBase implements IE
this.turnProgress = 2; this.turnProgress = 2;
} }
public boolean canProcess() { public boolean canProcess() {
if(power < 100) return false; if(power < 100) return false;
if(slots[1] == null || slots[2] == null) return false; if(slots[1] == null || slots[2] == null) return false;
ItemStack output = PressRecipes.getOutput(slots[2], slots[1]); ItemStack output = PressRecipes.getOutput(slots[2], slots[1]);
if(output == null) return false; if(output == null) return false;
if(slots[3] == null) return true; if(slots[3] == null) return true;
if(slots[3].stackSize + output.stackSize <= slots[3].getMaxStackSize() && slots[3].getItem() == output.getItem() && slots[3].getItemDamage() == output.getItemDamage()) return true; if(slots[3].stackSize + output.stackSize <= slots[3].getMaxStackSize() && slots[3].getItem() == output.getItem() && slots[3].getItemDamage() == output.getItemDamage()) return true;
return false; return false;
} }
private void updateConnections() { private void updateConnections() {
for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
this.trySubscribe(worldObj, xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ, dir); this.trySubscribe(worldObj, xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ, dir);
} }
@Override @Override
public boolean isItemValidForSlot(int i, ItemStack stack) { public boolean isItemValidForSlot(int i, ItemStack stack) {
if(stack.getItem() instanceof ItemStamp) if(stack.getItem() instanceof ItemStamp)
return i == 1; return i == 1;
return i == 2; return i == 2;
} }
@Override @Override
public int[] getAccessibleSlotsFromSide(int side) { public int[] getAccessibleSlotsFromSide(int side) {
return new int[] { 1, 2, 3 }; return new int[] { 1, 2, 3 };
@ -199,16 +202,16 @@ public class TileEntityMachineEPress extends TileEntityMachineBase implements IE
public boolean canExtractItem(int i, ItemStack itemStack, int j) { public boolean canExtractItem(int i, ItemStack itemStack, int j) {
return i == 3; return i == 3;
} }
@Override @Override
public void readFromNBT(NBTTagCompound nbt) { public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt); super.readFromNBT(nbt);
press = nbt.getInteger("press"); press = nbt.getInteger("press");
power = nbt.getInteger("power"); power = nbt.getInteger("power");
isRetracting = nbt.getBoolean("ret"); isRetracting = nbt.getBoolean("ret");
} }
@Override @Override
public void writeToNBT(NBTTagCompound nbt) { public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt); super.writeToNBT(nbt);
@ -221,7 +224,7 @@ public class TileEntityMachineEPress extends TileEntityMachineBase implements IE
@Override @Override
public void setPower(long i) { public void setPower(long i) {
power = i; power = i;
} }
@Override @Override
@ -233,19 +236,19 @@ public class TileEntityMachineEPress extends TileEntityMachineBase implements IE
public long getMaxPower() { public long getMaxPower() {
return maxPower; return maxPower;
} }
AxisAlignedBB aabb; AxisAlignedBB aabb;
@Override @Override
public AxisAlignedBB getRenderBoundingBox() { public AxisAlignedBB getRenderBoundingBox() {
if(aabb != null) if(aabb != null)
return aabb; return aabb;
aabb = AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 3, zCoord + 1); aabb = AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 3, zCoord + 1);
return aabb; return aabb;
} }
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public double getMaxRenderDistanceSquared() { public double getMaxRenderDistanceSquared() {
@ -277,9 +280,10 @@ public class TileEntityMachineEPress extends TileEntityMachineBase implements IE
} }
@Override @Override
public int getMaxLevel(UpgradeType type) { public HashMap<UpgradeType, Integer> getValidUpgrades() {
if(type == UpgradeType.SPEED) return 3; HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
return 0; upgrades.put(UpgradeType.SPEED, 3);
return upgrades;
} }
@Override @Override

View File

@ -1,12 +1,13 @@
package com.hbm.tileentity.machine; package com.hbm.tileentity.machine;
import java.util.HashMap;
import java.util.List; import java.util.List;
import com.hbm.blocks.ModBlocks; import com.hbm.blocks.ModBlocks;
import com.hbm.blocks.machine.MachineElectricFurnace; import com.hbm.blocks.machine.MachineElectricFurnace;
import com.hbm.handler.pollution.PollutionHandler; import com.hbm.handler.pollution.PollutionHandler;
import com.hbm.handler.pollution.PollutionHandler.PollutionType; import com.hbm.handler.pollution.PollutionHandler.PollutionType;
import com.hbm.inventory.UpgradeManager; import com.hbm.inventory.UpgradeManagerNT;
import com.hbm.inventory.container.ContainerElectricFurnace; import com.hbm.inventory.container.ContainerElectricFurnace;
import com.hbm.inventory.gui.GUIMachineElectricFurnace; import com.hbm.inventory.gui.GUIMachineElectricFurnace;
import com.hbm.items.machine.ItemMachineUpgrade.UpgradeType; import com.hbm.items.machine.ItemMachineUpgrade.UpgradeType;
@ -44,6 +45,8 @@ public class TileEntityMachineElectricFurnace extends TileEntityMachineBase impl
private static final int[] slots_io = new int[] { 0, 1, 2 }; private static final int[] slots_io = new int[] { 0, 1, 2 };
public UpgradeManagerNT upgradeManager = new UpgradeManagerNT();
public TileEntityMachineElectricFurnace() { public TileEntityMachineElectricFurnace() {
super(4); super(4);
} }
@ -69,7 +72,7 @@ public class TileEntityMachineElectricFurnace extends TileEntityMachineBase impl
@Override @Override
public void readFromNBT(NBTTagCompound nbt) { public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt); super.readFromNBT(nbt);
this.power = nbt.getLong("power"); this.power = nbt.getLong("power");
this.progress = nbt.getInteger("progress"); this.progress = nbt.getInteger("progress");
} }
@ -114,7 +117,7 @@ public class TileEntityMachineElectricFurnace extends TileEntityMachineBase impl
} }
public boolean canProcess() { public boolean canProcess() {
if(slots[1] == null || cooldown > 0) { if(slots[1] == null || cooldown > 0) {
return false; return false;
} }
@ -167,7 +170,7 @@ public class TileEntityMachineElectricFurnace extends TileEntityMachineBase impl
boolean markDirty = false; boolean markDirty = false;
if(!worldObj.isRemote) { if(!worldObj.isRemote) {
if(cooldown > 0) { if(cooldown > 0) {
cooldown--; cooldown--;
} }
@ -179,16 +182,16 @@ public class TileEntityMachineElectricFurnace extends TileEntityMachineBase impl
this.consumption = 50; this.consumption = 50;
this.maxProgress = 100; this.maxProgress = 100;
UpgradeManager.eval(slots, 3, 3); upgradeManager.checkSlots(this, slots, 3, 3);
int speedLevel = UpgradeManager.getLevel(UpgradeType.SPEED); int speedLevel = upgradeManager.getLevel(UpgradeType.SPEED);
int powerLevel = UpgradeManager.getLevel(UpgradeType.POWER); int powerLevel = upgradeManager.getLevel(UpgradeType.POWER);
maxProgress -= speedLevel * 25; maxProgress -= speedLevel * 25;
consumption += speedLevel * 50; consumption += speedLevel * 50;
maxProgress += powerLevel * 10; maxProgress += powerLevel * 10;
consumption -= powerLevel * 15; consumption -= powerLevel * 15;
if(!hasPower()) { if(!hasPower()) {
cooldown = 20; cooldown = 20;
} }
@ -197,7 +200,7 @@ public class TileEntityMachineElectricFurnace extends TileEntityMachineBase impl
progress++; progress++;
power -= consumption; power -= consumption;
if(worldObj.getTotalWorldTime() % 20 == 0) PollutionHandler.incrementPollution(worldObj, xCoord, yCoord, zCoord, PollutionType.SOOT, PollutionHandler.SOOT_PER_SECOND); if(worldObj.getTotalWorldTime() % 20 == 0) PollutionHandler.incrementPollution(worldObj, xCoord, yCoord, zCoord, PollutionType.SOOT, PollutionHandler.SOOT_PER_SECOND);
if(this.progress >= maxProgress) { if(this.progress >= maxProgress) {
@ -219,7 +222,7 @@ public class TileEntityMachineElectricFurnace extends TileEntityMachineBase impl
markDirty = true; markDirty = true;
MachineElectricFurnace.updateBlockState(this.progress > 0, this.worldObj, this.xCoord, this.yCoord, this.zCoord); MachineElectricFurnace.updateBlockState(this.progress > 0, this.worldObj, this.xCoord, this.yCoord, this.zCoord);
} }
this.networkPackNT(50); this.networkPackNT(50);
@ -228,7 +231,7 @@ public class TileEntityMachineElectricFurnace extends TileEntityMachineBase impl
} }
} }
} }
@Override @Override
public void serialize(ByteBuf buf) { public void serialize(ByteBuf buf) {
super.serialize(buf); super.serialize(buf);
@ -236,7 +239,7 @@ public class TileEntityMachineElectricFurnace extends TileEntityMachineBase impl
buf.writeInt(maxProgress); buf.writeInt(maxProgress);
buf.writeInt(progress); buf.writeInt(progress);
} }
@Override @Override
public void deserialize(ByteBuf buf) { public void deserialize(ByteBuf buf) {
super.deserialize(buf); super.deserialize(buf);
@ -244,7 +247,7 @@ public class TileEntityMachineElectricFurnace extends TileEntityMachineBase impl
maxProgress = buf.readInt(); maxProgress = buf.readInt();
progress = buf.readInt(); progress = buf.readInt();
} }
private void updateConnections() { private void updateConnections() {
for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
@ -298,9 +301,10 @@ public class TileEntityMachineElectricFurnace extends TileEntityMachineBase impl
} }
@Override @Override
public int getMaxLevel(UpgradeType type) { public HashMap<UpgradeType, Integer> getValidUpgrades() {
if(type == UpgradeType.SPEED) return 3; HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
if(type == UpgradeType.POWER) return 3; upgrades.put(UpgradeType.SPEED, 3);
return 0; upgrades.put(UpgradeType.POWER, 3);
return upgrades;
} }
} }

View File

@ -1,10 +1,7 @@
package com.hbm.tileentity.machine; package com.hbm.tileentity.machine;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.*;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
import com.hbm.blocks.BlockDummyable; import com.hbm.blocks.BlockDummyable;
import com.hbm.blocks.ModBlocks; import com.hbm.blocks.ModBlocks;
@ -12,7 +9,7 @@ import com.hbm.blocks.generic.BlockBedrockOreTE.TileEntityBedrockOre;
import com.hbm.blocks.network.CraneInserter; import com.hbm.blocks.network.CraneInserter;
import com.hbm.entity.item.EntityMovingItem; import com.hbm.entity.item.EntityMovingItem;
import com.hbm.interfaces.IControlReceiver; import com.hbm.interfaces.IControlReceiver;
import com.hbm.inventory.UpgradeManager; import com.hbm.inventory.UpgradeManagerNT;
import com.hbm.inventory.container.ContainerMachineExcavator; import com.hbm.inventory.container.ContainerMachineExcavator;
import com.hbm.inventory.fluid.Fluids; import com.hbm.inventory.fluid.Fluids;
import com.hbm.inventory.fluid.tank.FluidTank; import com.hbm.inventory.fluid.tank.FluidTank;
@ -65,13 +62,13 @@ public class TileEntityMachineExcavator extends TileEntityMachineBase implements
public static final long maxPower = 1_000_000; public static final long maxPower = 1_000_000;
public long power; public long power;
public boolean operational = false; public boolean operational = false;
public boolean enableDrill = false; public boolean enableDrill = false;
public boolean enableCrusher = false; public boolean enableCrusher = false;
public boolean enableWalling = false; public boolean enableWalling = false;
public boolean enableVeinMiner = false; public boolean enableVeinMiner = false;
public boolean enableSilkTouch = false; public boolean enableSilkTouch = false;
protected int ticksWorked = 0; protected int ticksWorked = 0;
protected int targetDepth = 0; //0 is the first block below null position protected int targetDepth = 0; //0 is the first block below null position
protected boolean bedrockDrilling = false; protected boolean bedrockDrilling = false;
@ -83,13 +80,15 @@ public class TileEntityMachineExcavator extends TileEntityMachineBase implements
public float crusherRotation = 0F; public float crusherRotation = 0F;
public float prevCrusherRotation = 0F; public float prevCrusherRotation = 0F;
public int chuteTimer = 0; public int chuteTimer = 0;
public double speed = 1.0D; public double speed = 1.0D;
public final long baseConsumption = 10_000L; public final long baseConsumption = 10_000L;
public long consumption = baseConsumption; public long consumption = baseConsumption;
public FluidTank tank; public FluidTank tank;
public UpgradeManagerNT upgradeManager = new UpgradeManagerNT();
public TileEntityMachineExcavator() { public TileEntityMachineExcavator() {
super(14); super(14);
this.tank = new FluidTank(Fluids.SULFURIC_ACID, 16_000); this.tank = new FluidTank(Fluids.SULFURIC_ACID, 16_000);
@ -102,48 +101,48 @@ public class TileEntityMachineExcavator extends TileEntityMachineBase implements
@Override @Override
public void updateEntity() { public void updateEntity() {
//needs to happen on client too for GUI rendering //needs to happen on client too for GUI rendering
UpgradeManager.eval(slots, 2, 3); upgradeManager.checkSlots(this, slots, 2, 3);
int speedLevel = Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 3); int speedLevel = upgradeManager.getLevel(UpgradeType.SPEED);
int powerLevel = Math.min(UpgradeManager.getLevel(UpgradeType.POWER), 3); int powerLevel = upgradeManager.getLevel(UpgradeType.POWER);
consumption = baseConsumption * (1 + speedLevel); consumption = baseConsumption * (1 + speedLevel);
consumption /= (1 + powerLevel); consumption /= (1 + powerLevel);
if(!worldObj.isRemote) { if(!worldObj.isRemote) {
this.tank.setType(1, slots); this.tank.setType(1, slots);
if(worldObj.getTotalWorldTime() % 20 == 0) { if(worldObj.getTotalWorldTime() % 20 == 0) {
tryEjectBuffer(); tryEjectBuffer();
for(DirPos pos : getConPos()) { for(DirPos pos : getConPos()) {
this.trySubscribe(worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); this.trySubscribe(worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
this.trySubscribe(tank.getTankType(), worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); this.trySubscribe(tank.getTankType(), worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
} }
} }
if(chuteTimer > 0) chuteTimer--; if(chuteTimer > 0) chuteTimer--;
this.power = Library.chargeTEFromItems(slots, 0, this.getPower(), this.getMaxPower()); this.power = Library.chargeTEFromItems(slots, 0, this.getPower(), this.getMaxPower());
this.operational = false; this.operational = false;
int radiusLevel = Math.min(UpgradeManager.getLevel(UpgradeType.EFFECT), 3); int radiusLevel = upgradeManager.getLevel(UpgradeType.EFFECT);
EnumDrillType type = this.getInstalledDrill(); EnumDrillType type = this.getInstalledDrill();
if(this.enableDrill && type != null && this.power >= this.getPowerConsumption()) { if(this.enableDrill && type != null && this.power >= this.getPowerConsumption()) {
operational = true; operational = true;
this.power -= this.getPowerConsumption(); this.power -= this.getPowerConsumption();
this.speed = type.speed; this.speed = type.speed;
this.speed *= (1 + speedLevel / 2D); this.speed *= (1 + speedLevel / 2D);
int maxDepth = this.yCoord - 4; int maxDepth = this.yCoord - 4;
if((bedrockDrilling || targetDepth <= maxDepth) && tryDrill(1 + radiusLevel * 2)) { if((bedrockDrilling || targetDepth <= maxDepth) && tryDrill(1 + radiusLevel * 2)) {
targetDepth++; targetDepth++;
if(targetDepth > maxDepth) { if(targetDepth > maxDepth) {
this.enableDrill = false; this.enableDrill = false;
} }
@ -151,17 +150,17 @@ public class TileEntityMachineExcavator extends TileEntityMachineBase implements
} else { } else {
this.targetDepth = 0; this.targetDepth = 0;
} }
this.networkPackNT(150); this.networkPackNT(150);
} else { } else {
this.prevDrillExtension = this.drillExtension; this.prevDrillExtension = this.drillExtension;
if(this.drillExtension != this.targetDepth) { if(this.drillExtension != this.targetDepth) {
float diff = Math.abs(this.drillExtension - this.targetDepth); float diff = Math.abs(this.drillExtension - this.targetDepth);
float speed = Math.max(0.15F, diff / 10F); float speed = Math.max(0.15F, diff / 10F);
if(diff <= speed) { if(diff <= speed) {
this.drillExtension = this.targetDepth; this.drillExtension = this.targetDepth;
} else { } else {
@ -172,31 +171,31 @@ public class TileEntityMachineExcavator extends TileEntityMachineBase implements
this.prevDrillRotation = this.drillRotation; this.prevDrillRotation = this.drillRotation;
this.prevCrusherRotation = this.crusherRotation; this.prevCrusherRotation = this.crusherRotation;
if(this.operational) { if(this.operational) {
this.drillRotation += 15F; this.drillRotation += 15F;
if(this.enableCrusher) { if(this.enableCrusher) {
this.crusherRotation += 15F; this.crusherRotation += 15F;
} }
} }
if(this.drillRotation >= 360F) { if(this.drillRotation >= 360F) {
this.drillRotation -= 360F; this.drillRotation -= 360F;
this.prevDrillRotation -= 360F; this.prevDrillRotation -= 360F;
} }
if(this.crusherRotation >= 360F) { if(this.crusherRotation >= 360F) {
this.crusherRotation -= 360F; this.crusherRotation -= 360F;
this.prevCrusherRotation -= 360F; this.prevCrusherRotation -= 360F;
} }
} }
} }
protected DirPos[] getConPos() { protected DirPos[] getConPos() {
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset); ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset);
ForgeDirection rot = dir.getRotation(ForgeDirection.UP); ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
return new DirPos[] { return new DirPos[] {
new DirPos(xCoord + dir.offsetX * 4 + rot.offsetX, yCoord + 1, zCoord + dir.offsetZ * 4 + rot.offsetZ, dir), new DirPos(xCoord + dir.offsetX * 4 + rot.offsetX, yCoord + 1, zCoord + dir.offsetZ * 4 + rot.offsetZ, dir),
new DirPos(xCoord + dir.offsetX * 4 - rot.offsetX, yCoord + 1, zCoord + dir.offsetZ * 4 - rot.offsetZ, dir), new DirPos(xCoord + dir.offsetX * 4 - rot.offsetX, yCoord + 1, zCoord + dir.offsetZ * 4 - rot.offsetZ, dir),
@ -204,7 +203,7 @@ public class TileEntityMachineExcavator extends TileEntityMachineBase implements
new DirPos(xCoord - rot.offsetX * 4, yCoord + 1, zCoord - rot.offsetZ * 4, rot.getOpposite()) new DirPos(xCoord - rot.offsetX * 4, yCoord + 1, zCoord - rot.offsetZ * 4, rot.getOpposite())
}; };
} }
@Override @Override
public void serialize(ByteBuf buf) { public void serialize(ByteBuf buf) {
super.serialize(buf); super.serialize(buf);
@ -219,7 +218,7 @@ public class TileEntityMachineExcavator extends TileEntityMachineBase implements
buf.writeLong(power); buf.writeLong(power);
tank.serialize(buf); tank.serialize(buf);
} }
@Override @Override
public void deserialize(ByteBuf buf) { public void deserialize(ByteBuf buf) {
super.deserialize(buf); super.deserialize(buf);
@ -234,11 +233,11 @@ public class TileEntityMachineExcavator extends TileEntityMachineBase implements
power = buf.readLong(); power = buf.readLong();
tank.deserialize(buf); tank.deserialize(buf);
} }
protected int getY() { protected int getY() {
return yCoord - targetDepth - 4; return yCoord - targetDepth - 4;
} }
/** Works outwards and tries to break a ring, returns true if all rings are broken (or ignorable) and the drill should extend. */ /** Works outwards and tries to break a ring, returns true if all rings are broken (or ignorable) and the drill should extend. */
protected boolean tryDrill(int radius) { protected boolean tryDrill(int radius) {
int y = getY(); int y = getY();
@ -246,22 +245,22 @@ public class TileEntityMachineExcavator extends TileEntityMachineBase implements
if(targetDepth == 0 || y == 0) { if(targetDepth == 0 || y == 0) {
radius = 1; radius = 1;
} }
for(int ring = 1; ring <= radius; ring++) { for(int ring = 1; ring <= radius; ring++) {
boolean ignoreAll = true; boolean ignoreAll = true;
float combinedHardness = 0F; float combinedHardness = 0F;
BlockPos bedrockOre = null; BlockPos bedrockOre = null;
bedrockDrilling = false; bedrockDrilling = false;
for(int x = xCoord - ring; x <= xCoord + ring; x++) { for(int x = xCoord - ring; x <= xCoord + ring; x++) {
for(int z = zCoord - ring; z <= zCoord + ring; z++) { for(int z = zCoord - ring; z <= zCoord + ring; z++) {
/* Process blocks either if we are in the inner ring (1 = 3x3) or if the target block is on the outer edge */ /* Process blocks either if we are in the inner ring (1 = 3x3) or if the target block is on the outer edge */
if(ring == 1 || (x == xCoord - ring || x == xCoord + ring || z == zCoord - ring || z == zCoord + ring)) { if(ring == 1 || (x == xCoord - ring || x == xCoord + ring || z == zCoord - ring || z == zCoord + ring)) {
Block b = worldObj.getBlock(x, y, z); Block b = worldObj.getBlock(x, y, z);
if(b == ModBlocks.ore_bedrock) { if(b == ModBlocks.ore_bedrock) {
combinedHardness = 5 * 60 * 20; combinedHardness = 5 * 60 * 20;
bedrockOre = new BlockPos(x, y, z); bedrockOre = new BlockPos(x, y, z);
@ -270,23 +269,23 @@ public class TileEntityMachineExcavator extends TileEntityMachineBase implements
ignoreAll = false; ignoreAll = false;
break; break;
} }
if(shouldIgnoreBlock(b, x, y ,z)) continue; if(shouldIgnoreBlock(b, x, y ,z)) continue;
ignoreAll = false; ignoreAll = false;
combinedHardness += b.getBlockHardness(worldObj, x, y, z); combinedHardness += b.getBlockHardness(worldObj, x, y, z);
} }
} }
} }
if(!ignoreAll) { if(!ignoreAll) {
ticksWorked++; ticksWorked++;
int ticksToWork = (int) Math.ceil(combinedHardness / this.speed); int ticksToWork = (int) Math.ceil(combinedHardness / this.speed);
if(ticksWorked >= ticksToWork) { if(ticksWorked >= ticksToWork) {
if(bedrockOre == null) { if(bedrockOre == null) {
breakBlocks(ring); breakBlocks(ring);
buildWall(ring + 1, ring == radius && this.enableWalling); buildWall(ring + 1, ring == radius && this.enableWalling);
@ -297,7 +296,7 @@ public class TileEntityMachineExcavator extends TileEntityMachineBase implements
} }
ticksWorked = 0; ticksWorked = 0;
} }
return false; return false;
} else { } else {
tryCollect(radius + 1); tryCollect(radius + 1);
@ -308,26 +307,26 @@ public class TileEntityMachineExcavator extends TileEntityMachineBase implements
ticksWorked = 0; ticksWorked = 0;
return true; return true;
} }
protected void collectBedrock(BlockPos pos) { protected void collectBedrock(BlockPos pos) {
TileEntity oreTile = Compat.getTileStandard(worldObj, pos.getX(), pos.getY(), pos.getZ()); TileEntity oreTile = Compat.getTileStandard(worldObj, pos.getX(), pos.getY(), pos.getZ());
if(oreTile instanceof TileEntityBedrockOre) { if(oreTile instanceof TileEntityBedrockOre) {
TileEntityBedrockOre ore = (TileEntityBedrockOre) oreTile; TileEntityBedrockOre ore = (TileEntityBedrockOre) oreTile;
if(ore.resource == null) return; if(ore.resource == null) return;
if(ore.tier > this.getInstalledDrill().tier) return; if(ore.tier > this.getInstalledDrill().tier) return;
if(ore.acidRequirement != null) { if(ore.acidRequirement != null) {
if(ore.acidRequirement.type != tank.getTankType() || ore.acidRequirement.fill > tank.getFill()) return; if(ore.acidRequirement.type != tank.getTankType() || ore.acidRequirement.fill > tank.getFill()) return;
tank.setFill(tank.getFill() - ore.acidRequirement.fill); tank.setFill(tank.getFill() - ore.acidRequirement.fill);
} }
ItemStack stack = ore.resource.copy(); ItemStack stack = ore.resource.copy();
List<ItemStack> stacks = new ArrayList(); List<ItemStack> stacks = new ArrayList();
stacks.add(stack); stacks.add(stack);
if(stack.getItem() == ModItems.bedrock_ore_base) { if(stack.getItem() == ModItems.bedrock_ore_base) {
ItemBedrockOreBase.setOreAmount(stack, pos.getX(), pos.getZ()); ItemBedrockOreBase.setOreAmount(stack, pos.getX(), pos.getZ());
} }
@ -337,63 +336,63 @@ public class TileEntityMachineExcavator extends TileEntityMachineBase implements
int x = xCoord + dir.offsetX * 4; int x = xCoord + dir.offsetX * 4;
int y = yCoord - 3; int y = yCoord - 3;
int z = zCoord + dir.offsetZ * 4; int z = zCoord + dir.offsetZ * 4;
/* try to insert into a valid container */ /* try to insert into a valid container */
TileEntity tile = worldObj.getTileEntity(x, y, z); TileEntity tile = worldObj.getTileEntity(x, y, z);
if(tile instanceof IInventory) { if(tile instanceof IInventory) {
supplyContainer((IInventory) tile, stacks, dir.getOpposite()); supplyContainer((IInventory) tile, stacks, dir.getOpposite());
} }
if(stack.stackSize <= 0) return; if(stack.stackSize <= 0) return;
/* try to place on conveyor belt */ /* try to place on conveyor belt */
Block b = worldObj.getBlock(x, y, z); Block b = worldObj.getBlock(x, y, z);
if(b instanceof IConveyorBelt) { if(b instanceof IConveyorBelt) {
supplyConveyor((IConveyorBelt) b, stacks, x, y, z); supplyConveyor((IConveyorBelt) b, stacks, x, y, z);
} }
if(stack.stackSize <= 0) return; if(stack.stackSize <= 0) return;
for(int i = 5; i < 14; i++) { for(int i = 5; i < 14; i++) {
if(slots[i] != null && slots[i].stackSize < slots[i].getMaxStackSize() && stack.isItemEqual(slots[i]) && ItemStack.areItemStackTagsEqual(stack, slots[i])) { if(slots[i] != null && slots[i].stackSize < slots[i].getMaxStackSize() && stack.isItemEqual(slots[i]) && ItemStack.areItemStackTagsEqual(stack, slots[i])) {
int toAdd = Math.min(slots[i].getMaxStackSize() - slots[i].stackSize, stack.stackSize); int toAdd = Math.min(slots[i].getMaxStackSize() - slots[i].stackSize, stack.stackSize);
slots[i].stackSize += toAdd; slots[i].stackSize += toAdd;
stack.stackSize -= toAdd; stack.stackSize -= toAdd;
chuteTimer = 40; chuteTimer = 40;
if(stack.stackSize <= 0) { if(stack.stackSize <= 0) {
return; return;
} }
} }
} }
/* add leftovers to empty slots */ /* add leftovers to empty slots */
for(int i = 5; i < 14; i++) { for(int i = 5; i < 14; i++) {
if(slots[i] == null) { if(slots[i] == null) {
chuteTimer = 40; chuteTimer = 40;
slots[i] = stack.copy(); slots[i] = stack.copy();
return; return;
} }
} }
} }
} }
/** breaks and drops all blocks in the specified ring */ /** breaks and drops all blocks in the specified ring */
protected void breakBlocks(int ring) { protected void breakBlocks(int ring) {
int y = getY(); int y = getY();
for(int x = xCoord - ring; x <= xCoord + ring; x++) { for(int x = xCoord - ring; x <= xCoord + ring; x++) {
for(int z = zCoord - ring; z <= zCoord + ring; z++) { for(int z = zCoord - ring; z <= zCoord + ring; z++) {
if(ring == 1 || (x == xCoord - ring || x == xCoord + ring || z == zCoord - ring || z == zCoord + ring)) { if(ring == 1 || (x == xCoord - ring || x == xCoord + ring || z == zCoord - ring || z == zCoord + ring)) {
Block b = worldObj.getBlock(x, y, z); Block b = worldObj.getBlock(x, y, z);
if(!this.shouldIgnoreBlock(b, x, y, z)) { if(!this.shouldIgnoreBlock(b, x, y, z)) {
tryMineAtLocation(x, y, z); tryMineAtLocation(x, y, z);
} }
@ -401,13 +400,13 @@ public class TileEntityMachineExcavator extends TileEntityMachineBase implements
} }
} }
} }
public void tryMineAtLocation(int x ,int y, int z) { public void tryMineAtLocation(int x ,int y, int z) {
Block b = worldObj.getBlock(x, y, z); Block b = worldObj.getBlock(x, y, z);
if(this.enableVeinMiner && this.getInstalledDrill().vein) { if(this.enableVeinMiner && this.getInstalledDrill().vein) {
if(isOre(x, y, z, b)) { if(isOre(x, y, z, b)) {
minX = x; minX = x;
minY = y; minY = y;
@ -417,51 +416,51 @@ public class TileEntityMachineExcavator extends TileEntityMachineBase implements
maxZ = z; maxZ = z;
breakRecursively(x, y, z, 10); breakRecursively(x, y, z, 10);
recursionBrake.clear(); recursionBrake.clear();
/* move all excavated items to the last drillable position which is also within collection range */ /* move all excavated items to the last drillable position which is also within collection range */
List<EntityItem> items = worldObj.getEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.getBoundingBox(minX, minY, minZ, maxX + 1, maxY + 1, maxZ + 1)); List<EntityItem> items = worldObj.getEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.getBoundingBox(minX, minY, minZ, maxX + 1, maxY + 1, maxZ + 1));
for(EntityItem item : items) item.setPosition(x + 0.5, y + 0.5, z + 0.5); for(EntityItem item : items) item.setPosition(x + 0.5, y + 0.5, z + 0.5);
return; return;
} }
} }
breakSingleBlock(b, x, y, z); breakSingleBlock(b, x, y, z);
} }
protected boolean isOre(int x ,int y, int z, Block b) { protected boolean isOre(int x ,int y, int z, Block b) {
/* doing this isn't terribly accurate but just for figuring out if there's OD it works */ /* doing this isn't terribly accurate but just for figuring out if there's OD it works */
Item blockItem = Item.getItemFromBlock(b); Item blockItem = Item.getItemFromBlock(b);
if(blockItem != null) { if(blockItem != null) {
List<String> names = ItemStackUtil.getOreDictNames(new ItemStack(blockItem)); List<String> names = ItemStackUtil.getOreDictNames(new ItemStack(blockItem));
for(String name : names) { for(String name : names) {
if(name.startsWith("ore")) { if(name.startsWith("ore")) {
return true; return true;
} }
} }
} }
return false; return false;
} }
private HashSet<BlockPos> recursionBrake = new HashSet(); private HashSet<BlockPos> recursionBrake = new HashSet();
private int minX = 0, minY = 0, minZ = 0, maxX = 0, maxY = 0, maxZ = 0; private int minX = 0, minY = 0, minZ = 0, maxX = 0, maxY = 0, maxZ = 0;
protected void breakRecursively(int x ,int y, int z, int depth) { protected void breakRecursively(int x ,int y, int z, int depth) {
if(depth < 0) return; if(depth < 0) return;
BlockPos pos = new BlockPos(x, y, z); BlockPos pos = new BlockPos(x, y, z);
if(recursionBrake.contains(pos)) return; if(recursionBrake.contains(pos)) return;
recursionBrake.add(pos); recursionBrake.add(pos);
Block b = worldObj.getBlock(x, y, z); Block b = worldObj.getBlock(x, y, z);
for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) { for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
int ix = x + dir.offsetX; int ix = x + dir.offsetX;
int iy = y + dir.offsetY; int iy = y + dir.offsetY;
int iz = z + dir.offsetZ; int iz = z + dir.offsetZ;
if(worldObj.getBlock(ix, iy, iz) == b) { if(worldObj.getBlock(ix, iy, iz) == b) {
breakRecursively(ix, iy, iz, depth - 1); breakRecursively(ix, iy, iz, depth - 1);
} }
@ -475,36 +474,36 @@ public class TileEntityMachineExcavator extends TileEntityMachineBase implements
if(y > maxY) maxY = y; if(y > maxY) maxY = y;
if(z < minZ) minZ = z; if(z < minZ) minZ = z;
if(z > maxZ) maxZ = z; if(z > maxZ) maxZ = z;
if(this.enableWalling) { if(this.enableWalling) {
worldObj.setBlock(x, y, z, ModBlocks.barricade); worldObj.setBlock(x, y, z, ModBlocks.barricade);
} }
} }
protected void breakSingleBlock(Block b, int x ,int y, int z) { protected void breakSingleBlock(Block b, int x ,int y, int z) {
List<ItemStack> items = b.getDrops(worldObj, x, y, z, worldObj.getBlockMetadata(x, y, z), this.getFortuneLevel()); List<ItemStack> items = b.getDrops(worldObj, x, y, z, worldObj.getBlockMetadata(x, y, z), this.getFortuneLevel());
if(this.canSilkTouch()) { if(this.canSilkTouch()) {
try { try {
Method createStackedBlock = ReflectionHelper.findMethod(Block.class, b, new String[] {"createStackedBlock", "func_149644_j"}, int.class); Method createStackedBlock = ReflectionHelper.findMethod(Block.class, b, new String[] {"createStackedBlock", "func_149644_j"}, int.class);
ItemStack result = (ItemStack) createStackedBlock.invoke(b, worldObj.getBlockMetadata(x, y, z)); ItemStack result = (ItemStack) createStackedBlock.invoke(b, worldObj.getBlockMetadata(x, y, z));
if(result != null) { if(result != null) {
items.clear(); items.clear();
items.add(result.copy()); items.add(result.copy());
} }
} catch(Exception ex) { } } catch(Exception ex) { }
} }
if(this.enableCrusher) { if(this.enableCrusher) {
List<ItemStack> list = new ArrayList(); List<ItemStack> list = new ArrayList();
for(ItemStack stack : items) { for(ItemStack stack : items) {
ItemStack crushed = ShredderRecipes.getShredderResult(stack).copy(); ItemStack crushed = ShredderRecipes.getShredderResult(stack).copy();
if(crushed.getItem() == ModItems.scrap || crushed.getItem() == ModItems.dust) { if(crushed.getItem() == ModItems.scrap || crushed.getItem() == ModItems.dust) {
list.add(stack); list.add(stack);
} else { } else {
@ -512,36 +511,36 @@ public class TileEntityMachineExcavator extends TileEntityMachineBase implements
list.add(crushed); list.add(crushed);
} }
} }
items = list; items = list;
} }
if(b == ModBlocks.barricade) if(b == ModBlocks.barricade)
items.clear(); items.clear();
for(ItemStack item : items) { for(ItemStack item : items) {
worldObj.spawnEntityInWorld(new EntityItem(worldObj, x + 0.5, y + 0.5, z + 0.5, item)); worldObj.spawnEntityInWorld(new EntityItem(worldObj, x + 0.5, y + 0.5, z + 0.5, item));
} }
worldObj.func_147480_a(x, y, z, false); worldObj.func_147480_a(x, y, z, false);
} }
/** builds a wall along the specified ring, replacing fluid blocks. if wallEverything is set, it will also wall off replacable blocks like air or grass */ /** builds a wall along the specified ring, replacing fluid blocks. if wallEverything is set, it will also wall off replacable blocks like air or grass */
protected void buildWall(int ring, boolean wallEverything) { protected void buildWall(int ring, boolean wallEverything) {
int y = getY(); int y = getY();
for(int x = xCoord - ring; x <= xCoord + ring; x++) { for(int x = xCoord - ring; x <= xCoord + ring; x++) {
for(int z = zCoord - ring; z <= zCoord + ring; z++) { for(int z = zCoord - ring; z <= zCoord + ring; z++) {
Block b = worldObj.getBlock(x, y, z); Block b = worldObj.getBlock(x, y, z);
if(x == xCoord - ring || x == xCoord + ring || z == zCoord - ring || z == zCoord + ring) { if(x == xCoord - ring || x == xCoord + ring || z == zCoord - ring || z == zCoord + ring) {
if(b.isReplaceable(worldObj, x, y, z) && (wallEverything || b.getMaterial().isLiquid())) { if(b.isReplaceable(worldObj, x, y, z) && (wallEverything || b.getMaterial().isLiquid())) {
worldObj.setBlock(x, y, z, ModBlocks.barricade); worldObj.setBlock(x, y, z, ModBlocks.barricade);
} }
} else { } else {
if(b.getMaterial().isLiquid()) { if(b.getMaterial().isLiquid()) {
worldObj.setBlockToAir(x, y, z); worldObj.setBlockToAir(x, y, z);
continue; continue;
@ -552,14 +551,14 @@ public class TileEntityMachineExcavator extends TileEntityMachineBase implements
} }
protected void mineOuterOres(int ring) { protected void mineOuterOres(int ring) {
int y = getY(); int y = getY();
for(int x = xCoord - ring; x <= xCoord + ring; x++) { for(int x = xCoord - ring; x <= xCoord + ring; x++) {
for(int z = zCoord - ring; z <= zCoord + ring; z++) { for(int z = zCoord - ring; z <= zCoord + ring; z++) {
if(ring == 1 || (x == xCoord - ring || x == xCoord + ring || z == zCoord - ring || z == zCoord + ring)) { if(ring == 1 || (x == xCoord - ring || x == xCoord + ring || z == zCoord - ring || z == zCoord + ring)) {
Block b = worldObj.getBlock(x, y, z); Block b = worldObj.getBlock(x, y, z);
if(!this.shouldIgnoreBlock(b, x, y, z) && this.isOre(x, y, z, b)) { if(!this.shouldIgnoreBlock(b, x, y, z) && this.isOre(x, y, z, b)) {
tryMineAtLocation(x, y, z); tryMineAtLocation(x, y, z);
} }
@ -567,7 +566,7 @@ public class TileEntityMachineExcavator extends TileEntityMachineBase implements
} }
} }
} }
protected void tryEjectBuffer() { protected void tryEjectBuffer() {
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10); ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10);
@ -575,32 +574,32 @@ public class TileEntityMachineExcavator extends TileEntityMachineBase implements
int x = xCoord + dir.offsetX * 4; int x = xCoord + dir.offsetX * 4;
int y = yCoord - 3; int y = yCoord - 3;
int z = zCoord + dir.offsetZ * 4; int z = zCoord + dir.offsetZ * 4;
List<ItemStack> items = new ArrayList(); List<ItemStack> items = new ArrayList();
for(int i = 5; i < 14; i++) { for(int i = 5; i < 14; i++) {
ItemStack stack = slots[i]; ItemStack stack = slots[i];
if(stack != null) { if(stack != null) {
items.add(stack.copy()); items.add(stack.copy());
} }
} }
TileEntity tile = worldObj.getTileEntity(x, y, z); TileEntity tile = worldObj.getTileEntity(x, y, z);
if(tile instanceof IInventory) { if(tile instanceof IInventory) {
supplyContainer((IInventory) tile, items, dir.getOpposite()); supplyContainer((IInventory) tile, items, dir.getOpposite());
} }
Block b = worldObj.getBlock(x, y, z); Block b = worldObj.getBlock(x, y, z);
if(b instanceof IConveyorBelt) { if(b instanceof IConveyorBelt) {
supplyConveyor((IConveyorBelt) b, items, x, y, z); supplyConveyor((IConveyorBelt) b, items, x, y, z);
} }
items.removeIf(i -> i == null || i.stackSize <= 0); items.removeIf(i -> i == null || i.stackSize <= 0);
for(int i = 5; i < 14; i++) { for(int i = 5; i < 14; i++) {
int index = i - 5; int index = i - 5;
if(items.size() > index) { if(items.size() > index) {
slots[i] = items.get(index).copy(); slots[i] = items.get(index).copy();
} else { } else {
@ -608,66 +607,66 @@ public class TileEntityMachineExcavator extends TileEntityMachineBase implements
} }
} }
} }
/** pulls up an AABB around the drillbit and tries to either conveyor output or buffer collected items */ /** pulls up an AABB around the drillbit and tries to either conveyor output or buffer collected items */
protected void tryCollect(int radius) { protected void tryCollect(int radius) {
int yLevel = getY(); int yLevel = getY();
List<EntityItem> items = worldObj.getEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.getBoundingBox(xCoord - radius, yLevel - 1, zCoord - radius, xCoord + radius + 1, yLevel + 2, zCoord + radius + 1)); List<EntityItem> items = worldObj.getEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.getBoundingBox(xCoord - radius, yLevel - 1, zCoord - radius, xCoord + radius + 1, yLevel + 2, zCoord + radius + 1));
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10); ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10);
int x = xCoord + dir.offsetX * 4; int x = xCoord + dir.offsetX * 4;
int y = yCoord - 3; int y = yCoord - 3;
int z = zCoord + dir.offsetZ * 4; int z = zCoord + dir.offsetZ * 4;
List<ItemStack> stacks = new ArrayList(); List<ItemStack> stacks = new ArrayList();
items.forEach(i -> stacks.add(i.getEntityItem())); items.forEach(i -> stacks.add(i.getEntityItem()));
/* try to insert into a valid container */ /* try to insert into a valid container */
TileEntity tile = worldObj.getTileEntity(x, y, z); TileEntity tile = worldObj.getTileEntity(x, y, z);
if(tile instanceof IInventory) { if(tile instanceof IInventory) {
supplyContainer((IInventory) tile, stacks, dir.getOpposite()); supplyContainer((IInventory) tile, stacks, dir.getOpposite());
} }
/* try to place on conveyor belt */ /* try to place on conveyor belt */
Block b = worldObj.getBlock(x, y, z); Block b = worldObj.getBlock(x, y, z);
if(b instanceof IConveyorBelt) { if(b instanceof IConveyorBelt) {
supplyConveyor((IConveyorBelt) b, stacks, x, y, z); supplyConveyor((IConveyorBelt) b, stacks, x, y, z);
} }
items.removeIf(i -> i.isDead || i.getEntityItem().stackSize <= 0); items.removeIf(i -> i.isDead || i.getEntityItem().stackSize <= 0);
/* collect remaining items in internal buffer */ /* collect remaining items in internal buffer */
outer: outer:
for(EntityItem item : items) { for(EntityItem item : items) {
ItemStack stack = item.getEntityItem(); ItemStack stack = item.getEntityItem();
/* adding items to existing stacks */ /* adding items to existing stacks */
for(int i = 5; i < 14; i++) { for(int i = 5; i < 14; i++) {
if(slots[i] != null && slots[i].stackSize < slots[i].getMaxStackSize() && stack.isItemEqual(slots[i]) && ItemStack.areItemStackTagsEqual(stack, slots[i])) { if(slots[i] != null && slots[i].stackSize < slots[i].getMaxStackSize() && stack.isItemEqual(slots[i]) && ItemStack.areItemStackTagsEqual(stack, slots[i])) {
int toAdd = Math.min(slots[i].getMaxStackSize() - slots[i].stackSize, stack.stackSize); int toAdd = Math.min(slots[i].getMaxStackSize() - slots[i].stackSize, stack.stackSize);
slots[i].stackSize += toAdd; slots[i].stackSize += toAdd;
stack.stackSize -= toAdd; stack.stackSize -= toAdd;
chuteTimer = 40; chuteTimer = 40;
if(stack.stackSize <= 0) { if(stack.stackSize <= 0) {
item.setDead(); item.setDead();
continue outer; continue outer;
} }
} }
} }
/* add leftovers to empty slots */ /* add leftovers to empty slots */
for(int i = 5; i < 14; i++) { for(int i = 5; i < 14; i++) {
if(slots[i] == null) { if(slots[i] == null) {
chuteTimer = 40; chuteTimer = 40;
slots[i] = stack.copy(); slots[i] = stack.copy();
item.setDead(); item.setDead();
break; break;
@ -675,60 +674,60 @@ public class TileEntityMachineExcavator extends TileEntityMachineBase implements
} }
} }
} }
/** places all items into a connected container, if possible */ /** places all items into a connected container, if possible */
protected void supplyContainer(IInventory inv, List<ItemStack> items, ForgeDirection dir) { protected void supplyContainer(IInventory inv, List<ItemStack> items, ForgeDirection dir) {
int side = dir.ordinal(); int side = dir.ordinal();
int[] access = null; int[] access = null;
if(inv instanceof ISidedInventory) { if(inv instanceof ISidedInventory) {
ISidedInventory sided = (ISidedInventory) inv; ISidedInventory sided = (ISidedInventory) inv;
access = InventoryUtil.masquerade(sided, dir.ordinal()); access = InventoryUtil.masquerade(sided, dir.ordinal());
} }
for(ItemStack item : items) { for(ItemStack item : items) {
if(item.stackSize <= 0) continue; if(item.stackSize <= 0) continue;
CraneInserter.addToInventory(inv, access, item, side); CraneInserter.addToInventory(inv, access, item, side);
chuteTimer = 40; chuteTimer = 40;
} }
} }
/** moves all items onto a connected conveyor belt */ /** moves all items onto a connected conveyor belt */
protected void supplyConveyor(IConveyorBelt belt, List<ItemStack> items, int x, int y, int z) { protected void supplyConveyor(IConveyorBelt belt, List<ItemStack> items, int x, int y, int z) {
Random rand = worldObj.rand; Random rand = worldObj.rand;
for(ItemStack item : items) { for(ItemStack item : items) {
if(item.stackSize <= 0) continue; if(item.stackSize <= 0) continue;
Vec3 base = Vec3.createVectorHelper(x + rand.nextDouble(), y + 0.5, z + rand.nextDouble()); Vec3 base = Vec3.createVectorHelper(x + rand.nextDouble(), y + 0.5, z + rand.nextDouble());
Vec3 vec = belt.getClosestSnappingPosition(worldObj, x, y, z, base); Vec3 vec = belt.getClosestSnappingPosition(worldObj, x, y, z, base);
EntityMovingItem moving = new EntityMovingItem(worldObj); EntityMovingItem moving = new EntityMovingItem(worldObj);
moving.setPosition(base.xCoord, vec.yCoord, base.zCoord); moving.setPosition(base.xCoord, vec.yCoord, base.zCoord);
moving.setItemStack(item.copy()); moving.setItemStack(item.copy());
worldObj.spawnEntityInWorld(moving); worldObj.spawnEntityInWorld(moving);
item.stackSize = 0; item.stackSize = 0;
chuteTimer = 40; chuteTimer = 40;
} }
} }
public long getPowerConsumption() { public long getPowerConsumption() {
return consumption; return consumption;
} }
public int getFortuneLevel() { public int getFortuneLevel() {
EnumDrillType type = getInstalledDrill(); EnumDrillType type = getInstalledDrill();
if(type != null) return type.fortune; if(type != null) return type.fortune;
return 0; return 0;
} }
public boolean shouldIgnoreBlock(Block block, int x, int y, int z) { public boolean shouldIgnoreBlock(Block block, int x, int y, int z) {
return block.isAir(worldObj, x, y, z) || block.getMaterial() == ModBlocks.materialGas || block.getBlockHardness(worldObj, x, y, z) < 0 || block.getMaterial().isLiquid() || block == Blocks.bedrock; return block.isAir(worldObj, x, y, z) || block.getMaterial() == ModBlocks.materialGas || block.getBlockHardness(worldObj, x, y, z) < 0 || block.getMaterial().isLiquid() || block == Blocks.bedrock;
} }
@ -740,32 +739,32 @@ public class TileEntityMachineExcavator extends TileEntityMachineBase implements
if(data.hasKey("walling")) this.enableWalling = !this.enableWalling; if(data.hasKey("walling")) this.enableWalling = !this.enableWalling;
if(data.hasKey("veinminer")) this.enableVeinMiner = !this.enableVeinMiner; if(data.hasKey("veinminer")) this.enableVeinMiner = !this.enableVeinMiner;
if(data.hasKey("silktouch")) this.enableSilkTouch = !this.enableSilkTouch; if(data.hasKey("silktouch")) this.enableSilkTouch = !this.enableSilkTouch;
this.markChanged(); this.markChanged();
} }
public EnumDrillType getInstalledDrill() { public EnumDrillType getInstalledDrill() {
if(slots[4] != null && slots[4].getItem() instanceof ItemDrillbit) { if(slots[4] != null && slots[4].getItem() instanceof ItemDrillbit) {
return EnumUtil.grabEnumSafely(EnumDrillType.class, slots[4].getItemDamage()); return EnumUtil.grabEnumSafely(EnumDrillType.class, slots[4].getItemDamage());
} }
return null; return null;
} }
public boolean canVeinMine() { public boolean canVeinMine() {
EnumDrillType type = getInstalledDrill(); EnumDrillType type = getInstalledDrill();
return this.enableVeinMiner && type != null && type.vein; return this.enableVeinMiner && type != null && type.vein;
} }
public boolean canSilkTouch() { public boolean canSilkTouch() {
EnumDrillType type = getInstalledDrill(); EnumDrillType type = getInstalledDrill();
return this.enableSilkTouch && type != null && type.silk; return this.enableSilkTouch && type != null && type.silk;
} }
@Override @Override
public void readFromNBT(NBTTagCompound nbt) { public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt); super.readFromNBT(nbt);
this.enableDrill = nbt.getBoolean("d"); this.enableDrill = nbt.getBoolean("d");
this.enableCrusher = nbt.getBoolean("c"); this.enableCrusher = nbt.getBoolean("c");
this.enableWalling = nbt.getBoolean("w"); this.enableWalling = nbt.getBoolean("w");
@ -775,11 +774,11 @@ public class TileEntityMachineExcavator extends TileEntityMachineBase implements
this.power = nbt.getLong("p"); this.power = nbt.getLong("p");
this.tank.readFromNBT(nbt, "tank"); this.tank.readFromNBT(nbt, "tank");
} }
@Override @Override
public void writeToNBT(NBTTagCompound nbt) { public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt); super.writeToNBT(nbt);
nbt.setBoolean("d", enableDrill); nbt.setBoolean("d", enableDrill);
nbt.setBoolean("c", enableCrusher); nbt.setBoolean("c", enableCrusher);
nbt.setBoolean("w", enableWalling); nbt.setBoolean("w", enableWalling);
@ -805,12 +804,12 @@ public class TileEntityMachineExcavator extends TileEntityMachineBase implements
public Object provideGUI(int ID, EntityPlayer player, World world, int x, int y, int z) { public Object provideGUI(int ID, EntityPlayer player, World world, int x, int y, int z) {
return new GUIMachineExcavator(player.inventory, this); return new GUIMachineExcavator(player.inventory, this);
} }
AxisAlignedBB bb = null; AxisAlignedBB bb = null;
@Override @Override
public AxisAlignedBB getRenderBoundingBox() { public AxisAlignedBB getRenderBoundingBox() {
if(bb == null) { if(bb == null) {
bb = AxisAlignedBB.getBoundingBox( bb = AxisAlignedBB.getBoundingBox(
xCoord - 3, xCoord - 3,
@ -821,10 +820,10 @@ public class TileEntityMachineExcavator extends TileEntityMachineBase implements
zCoord + 4 zCoord + 4
); );
} }
return bb; return bb;
} }
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public double getMaxRenderDistanceSquared() { public double getMaxRenderDistanceSquared() {
@ -874,10 +873,11 @@ public class TileEntityMachineExcavator extends TileEntityMachineBase implements
} }
@Override @Override
public int getMaxLevel(UpgradeType type) { public HashMap<UpgradeType, Integer> getValidUpgrades() {
if(type == UpgradeType.SPEED) return 3; HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
if(type == UpgradeType.POWER) return 3; upgrades.put(UpgradeType.SPEED, 3);
return 0; upgrades.put(UpgradeType.POWER, 3);
return upgrades;
} }
@Override @Override

View File

@ -1,9 +1,10 @@
package com.hbm.tileentity.machine; package com.hbm.tileentity.machine;
import java.util.HashMap;
import java.util.List; import java.util.List;
import com.hbm.blocks.ModBlocks; import com.hbm.blocks.ModBlocks;
import com.hbm.inventory.UpgradeManager; import com.hbm.inventory.UpgradeManagerNT;
import com.hbm.inventory.container.ContainerMachineExposureChamber; import com.hbm.inventory.container.ContainerMachineExposureChamber;
import com.hbm.inventory.gui.GUIMachineExposureChamber; import com.hbm.inventory.gui.GUIMachineExposureChamber;
import com.hbm.inventory.recipes.ExposureChamberRecipes; import com.hbm.inventory.recipes.ExposureChamberRecipes;
@ -31,10 +32,10 @@ import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityMachineExposureChamber extends TileEntityMachineBase implements IGUIProvider, IEnergyReceiverMK2, IUpgradeInfoProvider { public class TileEntityMachineExposureChamber extends TileEntityMachineBase implements IGUIProvider, IEnergyReceiverMK2, IUpgradeInfoProvider {
public long power; public long power;
public static final long maxPower = 1_000_000; public static final long maxPower = 1_000_000;
public int progress; public int progress;
public static final int processTimeBase = 200; public static final int processTimeBase = 200;
public int processTime = processTimeBase; public int processTime = processTimeBase;
@ -45,7 +46,9 @@ public class TileEntityMachineExposureChamber extends TileEntityMachineBase impl
public boolean isOn = false; public boolean isOn = false;
public float rotation; public float rotation;
public float prevRotation; public float prevRotation;
public UpgradeManagerNT upgradeManager = new UpgradeManagerNT();
@Override @Override
public void readFromNBT(NBTTagCompound nbt) { public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt); super.readFromNBT(nbt);
@ -53,7 +56,7 @@ public class TileEntityMachineExposureChamber extends TileEntityMachineBase impl
this.power = nbt.getLong("power"); this.power = nbt.getLong("power");
this.savedParticles = nbt.getInteger("savedParticles"); this.savedParticles = nbt.getInteger("savedParticles");
} }
@Override @Override
public void writeToNBT(NBTTagCompound nbt) { public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt); super.writeToNBT(nbt);
@ -82,39 +85,39 @@ public class TileEntityMachineExposureChamber extends TileEntityMachineBase impl
@Override @Override
public void updateEntity() { public void updateEntity() {
if(!worldObj.isRemote) { if(!worldObj.isRemote) {
this.isOn = false; this.isOn = false;
this.power = Library.chargeTEFromItems(slots, 5, power, maxPower); this.power = Library.chargeTEFromItems(slots, 5, power, maxPower);
if(worldObj.getTotalWorldTime() % 20 == 0) { if(worldObj.getTotalWorldTime() % 20 == 0) {
for(DirPos pos : getConPos()) this.trySubscribe(worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); for(DirPos pos : getConPos()) this.trySubscribe(worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
} }
UpgradeManager.eval(slots, 6, 7); upgradeManager.checkSlots(this, slots, 6, 7);
int speedLevel = Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 3); int speedLevel = upgradeManager.getLevel(UpgradeType.SPEED);
int powerLevel = Math.min(UpgradeManager.getLevel(UpgradeType.POWER), 3); int powerLevel = upgradeManager.getLevel(UpgradeType.POWER);
int overdriveLevel = Math.min(UpgradeManager.getLevel(UpgradeType.OVERDRIVE), 3); int overdriveLevel = upgradeManager.getLevel(UpgradeType.OVERDRIVE);
this.consumption = this.consumptionBase; this.consumption = this.consumptionBase;
this.processTime = this.processTimeBase - this.processTimeBase / 4 * speedLevel; this.processTime = this.processTimeBase - this.processTimeBase / 4 * speedLevel;
this.consumption *= (speedLevel / 2 + 1); this.consumption *= (speedLevel / 2 + 1);
this.processTime *= (powerLevel / 2 + 1); this.processTime *= (powerLevel / 2 + 1);
this.consumption /= (powerLevel + 1); this.consumption /= (powerLevel + 1);
this.processTime /= (overdriveLevel + 1); this.processTime /= (overdriveLevel + 1);
this.consumption *= (overdriveLevel * 2 + 1); this.consumption *= (overdriveLevel * 2 + 1);
if(slots[1] == null && slots[0] != null && slots[3] != null && this.savedParticles <= 0) { if(slots[1] == null && slots[0] != null && slots[3] != null && this.savedParticles <= 0) {
ExposureChamberRecipe recipe = this.getRecipe(slots[0], slots[3]); ExposureChamberRecipe recipe = this.getRecipe(slots[0], slots[3]);
if(recipe != null) { if(recipe != null) {
ItemStack container = slots[0].getItem().getContainerItem(slots[0]); ItemStack container = slots[0].getItem().getContainerItem(slots[0]);
boolean canStore = false; boolean canStore = false;
if(container == null) { if(container == null) {
canStore = true; canStore = true;
} else if(slots[2] == null) { } else if(slots[2] == null) {
@ -124,7 +127,7 @@ public class TileEntityMachineExposureChamber extends TileEntityMachineBase impl
slots[2].stackSize++; slots[2].stackSize++;
canStore = true; canStore = true;
} }
if(canStore) { if(canStore) {
slots[1] = slots[0].copy(); slots[1] = slots[0].copy();
slots[1].stackSize = 0; slots[1].stackSize = 0;
@ -133,47 +136,47 @@ public class TileEntityMachineExposureChamber extends TileEntityMachineBase impl
} }
} }
} }
if(slots[1] != null && this.savedParticles > 0 && this.power >= this.consumption) { if(slots[1] != null && this.savedParticles > 0 && this.power >= this.consumption) {
ExposureChamberRecipe recipe = this.getRecipe(slots[1], slots[3]); ExposureChamberRecipe recipe = this.getRecipe(slots[1], slots[3]);
if(recipe != null && (slots[4] == null || (slots[4].getItem() == recipe.output.getItem() && slots[4].getItemDamage() == recipe.output.getItemDamage() && slots[4].stackSize + recipe.output.stackSize <= slots[4].getMaxStackSize()))) { if(recipe != null && (slots[4] == null || (slots[4].getItem() == recipe.output.getItem() && slots[4].getItemDamage() == recipe.output.getItemDamage() && slots[4].stackSize + recipe.output.stackSize <= slots[4].getMaxStackSize()))) {
this.progress++; this.progress++;
this.power -= this.consumption; this.power -= this.consumption;
this.isOn = true; this.isOn = true;
if(this.progress >= this.processTime) { if(this.progress >= this.processTime) {
this.progress = 0; this.progress = 0;
this.savedParticles--; this.savedParticles--;
this.decrStackSize(3, 1); this.decrStackSize(3, 1);
if(slots[4] == null) { if(slots[4] == null) {
slots[4] = recipe.output.copy(); slots[4] = recipe.output.copy();
} else { } else {
slots[4].stackSize += recipe.output.stackSize; slots[4].stackSize += recipe.output.stackSize;
} }
} }
} else { } else {
this.progress = 0; this.progress = 0;
} }
} else { } else {
this.progress = 0; this.progress = 0;
} }
if(this.savedParticles <= 0) { if(this.savedParticles <= 0) {
slots[1] = null; slots[1] = null;
} }
this.networkPackNT(50); this.networkPackNT(50);
} else { } else {
this.prevRotation = this.rotation; this.prevRotation = this.rotation;
if(this.isOn) { if(this.isOn) {
this.rotation += 10D; this.rotation += 10D;
if(this.rotation >= 720D) { if(this.rotation >= 720D) {
this.rotation -= 720D; this.rotation -= 720D;
this.prevRotation -= 720D; this.prevRotation -= 720D;
@ -181,7 +184,7 @@ public class TileEntityMachineExposureChamber extends TileEntityMachineBase impl
} }
} }
} }
public DirPos[] getConPos() { public DirPos[] getConPos() {
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10); ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10);
ForgeDirection rot = dir.getRotation(ForgeDirection.UP).getOpposite(); ForgeDirection rot = dir.getRotation(ForgeDirection.UP).getOpposite();
@ -193,44 +196,44 @@ public class TileEntityMachineExposureChamber extends TileEntityMachineBase impl
new DirPos(xCoord + rot.offsetX * 9, yCoord, zCoord + rot.offsetZ * 9, rot) new DirPos(xCoord + rot.offsetX * 9, yCoord, zCoord + rot.offsetZ * 9, rot)
}; };
} }
public ExposureChamberRecipe getRecipe(ItemStack particle, ItemStack ingredient) { public ExposureChamberRecipe getRecipe(ItemStack particle, ItemStack ingredient) {
return ExposureChamberRecipes.getRecipe(particle, ingredient); return ExposureChamberRecipes.getRecipe(particle, ingredient);
} }
@Override @Override
public boolean isItemValidForSlot(int i, ItemStack stack) { public boolean isItemValidForSlot(int i, ItemStack stack) {
//will only load new capsules if there's no cached particles, this should prevent clogging //will only load new capsules if there's no cached particles, this should prevent clogging
//accept items when the slots are already partially filled, i.e. applicable //accept items when the slots are already partially filled, i.e. applicable
if(i == 0 && slots[0] != null) return true; if(i == 0 && slots[0] != null) return true;
if(i == 3 && slots[3] != null) return true; if(i == 3 && slots[3] != null) return true;
//if there's no particle stored, use the un-consumed capsule for reference //if there's no particle stored, use the un-consumed capsule for reference
ItemStack particle = slots[1] != null ? slots[1] : slots[0]; ItemStack particle = slots[1] != null ? slots[1] : slots[0];
//if no particle is loaded and an ingot is present //if no particle is loaded and an ingot is present
if(i == 0 && particle == null && slots[3] != null) { if(i == 0 && particle == null && slots[3] != null) {
ExposureChamberRecipe recipe = getRecipe(stack, slots[3]); ExposureChamberRecipe recipe = getRecipe(stack, slots[3]);
return recipe != null; return recipe != null;
} }
//if a particle is loaded but no ingot present //if a particle is loaded but no ingot present
if(i == 3 && particle != null && slots[3] == null) { if(i == 3 && particle != null && slots[3] == null) {
ExposureChamberRecipe recipe = getRecipe(slots[0], stack); ExposureChamberRecipe recipe = getRecipe(slots[0], stack);
return recipe != null; return recipe != null;
} }
//if there's nothing at all, find a reference recipe and see if the item matches anything //if there's nothing at all, find a reference recipe and see if the item matches anything
if(particle == null && slots[3] == null) { if(particle == null && slots[3] == null) {
for(ExposureChamberRecipe recipe : ExposureChamberRecipes.recipes) { for(ExposureChamberRecipe recipe : ExposureChamberRecipes.recipes) {
if(i == 0 && recipe.particle.matchesRecipe(stack, true)) return true; if(i == 0 && recipe.particle.matchesRecipe(stack, true)) return true;
if(i == 3 && recipe.ingredient.matchesRecipe(stack, true)) return true; if(i == 3 && recipe.ingredient.matchesRecipe(stack, true)) return true;
} }
} }
return false; return false;
} }
@ -253,7 +256,7 @@ public class TileEntityMachineExposureChamber extends TileEntityMachineBase impl
buf.writeLong(this.power); buf.writeLong(this.power);
buf.writeByte((byte) this.savedParticles); buf.writeByte((byte) this.savedParticles);
} }
@Override @Override
public void deserialize(ByteBuf buf) { public void deserialize(ByteBuf buf) {
this.isOn = buf.readBoolean(); this.isOn = buf.readBoolean();
@ -280,10 +283,10 @@ public class TileEntityMachineExposureChamber extends TileEntityMachineBase impl
} }
AxisAlignedBB bb = null; AxisAlignedBB bb = null;
@Override @Override
public AxisAlignedBB getRenderBoundingBox() { public AxisAlignedBB getRenderBoundingBox() {
if(bb == null) { if(bb == null) {
bb = AxisAlignedBB.getBoundingBox( bb = AxisAlignedBB.getBoundingBox(
xCoord - 8, xCoord - 8,
@ -294,10 +297,10 @@ public class TileEntityMachineExposureChamber extends TileEntityMachineBase impl
zCoord + 9 zCoord + 9
); );
} }
return bb; return bb;
} }
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public double getMaxRenderDistanceSquared() { public double getMaxRenderDistanceSquared() {
@ -337,10 +340,11 @@ public class TileEntityMachineExposureChamber extends TileEntityMachineBase impl
} }
@Override @Override
public int getMaxLevel(UpgradeType type) { public HashMap<UpgradeType, Integer> getValidUpgrades() {
if(type == UpgradeType.SPEED) return 3; HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
if(type == UpgradeType.POWER) return 3; upgrades.put(UpgradeType.SPEED, 3);
if(type == UpgradeType.OVERDRIVE) return 3; upgrades.put(UpgradeType.POWER, 3);
return 0; upgrades.put(UpgradeType.OVERDRIVE, 3);
return upgrades;
} }
} }

View File

@ -1,11 +1,12 @@
package com.hbm.tileentity.machine; package com.hbm.tileentity.machine;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.hbm.blocks.ModBlocks; import com.hbm.blocks.ModBlocks;
import com.hbm.inventory.UpgradeManager; import com.hbm.inventory.UpgradeManagerNT;
import com.hbm.inventory.container.ContainerMiningLaser; import com.hbm.inventory.container.ContainerMiningLaser;
import com.hbm.inventory.fluid.Fluids; import com.hbm.inventory.fluid.Fluids;
import com.hbm.inventory.fluid.tank.FluidTank; import com.hbm.inventory.fluid.tank.FluidTank;
@ -69,6 +70,8 @@ public class TileEntityMachineMiningLaser extends TileEntityMachineBase implemen
boolean lock = false; boolean lock = false;
double breakProgress; double breakProgress;
public UpgradeManagerNT upgradeManager = new UpgradeManagerNT();
public TileEntityMachineMiningLaser() { public TileEntityMachineMiningLaser() {
//slot 0: battery //slot 0: battery
@ -112,14 +115,14 @@ public class TileEntityMachineMiningLaser extends TileEntityMachineBase implemen
if(isOn) { if(isOn) {
UpgradeManager.eval(slots, 1, 8); upgradeManager.checkSlots(this, slots, 1, 8);
int cycles = 1 + UpgradeManager.getLevel(UpgradeType.OVERDRIVE); int cycles = 1 + upgradeManager.getLevel(UpgradeType.OVERDRIVE);
int speed = 1 + Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 12); int speed = 1 + upgradeManager.getLevel(UpgradeType.SPEED);
int range = 1 + Math.min(UpgradeManager.getLevel(UpgradeType.EFFECT) * 2, 24); int range = 1 + upgradeManager.getLevel(UpgradeType.EFFECT) * 2;
int fortune = Math.min(UpgradeManager.getLevel(UpgradeType.FORTUNE), 3); int fortune = upgradeManager.getLevel(UpgradeType.FORTUNE);
int consumption = this.consumption int consumption = this.consumption
- (this.consumption * Math.min(UpgradeManager.getLevel(UpgradeType.POWER), 12) / 16) - (this.consumption * upgradeManager.getLevel(UpgradeType.POWER) / 16)
+ (this.consumption * Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 12) / 16); + (this.consumption * upgradeManager.getLevel(UpgradeType.SPEED) / 16);
for(int i = 0; i < cycles; i++) { for(int i = 0; i < cycles; i++) {
@ -678,12 +681,13 @@ public class TileEntityMachineMiningLaser extends TileEntityMachineBase implemen
} }
@Override @Override
public int getMaxLevel(UpgradeType type) { public HashMap<UpgradeType, Integer> getValidUpgrades() {
if(type == UpgradeType.SPEED) return 12; HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
if(type == UpgradeType.POWER) return 12; upgrades.put(UpgradeType.SPEED, 12);
if(type == UpgradeType.EFFECT) return 12; upgrades.put(UpgradeType.POWER, 12);
if(type == UpgradeType.FORTUNE) return 3; upgrades.put(UpgradeType.EFFECT, 12);
if(type == UpgradeType.OVERDRIVE) return 9; upgrades.put(UpgradeType.FORTUNE, 3);
return 0; upgrades.put(UpgradeType.OVERDRIVE, 9);
return upgrades;
} }
} }

View File

@ -1,10 +1,11 @@
package com.hbm.tileentity.machine; package com.hbm.tileentity.machine;
import java.util.HashMap;
import java.util.List; import java.util.List;
import com.hbm.blocks.ModBlocks; import com.hbm.blocks.ModBlocks;
import com.hbm.interfaces.IControlReceiver; import com.hbm.interfaces.IControlReceiver;
import com.hbm.inventory.UpgradeManager; import com.hbm.inventory.UpgradeManagerNT;
import com.hbm.inventory.container.ContainerMixer; import com.hbm.inventory.container.ContainerMixer;
import com.hbm.inventory.fluid.Fluids; import com.hbm.inventory.fluid.Fluids;
import com.hbm.inventory.fluid.tank.FluidTank; import com.hbm.inventory.fluid.tank.FluidTank;
@ -32,21 +33,23 @@ import net.minecraft.util.EnumChatFormatting;
import net.minecraft.world.World; import net.minecraft.world.World;
public class TileEntityMachineMixer extends TileEntityMachineBase implements IControlReceiver, IGUIProvider, IEnergyReceiverMK2, IFluidStandardTransceiver, IUpgradeInfoProvider, IFluidCopiable { public class TileEntityMachineMixer extends TileEntityMachineBase implements IControlReceiver, IGUIProvider, IEnergyReceiverMK2, IFluidStandardTransceiver, IUpgradeInfoProvider, IFluidCopiable {
public long power; public long power;
public static final long maxPower = 10_000; public static final long maxPower = 10_000;
public int progress; public int progress;
public int processTime; public int processTime;
public int recipeIndex; public int recipeIndex;
public float rotation; public float rotation;
public float prevRotation; public float prevRotation;
public boolean wasOn = false; public boolean wasOn = false;
private int consumption = 50; private int consumption = 50;
public FluidTank[] tanks; public FluidTank[] tanks;
public UpgradeManagerNT upgradeManager = new UpgradeManagerNT();
public TileEntityMachineMixer() { public TileEntityMachineMixer() {
super(5); super(5);
this.tanks = new FluidTank[3]; this.tanks = new FluidTank[3];
@ -62,53 +65,53 @@ public class TileEntityMachineMixer extends TileEntityMachineBase implements ICo
@Override @Override
public void updateEntity() { public void updateEntity() {
if(!worldObj.isRemote) { if(!worldObj.isRemote) {
this.power = Library.chargeTEFromItems(slots, 0, power, maxPower); this.power = Library.chargeTEFromItems(slots, 0, power, maxPower);
tanks[2].setType(2, slots); tanks[2].setType(2, slots);
UpgradeManager.eval(slots, 3, 4); upgradeManager.checkSlots(this, slots, 3, 4);
int speedLevel = Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 3); int speedLevel = upgradeManager.getLevel(UpgradeType.SPEED);
int powerLevel = Math.min(UpgradeManager.getLevel(UpgradeType.POWER), 3); int powerLevel = upgradeManager.getLevel(UpgradeType.POWER);
int overLevel = UpgradeManager.getLevel(UpgradeType.OVERDRIVE); int overLevel = upgradeManager.getLevel(UpgradeType.OVERDRIVE);
this.consumption = 50; this.consumption = 50;
this.consumption += speedLevel * 150; this.consumption += speedLevel * 150;
this.consumption -= this.consumption * powerLevel * 0.25; this.consumption -= this.consumption * powerLevel * 0.25;
this.consumption *= (overLevel * 3 + 1); this.consumption *= (overLevel * 3 + 1);
for(DirPos pos : getConPos()) { for(DirPos pos : getConPos()) {
this.trySubscribe(worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); this.trySubscribe(worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
if(tanks[0].getTankType() != Fluids.NONE) this.trySubscribe(tanks[0].getTankType(), worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); if(tanks[0].getTankType() != Fluids.NONE) this.trySubscribe(tanks[0].getTankType(), worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
if(tanks[1].getTankType() != Fluids.NONE) this.trySubscribe(tanks[1].getTankType(), worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); if(tanks[1].getTankType() != Fluids.NONE) this.trySubscribe(tanks[1].getTankType(), worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
} }
this.wasOn = this.canProcess(); this.wasOn = this.canProcess();
if(this.wasOn) { if(this.wasOn) {
this.progress++; this.progress++;
this.power -= this.getConsumption(); this.power -= this.getConsumption();
this.processTime -= this.processTime * speedLevel / 4; this.processTime -= this.processTime * speedLevel / 4;
this.processTime /= (overLevel + 1); this.processTime /= (overLevel + 1);
if(processTime <= 0) this.processTime = 1; if(processTime <= 0) this.processTime = 1;
if(this.progress >= this.processTime) { if(this.progress >= this.processTime) {
this.process(); this.process();
this.progress = 0; this.progress = 0;
} }
} else { } else {
this.progress = 0; this.progress = 0;
} }
for(DirPos pos : getConPos()) { for(DirPos pos : getConPos()) {
if(tanks[2].getFill() > 0) this.sendFluid(tanks[2], worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); if(tanks[2].getFill() > 0) this.sendFluid(tanks[2], worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
} }
NBTTagCompound data = new NBTTagCompound(); NBTTagCompound data = new NBTTagCompound();
data.setLong("power", power); data.setLong("power", power);
data.setInteger("processTime", processTime); data.setInteger("processTime", processTime);
@ -119,22 +122,22 @@ public class TileEntityMachineMixer extends TileEntityMachineBase implements ICo
tanks[i].writeToNBT(data, i + ""); tanks[i].writeToNBT(data, i + "");
} }
this.networkPackNT(50); this.networkPackNT(50);
} else { } else {
this.prevRotation = this.rotation; this.prevRotation = this.rotation;
if(this.wasOn) { if(this.wasOn) {
this.rotation += 20F; this.rotation += 20F;
} }
if(this.rotation >= 360) { if(this.rotation >= 360) {
this.rotation -= 360; this.rotation -= 360;
this.prevRotation -= 360; this.prevRotation -= 360;
} }
} }
} }
@Override @Override
public void serialize(ByteBuf buf) { public void serialize(ByteBuf buf) {
super.serialize(buf); super.serialize(buf);
@ -143,10 +146,10 @@ public class TileEntityMachineMixer extends TileEntityMachineBase implements ICo
buf.writeInt(progress); buf.writeInt(progress);
buf.writeInt(recipeIndex); buf.writeInt(recipeIndex);
buf.writeBoolean(wasOn); buf.writeBoolean(wasOn);
for(int i = 0; i < tanks.length; i++) tanks[i].serialize(buf); for(int i = 0; i < tanks.length; i++) tanks[i].serialize(buf);
} }
@Override @Override
public void deserialize(ByteBuf buf) { public void deserialize(ByteBuf buf) {
super.deserialize(buf); super.deserialize(buf);
@ -155,10 +158,10 @@ public class TileEntityMachineMixer extends TileEntityMachineBase implements ICo
progress = buf.readInt(); progress = buf.readInt();
recipeIndex = buf.readInt(); recipeIndex = buf.readInt();
wasOn = buf.readBoolean(); wasOn = buf.readBoolean();
for(int i = 0; i < tanks.length; i++) tanks[i].deserialize(buf); for(int i = 0; i < tanks.length; i++) tanks[i].deserialize(buf);
} }
public boolean canProcess() { public boolean canProcess() {
MixerRecipe[] recipes = MixerRecipes.getOutput(tanks[2].getTankType()); MixerRecipe[] recipes = MixerRecipes.getOutput(tanks[2].getTankType());
@ -166,38 +169,38 @@ public class TileEntityMachineMixer extends TileEntityMachineBase implements ICo
this.recipeIndex = 0; this.recipeIndex = 0;
return false; return false;
} }
this.recipeIndex = this.recipeIndex % recipes.length; this.recipeIndex = this.recipeIndex % recipes.length;
MixerRecipe recipe = recipes[this.recipeIndex]; MixerRecipe recipe = recipes[this.recipeIndex];
if(recipe == null) { if(recipe == null) {
this.recipeIndex = 0; this.recipeIndex = 0;
return false; return false;
} }
tanks[0].setTankType(recipe.input1 != null ? recipe.input1.type : Fluids.NONE); tanks[0].setTankType(recipe.input1 != null ? recipe.input1.type : Fluids.NONE);
tanks[1].setTankType(recipe.input2 != null ? recipe.input2.type : Fluids.NONE); tanks[1].setTankType(recipe.input2 != null ? recipe.input2.type : Fluids.NONE);
if(recipe.input1 != null && tanks[0].getFill() < recipe.input1.fill) return false; if(recipe.input1 != null && tanks[0].getFill() < recipe.input1.fill) return false;
if(recipe.input2 != null && tanks[1].getFill() < recipe.input2.fill) return false; if(recipe.input2 != null && tanks[1].getFill() < recipe.input2.fill) return false;
/* simplest check would usually go first, but fluid checks also do the setup and we want that to happen even without power */ /* simplest check would usually go first, but fluid checks also do the setup and we want that to happen even without power */
if(this.power < getConsumption()) return false; if(this.power < getConsumption()) return false;
if(recipe.output + tanks[2].getFill() > tanks[2].getMaxFill()) return false; if(recipe.output + tanks[2].getFill() > tanks[2].getMaxFill()) return false;
if(recipe.solidInput != null) { if(recipe.solidInput != null) {
if(slots[1] == null) return false; if(slots[1] == null) return false;
if(!recipe.solidInput.matchesRecipe(slots[1], true) || recipe.solidInput.stacksize > slots[1].stackSize) return false; if(!recipe.solidInput.matchesRecipe(slots[1], true) || recipe.solidInput.stacksize > slots[1].stackSize) return false;
} }
this.processTime = recipe.processTime; this.processTime = recipe.processTime;
return true; return true;
} }
protected void process() { protected void process() {
MixerRecipe[] recipes = MixerRecipes.getOutput(tanks[2].getTankType()); MixerRecipe[] recipes = MixerRecipes.getOutput(tanks[2].getTankType());
MixerRecipe recipe = recipes[this.recipeIndex % recipes.length]; MixerRecipe recipe = recipes[this.recipeIndex % recipes.length];
@ -206,11 +209,11 @@ public class TileEntityMachineMixer extends TileEntityMachineBase implements ICo
if(recipe.solidInput != null) this.decrStackSize(1, recipe.solidInput.stacksize); if(recipe.solidInput != null) this.decrStackSize(1, recipe.solidInput.stacksize);
tanks[2].setFill(tanks[2].getFill() + recipe.output); tanks[2].setFill(tanks[2].getFill() + recipe.output);
} }
public int getConsumption() { public int getConsumption() {
return consumption; return consumption;
} }
protected DirPos[] getConPos() { protected DirPos[] getConPos() {
return new DirPos[] { return new DirPos[] {
new DirPos(xCoord, yCoord - 1, zCoord, Library.NEG_Y), new DirPos(xCoord, yCoord - 1, zCoord, Library.NEG_Y),
@ -220,7 +223,7 @@ public class TileEntityMachineMixer extends TileEntityMachineBase implements ICo
new DirPos(xCoord, yCoord, zCoord - 1, Library.NEG_Z), new DirPos(xCoord, yCoord, zCoord - 1, Library.NEG_Z),
}; };
} }
@Override @Override
public int[] getAccessibleSlotsFromSide(int meta) { public int[] getAccessibleSlotsFromSide(int meta) {
return new int[] { 1 }; return new int[] { 1 };
@ -228,16 +231,16 @@ public class TileEntityMachineMixer extends TileEntityMachineBase implements ICo
@Override @Override
public boolean isItemValidForSlot(int i, ItemStack itemStack) { public boolean isItemValidForSlot(int i, ItemStack itemStack) {
MixerRecipe[] recipes = MixerRecipes.getOutput(tanks[2].getTankType()); MixerRecipe[] recipes = MixerRecipes.getOutput(tanks[2].getTankType());
if(recipes == null || recipes.length <= 0) return false; if(recipes == null || recipes.length <= 0) return false;
MixerRecipe recipe = recipes[this.recipeIndex % recipes.length]; MixerRecipe recipe = recipes[this.recipeIndex % recipes.length];
if(recipe == null || recipe.solidInput == null) return false; if(recipe == null || recipe.solidInput == null) return false;
return recipe.solidInput.matchesRecipe(itemStack, true); return recipe.solidInput.matchesRecipe(itemStack, true);
} }
@Override @Override
public void readFromNBT(NBTTagCompound nbt) { public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt); super.readFromNBT(nbt);
@ -248,11 +251,11 @@ public class TileEntityMachineMixer extends TileEntityMachineBase implements ICo
this.recipeIndex = nbt.getInteger("recipe"); this.recipeIndex = nbt.getInteger("recipe");
for(int i = 0; i < 3; i++) this.tanks[i].readFromNBT(nbt, i + ""); for(int i = 0; i < 3; i++) this.tanks[i].readFromNBT(nbt, i + "");
} }
@Override @Override
public void writeToNBT(NBTTagCompound nbt) { public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt); super.writeToNBT(nbt);
nbt.setLong("power", power); nbt.setLong("power", power);
nbt.setInteger("progress", progress); nbt.setInteger("progress", progress);
nbt.setInteger("processTime", processTime); nbt.setInteger("processTime", processTime);
@ -300,19 +303,19 @@ public class TileEntityMachineMixer extends TileEntityMachineBase implements ICo
public Object provideGUI(int ID, EntityPlayer player, World world, int x, int y, int z) { public Object provideGUI(int ID, EntityPlayer player, World world, int x, int y, int z) {
return new GUIMixer(player.inventory, this); return new GUIMixer(player.inventory, this);
} }
AxisAlignedBB aabb; AxisAlignedBB aabb;
@Override @Override
public AxisAlignedBB getRenderBoundingBox() { public AxisAlignedBB getRenderBoundingBox() {
if(aabb != null) if(aabb != null)
return aabb; return aabb;
aabb = AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 3, zCoord + 1); aabb = AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 3, zCoord + 1);
return aabb; return aabb;
} }
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public double getMaxRenderDistanceSquared() { public double getMaxRenderDistanceSquared() {
@ -350,11 +353,12 @@ public class TileEntityMachineMixer extends TileEntityMachineBase implements ICo
} }
@Override @Override
public int getMaxLevel(UpgradeType type) { public HashMap<UpgradeType, Integer> getValidUpgrades() {
if(type == UpgradeType.SPEED) return 3; HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
if(type == UpgradeType.POWER) return 3; upgrades.put(UpgradeType.SPEED, 3);
if(type == UpgradeType.OVERDRIVE) return 6; upgrades.put(UpgradeType.POWER, 3);
return 0; upgrades.put(UpgradeType.OVERDRIVE, 6);
return upgrades;
} }
@Override @Override

View File

@ -1,9 +1,10 @@
package com.hbm.tileentity.machine; package com.hbm.tileentity.machine;
import java.util.HashMap;
import java.util.List; import java.util.List;
import com.hbm.blocks.ModBlocks; import com.hbm.blocks.ModBlocks;
import com.hbm.inventory.UpgradeManager; import com.hbm.inventory.UpgradeManagerNT;
import com.hbm.inventory.container.ContainerOreSlopper; import com.hbm.inventory.container.ContainerOreSlopper;
import com.hbm.inventory.fluid.FluidType; import com.hbm.inventory.fluid.FluidType;
import com.hbm.inventory.fluid.Fluids; import com.hbm.inventory.fluid.Fluids;
@ -47,18 +48,18 @@ import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityMachineOreSlopper extends TileEntityMachineBase implements IEnergyReceiverMK2, IFluidStandardTransceiver, IGUIProvider, IUpgradeInfoProvider, IFluidCopiable { public class TileEntityMachineOreSlopper extends TileEntityMachineBase implements IEnergyReceiverMK2, IFluidStandardTransceiver, IGUIProvider, IUpgradeInfoProvider, IFluidCopiable {
public long power; public long power;
public static final long maxPower = 100_000; public static final long maxPower = 100_000;
public static final int waterUsedBase = 1_000; public static final int waterUsedBase = 1_000;
public int waterUsed = waterUsedBase; public int waterUsed = waterUsedBase;
public static final long consumptionBase = 200; public static final long consumptionBase = 200;
public long consumption = consumptionBase; public long consumption = consumptionBase;
public float progress; public float progress;
public boolean processing; public boolean processing;
public SlopperAnimation animation = SlopperAnimation.LOWERING; public SlopperAnimation animation = SlopperAnimation.LOWERING;
public float slider; public float slider;
public float prevSlider; public float prevSlider;
@ -69,10 +70,12 @@ public class TileEntityMachineOreSlopper extends TileEntityMachineBase implement
public float fan; public float fan;
public float prevFan; public float prevFan;
public int delay; public int delay;
public FluidTank[] tanks; public FluidTank[] tanks;
public double[] ores = new double[BedrockOreType.values().length]; public double[] ores = new double[BedrockOreType.values().length];
public UpgradeManagerNT upgradeManager = new UpgradeManagerNT();
public TileEntityMachineOreSlopper() { public TileEntityMachineOreSlopper() {
super(11); super(11);
tanks = new FluidTank[2]; tanks = new FluidTank[2];
@ -84,75 +87,75 @@ public class TileEntityMachineOreSlopper extends TileEntityMachineBase implement
public String getName() { public String getName() {
return "container.machineOreSlopper"; return "container.machineOreSlopper";
} }
public static enum SlopperAnimation { public static enum SlopperAnimation {
LOWERING, LIFTING, MOVE_SHREDDER, DUMPING, MOVE_BUCKET LOWERING, LIFTING, MOVE_SHREDDER, DUMPING, MOVE_BUCKET
} }
@Override @Override
public void updateEntity() { public void updateEntity() {
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10); ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10);
if(!worldObj.isRemote) { if(!worldObj.isRemote) {
this.power = Library.chargeTEFromItems(slots, 0, power, maxPower); this.power = Library.chargeTEFromItems(slots, 0, power, maxPower);
tanks[0].setType(1, slots); tanks[0].setType(1, slots);
FluidType conversion = this.getFluidOutput(tanks[0].getTankType()); FluidType conversion = this.getFluidOutput(tanks[0].getTankType());
if(conversion != null) tanks[1].setTankType(conversion); if(conversion != null) tanks[1].setTankType(conversion);
for(DirPos pos : getConPos()) { for(DirPos pos : getConPos()) {
this.trySubscribe(worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); this.trySubscribe(worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
this.trySubscribe(tanks[0].getTankType(), worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); this.trySubscribe(tanks[0].getTankType(), worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
if(tanks[1].getFill() > 0) this.sendFluid(tanks[1], worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); if(tanks[1].getFill() > 0) this.sendFluid(tanks[1], worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
} }
this.processing = false; this.processing = false;
UpgradeManager.eval(slots, 9, 10); upgradeManager.checkSlots(this, slots, 9, 10);
int speed = Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 3); int speed = upgradeManager.getLevel(UpgradeType.SPEED);
int efficiency = Math.min(UpgradeManager.getLevel(UpgradeType.EFFECT), 3); int efficiency = upgradeManager.getLevel(UpgradeType.EFFECT);
this.consumption = this.consumptionBase + (this.consumptionBase * speed) / 2 + (this.consumptionBase * efficiency); this.consumption = this.consumptionBase + (this.consumptionBase * speed) / 2 + (this.consumptionBase * efficiency);
if(canSlop()) { if(canSlop()) {
this.power -= this.consumption; this.power -= this.consumption;
this.progress += 1F / (600 - speed * 150); this.progress += 1F / (600 - speed * 150);
this.processing = true; this.processing = true;
boolean markDirty = false; boolean markDirty = false;
while(progress >= 1F && canSlop()) { while(progress >= 1F && canSlop()) {
progress -= 1F; progress -= 1F;
for(BedrockOreType type : BedrockOreType.values()) { for(BedrockOreType type : BedrockOreType.values()) {
ores[type.ordinal()] += (ItemBedrockOreBase.getOreAmount(slots[2], type) * (1D + efficiency * 0.1)); ores[type.ordinal()] += (ItemBedrockOreBase.getOreAmount(slots[2], type) * (1D + efficiency * 0.1));
} }
this.decrStackSize(2, 1); this.decrStackSize(2, 1);
this.tanks[0].setFill(this.tanks[0].getFill() - waterUsed); this.tanks[0].setFill(this.tanks[0].getFill() - waterUsed);
this.tanks[1].setFill(this.tanks[1].getFill() + waterUsed); this.tanks[1].setFill(this.tanks[1].getFill() + waterUsed);
markDirty = true; markDirty = true;
} }
if(markDirty) this.markDirty(); if(markDirty) this.markDirty();
List<Entity> entities = worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(xCoord - 0.5, yCoord + 1, zCoord - 0.5, xCoord + 1.5, yCoord + 3, zCoord + 1.5).offset(dir.offsetX, 0, dir.offsetZ)); List<Entity> entities = worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(xCoord - 0.5, yCoord + 1, zCoord - 0.5, xCoord + 1.5, yCoord + 3, zCoord + 1.5).offset(dir.offsetX, 0, dir.offsetZ));
for(Entity e : entities) { for(Entity e : entities) {
e.attackEntityFrom(ModDamageSource.turbofan, 1000F); e.attackEntityFrom(ModDamageSource.turbofan, 1000F);
if(!e.isEntityAlive() && e instanceof EntityLivingBase) { if(!e.isEntityAlive() && e instanceof EntityLivingBase) {
NBTTagCompound vdat = new NBTTagCompound(); NBTTagCompound vdat = new NBTTagCompound();
vdat.setString("type", "giblets"); vdat.setString("type", "giblets");
vdat.setInteger("ent", e.getEntityId()); vdat.setInteger("ent", e.getEntityId());
vdat.setInteger("cDiv", 5); vdat.setInteger("cDiv", 5);
PacketDispatcher.wrapper.sendToAllAround(new AuxParticlePacketNT(vdat, e.posX, e.posY + e.height * 0.5, e.posZ), new TargetPoint(e.dimension, e.posX, e.posY + e.height * 0.5, e.posZ, 150)); PacketDispatcher.wrapper.sendToAllAround(new AuxParticlePacketNT(vdat, e.posX, e.posY + e.height * 0.5, e.posZ), new TargetPoint(e.dimension, e.posX, e.posY + e.height * 0.5, e.posZ, 150));
worldObj.playSoundEffect(e.posX, e.posY, e.posZ, "mob.zombie.woodbreak", 2.0F, 0.95F + worldObj.rand.nextFloat() * 0.2F); worldObj.playSoundEffect(e.posX, e.posY, e.posZ, "mob.zombie.woodbreak", 2.0F, 0.95F + worldObj.rand.nextFloat() * 0.2F);
} }
} }
} else { } else {
this.progress = 0; this.progress = 0;
} }
@ -169,31 +172,31 @@ public class TileEntityMachineOreSlopper extends TileEntityMachineBase implement
break outer; break outer;
} }
} }
this.networkPackNT(150); this.networkPackNT(150);
} else { } else {
this.prevSlider = this.slider; this.prevSlider = this.slider;
this.prevBucket = this.bucket; this.prevBucket = this.bucket;
this.prevBlades = this.blades; this.prevBlades = this.blades;
this.prevFan = this.fan; this.prevFan = this.fan;
if(this.processing) { if(this.processing) {
this.blades += 15F; this.blades += 15F;
this.fan += 35F; this.fan += 35F;
if(blades >= 360) { if(blades >= 360) {
blades -= 360; blades -= 360;
prevBlades -= 360; prevBlades -= 360;
} }
if(fan >= 360) { if(fan >= 360) {
fan -= 360; fan -= 360;
prevFan -= 360; prevFan -= 360;
} }
if(animation == animation.DUMPING && MainRegistry.proxy.me().getDistance(xCoord + 0.5, yCoord + 4, zCoord + 0.5) <= 50) { if(animation == animation.DUMPING && MainRegistry.proxy.me().getDistance(xCoord + 0.5, yCoord + 4, zCoord + 0.5) <= 50) {
NBTTagCompound data = new NBTTagCompound(); NBTTagCompound data = new NBTTagCompound();
data.setString("type", "vanillaExt"); data.setString("type", "vanillaExt");
@ -205,12 +208,12 @@ public class TileEntityMachineOreSlopper extends TileEntityMachineBase implement
data.setDouble("mY", -0.2D); data.setDouble("mY", -0.2D);
MainRegistry.proxy.effectNT(data); MainRegistry.proxy.effectNT(data);
} }
if(delay > 0) { if(delay > 0) {
delay--; delay--;
return; return;
} }
switch(animation) { switch(animation) {
case LOWERING: case LOWERING:
this.bucket += 1F/40F; this.bucket += 1F/40F;
@ -250,11 +253,11 @@ public class TileEntityMachineOreSlopper extends TileEntityMachineBase implement
} }
} }
} }
public DirPos[] getConPos() { public DirPos[] getConPos() {
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10); ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10);
ForgeDirection rot = dir.getRotation(ForgeDirection.UP); ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
return new DirPos[] { return new DirPos[] {
new DirPos(xCoord + dir.offsetX * 4, yCoord, zCoord + dir.offsetZ * 4, dir), new DirPos(xCoord + dir.offsetX * 4, yCoord, zCoord + dir.offsetZ * 4, dir),
new DirPos(xCoord - dir.offsetX * 4, yCoord, zCoord - dir.offsetZ * 4, dir.getOpposite()), new DirPos(xCoord - dir.offsetX * 4, yCoord, zCoord - dir.offsetZ * 4, dir.getOpposite()),
@ -278,7 +281,7 @@ public class TileEntityMachineOreSlopper extends TileEntityMachineBase implement
} }
private static final int[] slot_access = new int[] {2, 3, 4, 5, 6, 7, 8}; private static final int[] slot_access = new int[] {2, 3, 4, 5, 6, 7, 8};
@Override @Override
public int[] getAccessibleSlotsFromSide(int side) { public int[] getAccessibleSlotsFromSide(int side) {
return slot_access; return slot_access;
@ -293,7 +296,7 @@ public class TileEntityMachineOreSlopper extends TileEntityMachineBase implement
tanks[0].serialize(buf); tanks[0].serialize(buf);
tanks[1].serialize(buf); tanks[1].serialize(buf);
} }
@Override public void deserialize(ByteBuf buf) { @Override public void deserialize(ByteBuf buf) {
super.deserialize(buf); super.deserialize(buf);
this.power = buf.readLong(); this.power = buf.readLong();
@ -303,7 +306,7 @@ public class TileEntityMachineOreSlopper extends TileEntityMachineBase implement
tanks[0].deserialize(buf); tanks[0].deserialize(buf);
tanks[1].deserialize(buf); tanks[1].deserialize(buf);
} }
@Override @Override
public void readFromNBT(NBTTagCompound nbt) { public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt); super.readFromNBT(nbt);
@ -312,7 +315,7 @@ public class TileEntityMachineOreSlopper extends TileEntityMachineBase implement
tanks[0].readFromNBT(nbt, "water"); tanks[0].readFromNBT(nbt, "water");
tanks[1].readFromNBT(nbt, "slop"); tanks[1].readFromNBT(nbt, "slop");
} }
@Override @Override
public void writeToNBT(NBTTagCompound nbt) { public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt); super.writeToNBT(nbt);
@ -321,16 +324,16 @@ public class TileEntityMachineOreSlopper extends TileEntityMachineBase implement
tanks[0].writeToNBT(nbt, "water"); tanks[0].writeToNBT(nbt, "water");
tanks[1].writeToNBT(nbt, "slop"); tanks[1].writeToNBT(nbt, "slop");
} }
public boolean canSlop() { public boolean canSlop() {
if(this.getFluidOutput(tanks[0].getTankType()) == null) return false; if(this.getFluidOutput(tanks[0].getTankType()) == null) return false;
if(tanks[0].getFill() < waterUsed) return false; if(tanks[0].getFill() < waterUsed) return false;
if(tanks[1].getFill() + waterUsed > tanks[1].getMaxFill()) return false; if(tanks[1].getFill() + waterUsed > tanks[1].getMaxFill()) return false;
if(power < consumption) return false; if(power < consumption) return false;
return slots[2] != null && slots[2].getItem() == ModItems.bedrock_ore_base; return slots[2] != null && slots[2].getItem() == ModItems.bedrock_ore_base;
} }
public FluidType getFluidOutput(FluidType input) { public FluidType getFluidOutput(FluidType input) {
if(input == Fluids.WATER) return Fluids.SLOP; if(input == Fluids.WATER) return Fluids.SLOP;
return null; return null;
@ -343,12 +346,12 @@ public class TileEntityMachineOreSlopper extends TileEntityMachineBase implement
@Override public FluidTank[] getAllTanks() { return tanks; } @Override public FluidTank[] getAllTanks() { return tanks; }
@Override public FluidTank[] getSendingTanks() { return new FluidTank[] {tanks[1]}; } @Override public FluidTank[] getSendingTanks() { return new FluidTank[] {tanks[1]}; }
@Override public FluidTank[] getReceivingTanks() { return new FluidTank[] {tanks[0]}; } @Override public FluidTank[] getReceivingTanks() { return new FluidTank[] {tanks[0]}; }
AxisAlignedBB bb = null; AxisAlignedBB bb = null;
@Override @Override
public AxisAlignedBB getRenderBoundingBox() { public AxisAlignedBB getRenderBoundingBox() {
if(bb == null) { if(bb == null) {
bb = AxisAlignedBB.getBoundingBox( bb = AxisAlignedBB.getBoundingBox(
xCoord - 3, xCoord - 3,
@ -359,10 +362,10 @@ public class TileEntityMachineOreSlopper extends TileEntityMachineBase implement
zCoord + 4 zCoord + 4
); );
} }
return bb; return bb;
} }
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public double getMaxRenderDistanceSquared() { public double getMaxRenderDistanceSquared() {
@ -399,9 +402,10 @@ public class TileEntityMachineOreSlopper extends TileEntityMachineBase implement
} }
@Override @Override
public int getMaxLevel(UpgradeType type) { public HashMap<UpgradeType, Integer> getValidUpgrades() {
if(type == UpgradeType.SPEED) return 3; HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
if(type == UpgradeType.EFFECT) return 3; upgrades.put(UpgradeType.SPEED, 3);
return 0; upgrades.put(UpgradeType.EFFECT, 3);
return upgrades;
} }
} }

View File

@ -1,10 +1,11 @@
package com.hbm.tileentity.machine; package com.hbm.tileentity.machine;
import java.util.HashMap;
import java.util.List; import java.util.List;
import com.hbm.blocks.ModBlocks; import com.hbm.blocks.ModBlocks;
import com.hbm.interfaces.IControlReceiver; import com.hbm.interfaces.IControlReceiver;
import com.hbm.inventory.UpgradeManager; import com.hbm.inventory.UpgradeManagerNT;
import com.hbm.inventory.RecipesCommon.AStack; import com.hbm.inventory.RecipesCommon.AStack;
import com.hbm.inventory.container.ContainerMachineSolderingStation; import com.hbm.inventory.container.ContainerMachineSolderingStation;
import com.hbm.inventory.fluid.Fluids; import com.hbm.inventory.fluid.Fluids;
@ -53,6 +54,8 @@ public class TileEntityMachineSolderingStation extends TileEntityMachineBase imp
public FluidTank tank; public FluidTank tank;
public ItemStack display; public ItemStack display;
public UpgradeManagerNT upgradeManager = new UpgradeManagerNT();
public TileEntityMachineSolderingStation() { public TileEntityMachineSolderingStation() {
super(11); super(11);
this.tank = new FluidTank(Fluids.NONE, 8_000); this.tank = new FluidTank(Fluids.NONE, 8_000);
@ -92,9 +95,9 @@ public class TileEntityMachineSolderingStation extends TileEntityMachineBase imp
recipe = SolderingRecipes.getRecipe(new ItemStack[] {slots[0], slots[1], slots[2], slots[3], slots[4], slots[5]}); recipe = SolderingRecipes.getRecipe(new ItemStack[] {slots[0], slots[1], slots[2], slots[3], slots[4], slots[5]});
long intendedMaxPower; long intendedMaxPower;
UpgradeManager.eval(slots, 9, 10); upgradeManager.checkSlots(this, slots, 9, 10);
int redLevel = Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 3); int redLevel = upgradeManager.getLevel(UpgradeType.SPEED);
int blueLevel = Math.min(UpgradeManager.getLevel(UpgradeType.POWER), 3); int blueLevel = upgradeManager.getLevel(UpgradeType.POWER);
if(recipe != null) { if(recipe != null) {
this.processTime = recipe.duration - (recipe.duration * redLevel / 6) + (recipe.duration * blueLevel / 3); this.processTime = recipe.duration - (recipe.duration * redLevel / 6) + (recipe.duration * blueLevel / 3);
@ -374,10 +377,11 @@ public class TileEntityMachineSolderingStation extends TileEntityMachineBase imp
} }
@Override @Override
public int getMaxLevel(UpgradeType type) { public HashMap<UpgradeType, Integer> getValidUpgrades() {
if(type == UpgradeType.SPEED) return 3; HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
if(type == UpgradeType.POWER) return 3; upgrades.put(UpgradeType.SPEED, 3);
return 0; upgrades.put(UpgradeType.POWER, 3);
return upgrades;
} }
@Override @Override

View File

@ -1,11 +1,12 @@
package com.hbm.tileentity.machine; package com.hbm.tileentity.machine;
import java.util.HashMap;
import java.util.List; import java.util.List;
import com.hbm.blocks.BlockDummyable; import com.hbm.blocks.BlockDummyable;
import com.hbm.blocks.ModBlocks; import com.hbm.blocks.ModBlocks;
import com.hbm.handler.MultiblockHandlerXR; import com.hbm.handler.MultiblockHandlerXR;
import com.hbm.inventory.UpgradeManager; import com.hbm.inventory.UpgradeManagerNT;
import com.hbm.inventory.container.ContainerMachineTurbofan; import com.hbm.inventory.container.ContainerMachineTurbofan;
import com.hbm.inventory.fluid.Fluids; import com.hbm.inventory.fluid.Fluids;
import com.hbm.inventory.fluid.tank.FluidTank; import com.hbm.inventory.fluid.tank.FluidTank;
@ -54,7 +55,7 @@ public class TileEntityMachineTurbofan extends TileEntityMachinePolluting implem
public static final long maxPower = 1_000_000; public static final long maxPower = 1_000_000;
public FluidTank tank; public FluidTank tank;
public FluidTank blood; public FluidTank blood;
public int afterburner; public int afterburner;
public boolean wasOn; public boolean wasOn;
public boolean showBlood = false; public boolean showBlood = false;
@ -64,9 +65,11 @@ public class TileEntityMachineTurbofan extends TileEntityMachinePolluting implem
public float spin; public float spin;
public float lastSpin; public float lastSpin;
public int momentum = 0; public int momentum = 0;
private AudioWrapper audio; private AudioWrapper audio;
public UpgradeManagerNT upgradeManager = new UpgradeManagerNT();
public TileEntityMachineTurbofan() { public TileEntityMachineTurbofan() {
super(5, 150); super(5, 150);
tank = new FluidTank(Fluids.KEROSENE, 24000); tank = new FluidTank(Fluids.KEROSENE, 24000);
@ -91,7 +94,7 @@ public class TileEntityMachineTurbofan extends TileEntityMachinePolluting implem
@Override @Override
public void writeToNBT(NBTTagCompound nbt) { public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt); super.writeToNBT(nbt);
nbt.setLong("powerTime", power); nbt.setLong("powerTime", power);
tank.writeToNBT(nbt, "fuel"); tank.writeToNBT(nbt, "fuel");
blood.writeToNBT(nbt, "blood"); blood.writeToNBT(nbt, "blood");
@ -101,12 +104,12 @@ public class TileEntityMachineTurbofan extends TileEntityMachinePolluting implem
public long getPowerScaled(long i) { public long getPowerScaled(long i) {
return (power * i) / maxPower; return (power * i) / maxPower;
} }
protected DirPos[] getConPos() { protected DirPos[] getConPos() {
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10).getRotation(ForgeDirection.UP); ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10).getRotation(ForgeDirection.UP);
ForgeDirection rot = dir.getRotation(ForgeDirection.DOWN); ForgeDirection rot = dir.getRotation(ForgeDirection.DOWN);
return new DirPos[] { return new DirPos[] {
new DirPos(this.xCoord + rot.offsetX * 2, this.yCoord, this.zCoord + rot.offsetZ * 2, rot), new DirPos(this.xCoord + rot.offsetX * 2, this.yCoord, this.zCoord + rot.offsetZ * 2, rot),
new DirPos(this.xCoord + rot.offsetX * 2 - dir.offsetX, this.yCoord, this.zCoord + rot.offsetZ * 2 - dir.offsetZ, rot), new DirPos(this.xCoord + rot.offsetX * 2 - dir.offsetX, this.yCoord, this.zCoord + rot.offsetZ * 2 - dir.offsetZ, rot),
@ -117,12 +120,12 @@ public class TileEntityMachineTurbofan extends TileEntityMachinePolluting implem
@Override @Override
public void updateEntity() { public void updateEntity() {
if(!worldObj.isRemote) { if(!worldObj.isRemote) {
this.output = 0; this.output = 0;
this.consumption = 0; this.consumption = 0;
//meta below 12 means that it's an old multiblock configuration //meta below 12 means that it's an old multiblock configuration
if(this.getBlockMetadata() < 12) { if(this.getBlockMetadata() < 12) {
//get old direction //get old direction
@ -144,54 +147,54 @@ public class TileEntityMachineTurbofan extends TileEntityMachinePolluting implem
worldObj.getTileEntity(xCoord, yCoord, zCoord).readFromNBT(data); worldObj.getTileEntity(xCoord, yCoord, zCoord).readFromNBT(data);
return; return;
} }
tank.setType(4, slots); tank.setType(4, slots);
tank.loadTank(0, 1, slots); tank.loadTank(0, 1, slots);
blood.setTankType(Fluids.BLOOD); blood.setTankType(Fluids.BLOOD);
this.wasOn = false; this.wasOn = false;
UpgradeManager.eval(slots, 2, 2); upgradeManager.checkSlots(this, slots, 2, 2);
this.afterburner = UpgradeManager.getLevel(UpgradeType.AFTERBURN); this.afterburner = upgradeManager.getLevel(UpgradeType.AFTERBURN);
if(slots[2] != null && slots[2].getItem() == ModItems.flame_pony) if(slots[2] != null && slots[2].getItem() == ModItems.flame_pony)
this.afterburner = 100; this.afterburner = 100;
long burnValue = 0; long burnValue = 0;
int amount = 1 + this.afterburner; int amount = 1 + this.afterburner;
if(tank.getTankType().hasTrait(FT_Combustible.class) && tank.getTankType().getTrait(FT_Combustible.class).getGrade() == FuelGrade.AERO) { if(tank.getTankType().hasTrait(FT_Combustible.class) && tank.getTankType().getTrait(FT_Combustible.class).getGrade() == FuelGrade.AERO) {
burnValue = tank.getTankType().getTrait(FT_Combustible.class).getCombustionEnergy() / 1_000; burnValue = tank.getTankType().getTrait(FT_Combustible.class).getCombustionEnergy() / 1_000;
} }
int amountToBurn = Math.min(amount, this.tank.getFill()); int amountToBurn = Math.min(amount, this.tank.getFill());
if(amountToBurn > 0) { if(amountToBurn > 0) {
this.wasOn = true; this.wasOn = true;
this.tank.setFill(this.tank.getFill() - amountToBurn); this.tank.setFill(this.tank.getFill() - amountToBurn);
this.output = (int) (burnValue * amountToBurn * (1 + Math.min(this.afterburner / 3D, 4))); this.output = (int) (burnValue * amountToBurn * (1 + Math.min(this.afterburner / 3D, 4)));
this.power += this.output; this.power += this.output;
this.consumption = amountToBurn; this.consumption = amountToBurn;
if(worldObj.getTotalWorldTime() % 20 == 0) super.pollute(tank.getTankType(), FluidTrait.FluidReleaseType.BURN, amountToBurn * 5);; if(worldObj.getTotalWorldTime() % 20 == 0) super.pollute(tank.getTankType(), FluidTrait.FluidReleaseType.BURN, amountToBurn * 5);;
} }
power = Library.chargeItemsFromTE(slots, 3, power, power); power = Library.chargeItemsFromTE(slots, 3, power, power);
for(DirPos pos : getConPos()) { for(DirPos pos : getConPos()) {
this.tryProvide(worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); this.tryProvide(worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
this.trySubscribe(tank.getTankType(), worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); this.trySubscribe(tank.getTankType(), worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
if(this.blood.getFill() > 0) this.sendFluid(blood, worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); if(this.blood.getFill() > 0) this.sendFluid(blood, worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
this.sendSmoke(pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); this.sendSmoke(pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
} }
if(burnValue > 0 && amountToBurn > 0) { if(burnValue > 0 && amountToBurn > 0) {
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10).getRotation(ForgeDirection.UP); ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10).getRotation(ForgeDirection.UP);
ForgeDirection rot = dir.getRotation(ForgeDirection.UP); ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
if(this.afterburner > 0) { if(this.afterburner > 0) {
for(int i = 0; i < 2; i++) { for(int i = 0; i < 2; i++) {
double speed = 2 + worldObj.rand.nextDouble() * 3; double speed = 2 + worldObj.rand.nextDouble() * 3;
double deviation = worldObj.rand.nextGaussian() * 0.2; double deviation = worldObj.rand.nextGaussian() * 0.2;
@ -202,15 +205,15 @@ public class TileEntityMachineTurbofan extends TileEntityMachinePolluting implem
data.setFloat("scale", 8F); data.setFloat("scale", 8F);
PacketDispatcher.wrapper.sendToAllAround(new AuxParticlePacketNT(data, this.xCoord + 0.5F - dir.offsetX * (3 - i), this.yCoord + 1.5F, this.zCoord + 0.5F - dir.offsetZ * (3 - i)), new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 150)); PacketDispatcher.wrapper.sendToAllAround(new AuxParticlePacketNT(data, this.xCoord + 0.5F - dir.offsetX * (3 - i), this.yCoord + 1.5F, this.zCoord + 0.5F - dir.offsetZ * (3 - i)), new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 150));
} }
/*if(this.afterburner > 90 && worldObj.rand.nextInt(60) == 0) { /*if(this.afterburner > 90 && worldObj.rand.nextInt(60) == 0) {
worldObj.newExplosion(null, xCoord + 0.5 + dir.offsetX * 3.5, yCoord + 0.5, zCoord + 0.5 + dir.offsetZ * 3.5, 3F, false, false); worldObj.newExplosion(null, xCoord + 0.5 + dir.offsetX * 3.5, yCoord + 0.5, zCoord + 0.5 + dir.offsetZ * 3.5, 3F, false, false);
}*/ }*/
if(this.afterburner > 90 && worldObj.rand.nextInt(30) == 0) { if(this.afterburner > 90 && worldObj.rand.nextInt(30) == 0) {
worldObj.playSoundEffect(xCoord + 0.5, yCoord + 1.5, zCoord + 0.5, "hbm:block.damage", 3.0F, 0.95F + worldObj.rand.nextFloat() * 0.2F); worldObj.playSoundEffect(xCoord + 0.5, yCoord + 1.5, zCoord + 0.5, "hbm:block.damage", 3.0F, 0.95F + worldObj.rand.nextFloat() * 0.2F);
} }
if(this.afterburner > 90) { if(this.afterburner > 90) {
NBTTagCompound data = new NBTTagCompound(); NBTTagCompound data = new NBTTagCompound();
data.setString("type", "gasfire"); data.setString("type", "gasfire");
@ -223,16 +226,16 @@ public class TileEntityMachineTurbofan extends TileEntityMachinePolluting implem
), new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 150)); ), new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 150));
} }
} }
double minX = this.xCoord + 0.5 - dir.offsetX * 3.5 - rot.offsetX * 1.5; double minX = this.xCoord + 0.5 - dir.offsetX * 3.5 - rot.offsetX * 1.5;
double maxX = this.xCoord + 0.5 - dir.offsetX * 19.5 + rot.offsetX * 1.5; double maxX = this.xCoord + 0.5 - dir.offsetX * 19.5 + rot.offsetX * 1.5;
double minZ = this.zCoord + 0.5 - dir.offsetZ * 3.5 - rot.offsetZ * 1.5; double minZ = this.zCoord + 0.5 - dir.offsetZ * 3.5 - rot.offsetZ * 1.5;
double maxZ = this.zCoord + 0.5 - dir.offsetZ * 19.5 + rot.offsetZ * 1.5; double maxZ = this.zCoord + 0.5 - dir.offsetZ * 19.5 + rot.offsetZ * 1.5;
List<Entity> list = worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(Math.min(minX, maxX), yCoord, Math.min(minZ, maxZ), Math.max(minX, maxX), yCoord + 3, Math.max(minZ, maxZ))); List<Entity> list = worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(Math.min(minX, maxX), yCoord, Math.min(minZ, maxZ), Math.max(minX, maxX), yCoord + 3, Math.max(minZ, maxZ)));
for(Entity e : list) { for(Entity e : list) {
if(this.afterburner > 0) { if(this.afterburner > 0) {
e.setFire(5); e.setFire(5);
e.attackEntityFrom(DamageSource.onFire, 5F); e.attackEntityFrom(DamageSource.onFire, 5F);
@ -240,40 +243,40 @@ public class TileEntityMachineTurbofan extends TileEntityMachinePolluting implem
e.motionX -= dir.offsetX * 0.2; e.motionX -= dir.offsetX * 0.2;
e.motionZ -= dir.offsetZ * 0.2; e.motionZ -= dir.offsetZ * 0.2;
} }
minX = this.xCoord + 0.5 + dir.offsetX * 3.5 - rot.offsetX * 1.5; minX = this.xCoord + 0.5 + dir.offsetX * 3.5 - rot.offsetX * 1.5;
maxX = this.xCoord + 0.5 + dir.offsetX * 8.5 + rot.offsetX * 1.5; maxX = this.xCoord + 0.5 + dir.offsetX * 8.5 + rot.offsetX * 1.5;
minZ = this.zCoord + 0.5 + dir.offsetZ * 3.5 - rot.offsetZ * 1.5; minZ = this.zCoord + 0.5 + dir.offsetZ * 3.5 - rot.offsetZ * 1.5;
maxZ = this.zCoord + 0.5 + dir.offsetZ * 8.5 + rot.offsetZ * 1.5; maxZ = this.zCoord + 0.5 + dir.offsetZ * 8.5 + rot.offsetZ * 1.5;
list = worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(Math.min(minX, maxX), yCoord, Math.min(minZ, maxZ), Math.max(minX, maxX), yCoord + 3, Math.max(minZ, maxZ))); list = worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(Math.min(minX, maxX), yCoord, Math.min(minZ, maxZ), Math.max(minX, maxX), yCoord + 3, Math.max(minZ, maxZ)));
for(Entity e : list) { for(Entity e : list) {
e.motionX -= dir.offsetX * 0.2; e.motionX -= dir.offsetX * 0.2;
e.motionZ -= dir.offsetZ * 0.2; e.motionZ -= dir.offsetZ * 0.2;
} }
minX = this.xCoord + 0.5 + dir.offsetX * 3.5 - rot.offsetX * 1.5; minX = this.xCoord + 0.5 + dir.offsetX * 3.5 - rot.offsetX * 1.5;
maxX = this.xCoord + 0.5 + dir.offsetX * 3.75 + rot.offsetX * 1.5; maxX = this.xCoord + 0.5 + dir.offsetX * 3.75 + rot.offsetX * 1.5;
minZ = this.zCoord + 0.5 + dir.offsetZ * 3.5 - rot.offsetZ * 1.5; minZ = this.zCoord + 0.5 + dir.offsetZ * 3.5 - rot.offsetZ * 1.5;
maxZ = this.zCoord + 0.5 + dir.offsetZ * 3.75 + rot.offsetZ * 1.5; maxZ = this.zCoord + 0.5 + dir.offsetZ * 3.75 + rot.offsetZ * 1.5;
list = worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(Math.min(minX, maxX), yCoord, Math.min(minZ, maxZ), Math.max(minX, maxX), yCoord + 3, Math.max(minZ, maxZ))); list = worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(Math.min(minX, maxX), yCoord, Math.min(minZ, maxZ), Math.max(minX, maxX), yCoord + 3, Math.max(minZ, maxZ)));
for(Entity e : list) { for(Entity e : list) {
e.attackEntityFrom(ModDamageSource.turbofan, 1000); e.attackEntityFrom(ModDamageSource.turbofan, 1000);
e.setInWeb(); e.setInWeb();
if(!e.isEntityAlive() && e instanceof EntityLivingBase) { if(!e.isEntityAlive() && e instanceof EntityLivingBase) {
NBTTagCompound vdat = new NBTTagCompound(); NBTTagCompound vdat = new NBTTagCompound();
vdat.setString("type", "giblets"); vdat.setString("type", "giblets");
vdat.setInteger("ent", e.getEntityId()); vdat.setInteger("ent", e.getEntityId());
vdat.setInteger("cDiv", 5); vdat.setInteger("cDiv", 5);
PacketDispatcher.wrapper.sendToAllAround(new AuxParticlePacketNT(vdat, e.posX, e.posY + e.height * 0.5, e.posZ), new TargetPoint(e.dimension, e.posX, e.posY + e.height * 0.5, e.posZ, 150)); PacketDispatcher.wrapper.sendToAllAround(new AuxParticlePacketNT(vdat, e.posX, e.posY + e.height * 0.5, e.posZ), new TargetPoint(e.dimension, e.posX, e.posY + e.height * 0.5, e.posZ, 150));
worldObj.playSoundEffect(e.posX, e.posY, e.posZ, "mob.zombie.woodbreak", 2.0F, 0.95F + worldObj.rand.nextFloat() * 0.2F); worldObj.playSoundEffect(e.posX, e.posY, e.posZ, "mob.zombie.woodbreak", 2.0F, 0.95F + worldObj.rand.nextFloat() * 0.2F);
blood.setFill(blood.getFill() + 50); blood.setFill(blood.getFill() + 50);
if(blood.getFill() > blood.getMaxFill()) { if(blood.getFill() > blood.getMaxFill()) {
blood.setFill(blood.getMaxFill()); blood.setFill(blood.getMaxFill());
} }
@ -281,17 +284,17 @@ public class TileEntityMachineTurbofan extends TileEntityMachinePolluting implem
} }
} }
} }
if(this.power > this.maxPower) { if(this.power > this.maxPower) {
this.power = this.maxPower; this.power = this.maxPower;
} }
this.networkPackNT(150); this.networkPackNT(150);
} else { } else {
this.lastSpin = this.spin; this.lastSpin = this.spin;
if(wasOn) { if(wasOn) {
if(this.momentum < 100F) if(this.momentum < 100F)
this.momentum++; this.momentum++;
@ -299,16 +302,16 @@ public class TileEntityMachineTurbofan extends TileEntityMachinePolluting implem
if(this.momentum > 0) if(this.momentum > 0)
this.momentum--; this.momentum--;
} }
this.spin += momentum / 2; this.spin += momentum / 2;
if(this.spin >= 360) { if(this.spin >= 360) {
this.spin -= 360F; this.spin -= 360F;
this.lastSpin -= 360F; this.lastSpin -= 360F;
} }
if(momentum > 0) { if(momentum > 0) {
if(audio == null) { if(audio == null) {
audio = createAudioLoop(); audio = createAudioLoop();
audio.startSound(); audio.startSound();
@ -319,9 +322,9 @@ public class TileEntityMachineTurbofan extends TileEntityMachinePolluting implem
audio.keepAlive(); audio.keepAlive();
audio.updateVolume(getVolume(momentum / 50F)); audio.updateVolume(getVolume(momentum / 50F));
audio.updatePitch(momentum / 200F + 0.5F + this.afterburner * 0.16F); audio.updatePitch(momentum / 200F + 0.5F + this.afterburner * 0.16F);
} else { } else {
if(audio != null) { if(audio != null) {
audio.stopSound(); audio.stopSound();
audio = null; audio = null;
@ -340,37 +343,37 @@ public class TileEntityMachineTurbofan extends TileEntityMachinePolluting implem
double maxX = this.xCoord + 0.5 - dir.offsetX * 19.5 + rot.offsetX * 1.5; double maxX = this.xCoord + 0.5 - dir.offsetX * 19.5 + rot.offsetX * 1.5;
double minZ = this.zCoord + 0.5 - dir.offsetZ * 3.5 - rot.offsetZ * 1.5; double minZ = this.zCoord + 0.5 - dir.offsetZ * 3.5 - rot.offsetZ * 1.5;
double maxZ = this.zCoord + 0.5 - dir.offsetZ * 19.5 + rot.offsetZ * 1.5; double maxZ = this.zCoord + 0.5 - dir.offsetZ * 19.5 + rot.offsetZ * 1.5;
List<Entity> list = worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(Math.min(minX, maxX), yCoord, Math.min(minZ, maxZ), Math.max(minX, maxX), yCoord + 3, Math.max(minZ, maxZ))); List<Entity> list = worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(Math.min(minX, maxX), yCoord, Math.min(minZ, maxZ), Math.max(minX, maxX), yCoord + 3, Math.max(minZ, maxZ)));
for(Entity e : list) { for(Entity e : list) {
if(e == MainRegistry.proxy.me()) { if(e == MainRegistry.proxy.me()) {
e.motionX -= dir.offsetX * 0.2; e.motionX -= dir.offsetX * 0.2;
e.motionZ -= dir.offsetZ * 0.2; e.motionZ -= dir.offsetZ * 0.2;
} }
} }
minX = this.xCoord + 0.5 + dir.offsetX * 3.5 - rot.offsetX * 1.5; minX = this.xCoord + 0.5 + dir.offsetX * 3.5 - rot.offsetX * 1.5;
maxX = this.xCoord + 0.5 + dir.offsetX * 8.5 + rot.offsetX * 1.5; maxX = this.xCoord + 0.5 + dir.offsetX * 8.5 + rot.offsetX * 1.5;
minZ = this.zCoord + 0.5 + dir.offsetZ * 3.5 - rot.offsetZ * 1.5; minZ = this.zCoord + 0.5 + dir.offsetZ * 3.5 - rot.offsetZ * 1.5;
maxZ = this.zCoord + 0.5 + dir.offsetZ * 8.5 + rot.offsetZ * 1.5; maxZ = this.zCoord + 0.5 + dir.offsetZ * 8.5 + rot.offsetZ * 1.5;
list = worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(Math.min(minX, maxX), yCoord, Math.min(minZ, maxZ), Math.max(minX, maxX), yCoord + 3, Math.max(minZ, maxZ))); list = worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(Math.min(minX, maxX), yCoord, Math.min(minZ, maxZ), Math.max(minX, maxX), yCoord + 3, Math.max(minZ, maxZ)));
for(Entity e : list) { for(Entity e : list) {
if(e == MainRegistry.proxy.me()) { if(e == MainRegistry.proxy.me()) {
e.motionX -= dir.offsetX * 0.2; e.motionX -= dir.offsetX * 0.2;
e.motionZ -= dir.offsetZ * 0.2; e.motionZ -= dir.offsetZ * 0.2;
} }
} }
minX = this.xCoord + 0.5 + dir.offsetX * 3.5 - rot.offsetX * 1.5; minX = this.xCoord + 0.5 + dir.offsetX * 3.5 - rot.offsetX * 1.5;
maxX = this.xCoord + 0.5 + dir.offsetX * 3.75 + rot.offsetX * 1.5; maxX = this.xCoord + 0.5 + dir.offsetX * 3.75 + rot.offsetX * 1.5;
minZ = this.zCoord + 0.5 + dir.offsetZ * 3.5 - rot.offsetZ * 1.5; minZ = this.zCoord + 0.5 + dir.offsetZ * 3.5 - rot.offsetZ * 1.5;
maxZ = this.zCoord + 0.5 + dir.offsetZ * 3.75 + rot.offsetZ * 1.5; maxZ = this.zCoord + 0.5 + dir.offsetZ * 3.75 + rot.offsetZ * 1.5;
list = worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(Math.min(minX, maxX), yCoord, Math.min(minZ, maxZ), Math.max(minX, maxX), yCoord + 3, Math.max(minZ, maxZ))); list = worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(Math.min(minX, maxX), yCoord, Math.min(minZ, maxZ), Math.max(minX, maxX), yCoord + 3, Math.max(minZ, maxZ)));
for(Entity e : list) { for(Entity e : list) {
if(e == MainRegistry.proxy.me()) { if(e == MainRegistry.proxy.me()) {
e.setInWeb(); e.setInWeb();
@ -401,7 +404,7 @@ public class TileEntityMachineTurbofan extends TileEntityMachinePolluting implem
tank.deserialize(buf); tank.deserialize(buf);
blood.deserialize(buf); blood.deserialize(buf);
} }
public AudioWrapper createAudioLoop() { public AudioWrapper createAudioLoop() {
return MainRegistry.proxy.getLoopedSound("hbm:block.turbofanOperate", xCoord, yCoord, zCoord, 1.0F, 50F, 1.0F, 20); return MainRegistry.proxy.getLoopedSound("hbm:block.turbofanOperate", xCoord, yCoord, zCoord, 1.0F, 50F, 1.0F, 20);
} }
@ -440,7 +443,7 @@ public class TileEntityMachineTurbofan extends TileEntityMachinePolluting implem
public void setPower(long i) { public void setPower(long i) {
this.power = i; this.power = i;
} }
@Override @Override
public AxisAlignedBB getRenderBoundingBox() { public AxisAlignedBB getRenderBoundingBox() {
return TileEntity.INFINITE_EXTENT_AABB; return TileEntity.INFINITE_EXTENT_AABB;
@ -493,9 +496,10 @@ public class TileEntityMachineTurbofan extends TileEntityMachinePolluting implem
} }
@Override @Override
public int getMaxLevel(UpgradeType type) { public HashMap<UpgradeType, Integer> getValidUpgrades() {
if(type == UpgradeType.AFTERBURN) return 3; HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
return 0; upgrades.put(UpgradeType.AFTERBURN, 3);
return upgrades;
} }
@Override @Override

View File

@ -1,10 +1,11 @@
package com.hbm.tileentity.machine.oil; package com.hbm.tileentity.machine.oil;
import java.util.HashMap;
import java.util.List; import java.util.List;
import com.hbm.blocks.ModBlocks; import com.hbm.blocks.ModBlocks;
import com.hbm.interfaces.IControlReceiver; import com.hbm.interfaces.IControlReceiver;
import com.hbm.inventory.UpgradeManager; import com.hbm.inventory.UpgradeManagerNT;
import com.hbm.inventory.container.ContainerMachineGasFlare; import com.hbm.inventory.container.ContainerMachineGasFlare;
import com.hbm.inventory.fluid.Fluids; import com.hbm.inventory.fluid.Fluids;
import com.hbm.inventory.fluid.tank.FluidTank; import com.hbm.inventory.fluid.tank.FluidTank;
@ -52,6 +53,8 @@ public class TileEntityMachineGasFlare extends TileEntityMachineBase implements
protected int fluidUsed = 0; protected int fluidUsed = 0;
protected int output = 0; protected int output = 0;
public UpgradeManagerNT upgradeManager = new UpgradeManagerNT();
public TileEntityMachineGasFlare() { public TileEntityMachineGasFlare() {
super(6); super(6);
tank = new FluidTank(Fluids.GAS, 64000); tank = new FluidTank(Fluids.GAS, 64000);
@ -117,9 +120,9 @@ public class TileEntityMachineGasFlare extends TileEntityMachineBase implements
if(isOn && tank.getFill() > 0) { if(isOn && tank.getFill() > 0) {
UpgradeManager.eval(slots, 4, 5); upgradeManager.checkSlots(this, slots, 4, 5);
int burn = Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 3); int burn = upgradeManager.getLevel(UpgradeType.SPEED);
int yield = Math.min(UpgradeManager.getLevel(UpgradeType.EFFECT), 3); int yield = upgradeManager.getLevel(UpgradeType.EFFECT);
maxVent += maxVent * burn; maxVent += maxVent * burn;
maxBurn += maxBurn * burn; maxBurn += maxBurn * burn;
@ -319,10 +322,11 @@ public class TileEntityMachineGasFlare extends TileEntityMachineBase implements
} }
@Override @Override
public int getMaxLevel(UpgradeType type) { public HashMap<UpgradeType, Integer> getValidUpgrades() {
if(type == UpgradeType.SPEED) return 3; HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
if(type == UpgradeType.EFFECT) return 3; upgrades.put(UpgradeType.SPEED, 3);
return 0; upgrades.put(UpgradeType.EFFECT, 3);
return upgrades;
} }
@Override @Override

View File

@ -1,10 +1,11 @@
package com.hbm.tileentity.machine.oil; package com.hbm.tileentity.machine.oil;
import java.util.HashMap;
import java.util.List; import java.util.List;
import com.hbm.blocks.ModBlocks; import com.hbm.blocks.ModBlocks;
import com.hbm.inventory.FluidStack; import com.hbm.inventory.FluidStack;
import com.hbm.inventory.UpgradeManager; import com.hbm.inventory.UpgradeManagerNT;
import com.hbm.inventory.container.ContainerLiquefactor; import com.hbm.inventory.container.ContainerLiquefactor;
import com.hbm.inventory.fluid.Fluids; import com.hbm.inventory.fluid.Fluids;
import com.hbm.inventory.fluid.tank.FluidTank; import com.hbm.inventory.fluid.tank.FluidTank;
@ -44,9 +45,11 @@ public class TileEntityMachineLiquefactor extends TileEntityMachineBase implemen
public int progress; public int progress;
public static final int processTimeBase = 100; public static final int processTimeBase = 100;
public int processTime; public int processTime;
public FluidTank tank; public FluidTank tank;
public UpgradeManagerNT upgradeManager = new UpgradeManagerNT();
public TileEntityMachineLiquefactor() { public TileEntityMachineLiquefactor() {
super(4); super(4);
tank = new FluidTank(Fluids.NONE, 24_000); tank = new FluidTank(Fluids.NONE, 24_000);
@ -59,42 +62,42 @@ public class TileEntityMachineLiquefactor extends TileEntityMachineBase implemen
@Override @Override
public void updateEntity() { public void updateEntity() {
if(!worldObj.isRemote) { if(!worldObj.isRemote) {
this.power = Library.chargeTEFromItems(slots, 1, power, maxPower); this.power = Library.chargeTEFromItems(slots, 1, power, maxPower);
this.updateConnections(); this.updateConnections();
UpgradeManager.eval(slots, 2, 3); upgradeManager.checkSlots(this, slots, 2, 3);
int speed = Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 3); int speed = upgradeManager.getLevel(UpgradeType.SPEED);
int power = Math.min(UpgradeManager.getLevel(UpgradeType.POWER), 3); int power = upgradeManager.getLevel(UpgradeType.POWER);
this.processTime = processTimeBase - (processTimeBase / 4) * speed; this.processTime = processTimeBase - (processTimeBase / 4) * speed;
this.usage = (usageBase + (usageBase * speed)) / (power + 1); this.usage = (usageBase + (usageBase * speed)) / (power + 1);
if(this.canProcess()) if(this.canProcess())
this.process(); this.process();
else else
this.progress = 0; this.progress = 0;
this.sendFluid(); this.sendFluid();
this.networkPackNT(50); this.networkPackNT(50);
} }
} }
private void updateConnections() { private void updateConnections() {
for(DirPos pos : getConPos()) { for(DirPos pos : getConPos()) {
this.trySubscribe(worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); this.trySubscribe(worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
} }
} }
private void sendFluid() { private void sendFluid() {
for(DirPos pos : getConPos()) { for(DirPos pos : getConPos()) {
this.sendFluid(tank, worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); this.sendFluid(tank, worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
} }
} }
private DirPos[] getConPos() { private DirPos[] getConPos() {
return new DirPos[] { return new DirPos[] {
new DirPos(xCoord, yCoord + 4, zCoord, Library.POS_Y), new DirPos(xCoord, yCoord + 4, zCoord, Library.POS_Y),
@ -115,36 +118,36 @@ public class TileEntityMachineLiquefactor extends TileEntityMachineBase implemen
public int[] getAccessibleSlotsFromSide(int side) { public int[] getAccessibleSlotsFromSide(int side) {
return new int[] { 0 }; return new int[] { 0 };
} }
public boolean canProcess() { public boolean canProcess() {
if(this.power < usage) return false; if(this.power < usage) return false;
if(slots[0] == null) return false; if(slots[0] == null) return false;
FluidStack out = LiquefactionRecipes.getOutput(slots[0]); FluidStack out = LiquefactionRecipes.getOutput(slots[0]);
if(out == null) return false; if(out == null) return false;
if(out.type != tank.getTankType() && tank.getFill() > 0) return false; if(out.type != tank.getTankType() && tank.getFill() > 0) return false;
if(out.fill + tank.getFill() > tank.getMaxFill()) return false; if(out.fill + tank.getFill() > tank.getMaxFill()) return false;
return true; return true;
} }
public void process() { public void process() {
this.power -= usage; this.power -= usage;
progress++; progress++;
if(progress >= processTime) { if(progress >= processTime) {
FluidStack out = LiquefactionRecipes.getOutput(slots[0]); FluidStack out = LiquefactionRecipes.getOutput(slots[0]);
tank.setTankType(out.type); tank.setTankType(out.type);
tank.setFill(tank.getFill() + out.fill); tank.setFill(tank.getFill() + out.fill);
this.decrStackSize(0, 1); this.decrStackSize(0, 1);
progress = 0; progress = 0;
this.markDirty(); this.markDirty();
} }
} }
@ -168,13 +171,13 @@ public class TileEntityMachineLiquefactor extends TileEntityMachineBase implemen
this.processTime = buf.readInt(); this.processTime = buf.readInt();
tank.deserialize(buf); tank.deserialize(buf);
} }
@Override @Override
public void readFromNBT(NBTTagCompound nbt) { public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt); super.readFromNBT(nbt);
tank.readFromNBT(nbt, "tank"); tank.readFromNBT(nbt, "tank");
} }
@Override @Override
public void writeToNBT(NBTTagCompound nbt) { public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt); super.writeToNBT(nbt);
@ -197,10 +200,10 @@ public class TileEntityMachineLiquefactor extends TileEntityMachineBase implemen
} }
AxisAlignedBB bb = null; AxisAlignedBB bb = null;
@Override @Override
public AxisAlignedBB getRenderBoundingBox() { public AxisAlignedBB getRenderBoundingBox() {
if(bb == null) { if(bb == null) {
bb = AxisAlignedBB.getBoundingBox( bb = AxisAlignedBB.getBoundingBox(
xCoord - 1, xCoord - 1,
@ -211,10 +214,10 @@ public class TileEntityMachineLiquefactor extends TileEntityMachineBase implemen
zCoord + 2 zCoord + 2
); );
} }
return bb; return bb;
} }
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public double getMaxRenderDistanceSquared() { public double getMaxRenderDistanceSquared() {
@ -260,10 +263,11 @@ public class TileEntityMachineLiquefactor extends TileEntityMachineBase implemen
} }
@Override @Override
public int getMaxLevel(UpgradeType type) { public HashMap<UpgradeType, Integer> getValidUpgrades() {
if(type == UpgradeType.SPEED) return 3; HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
if(type == UpgradeType.POWER) return 3; upgrades.put(UpgradeType.SPEED, 3);
return 0; upgrades.put(UpgradeType.POWER, 3);
return upgrades;
} }
@Override @Override

View File

@ -1,11 +1,12 @@
package com.hbm.tileentity.machine.oil; package com.hbm.tileentity.machine.oil;
import java.util.HashMap;
import java.util.List; import java.util.List;
import com.hbm.blocks.ModBlocks; import com.hbm.blocks.ModBlocks;
import com.hbm.handler.pollution.PollutionHandler; import com.hbm.handler.pollution.PollutionHandler;
import com.hbm.handler.pollution.PollutionHandler.PollutionType; import com.hbm.handler.pollution.PollutionHandler.PollutionType;
import com.hbm.inventory.UpgradeManager; import com.hbm.inventory.UpgradeManagerNT;
import com.hbm.inventory.container.ContainerPyroOven; import com.hbm.inventory.container.ContainerPyroOven;
import com.hbm.inventory.fluid.Fluids; import com.hbm.inventory.fluid.Fluids;
import com.hbm.inventory.fluid.tank.FluidTank; import com.hbm.inventory.fluid.tank.FluidTank;
@ -40,21 +41,23 @@ import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityMachinePyroOven extends TileEntityMachinePolluting implements IEnergyReceiverMK2, IFluidStandardTransceiver, IGUIProvider, IUpgradeInfoProvider, IFluidCopiable { public class TileEntityMachinePyroOven extends TileEntityMachinePolluting implements IEnergyReceiverMK2, IFluidStandardTransceiver, IGUIProvider, IUpgradeInfoProvider, IFluidCopiable {
public long power; public long power;
public static final long maxPower = 10_000_000; public static final long maxPower = 10_000_000;
public boolean isVenting; public boolean isVenting;
public boolean isProgressing; public boolean isProgressing;
public float progress; public float progress;
public static int consumption = 10_000; public static int consumption = 10_000;
public int prevAnim; public int prevAnim;
public int anim = 0; public int anim = 0;
public FluidTank[] tanks; public FluidTank[] tanks;
private AudioWrapper audio; private AudioWrapper audio;
public UpgradeManagerNT upgradeManager = new UpgradeManagerNT();
public TileEntityMachinePyroOven() { public TileEntityMachinePyroOven() {
super(6, 50); super(6, 50);
tanks = new FluidTank[2]; tanks = new FluidTank[2];
@ -65,7 +68,7 @@ public class TileEntityMachinePyroOven extends TileEntityMachinePolluting implem
@Override @Override
public void setInventorySlotContents(int i, ItemStack stack) { public void setInventorySlotContents(int i, ItemStack stack) {
super.setInventorySlotContents(i, stack); super.setInventorySlotContents(i, stack);
if(stack != null && stack.getItem() instanceof ItemMachineUpgrade && i >= 4 && i <= 5) { if(stack != null && stack.getItem() instanceof ItemMachineUpgrade && i >= 4 && i <= 5) {
worldObj.playSoundEffect(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5, "hbm:item.upgradePlug", 1.0F, 1.0F); worldObj.playSoundEffect(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5, "hbm:item.upgradePlug", 1.0F, 1.0F);
} }
@ -78,12 +81,12 @@ public class TileEntityMachinePyroOven extends TileEntityMachinePolluting implem
@Override @Override
public void updateEntity() { public void updateEntity() {
if(!worldObj.isRemote) { if(!worldObj.isRemote) {
this.power = Library.chargeTEFromItems(slots, 0, power, maxPower); this.power = Library.chargeTEFromItems(slots, 0, power, maxPower);
tanks[0].setType(3, slots); tanks[0].setType(3, slots);
for(DirPos pos : getConPos()) { for(DirPos pos : getConPos()) {
this.trySubscribe(worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); this.trySubscribe(worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
if(tanks[0].getTankType() != Fluids.NONE) this.trySubscribe(tanks[0].getTankType(), worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); if(tanks[0].getTankType() != Fluids.NONE) this.trySubscribe(tanks[0].getTankType(), worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
@ -93,50 +96,50 @@ public class TileEntityMachinePyroOven extends TileEntityMachinePolluting implem
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10); ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10);
ForgeDirection rot = dir.getRotation(ForgeDirection.DOWN); ForgeDirection rot = dir.getRotation(ForgeDirection.DOWN);
if(smoke.getFill() > 0) this.sendFluid(smoke, worldObj, xCoord - rot.offsetX, yCoord + 3, zCoord - rot.offsetZ, Library.POS_Y); if(smoke.getFill() > 0) this.sendFluid(smoke, worldObj, xCoord - rot.offsetX, yCoord + 3, zCoord - rot.offsetZ, Library.POS_Y);
UpgradeManager.eval(slots, 4, 5); upgradeManager.checkSlots(this, slots, 4, 5);
int speed = Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 3); int speed = upgradeManager.getLevel(UpgradeType.SPEED);
int powerSaving = Math.min(UpgradeManager.getLevel(UpgradeType.POWER), 3); int powerSaving = upgradeManager.getLevel(UpgradeType.POWER);
int overdrive = Math.min(UpgradeManager.getLevel(UpgradeType.OVERDRIVE), 3); int overdrive = upgradeManager.getLevel(UpgradeType.OVERDRIVE);
this.isProgressing = false; this.isProgressing = false;
this.isVenting = false; this.isVenting = false;
if(this.canProcess()) { if(this.canProcess()) {
PyroOvenRecipe recipe = getMatchingRecipe(); PyroOvenRecipe recipe = getMatchingRecipe();
this.progress += 1F / Math.max((recipe.duration - speed * (recipe.duration / 4)) / (overdrive * 2 + 1), 1); this.progress += 1F / Math.max((recipe.duration - speed * (recipe.duration / 4)) / (overdrive * 2 + 1), 1);
this.isProgressing = true; this.isProgressing = true;
this.power -= this.getConsumption(speed + overdrive * 2, powerSaving); this.power -= this.getConsumption(speed + overdrive * 2, powerSaving);
if(progress >= 1F) { if(progress >= 1F) {
this.progress = 0F; this.progress = 0F;
this.finishRecipe(recipe); this.finishRecipe(recipe);
this.markDirty(); this.markDirty();
} }
this.pollute(PollutionType.SOOT, PollutionHandler.SOOT_PER_SECOND); this.pollute(PollutionType.SOOT, PollutionHandler.SOOT_PER_SECOND);
} else { } else {
this.progress = 0F; this.progress = 0F;
} }
this.networkPackNT(50); this.networkPackNT(50);
} else { } else {
this.prevAnim = this.anim; this.prevAnim = this.anim;
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10); ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10);
ForgeDirection rot = dir.getRotation(ForgeDirection.DOWN); ForgeDirection rot = dir.getRotation(ForgeDirection.DOWN);
if(isProgressing) { if(isProgressing) {
this.anim++; this.anim++;
if(audio == null) { if(audio == null) {
audio = createAudioLoop(); audio = createAudioLoop();
audio.startSound(); audio.startSound();
} else if(!audio.isPlaying()) { } else if(!audio.isPlaying()) {
audio = rebootAudio(audio); audio = rebootAudio(audio);
} }
audio.keepAlive(); audio.keepAlive();
audio.updateVolume(this.getVolume(1F)); audio.updateVolume(this.getVolume(1F));
@ -146,15 +149,15 @@ public class TileEntityMachinePyroOven extends TileEntityMachinePolluting implem
if(worldObj.rand.nextInt(20) == 0) worldObj.spawnParticle("cloud", xCoord + 0.5 - rot.offsetX + dir.offsetX * 0.875, yCoord + 3, zCoord + 0.5 - rot.offsetZ + dir.offsetZ * 0.875, 0.0, 0.05, 0.0); if(worldObj.rand.nextInt(20) == 0) worldObj.spawnParticle("cloud", xCoord + 0.5 - rot.offsetX + dir.offsetX * 0.875, yCoord + 3, zCoord + 0.5 - rot.offsetZ + dir.offsetZ * 0.875, 0.0, 0.05, 0.0);
if(worldObj.rand.nextInt(20) == 0) worldObj.spawnParticle("cloud", xCoord + 0.5 - rot.offsetX + dir.offsetX * 2.375, yCoord + 3, zCoord + 0.5 - rot.offsetZ + dir.offsetZ * 2.375, 0.0, 0.05, 0.0); if(worldObj.rand.nextInt(20) == 0) worldObj.spawnParticle("cloud", xCoord + 0.5 - rot.offsetX + dir.offsetX * 2.375, yCoord + 3, zCoord + 0.5 - rot.offsetZ + dir.offsetZ * 2.375, 0.0, 0.05, 0.0);
} }
} else { } else {
if(audio != null) { if(audio != null) {
audio.stopSound(); audio.stopSound();
audio = null; audio = null;
} }
} }
if(this.isVenting) { if(this.isVenting) {
if(worldObj.getTotalWorldTime() % 2 == 0) { if(worldObj.getTotalWorldTime() % 2 == 0) {
@ -173,29 +176,29 @@ public class TileEntityMachinePyroOven extends TileEntityMachinePolluting implem
} }
} }
} }
public static int getConsumption(int speed, int powerSaving) { public static int getConsumption(int speed, int powerSaving) {
return (int) (consumption * Math.pow(speed + 1, 2)) / (powerSaving + 1); return (int) (consumption * Math.pow(speed + 1, 2)) / (powerSaving + 1);
} }
protected PyroOvenRecipe lastValidRecipe; protected PyroOvenRecipe lastValidRecipe;
public PyroOvenRecipe getMatchingRecipe() { public PyroOvenRecipe getMatchingRecipe() {
if(lastValidRecipe != null && doesRecipeMatch(lastValidRecipe)) return lastValidRecipe; if(lastValidRecipe != null && doesRecipeMatch(lastValidRecipe)) return lastValidRecipe;
for(PyroOvenRecipe rec : PyroOvenRecipes.recipes) { for(PyroOvenRecipe rec : PyroOvenRecipes.recipes) {
if(doesRecipeMatch(rec)) { if(doesRecipeMatch(rec)) {
lastValidRecipe = rec; lastValidRecipe = rec;
return rec; return rec;
} }
} }
return null; return null;
} }
public boolean doesRecipeMatch(PyroOvenRecipe recipe) { public boolean doesRecipeMatch(PyroOvenRecipe recipe) {
if(recipe.inputFluid != null) { if(recipe.inputFluid != null) {
if(tanks[0].getTankType() != recipe.inputFluid.type) return false; // recipe needs fluid, fluid doesn't match if(tanks[0].getTankType() != recipe.inputFluid.type) return false; // recipe needs fluid, fluid doesn't match
} }
@ -205,15 +208,15 @@ public class TileEntityMachinePyroOven extends TileEntityMachinePolluting implem
} else { } else {
if(slots[1] != null) return false; // recipe does not need item, but item is present if(slots[1] != null) return false; // recipe does not need item, but item is present
} }
return true; return true;
} }
public boolean canProcess() { public boolean canProcess() {
int speed = Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 3); int speed = upgradeManager.getLevel(UpgradeType.SPEED);
int powerSaving = Math.min(UpgradeManager.getLevel(UpgradeType.POWER), 3); int powerSaving = upgradeManager.getLevel(UpgradeType.POWER);
if(power < this.getConsumption(speed, powerSaving)) return false; // not enough power if(power < this.getConsumption(speed, powerSaving)) return false; // not enough power
PyroOvenRecipe recipe = this.getMatchingRecipe(); PyroOvenRecipe recipe = this.getMatchingRecipe();
if(recipe == null) return false; // no matching recipe if(recipe == null) return false; // no matching recipe
if(recipe.inputFluid != null && tanks[0].getFill() < recipe.inputFluid.fill) return false; // not enough input fluid if(recipe.inputFluid != null && tanks[0].getFill() < recipe.inputFluid.fill) return false; // not enough input fluid
@ -222,10 +225,10 @@ public class TileEntityMachinePyroOven extends TileEntityMachinePolluting implem
if(recipe.outputItem != null && slots[2] != null && recipe.outputItem.stackSize + slots[2].stackSize > slots[2].getMaxStackSize()) return false; // too much output item if(recipe.outputItem != null && slots[2] != null && recipe.outputItem.stackSize + slots[2].stackSize > slots[2].getMaxStackSize()) return false; // too much output item
if(recipe.outputItem != null && slots[2] != null && recipe.outputItem.getItem() != slots[2].getItem()) return false; // output item doesn't match if(recipe.outputItem != null && slots[2] != null && recipe.outputItem.getItem() != slots[2].getItem()) return false; // output item doesn't match
if(recipe.outputItem != null && slots[2] != null && recipe.outputItem.getItemDamage() != slots[2].getItemDamage()) return false; // output meta doesn't match if(recipe.outputItem != null && slots[2] != null && recipe.outputItem.getItemDamage() != slots[2].getItemDamage()) return false; // output meta doesn't match
return true; return true;
} }
public void finishRecipe(PyroOvenRecipe recipe) { public void finishRecipe(PyroOvenRecipe recipe) {
if(recipe.outputItem != null) { if(recipe.outputItem != null) {
if(slots[2] == null) { if(slots[2] == null) {
@ -245,11 +248,11 @@ public class TileEntityMachinePyroOven extends TileEntityMachinePolluting implem
tanks[0].setFill(tanks[0].getFill() - recipe.inputFluid.fill); tanks[0].setFill(tanks[0].getFill() - recipe.inputFluid.fill);
} }
} }
protected DirPos[] getConPos() { protected DirPos[] getConPos() {
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10); ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10);
ForgeDirection rot = dir.getRotation(ForgeDirection.DOWN); ForgeDirection rot = dir.getRotation(ForgeDirection.DOWN);
return new DirPos[] { return new DirPos[] {
new DirPos(xCoord + dir.offsetX * 2 + rot.offsetX * 3, yCoord, zCoord + dir.offsetZ * 2 + rot.offsetZ * 3, rot), new DirPos(xCoord + dir.offsetX * 2 + rot.offsetX * 3, yCoord, zCoord + dir.offsetZ * 2 + rot.offsetZ * 3, rot),
new DirPos(xCoord + dir.offsetX * 1 + rot.offsetX * 3, yCoord, zCoord + dir.offsetZ * 1 + rot.offsetZ * 3, rot), new DirPos(xCoord + dir.offsetX * 1 + rot.offsetX * 3, yCoord, zCoord + dir.offsetZ * 1 + rot.offsetZ * 3, rot),
@ -268,7 +271,7 @@ public class TileEntityMachinePyroOven extends TileEntityMachinePolluting implem
buf.writeBoolean(isProgressing); buf.writeBoolean(isProgressing);
buf.writeFloat(progress); buf.writeFloat(progress);
} }
@Override public void deserialize(ByteBuf buf) { @Override public void deserialize(ByteBuf buf) {
super.deserialize(buf); super.deserialize(buf);
tanks[0].deserialize(buf); tanks[0].deserialize(buf);
@ -278,7 +281,7 @@ public class TileEntityMachinePyroOven extends TileEntityMachinePolluting implem
isProgressing = buf.readBoolean(); isProgressing = buf.readBoolean();
progress = buf.readFloat(); progress = buf.readFloat();
} }
@Override @Override
public void readFromNBT(NBTTagCompound nbt) { public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt); super.readFromNBT(nbt);
@ -287,7 +290,7 @@ public class TileEntityMachinePyroOven extends TileEntityMachinePolluting implem
this.progress = nbt.getFloat("prog"); this.progress = nbt.getFloat("prog");
this.power = nbt.getLong("power"); this.power = nbt.getLong("power");
} }
@Override @Override
public void writeToNBT(NBTTagCompound nbt) { public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt); super.writeToNBT(nbt);
@ -296,18 +299,18 @@ public class TileEntityMachinePyroOven extends TileEntityMachinePolluting implem
nbt.setFloat("prog", progress); nbt.setFloat("prog", progress);
nbt.setLong("power", power); nbt.setLong("power", power);
} }
@Override public int[] getAccessibleSlotsFromSide(int meta) { return new int[] { 1, 2 }; } @Override public int[] getAccessibleSlotsFromSide(int meta) { return new int[] { 1, 2 }; }
@Override public boolean isItemValidForSlot(int i, ItemStack itemStack) { return i == 1; } @Override public boolean isItemValidForSlot(int i, ItemStack itemStack) { return i == 1; }
@Override public boolean canExtractItem(int i, ItemStack itemStack, int j) { return i == 2; } @Override public boolean canExtractItem(int i, ItemStack itemStack, int j) { return i == 2; }
@Override @Override
public void pollute(PollutionType type, float amount) { public void pollute(PollutionType type, float amount) {
FluidTank tank = type == PollutionType.SOOT ? smoke : type == PollutionType.HEAVYMETAL ? smoke_leaded : smoke_poison; FluidTank tank = type == PollutionType.SOOT ? smoke : type == PollutionType.HEAVYMETAL ? smoke_leaded : smoke_poison;
int fluidAmount = (int) Math.ceil(amount * 100); int fluidAmount = (int) Math.ceil(amount * 100);
tank.setFill(tank.getFill() + fluidAmount); tank.setFill(tank.getFill() + fluidAmount);
if(tank.getFill() > tank.getMaxFill()) { if(tank.getFill() > tank.getMaxFill()) {
int overflow = tank.getFill() - tank.getMaxFill(); int overflow = tank.getFill() - tank.getMaxFill();
tank.setFill(tank.getMaxFill()); tank.setFill(tank.getMaxFill());
@ -319,7 +322,7 @@ public class TileEntityMachinePyroOven extends TileEntityMachinePolluting implem
@Override public AudioWrapper createAudioLoop() { @Override public AudioWrapper createAudioLoop() {
return MainRegistry.proxy.getLoopedSound("hbm:block.pyroOperate", xCoord, yCoord, zCoord, 1.0F, 15F, 1.0F, 20); return MainRegistry.proxy.getLoopedSound("hbm:block.pyroOperate", xCoord, yCoord, zCoord, 1.0F, 15F, 1.0F, 20);
} }
@Override public void onChunkUnload() { @Override public void onChunkUnload() {
if(audio != null) { audio.stopSound(); audio = null; } if(audio != null) { audio.stopSound(); audio = null; }
} }
@ -328,15 +331,15 @@ public class TileEntityMachinePyroOven extends TileEntityMachinePolluting implem
super.invalidate(); super.invalidate();
if(audio != null) { audio.stopSound(); audio = null; } if(audio != null) { audio.stopSound(); audio = null; }
} }
AxisAlignedBB bb = null; AxisAlignedBB bb = null;
@Override @Override
public AxisAlignedBB getRenderBoundingBox() { public AxisAlignedBB getRenderBoundingBox() {
if(bb == null) bb = AxisAlignedBB.getBoundingBox(xCoord - 3, yCoord, zCoord - 3, xCoord + 4, yCoord + 3.5, zCoord + 4); if(bb == null) bb = AxisAlignedBB.getBoundingBox(xCoord - 3, yCoord, zCoord - 3, xCoord + 4, yCoord + 3.5, zCoord + 4);
return bb; return bb;
} }
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public double getMaxRenderDistanceSquared() { public double getMaxRenderDistanceSquared() {
@ -375,10 +378,11 @@ public class TileEntityMachinePyroOven extends TileEntityMachinePolluting implem
} }
@Override @Override
public int getMaxLevel(UpgradeType type) { public HashMap<UpgradeType, Integer> getValidUpgrades() {
if(type == UpgradeType.SPEED) return 3; HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
if(type == UpgradeType.POWER) return 3; upgrades.put(UpgradeType.SPEED, 3);
if(type == UpgradeType.OVERDRIVE) return 3; upgrades.put(UpgradeType.POWER, 3);
return 0; upgrades.put(UpgradeType.OVERDRIVE, 3);
return upgrades;
} }
} }

View File

@ -1,9 +1,10 @@
package com.hbm.tileentity.machine.oil; package com.hbm.tileentity.machine.oil;
import java.util.HashMap;
import java.util.List; import java.util.List;
import com.hbm.blocks.ModBlocks; import com.hbm.blocks.ModBlocks;
import com.hbm.inventory.UpgradeManager; import com.hbm.inventory.UpgradeManagerNT;
import com.hbm.inventory.container.ContainerSolidifier; import com.hbm.inventory.container.ContainerSolidifier;
import com.hbm.inventory.fluid.Fluids; import com.hbm.inventory.fluid.Fluids;
import com.hbm.inventory.fluid.tank.FluidTank; import com.hbm.inventory.fluid.tank.FluidTank;
@ -43,9 +44,11 @@ public class TileEntityMachineSolidifier extends TileEntityMachineBase implement
public int progress; public int progress;
public static final int processTimeBase = 100; public static final int processTimeBase = 100;
public int processTime; public int processTime;
public FluidTank tank; public FluidTank tank;
public UpgradeManagerNT upgradeManager = new UpgradeManagerNT();
public TileEntityMachineSolidifier() { public TileEntityMachineSolidifier() {
super(5); super(5);
tank = new FluidTank(Fluids.NONE, 24_000); tank = new FluidTank(Fluids.NONE, 24_000);
@ -58,20 +61,20 @@ public class TileEntityMachineSolidifier extends TileEntityMachineBase implement
@Override @Override
public void updateEntity() { public void updateEntity() {
if(!worldObj.isRemote) { if(!worldObj.isRemote) {
this.power = Library.chargeTEFromItems(slots, 1, power, maxPower); this.power = Library.chargeTEFromItems(slots, 1, power, maxPower);
tank.setType(4, slots); tank.setType(4, slots);
this.updateConnections(); this.updateConnections();
UpgradeManager.eval(slots, 2, 3); upgradeManager.checkSlots(this, slots, 2, 3);
int speed = Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 3); int speed = upgradeManager.getLevel(UpgradeType.SPEED);
int power = Math.min(UpgradeManager.getLevel(UpgradeType.POWER), 3); int power = upgradeManager.getLevel(UpgradeType.POWER);
this.processTime = processTimeBase - (processTimeBase / 4) * speed; this.processTime = processTimeBase - (processTimeBase / 4) * speed;
this.usage = (usageBase + (usageBase * speed)) / (power + 1); this.usage = (usageBase + (usageBase * speed)) / (power + 1);
if(this.canProcess()) if(this.canProcess())
this.process(); this.process();
else else
@ -80,14 +83,14 @@ public class TileEntityMachineSolidifier extends TileEntityMachineBase implement
this.networkPackNT(50); this.networkPackNT(50);
} }
} }
private void updateConnections() { private void updateConnections() {
for(DirPos pos : getConPos()) { for(DirPos pos : getConPos()) {
this.trySubscribe(worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); this.trySubscribe(worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
this.trySubscribe(tank.getTankType(), worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); this.trySubscribe(tank.getTankType(), worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
} }
} }
private DirPos[] getConPos() { private DirPos[] getConPos() {
return new DirPos[] { return new DirPos[] {
new DirPos(xCoord, yCoord + 4, zCoord, Library.POS_Y), new DirPos(xCoord, yCoord + 4, zCoord, Library.POS_Y),
@ -108,59 +111,59 @@ public class TileEntityMachineSolidifier extends TileEntityMachineBase implement
public int[] getAccessibleSlotsFromSide(int side) { public int[] getAccessibleSlotsFromSide(int side) {
return new int[] { 0 }; return new int[] { 0 };
} }
public boolean canProcess() { public boolean canProcess() {
if(this.power < usage) if(this.power < usage)
return false; return false;
Pair<Integer, ItemStack> out = SolidificationRecipes.getOutput(tank.getTankType()); Pair<Integer, ItemStack> out = SolidificationRecipes.getOutput(tank.getTankType());
if(out == null) if(out == null)
return false; return false;
int req = out.getKey(); int req = out.getKey();
ItemStack stack = out.getValue(); ItemStack stack = out.getValue();
if(req > tank.getFill()) if(req > tank.getFill())
return false; return false;
if(slots[0] != null) { if(slots[0] != null) {
if(slots[0].getItem() != stack.getItem()) if(slots[0].getItem() != stack.getItem())
return false; return false;
if(slots[0].getItemDamage() != stack.getItemDamage()) if(slots[0].getItemDamage() != stack.getItemDamage())
return false; return false;
if(slots[0].stackSize + stack.stackSize > slots[0].getMaxStackSize()) if(slots[0].stackSize + stack.stackSize > slots[0].getMaxStackSize())
return false; return false;
} }
return true; return true;
} }
public void process() { public void process() {
this.power -= usage; this.power -= usage;
progress++; progress++;
if(progress >= processTime) { if(progress >= processTime) {
Pair<Integer, ItemStack> out = SolidificationRecipes.getOutput(tank.getTankType()); Pair<Integer, ItemStack> out = SolidificationRecipes.getOutput(tank.getTankType());
int req = out.getKey(); int req = out.getKey();
ItemStack stack = out.getValue(); ItemStack stack = out.getValue();
tank.setFill(tank.getFill() - req); tank.setFill(tank.getFill() - req);
if(slots[0] == null) { if(slots[0] == null) {
slots[0] = stack.copy(); slots[0] = stack.copy();
} else { } else {
slots[0].stackSize += stack.stackSize; slots[0].stackSize += stack.stackSize;
} }
progress = 0; progress = 0;
this.markDirty(); this.markDirty();
} }
} }
@ -184,13 +187,13 @@ public class TileEntityMachineSolidifier extends TileEntityMachineBase implement
this.processTime = buf.readInt(); this.processTime = buf.readInt();
tank.deserialize(buf); tank.deserialize(buf);
} }
@Override @Override
public void readFromNBT(NBTTagCompound nbt) { public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt); super.readFromNBT(nbt);
tank.readFromNBT(nbt, "tank"); tank.readFromNBT(nbt, "tank");
} }
@Override @Override
public void writeToNBT(NBTTagCompound nbt) { public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt); super.writeToNBT(nbt);
@ -211,12 +214,12 @@ public class TileEntityMachineSolidifier extends TileEntityMachineBase implement
public long getMaxPower() { public long getMaxPower() {
return maxPower; return maxPower;
} }
AxisAlignedBB bb = null; AxisAlignedBB bb = null;
@Override @Override
public AxisAlignedBB getRenderBoundingBox() { public AxisAlignedBB getRenderBoundingBox() {
if(bb == null) { if(bb == null) {
bb = AxisAlignedBB.getBoundingBox( bb = AxisAlignedBB.getBoundingBox(
xCoord - 1, xCoord - 1,
@ -227,10 +230,10 @@ public class TileEntityMachineSolidifier extends TileEntityMachineBase implement
zCoord + 2 zCoord + 2
); );
} }
return bb; return bb;
} }
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public double getMaxRenderDistanceSquared() { public double getMaxRenderDistanceSquared() {
@ -276,10 +279,11 @@ public class TileEntityMachineSolidifier extends TileEntityMachineBase implement
} }
@Override @Override
public int getMaxLevel(UpgradeType type) { public HashMap<UpgradeType, Integer> getValidUpgrades() {
if(type == UpgradeType.SPEED) return 3; HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
if(type == UpgradeType.POWER) return 3; upgrades.put(UpgradeType.SPEED, 3);
return 0; upgrades.put(UpgradeType.POWER, 3);
return upgrades;
} }
@Override @Override

View File

@ -1,9 +1,10 @@
package com.hbm.tileentity.machine.oil; package com.hbm.tileentity.machine.oil;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import com.hbm.blocks.ModBlocks; import com.hbm.blocks.ModBlocks;
import com.hbm.inventory.UpgradeManager; import com.hbm.inventory.UpgradeManagerNT;
import com.hbm.inventory.fluid.Fluids; import com.hbm.inventory.fluid.Fluids;
import com.hbm.inventory.fluid.tank.FluidTank; import com.hbm.inventory.fluid.tank.FluidTank;
import com.hbm.items.machine.ItemMachineUpgrade; import com.hbm.items.machine.ItemMachineUpgrade;
@ -30,31 +31,33 @@ import net.minecraftforge.common.util.ForgeDirection;
public abstract class TileEntityOilDrillBase extends TileEntityMachineBase implements IEnergyReceiverMK2, IFluidStandardTransceiver, IConfigurableMachine, IPersistentNBT, IGUIProvider, IUpgradeInfoProvider, IFluidCopiable { public abstract class TileEntityOilDrillBase extends TileEntityMachineBase implements IEnergyReceiverMK2, IFluidStandardTransceiver, IConfigurableMachine, IPersistentNBT, IGUIProvider, IUpgradeInfoProvider, IFluidCopiable {
public int indicator = 0; public int indicator = 0;
public long power; public long power;
public FluidTank[] tanks; public FluidTank[] tanks;
public UpgradeManagerNT upgradeManager = new UpgradeManagerNT();
public TileEntityOilDrillBase() { public TileEntityOilDrillBase() {
super(8); super(8);
tanks = new FluidTank[2]; tanks = new FluidTank[2];
tanks[0] = new FluidTank(Fluids.OIL, 64_000); tanks[0] = new FluidTank(Fluids.OIL, 64_000);
tanks[1] = new FluidTank(Fluids.GAS, 64_000); tanks[1] = new FluidTank(Fluids.GAS, 64_000);
} }
@Override @Override
public void readFromNBT(NBTTagCompound nbt) { public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt); super.readFromNBT(nbt);
this.power = nbt.getLong("power"); this.power = nbt.getLong("power");
for(int i = 0; i < this.tanks.length; i++) for(int i = 0; i < this.tanks.length; i++)
this.tanks[i].readFromNBT(nbt, "t" + i); this.tanks[i].readFromNBT(nbt, "t" + i);
} }
@Override @Override
public void writeToNBT(NBTTagCompound nbt) { public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt); super.writeToNBT(nbt);
nbt.setLong("power", power); nbt.setLong("power", power);
for(int i = 0; i < this.tanks.length; i++) for(int i = 0; i < this.tanks.length; i++)
this.tanks[i].writeToNBT(nbt, "t" + i); this.tanks[i].writeToNBT(nbt, "t" + i);
@ -62,10 +65,10 @@ public abstract class TileEntityOilDrillBase extends TileEntityMachineBase imple
@Override @Override
public void writeNBT(NBTTagCompound nbt) { public void writeNBT(NBTTagCompound nbt) {
boolean empty = power == 0; boolean empty = power == 0;
for(FluidTank tank : tanks) if(tank.getFill() > 0) empty = false; for(FluidTank tank : tanks) if(tank.getFill() > 0) empty = false;
if(!empty) { if(!empty) {
nbt.setLong("power", power); nbt.setLong("power", power);
for(int i = 0; i < this.tanks.length; i++) { for(int i = 0; i < this.tanks.length; i++) {
@ -95,11 +98,11 @@ public abstract class TileEntityOilDrillBase extends TileEntityMachineBase imple
this.tanks[0].unloadTank(1, 2, slots); this.tanks[0].unloadTank(1, 2, slots);
this.tanks[1].unloadTank(3, 4, slots); this.tanks[1].unloadTank(3, 4, slots);
UpgradeManager.eval(slots, 5, 7); upgradeManager.checkSlots(this, slots, 5, 7);
this.speedLevel = Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 3); this.speedLevel = upgradeManager.getLevel(UpgradeType.SPEED);
this.energyLevel = Math.min(UpgradeManager.getLevel(UpgradeType.POWER), 3); this.energyLevel = upgradeManager.getLevel(UpgradeType.POWER);
this.overLevel = Math.min(UpgradeManager.getLevel(UpgradeType.OVERDRIVE), 3) + 1; this.overLevel = upgradeManager.getLevel(UpgradeType.OVERDRIVE) + 1;
int abLevel = Math.min(UpgradeManager.getLevel(UpgradeType.AFTERBURN), 3); int abLevel = upgradeManager.getLevel(UpgradeType.AFTERBURN);
int toBurn = Math.min(tanks[1].getFill(), abLevel * 10); int toBurn = Math.min(tanks[1].getFill(), abLevel * 10);
@ -169,7 +172,7 @@ public abstract class TileEntityOilDrillBase extends TileEntityMachineBase imple
this.indicator = buf.readInt(); this.indicator = buf.readInt();
for (FluidTank tank : tanks) tank.deserialize(buf); for (FluidTank tank : tanks) tank.deserialize(buf);
} }
public boolean canPump() { public boolean canPump() {
return true; return true;
} }
@ -177,27 +180,27 @@ public abstract class TileEntityOilDrillBase extends TileEntityMachineBase imple
@Override @Override
public void setInventorySlotContents(int i, ItemStack stack) { public void setInventorySlotContents(int i, ItemStack stack) {
super.setInventorySlotContents(i, stack); super.setInventorySlotContents(i, stack);
if(stack != null && i >= 5 && i <= 7 && stack.getItem() instanceof ItemMachineUpgrade) if(stack != null && i >= 5 && i <= 7 && stack.getItem() instanceof ItemMachineUpgrade)
worldObj.playSoundEffect(xCoord + 0.5, yCoord + 1.5, zCoord + 0.5, "hbm:item.upgradePlug", 1.0F, 1.0F); worldObj.playSoundEffect(xCoord + 0.5, yCoord + 1.5, zCoord + 0.5, "hbm:item.upgradePlug", 1.0F, 1.0F);
} }
public int getPowerReqEff() { public int getPowerReqEff() {
int req = this.getPowerReq(); int req = this.getPowerReq();
return (req + (req / 4 * this.speedLevel) - (req / 4 * this.energyLevel)) * this.overLevel; return (req + (req / 4 * this.speedLevel) - (req / 4 * this.energyLevel)) * this.overLevel;
} }
public int getDelayEff() { public int getDelayEff() {
int delay = getDelay(); int delay = getDelay();
return Math.max((delay - (delay / 4 * this.speedLevel) + (delay / 10 * this.energyLevel)) / this.overLevel, 1); return Math.max((delay - (delay / 4 * this.speedLevel) + (delay / 10 * this.energyLevel)) / this.overLevel, 1);
} }
public abstract int getPowerReq(); public abstract int getPowerReq();
public abstract int getDelay(); public abstract int getDelay();
public void tryDrill(int y) { public void tryDrill(int y) {
Block b = worldObj.getBlock(xCoord, y, zCoord); Block b = worldObj.getBlock(xCoord, y, zCoord);
if(b.getExplosionResistance(null) < 1000) { if(b.getExplosionResistance(null) < 1000) {
onDrill(y); onDrill(y);
worldObj.setBlock(xCoord, y, zCoord, ModBlocks.oil_pipe); worldObj.setBlock(xCoord, y, zCoord, ModBlocks.oil_pipe);
@ -205,72 +208,72 @@ public abstract class TileEntityOilDrillBase extends TileEntityMachineBase imple
this.indicator = 2; this.indicator = 2;
} }
} }
public void onDrill(int y) { } public void onDrill(int y) { }
public int getDrillDepth() { public int getDrillDepth() {
return 5; return 5;
} }
public boolean trySuck(int y) { public boolean trySuck(int y) {
Block b = worldObj.getBlock(xCoord, y, zCoord); Block b = worldObj.getBlock(xCoord, y, zCoord);
if(!canSuckBlock(b)) if(!canSuckBlock(b))
return false; return false;
if(!this.canPump()) if(!this.canPump())
return true; return true;
trace.clear(); trace.clear();
return suckRec(xCoord, y, zCoord, 0); return suckRec(xCoord, y, zCoord, 0);
} }
public boolean canSuckBlock(Block b) { public boolean canSuckBlock(Block b) {
return b == ModBlocks.ore_oil || b == ModBlocks.ore_oil_empty; return b == ModBlocks.ore_oil || b == ModBlocks.ore_oil_empty;
} }
protected HashSet<Tuple.Triplet<Integer, Integer, Integer>> trace = new HashSet(); protected HashSet<Tuple.Triplet<Integer, Integer, Integer>> trace = new HashSet();
public boolean suckRec(int x, int y, int z, int layer) { public boolean suckRec(int x, int y, int z, int layer) {
Triplet<Integer, Integer, Integer> pos = new Triplet(x, y, z); Triplet<Integer, Integer, Integer> pos = new Triplet(x, y, z);
if(trace.contains(pos)) if(trace.contains(pos))
return false; return false;
trace.add(pos); trace.add(pos);
if(layer > 64) if(layer > 64)
return false; return false;
Block b = worldObj.getBlock(x, y, z); Block b = worldObj.getBlock(x, y, z);
if(b == ModBlocks.ore_oil || b == ModBlocks.ore_bedrock_oil) { if(b == ModBlocks.ore_oil || b == ModBlocks.ore_bedrock_oil) {
doSuck(x, y, z); doSuck(x, y, z);
return true; return true;
} }
if(b == ModBlocks.ore_oil_empty) { if(b == ModBlocks.ore_oil_empty) {
ForgeDirection[] dirs = BobMathUtil.getShuffledDirs(); ForgeDirection[] dirs = BobMathUtil.getShuffledDirs();
for(ForgeDirection dir : dirs) { for(ForgeDirection dir : dirs) {
if(suckRec(x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ, layer + 1)) if(suckRec(x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ, layer + 1))
return true; return true;
} }
} }
return false; return false;
} }
public void doSuck(int x, int y, int z) { public void doSuck(int x, int y, int z) {
if(worldObj.getBlock(x, y, z) == ModBlocks.ore_oil) { if(worldObj.getBlock(x, y, z) == ModBlocks.ore_oil) {
onSuck(x, y, z); onSuck(x, y, z);
} }
} }
public abstract void onSuck(int x, int y, int z); public abstract void onSuck(int x, int y, int z);
@Override @Override
@ -308,7 +311,7 @@ public abstract class TileEntityOilDrillBase extends TileEntityMachineBase imple
public FluidTank[] getAllTanks() { public FluidTank[] getAllTanks() {
return tanks; return tanks;
} }
public abstract DirPos[] getConPos(); public abstract DirPos[] getConPos();
protected void updateConnections() { protected void updateConnections() {
@ -323,12 +326,13 @@ public abstract class TileEntityOilDrillBase extends TileEntityMachineBase imple
} }
@Override @Override
public int getMaxLevel(UpgradeType type) { public HashMap<UpgradeType, Integer> getValidUpgrades() {
if(type == UpgradeType.SPEED) return 3; HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
if(type == UpgradeType.POWER) return 3; upgrades.put(UpgradeType.SPEED, 3);
if(type == UpgradeType.AFTERBURN) return 3; upgrades.put(UpgradeType.POWER, 3);
if(type == UpgradeType.OVERDRIVE) return 3; upgrades.put(UpgradeType.AFTERBURN, 3);
return 0; upgrades.put(UpgradeType.OVERDRIVE, 3);
return upgrades;
} }
@Override @Override

View File

@ -1,6 +1,7 @@
package com.hbm.tileentity.turret; package com.hbm.tileentity.turret;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import com.hbm.blocks.ModBlocks; import com.hbm.blocks.ModBlocks;
@ -97,13 +98,14 @@ public class TileEntityTurretMaxwell extends TileEntityTurretBaseNT implements I
} }
@Override @Override
public int getMaxLevel(UpgradeType type) { public HashMap<UpgradeType, Integer> getValidUpgrades() {
if(type == UpgradeType.SPEED) return 27; HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
if(type == UpgradeType.POWER) return 27; upgrades.put(UpgradeType.SPEED, 27);
if(type == UpgradeType.EFFECT) return 27; upgrades.put(UpgradeType.POWER, 27);
if(type == UpgradeType.AFTERBURN) return 27; upgrades.put(UpgradeType.EFFECT, 27);
if(type == UpgradeType.OVERDRIVE) return 27; upgrades.put(UpgradeType.AFTERBURN, 27);
return 0; upgrades.put(UpgradeType.OVERDRIVE, 27);
return upgrades;
} }
@Override @Override