mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
Upgrade rework, now with 3463% more caching!
(it was slow and needed a redo)
This commit is contained in:
parent
42e200ac7a
commit
e38ce02ccf
@ -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;
|
||||
}
|
||||
}
|
||||
80
src/main/java/com/hbm/inventory/UpgradeManagerNT.java
Normal file
80
src/main/java/com/hbm/inventory/UpgradeManagerNT.java
Normal 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);
|
||||
}
|
||||
}
|
||||
@ -40,36 +40,36 @@ public abstract class GuiInfoContainer extends GuiContainer implements INEIGuiHa
|
||||
public GuiInfoContainer(Container 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) {
|
||||
if(x <= mouseX && x + width > mouseX && y < mouseY && y + height >= 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, List text) {
|
||||
|
||||
|
||||
if(x <= mouseX && x + width > mouseX && y < mouseY && y + height >= mouseY)
|
||||
this.func_146283_a(text, tPosX, tPosY);
|
||||
}
|
||||
|
||||
|
||||
public void drawInfo(String[] text, int x, int 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! */
|
||||
public List<String> getUpgradeInfo(TileEntity tile) {
|
||||
List<String> lines = new ArrayList();
|
||||
|
||||
|
||||
if(tile instanceof IUpgradeInfoProvider) {
|
||||
IUpgradeInfoProvider provider = (IUpgradeInfoProvider) tile;
|
||||
|
||||
|
||||
lines.add(I18nUtil.resolveKey("upgrade.gui.title"));
|
||||
|
||||
|
||||
for(UpgradeType type : UpgradeType.values()) {
|
||||
if(provider.canProvideInfo(type, 0, false)) {
|
||||
int maxLevel = provider.getMaxLevel(type);
|
||||
int maxLevel = provider.getValidUpgrades().get(type);
|
||||
switch(type) {
|
||||
case SPEED: lines.add(I18nUtil.resolveKey("upgrade.gui.speed", 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;
|
||||
}
|
||||
|
||||
|
||||
@Deprecated
|
||||
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)
|
||||
this.func_146283_a(Arrays.asList(text), mouseX, mouseY);
|
||||
}
|
||||
|
||||
|
||||
public void drawInfoPanel(int x, int y, int width, int height, int type) {
|
||||
|
||||
Minecraft.getMinecraft().getTextureManager().bindTexture(guiUtil);
|
||||
|
||||
|
||||
switch(type) {
|
||||
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
|
||||
@ -110,7 +110,7 @@ public abstract class GuiInfoContainer extends GuiContainer implements INEIGuiHa
|
||||
case 11: drawTexturedModalRect(x, y, 24, 32, 16, 16); break; //Large grey *
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected boolean isMouseOverSlot(Slot slot, int x, int 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;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/* Getters for external use of the GUI's rect rendering, such as NumberDisplay */
|
||||
public int getGuiTop() {
|
||||
return this.guiTop;
|
||||
}
|
||||
|
||||
|
||||
public int getGuiLeft() {
|
||||
return this.guiLeft;
|
||||
}
|
||||
|
||||
|
||||
public float getZLevel() {
|
||||
return this.zLevel;
|
||||
}
|
||||
|
||||
|
||||
public void setZLevel(float level) {
|
||||
this.zLevel = level;
|
||||
}
|
||||
|
||||
|
||||
public RenderItem getItemRenderer() {
|
||||
return this.itemRender;
|
||||
}
|
||||
|
||||
|
||||
public FontRenderer getFontRenderer() {
|
||||
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) {
|
||||
|
||||
|
||||
if(!lines.isEmpty()) {
|
||||
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
@ -189,11 +189,11 @@ public abstract class GuiInfoContainer extends GuiContainer implements INEIGuiHa
|
||||
while(iterator.hasNext()) {
|
||||
Object[] line = (Object[]) iterator.next();
|
||||
int lineWidth = 0;
|
||||
|
||||
|
||||
boolean hasStack = false;
|
||||
|
||||
|
||||
for(Object o : line) {
|
||||
|
||||
|
||||
if(o instanceof String) {
|
||||
lineWidth += font.getStringWidth((String) o);
|
||||
} else {
|
||||
@ -201,7 +201,7 @@ public abstract class GuiInfoContainer extends GuiContainer implements INEIGuiHa
|
||||
hasStack = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(hasStack) {
|
||||
height += 18;
|
||||
} 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);
|
||||
|
||||
for(int index = 0; index < lines.size(); ++index) {
|
||||
|
||||
|
||||
Object[] line = (Object[]) lines.get(index);
|
||||
int indent = 0;
|
||||
boolean hasStack = false;
|
||||
|
||||
|
||||
for(Object o : line) {
|
||||
if(!(o instanceof String)) {
|
||||
hasStack = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for(Object o : line) {
|
||||
|
||||
|
||||
if(o instanceof String) {
|
||||
font.drawStringWithShadow((String) o, minX + indent, minY + (hasStack ? 4 : 0), -1);
|
||||
indent += font.getStringWidth((String) o) + 2;
|
||||
@ -301,7 +301,7 @@ public abstract class GuiInfoContainer extends GuiContainer implements INEIGuiHa
|
||||
if(inventorySlots instanceof ContainerBase) {
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
tag.setInteger("slot", slot.slotNumber);
|
||||
|
||||
|
||||
NBTTagCompound item = new NBTTagCompound();
|
||||
stack.writeToNBT(item);
|
||||
tag.setTag("stack", item);
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.hbm.tileentity;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
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 */
|
||||
public boolean canProvideInfo(UpgradeType type, int level, 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) {
|
||||
return EnumChatFormatting.GREEN.YELLOW + ">>> " + I18nUtil.resolveKey(block.getUnlocalizedName() + ".name") + " <<<";
|
||||
}
|
||||
|
||||
@ -1,12 +1,13 @@
|
||||
package com.hbm.tileentity.machine;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import com.hbm.blocks.BlockDummyable;
|
||||
import com.hbm.blocks.ModBlocks;
|
||||
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.ContainerElectrolyserMetal;
|
||||
import com.hbm.inventory.fluid.Fluids;
|
||||
@ -49,14 +50,14 @@ import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public class TileEntityElectrolyser extends TileEntityMachineBase implements IEnergyReceiverMK2, IFluidStandardTransceiver, IControlReceiver, IGUIProvider, IUpgradeInfoProvider, IFluidCopiable, IMetalCopiable {
|
||||
|
||||
|
||||
public long power;
|
||||
public static final long maxPower = 20000000;
|
||||
public static final int usageOreBase = 10_000;
|
||||
public static final int usageFluidBase = 10_000;
|
||||
public int usageOre;
|
||||
public int usageFluid;
|
||||
|
||||
|
||||
public int progressFluid;
|
||||
public int processFluidTime = 100;
|
||||
public int progressOre;
|
||||
@ -68,6 +69,8 @@ public class TileEntityElectrolyser extends TileEntityMachineBase implements IEn
|
||||
|
||||
public FluidTank[] tanks;
|
||||
|
||||
public UpgradeManagerNT upgradeManager = new UpgradeManagerNT();
|
||||
|
||||
public TileEntityElectrolyser() {
|
||||
//0: Battery
|
||||
//1-2: Upgrades
|
||||
@ -129,9 +132,9 @@ public class TileEntityElectrolyser extends TileEntityMachineBase implements IEn
|
||||
}
|
||||
}
|
||||
|
||||
UpgradeManager.eval(slots, 1, 2);
|
||||
int speedLevel = Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 3);
|
||||
int powerLevel = Math.min(UpgradeManager.getLevel(UpgradeType.POWER), 3);
|
||||
upgradeManager.checkSlots(this, slots, 1, 2);
|
||||
int speedLevel = upgradeManager.getLevel(UpgradeType.SPEED);
|
||||
int powerLevel = upgradeManager.getLevel(UpgradeType.POWER);
|
||||
|
||||
usageOre = usageOreBase - usageOreBase * powerLevel / 4;
|
||||
usageFluid = usageFluidBase - usageFluidBase * powerLevel / 4;
|
||||
@ -390,19 +393,19 @@ public class TileEntityElectrolyser extends TileEntityMachineBase implements IEn
|
||||
public int getDurationMetal() {
|
||||
ElectrolysisMetalRecipe result = ElectrolyserMetalRecipes.getRecipe(slots[14]);
|
||||
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)));
|
||||
}
|
||||
public int getDurationFluid() {
|
||||
ElectrolysisRecipe result = ElectrolyserFluidRecipes.getRecipe(tanks[0].getTankType());
|
||||
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)));
|
||||
|
||||
}
|
||||
|
||||
public int getCycleCount() {
|
||||
int speed = UpgradeManager.getLevel(UpgradeType.OVERDRIVE);
|
||||
int speed = upgradeManager.getLevel(UpgradeType.OVERDRIVE);
|
||||
return Math.min(1 + speed * 2, 7);
|
||||
}
|
||||
|
||||
@ -513,7 +516,7 @@ public class TileEntityElectrolyser extends TileEntityMachineBase implements IEn
|
||||
|
||||
@Override
|
||||
public void receiveControl(NBTTagCompound data) { }
|
||||
|
||||
|
||||
@Override
|
||||
public void receiveControl(EntityPlayer player, NBTTagCompound data) {
|
||||
|
||||
@ -548,11 +551,12 @@ public class TileEntityElectrolyser extends TileEntityMachineBase implements IEn
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel(UpgradeType type) {
|
||||
if(type == UpgradeType.SPEED) return 3;
|
||||
if(type == UpgradeType.POWER) return 3;
|
||||
if(type == UpgradeType.OVERDRIVE) return 3;
|
||||
return 0;
|
||||
public HashMap<UpgradeType, Integer> getValidUpgrades() {
|
||||
HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
|
||||
upgrades.put(UpgradeType.SPEED, 3);
|
||||
upgrades.put(UpgradeType.POWER, 3);
|
||||
upgrades.put(UpgradeType.OVERDRIVE, 3);
|
||||
return upgrades;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
package com.hbm.tileentity.machine;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import com.hbm.blocks.ModBlocks;
|
||||
import com.hbm.handler.pollution.PollutionHandler;
|
||||
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.gui.GUIFurnaceIron;
|
||||
import com.hbm.items.machine.ItemMachineUpgrade.UpgradeType;
|
||||
@ -29,7 +30,7 @@ import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public class TileEntityFurnaceIron extends TileEntityMachineBase implements IGUIProvider, IUpgradeInfoProvider {
|
||||
|
||||
|
||||
public int maxBurnTime;
|
||||
public int burnTime;
|
||||
public boolean wasOn = false;
|
||||
@ -37,12 +38,14 @@ public class TileEntityFurnaceIron extends TileEntityMachineBase implements IGUI
|
||||
public int progress;
|
||||
public int processingTime;
|
||||
public static final int baseTime = 160;
|
||||
|
||||
|
||||
public ModuleBurnTime burnModule;
|
||||
|
||||
public UpgradeManagerNT upgradeManager = new UpgradeManagerNT();
|
||||
|
||||
public TileEntityFurnaceIron() {
|
||||
super(5);
|
||||
|
||||
|
||||
burnModule = new ModuleBurnTime()
|
||||
.setLigniteTimeMod(1.25)
|
||||
.setCoalTimeMod(1.25)
|
||||
@ -59,21 +62,21 @@ public class TileEntityFurnaceIron extends TileEntityMachineBase implements IGUI
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
|
||||
UpgradeManager.eval(slots, 4, 4);
|
||||
this.processingTime = baseTime - ((baseTime / 2) * Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 3) / 3);
|
||||
|
||||
|
||||
upgradeManager.checkSlots(this, slots, 4, 4);
|
||||
this.processingTime = baseTime - ((baseTime / 2) * upgradeManager.getLevel(UpgradeType.SPEED) / 3);
|
||||
|
||||
wasOn = false;
|
||||
|
||||
|
||||
if(burnTime <= 0) {
|
||||
|
||||
|
||||
for(int i = 1; i < 3; i++) {
|
||||
if(slots[i] != null) {
|
||||
|
||||
|
||||
int fuel = burnModule.getBurnTime(slots[i]);
|
||||
|
||||
|
||||
if(fuel > 0) {
|
||||
this.maxBurnTime = this.burnTime = fuel;
|
||||
slots[i].stackSize--;
|
||||
@ -81,33 +84,33 @@ public class TileEntityFurnaceIron extends TileEntityMachineBase implements IGUI
|
||||
if(slots[i].stackSize == 0) {
|
||||
slots[i] = slots[i].getItem().getContainerItem(slots[i]);
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(canSmelt()) {
|
||||
wasOn = true;
|
||||
this.progress++;
|
||||
this.burnTime--;
|
||||
|
||||
|
||||
if(this.progress % 15 == 0 && !this.muffled) {
|
||||
worldObj.playSoundEffect(xCoord, yCoord, zCoord, "fire.fire", 1.0F, 0.5F + worldObj.rand.nextFloat() * 0.5F);
|
||||
}
|
||||
|
||||
|
||||
if(this.progress >= this.processingTime) {
|
||||
ItemStack result = FurnaceRecipes.smelting().getSmeltingResult(slots[0]);
|
||||
|
||||
|
||||
if(slots[3] == null) {
|
||||
slots[3] = result.copy();
|
||||
} else {
|
||||
slots[3].stackSize += result.stackSize;
|
||||
}
|
||||
|
||||
|
||||
this.decrStackSize(0, 1);
|
||||
|
||||
|
||||
this.progress = 0;
|
||||
this.markDirty();
|
||||
}
|
||||
@ -118,14 +121,14 @@ public class TileEntityFurnaceIron extends TileEntityMachineBase implements IGUI
|
||||
|
||||
this.networkPackNT(50);
|
||||
} else {
|
||||
|
||||
|
||||
if(this.progress > 0) {
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10);
|
||||
ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
|
||||
|
||||
|
||||
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);
|
||||
|
||||
|
||||
if(this.progress % 5 == 0) {
|
||||
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);
|
||||
@ -155,21 +158,21 @@ public class TileEntityFurnaceIron extends TileEntityMachineBase implements IGUI
|
||||
}
|
||||
|
||||
public boolean canSmelt() {
|
||||
|
||||
|
||||
if(this.burnTime <= 0) return false;
|
||||
if(slots[0] == null) return false;
|
||||
|
||||
|
||||
ItemStack result = FurnaceRecipes.smelting().getSmeltingResult(slots[0]);
|
||||
|
||||
|
||||
if(result == null) return false;
|
||||
if(slots[3] == null) return true;
|
||||
|
||||
|
||||
if(!result.isItemEqual(slots[3])) return false;
|
||||
if(result.stackSize + slots[3].stackSize > slots[3].getMaxStackSize()) return false;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsFromSide(int meta) {
|
||||
return new int[] { 0, 1, 2, 3 };
|
||||
@ -177,13 +180,13 @@ public class TileEntityFurnaceIron extends TileEntityMachineBase implements IGUI
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemStack) {
|
||||
|
||||
|
||||
if(i == 0)
|
||||
return FurnaceRecipes.smelting().getSmeltingResult(itemStack) != null;
|
||||
|
||||
|
||||
if(i < 3)
|
||||
return burnModule.getBurnTime(itemStack) > 0;
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -191,7 +194,7 @@ public class TileEntityFurnaceIron extends TileEntityMachineBase implements IGUI
|
||||
public boolean canExtractItem(int i, ItemStack itemStack, int j) {
|
||||
return i == 3;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
super.readFromNBT(nbt);
|
||||
@ -200,7 +203,7 @@ public class TileEntityFurnaceIron extends TileEntityMachineBase implements IGUI
|
||||
this.burnTime = nbt.getInteger("burnTime");
|
||||
this.progress = nbt.getInteger("progress");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound 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) {
|
||||
return new GUIFurnaceIron(player.inventory, this);
|
||||
}
|
||||
|
||||
|
||||
AxisAlignedBB bb = null;
|
||||
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getRenderBoundingBox() {
|
||||
|
||||
|
||||
if(bb == null) {
|
||||
bb = AxisAlignedBB.getBoundingBox(
|
||||
xCoord - 1,
|
||||
@ -236,10 +239,10 @@ public class TileEntityFurnaceIron extends TileEntityMachineBase implements IGUI
|
||||
zCoord + 2
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
return bb;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public double getMaxRenderDistanceSquared() {
|
||||
@ -260,8 +263,9 @@ public class TileEntityFurnaceIron extends TileEntityMachineBase implements IGUI
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel(UpgradeType type) {
|
||||
if(type == UpgradeType.SPEED) return 3;
|
||||
return 0;
|
||||
public HashMap<UpgradeType, Integer> getValidUpgrades() {
|
||||
HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
|
||||
upgrades.put(UpgradeType.SPEED, 3);
|
||||
return upgrades;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,13 +1,14 @@
|
||||
package com.hbm.tileentity.machine;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import com.hbm.blocks.ModBlocks;
|
||||
import com.hbm.handler.pollution.PollutionHandler;
|
||||
import com.hbm.handler.pollution.PollutionHandler.PollutionType;
|
||||
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.gui.GUIMachineArcFurnaceLarge;
|
||||
import com.hbm.inventory.material.MaterialShapes;
|
||||
@ -47,7 +48,7 @@ import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public class TileEntityMachineArcFurnaceLarge extends TileEntityMachineBase implements IEnergyReceiverMK2, IControlReceiver, IGUIProvider, IUpgradeInfoProvider {
|
||||
|
||||
|
||||
public long power;
|
||||
public static final long maxPower = 2_500_000;
|
||||
public boolean liquidMode = false;
|
||||
@ -56,25 +57,27 @@ public class TileEntityMachineArcFurnaceLarge extends TileEntityMachineBase impl
|
||||
public boolean hasMaterial;
|
||||
public int delay;
|
||||
public int upgrade;
|
||||
|
||||
|
||||
public float lid;
|
||||
public float prevLid;
|
||||
public int approachNum;
|
||||
public float syncLid;
|
||||
|
||||
|
||||
private AudioWrapper audioLid;
|
||||
private AudioWrapper audioProgress;
|
||||
|
||||
|
||||
public UpgradeManagerNT upgradeManager = new UpgradeManagerNT();
|
||||
|
||||
public byte[] electrodes = new byte[3];
|
||||
public static final byte ELECTRODE_NONE = 0;
|
||||
public static final byte ELECTRODE_FRESH = 1;
|
||||
public static final byte ELECTRODE_USED = 2;
|
||||
public static final byte ELECTRODE_DEPLETED = 3;
|
||||
|
||||
|
||||
public int getMaxInputSize() {
|
||||
return upgrade == 0 ? 1 : upgrade == 1 ? 4 : upgrade == 2 ? 8 : 16;
|
||||
}
|
||||
|
||||
|
||||
public static final int maxLiquid = MaterialShapes.BLOCK.q(128);
|
||||
public List<MaterialStack> liquids = new ArrayList();
|
||||
|
||||
@ -90,7 +93,7 @@ public class TileEntityMachineArcFurnaceLarge extends TileEntityMachineBase impl
|
||||
@Override
|
||||
public void setInventorySlotContents(int i, ItemStack stack) {
|
||||
super.setInventorySlotContents(i, stack);
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
@ -98,31 +101,31 @@ public class TileEntityMachineArcFurnaceLarge extends TileEntityMachineBase impl
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
|
||||
UpgradeManager.eval(slots, 4, 4);
|
||||
this.upgrade = Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 3);
|
||||
|
||||
|
||||
upgradeManager.checkSlots(this, slots, 4, 4);
|
||||
this.upgrade = upgradeManager.getLevel(UpgradeType.SPEED);
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
|
||||
|
||||
this.power = Library.chargeTEFromItems(slots, 3, power, maxPower);
|
||||
this.isProgressing = false;
|
||||
|
||||
|
||||
for(DirPos pos : getConPos()) this.trySubscribe(worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
|
||||
|
||||
|
||||
if(power > 0) {
|
||||
|
||||
|
||||
boolean ingredients = this.hasIngredients();
|
||||
boolean electrodes = this.hasElectrodes();
|
||||
|
||||
|
||||
int consumption = (int) (1_000 * Math.pow(5, upgrade));
|
||||
|
||||
|
||||
if(ingredients && electrodes && delay <= 0 && this.liquids.isEmpty()) {
|
||||
if(lid > 0) {
|
||||
lid -= 1F / (60F / (upgrade * 0.5 + 1));
|
||||
if(lid < 0) lid = 0;
|
||||
this.progress = 0;
|
||||
} else {
|
||||
|
||||
|
||||
if(power >= consumption) {
|
||||
int duration = 400 / (upgrade * 2 + 1);
|
||||
this.progress += 1F / duration;
|
||||
@ -145,18 +148,18 @@ public class TileEntityMachineArcFurnaceLarge extends TileEntityMachineBase impl
|
||||
if(lid > 1) lid = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
hasMaterial = ingredients;
|
||||
}
|
||||
|
||||
|
||||
this.decideElectrodeState();
|
||||
|
||||
|
||||
if(!hasMaterial) hasMaterial = this.hasIngredients();
|
||||
|
||||
|
||||
if(!this.liquids.isEmpty() && this.lid > 0F) {
|
||||
|
||||
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10);
|
||||
|
||||
|
||||
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);
|
||||
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.liquids.removeIf(o -> o.amount <= 0);
|
||||
|
||||
|
||||
this.networkPackNT(150);
|
||||
} else {
|
||||
|
||||
this.prevLid = this.lid;
|
||||
|
||||
|
||||
if(this.approachNum > 0) {
|
||||
this.lid = this.lid + ((this.syncLid - this.lid) / (float) this.approachNum);
|
||||
--this.approachNum;
|
||||
} else {
|
||||
this.lid = this.syncLid;
|
||||
}
|
||||
|
||||
|
||||
if(this.lid != this.prevLid) {
|
||||
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);
|
||||
@ -198,11 +201,11 @@ public class TileEntityMachineArcFurnaceLarge extends TileEntityMachineBase impl
|
||||
this.audioLid = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
if(this.isProgressing) {
|
||||
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);
|
||||
@ -216,7 +219,7 @@ public class TileEntityMachineArcFurnaceLarge extends TileEntityMachineBase impl
|
||||
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) {
|
||||
NBTTagCompound data = new NBTTagCompound();
|
||||
data.setString("type", "tower");
|
||||
@ -233,7 +236,7 @@ public class TileEntityMachineArcFurnaceLarge extends TileEntityMachineBase impl
|
||||
data.setFloat("strafe", 0.05F);
|
||||
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) {
|
||||
/*NBTTagCompound data = new NBTTagCompound();
|
||||
data.setString("type", "tower");
|
||||
@ -249,7 +252,7 @@ public class TileEntityMachineArcFurnaceLarge extends TileEntityMachineBase impl
|
||||
data.setInteger("color", 0x808080);
|
||||
data.setFloat("strafe", 0.15F);
|
||||
MainRegistry.proxy.effectNT(data);*/
|
||||
|
||||
|
||||
if(worldObj.rand.nextInt(5) == 0) {
|
||||
NBTTagCompound flame = new NBTTagCompound();
|
||||
flame.setString("type", "rbmkflame");
|
||||
@ -262,10 +265,10 @@ public class TileEntityMachineArcFurnaceLarge extends TileEntityMachineBase impl
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void decideElectrodeState() {
|
||||
for(int i = 0; i < 3; i++) {
|
||||
|
||||
|
||||
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) {
|
||||
@ -277,26 +280,26 @@ public class TileEntityMachineArcFurnaceLarge extends TileEntityMachineBase impl
|
||||
this.electrodes[i] = this.ELECTRODE_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void process() {
|
||||
|
||||
|
||||
for(int i = 5; i < 25; i++) {
|
||||
if(slots[i] == null) continue;
|
||||
ArcFurnaceRecipe recipe = ArcFurnaceRecipes.getOutput(slots[i], this.liquidMode);
|
||||
if(recipe == null) continue;
|
||||
|
||||
|
||||
if(!liquidMode && recipe.solidOutput != null) {
|
||||
int amount = slots[i].stackSize;
|
||||
slots[i] = recipe.solidOutput.copy();
|
||||
slots[i].stackSize *= amount;
|
||||
}
|
||||
|
||||
|
||||
if(liquidMode && recipe.fluidOutput != null) {
|
||||
|
||||
|
||||
while(slots[i] != null && slots[i].stackSize > 0) {
|
||||
int liquid = this.getStackAmount(liquids);
|
||||
int toAdd = this.getStackAmount(recipe.fluidOutput);
|
||||
|
||||
|
||||
if(liquid + toAdd <= this.maxLiquid) {
|
||||
this.decrStackSize(i, 1);
|
||||
for(MaterialStack stack : recipe.fluidOutput) {
|
||||
@ -308,16 +311,16 @@ public class TileEntityMachineArcFurnaceLarge extends TileEntityMachineBase impl
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for(int i = 0; i < 3; i++) {
|
||||
if(ItemArcElectrode.damage(slots[i])) {
|
||||
slots[i] = new ItemStack(ModItems.arc_electrode_burnt, 1, slots[i].getItemDamage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean hasIngredients() {
|
||||
|
||||
|
||||
for(int i = 5; i < 25; i++) {
|
||||
if(slots[i] == null) continue;
|
||||
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.solidOutput != null) return true;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public boolean hasElectrodes() {
|
||||
for(int i = 0; i < 3; i++) {
|
||||
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;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public void addToStack(MaterialStack matStack) {
|
||||
|
||||
|
||||
for(MaterialStack mat : liquids) {
|
||||
if(mat.material == matStack.material) {
|
||||
mat.amount += matStack.amount;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
liquids.add(matStack.copy());
|
||||
}
|
||||
|
||||
|
||||
public static int getStackAmount(List<MaterialStack> stack) {
|
||||
int amount = 0;
|
||||
for(MaterialStack mat : stack) amount += mat.amount;
|
||||
return amount;
|
||||
}
|
||||
|
||||
|
||||
public static int getStackAmount(MaterialStack[] stack) {
|
||||
int amount = 0;
|
||||
for(MaterialStack mat : stack) amount += mat.amount;
|
||||
return amount;
|
||||
}
|
||||
|
||||
|
||||
protected DirPos[] getConPos() {
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10);
|
||||
ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
|
||||
|
||||
|
||||
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),
|
||||
@ -432,17 +435,17 @@ public class TileEntityMachineArcFurnaceLarge extends TileEntityMachineBase impl
|
||||
buf.writeBoolean(isProgressing);
|
||||
buf.writeBoolean(liquidMode);
|
||||
buf.writeBoolean(hasMaterial);
|
||||
|
||||
|
||||
for(int i = 0; i < 3; i++) buf.writeByte(electrodes[i]);
|
||||
|
||||
|
||||
buf.writeShort(liquids.size());
|
||||
|
||||
|
||||
for(MaterialStack mat : liquids) {
|
||||
buf.writeInt(mat.material.id);
|
||||
buf.writeInt(mat.amount);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void deserialize(ByteBuf buf) {
|
||||
super.deserialize(buf);
|
||||
@ -452,32 +455,32 @@ public class TileEntityMachineArcFurnaceLarge extends TileEntityMachineBase impl
|
||||
this.isProgressing = buf.readBoolean();
|
||||
this.liquidMode = buf.readBoolean();
|
||||
this.hasMaterial = buf.readBoolean();
|
||||
|
||||
|
||||
for(int i = 0; i < 3; i++) electrodes[i] = buf.readByte();
|
||||
|
||||
|
||||
int mats = buf.readShort();
|
||||
|
||||
|
||||
this.liquids.clear();
|
||||
for(int i = 0; i < mats; i++) {
|
||||
liquids.add(new MaterialStack(Mats.matById.get(buf.readInt()), buf.readInt()));
|
||||
}
|
||||
|
||||
|
||||
if(syncLid != 0 && syncLid != 1) this.approachNum = 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
super.readFromNBT(nbt);
|
||||
|
||||
|
||||
this.power = nbt.getLong("power");
|
||||
this.liquidMode = nbt.getBoolean("liquidMode");
|
||||
this.progress = nbt.getFloat("progress");
|
||||
this.lid = nbt.getFloat("lid");
|
||||
this.delay = nbt.getInteger("delay");
|
||||
|
||||
|
||||
int count = nbt.getShort("count");
|
||||
liquids.clear();
|
||||
|
||||
|
||||
for(int i = 0; i < count; 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("lid", lid);
|
||||
nbt.setInteger("delay", delay);
|
||||
|
||||
|
||||
int count = liquids.size();
|
||||
nbt.setShort("count", (short) count);
|
||||
for(int i = 0; i < count; i++) {
|
||||
@ -515,12 +518,12 @@ public class TileEntityMachineArcFurnaceLarge extends TileEntityMachineBase impl
|
||||
public long getMaxPower() {
|
||||
return maxPower;
|
||||
}
|
||||
|
||||
|
||||
AxisAlignedBB bb = null;
|
||||
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getRenderBoundingBox() {
|
||||
|
||||
|
||||
if(bb == null) {
|
||||
bb = AxisAlignedBB.getBoundingBox(
|
||||
xCoord - 3,
|
||||
@ -531,10 +534,10 @@ public class TileEntityMachineArcFurnaceLarge extends TileEntityMachineBase impl
|
||||
zCoord + 4
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
return bb;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public double getMaxRenderDistanceSquared() {
|
||||
@ -580,8 +583,10 @@ public class TileEntityMachineArcFurnaceLarge extends TileEntityMachineBase impl
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel(UpgradeType type) {
|
||||
if(type == UpgradeType.SPEED) return 3;
|
||||
return 0;
|
||||
public HashMap<UpgradeType, Integer> getValidUpgrades() {
|
||||
HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
|
||||
upgrades.put(UpgradeType.SPEED, 3);
|
||||
return upgrades;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
package com.hbm.tileentity.machine;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import com.hbm.inventory.RecipesCommon.AStack;
|
||||
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.fluid.Fluids;
|
||||
import com.hbm.inventory.fluid.tank.FluidTank;
|
||||
@ -38,17 +39,19 @@ import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public class TileEntityMachineArcWelder extends TileEntityMachineBase implements IEnergyReceiverMK2, IFluidStandardReceiver, IConditionalInvAccess, IGUIProvider, IUpgradeInfoProvider, IFluidCopiable {
|
||||
|
||||
|
||||
public long power;
|
||||
public long maxPower = 2_000;
|
||||
public long consumption;
|
||||
|
||||
|
||||
public int progress;
|
||||
public int processTime = 1;
|
||||
|
||||
|
||||
public FluidTank tank;
|
||||
public ItemStack display;
|
||||
|
||||
public UpgradeManagerNT upgradeManager = new UpgradeManagerNT();
|
||||
|
||||
public TileEntityMachineArcWelder() {
|
||||
super(8);
|
||||
this.tank = new FluidTank(Fluids.NONE, 24_000);
|
||||
@ -62,7 +65,7 @@ public class TileEntityMachineArcWelder extends TileEntityMachineBase implements
|
||||
@Override
|
||||
public void setInventorySlotContents(int i, ItemStack stack) {
|
||||
super.setInventorySlotContents(i, stack);
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
@ -70,48 +73,48 @@ public class TileEntityMachineArcWelder extends TileEntityMachineBase implements
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
|
||||
|
||||
this.power = Library.chargeTEFromItems(slots, 4, this.getPower(), this.getMaxPower());
|
||||
this.tank.setType(5, slots);
|
||||
|
||||
|
||||
if(worldObj.getTotalWorldTime() % 20 == 0) {
|
||||
for(DirPos pos : getConPos()) {
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ArcWelderRecipe recipe = ArcWelderRecipes.getRecipe(slots[0], slots[1], slots[2]);
|
||||
long intendedMaxPower;
|
||||
|
||||
UpgradeManager.eval(slots, 6, 7);
|
||||
int redLevel = Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 3);
|
||||
int blueLevel = Math.min(UpgradeManager.getLevel(UpgradeType.POWER), 3);
|
||||
|
||||
|
||||
upgradeManager.checkSlots(this, slots, 6, 7);
|
||||
int redLevel = upgradeManager.getLevel(UpgradeType.SPEED);
|
||||
int blueLevel = upgradeManager.getLevel(UpgradeType.POWER);
|
||||
|
||||
if(recipe != null) {
|
||||
this.processTime = recipe.duration - (recipe.duration * redLevel / 6) + (recipe.duration * blueLevel / 3);
|
||||
this.consumption = recipe.consumption + (recipe.consumption * redLevel) - (recipe.consumption * blueLevel / 6);
|
||||
intendedMaxPower = recipe.consumption * 20;
|
||||
|
||||
|
||||
if(canProcess(recipe)) {
|
||||
this.progress++;
|
||||
this.power -= this.consumption;
|
||||
|
||||
|
||||
if(progress >= processTime) {
|
||||
this.progress = 0;
|
||||
this.consumeItems(recipe);
|
||||
|
||||
|
||||
if(slots[3] == null) {
|
||||
slots[3] = recipe.output.copy();
|
||||
} else {
|
||||
slots[3].stackSize += recipe.output.stackSize;
|
||||
}
|
||||
|
||||
|
||||
this.markDirty();
|
||||
}
|
||||
|
||||
|
||||
if(worldObj.getTotalWorldTime() % 2 == 0) {
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10);
|
||||
NBTTagCompound dPart = new NBTTagCompound();
|
||||
@ -119,23 +122,23 @@ public class TileEntityMachineArcWelder extends TileEntityMachineBase implements
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
this.progress = 0;
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
this.progress = 0;
|
||||
this.consumption = 100;
|
||||
intendedMaxPower = 2000;
|
||||
}
|
||||
|
||||
|
||||
this.maxPower = Math.max(intendedMaxPower, power);
|
||||
|
||||
|
||||
this.networkPackNT(25);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void serialize(ByteBuf buf) {
|
||||
super.serialize(buf);
|
||||
@ -144,11 +147,11 @@ public class TileEntityMachineArcWelder extends TileEntityMachineBase implements
|
||||
buf.writeLong(consumption);
|
||||
buf.writeInt(progress);
|
||||
buf.writeInt(processTime);
|
||||
|
||||
|
||||
tank.serialize(buf);
|
||||
|
||||
|
||||
ArcWelderRecipe recipe = ArcWelderRecipes.getRecipe(slots[0], slots[1], slots[2]);
|
||||
|
||||
|
||||
if(recipe != null) {
|
||||
buf.writeBoolean(true);
|
||||
buf.writeInt(Item.getIdFromItem(recipe.output.getItem()));
|
||||
@ -156,7 +159,7 @@ public class TileEntityMachineArcWelder extends TileEntityMachineBase implements
|
||||
} else
|
||||
buf.writeBoolean(false);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void deserialize(ByteBuf buf) {
|
||||
super.deserialize(buf);
|
||||
@ -165,37 +168,37 @@ public class TileEntityMachineArcWelder extends TileEntityMachineBase implements
|
||||
consumption = buf.readLong();
|
||||
progress = buf.readInt();
|
||||
processTime = buf.readInt();
|
||||
|
||||
|
||||
tank.deserialize(buf);
|
||||
|
||||
|
||||
if(buf.readBoolean()) {
|
||||
this.display = new ItemStack(Item.getItemById(buf.readInt()), 1, buf.readInt());
|
||||
} else
|
||||
this.display = null;
|
||||
}
|
||||
|
||||
|
||||
public boolean canProcess(ArcWelderRecipe recipe) {
|
||||
|
||||
|
||||
if(this.power < this.consumption) return false;
|
||||
|
||||
|
||||
if(recipe.fluid != null) {
|
||||
if(this.tank.getTankType() != recipe.fluid.type) return false;
|
||||
if(this.tank.getFill() < recipe.fluid.fill) return false;
|
||||
}
|
||||
|
||||
|
||||
if(slots[3] != null) {
|
||||
if(slots[3].getItem() != recipe.output.getItem()) return false;
|
||||
if(slots[3].getItemDamage() != recipe.output.getItemDamage()) return false;
|
||||
if(slots[3].stackSize + recipe.output.stackSize > slots[3].getMaxStackSize()) return false;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public void consumeItems(ArcWelderRecipe recipe) {
|
||||
|
||||
|
||||
for(AStack aStack : recipe.ingredients) {
|
||||
|
||||
|
||||
for(int i = 0; i < 3; i++) {
|
||||
ItemStack stack = slots[i];
|
||||
if(aStack.matchesRecipe(stack, true) && stack.stackSize >= aStack.stacksize) {
|
||||
@ -204,17 +207,17 @@ public class TileEntityMachineArcWelder extends TileEntityMachineBase implements
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(recipe.fluid != null) {
|
||||
this.tank.setFill(tank.getFill() - recipe.fluid.fill);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected DirPos[] getConPos() {
|
||||
|
||||
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10);
|
||||
ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
|
||||
|
||||
|
||||
return new DirPos[] {
|
||||
new DirPos(xCoord + dir.offsetX, yCoord, zCoord + dir.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())
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
super.readFromNBT(nbt);
|
||||
@ -239,7 +242,7 @@ public class TileEntityMachineArcWelder extends TileEntityMachineBase implements
|
||||
this.processTime = nbt.getInteger("processTime");
|
||||
tank.readFromNBT(nbt, "t");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
super.writeToNBT(nbt);
|
||||
@ -312,19 +315,19 @@ public class TileEntityMachineArcWelder extends TileEntityMachineBase implements
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10);
|
||||
ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
|
||||
BlockPos core = new BlockPos(xCoord, yCoord, zCoord);
|
||||
|
||||
|
||||
//Red
|
||||
if(pos.equals(core.clone().offset(rot)) || pos.equals(core.clone().offset(rot.getOpposite()).offset(dir.getOpposite())))
|
||||
return new int[] { 0, 3 };
|
||||
|
||||
|
||||
//Yellow
|
||||
if(pos.equals(core.clone().offset(dir.getOpposite())))
|
||||
return new int[] { 1, 3 };
|
||||
|
||||
|
||||
//Green
|
||||
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[] { };
|
||||
}
|
||||
|
||||
@ -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) {
|
||||
return new GUIMachineArcWelder(player.inventory, this);
|
||||
}
|
||||
|
||||
|
||||
AxisAlignedBB bb = null;
|
||||
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getRenderBoundingBox() {
|
||||
|
||||
|
||||
if(bb == null) {
|
||||
bb = AxisAlignedBB.getBoundingBox(
|
||||
xCoord - 1,
|
||||
@ -354,10 +357,10 @@ public class TileEntityMachineArcWelder extends TileEntityMachineBase implements
|
||||
zCoord + 2
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
return bb;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public double getMaxRenderDistanceSquared() {
|
||||
@ -383,10 +386,11 @@ public class TileEntityMachineArcWelder extends TileEntityMachineBase implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel(UpgradeType type) {
|
||||
if(type == UpgradeType.SPEED) return 3;
|
||||
if(type == UpgradeType.POWER) return 3;
|
||||
return 0;
|
||||
public HashMap<UpgradeType, Integer> getValidUpgrades() {
|
||||
HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
|
||||
upgrades.put(UpgradeType.SPEED, 3);
|
||||
upgrades.put(UpgradeType.POWER, 3);
|
||||
return upgrades;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1,12 +1,13 @@
|
||||
package com.hbm.tileentity.machine;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import com.hbm.blocks.BlockDummyable;
|
||||
import com.hbm.blocks.ModBlocks;
|
||||
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.gui.GUIMachineAssembler;
|
||||
import com.hbm.items.machine.ItemMachineUpgrade.UpgradeType;
|
||||
@ -31,11 +32,13 @@ import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public class TileEntityMachineAssembler extends TileEntityMachineAssemblerBase implements IUpgradeInfoProvider {
|
||||
|
||||
|
||||
public int recipe = -1;
|
||||
|
||||
public UpgradeManagerNT upgradeManager = new UpgradeManagerNT();
|
||||
|
||||
Random rand = new Random();
|
||||
|
||||
|
||||
public TileEntityMachineAssembler() {
|
||||
super(18);
|
||||
}
|
||||
@ -50,19 +53,19 @@ public class TileEntityMachineAssembler extends TileEntityMachineAssemblerBase i
|
||||
if(i == 0)
|
||||
if(itemStack.getItem() instanceof IBatteryItem)
|
||||
return true;
|
||||
|
||||
|
||||
if(i == 1)
|
||||
return true;
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
|
||||
|
||||
//meta below 12 means that it's an old multiblock configuration
|
||||
if(this.getBlockMetadata() < 12) {
|
||||
int meta = this.getBlockMetadata();
|
||||
@ -83,18 +86,18 @@ public class TileEntityMachineAssembler extends TileEntityMachineAssemblerBase i
|
||||
worldObj.getTileEntity(xCoord, yCoord, zCoord).readFromNBT(data);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
this.updateConnections();
|
||||
|
||||
this.consumption = 100;
|
||||
this.speed = 100;
|
||||
|
||||
UpgradeManager.eval(slots, 1, 3);
|
||||
|
||||
int speedLevel = Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 3);
|
||||
int powerLevel = Math.min(UpgradeManager.getLevel(UpgradeType.POWER), 3);
|
||||
int overLevel = UpgradeManager.getLevel(UpgradeType.OVERDRIVE);
|
||||
|
||||
upgradeManager.checkSlots(this, slots, 1, 3);
|
||||
|
||||
int speedLevel = upgradeManager.getLevel(UpgradeType.SPEED);
|
||||
int powerLevel = upgradeManager.getLevel(UpgradeType.POWER);
|
||||
int overLevel = upgradeManager.getLevel(UpgradeType.OVERDRIVE);
|
||||
|
||||
speed -= speedLevel * 25;
|
||||
consumption += speedLevel * 300;
|
||||
speed += powerLevel * 5;
|
||||
@ -107,14 +110,14 @@ public class TileEntityMachineAssembler extends TileEntityMachineAssemblerBase i
|
||||
ComparableStack comp = ItemAssemblyTemplate.readType(slots[4]);
|
||||
rec = AssemblerRecipes.recipeList.indexOf(comp);
|
||||
}*/
|
||||
|
||||
|
||||
this.networkPackNT(150);
|
||||
} else {
|
||||
|
||||
|
||||
float volume = this.getVolume(2F);
|
||||
|
||||
if(isProgressing && volume > 0) {
|
||||
|
||||
|
||||
if(audio == null) {
|
||||
audio = this.createAudioLoop();
|
||||
audio.updateVolume(volume);
|
||||
@ -123,9 +126,9 @@ public class TileEntityMachineAssembler extends TileEntityMachineAssemblerBase i
|
||||
audio = rebootAudio(audio);
|
||||
audio.updateVolume(volume);
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
if(audio != null) {
|
||||
audio.stopSound();
|
||||
audio = null;
|
||||
@ -133,7 +136,7 @@ public class TileEntityMachineAssembler extends TileEntityMachineAssemblerBase i
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void serialize(ByteBuf buf) {
|
||||
super.serialize(buf);
|
||||
@ -142,11 +145,11 @@ public class TileEntityMachineAssembler extends TileEntityMachineAssemblerBase i
|
||||
buf.writeInt(progress[i]);
|
||||
buf.writeInt(maxProgress[i]);
|
||||
}
|
||||
|
||||
|
||||
buf.writeBoolean(isProgressing);
|
||||
buf.writeInt(recipe);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void deserialize(ByteBuf buf) {
|
||||
super.deserialize(buf);
|
||||
@ -155,28 +158,28 @@ public class TileEntityMachineAssembler extends TileEntityMachineAssemblerBase i
|
||||
progress[i] = buf.readInt();
|
||||
maxProgress[i] = buf.readInt();
|
||||
}
|
||||
|
||||
|
||||
isProgressing = buf.readBoolean();
|
||||
recipe = buf.readInt();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public AudioWrapper createAudioLoop() {
|
||||
return MainRegistry.proxy.getLoopedSound("hbm:block.assemblerOperate", xCoord, yCoord, zCoord, 1.0F, 10F, 1.0F);
|
||||
}
|
||||
|
||||
|
||||
private void updateConnections() {
|
||||
|
||||
|
||||
for(DirPos pos : getConPos()) {
|
||||
this.trySubscribe(worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public DirPos[] getConPos() {
|
||||
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset).getOpposite();
|
||||
ForgeDirection rot = dir.getRotation(ForgeDirection.DOWN);
|
||||
|
||||
|
||||
return new DirPos[] {
|
||||
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()),
|
||||
@ -204,7 +207,7 @@ public class TileEntityMachineAssembler extends TileEntityMachineAssemblerBase i
|
||||
audio = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private AudioWrapper audio;
|
||||
|
||||
@Override
|
||||
@ -244,12 +247,12 @@ public class TileEntityMachineAssembler extends TileEntityMachineAssemblerBase i
|
||||
public long getMaxPower() {
|
||||
return 100_000;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getRenderBoundingBox() {
|
||||
return AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 1, zCoord + 1).expand(2, 1, 2);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public double getMaxRenderDistanceSquared() {
|
||||
@ -289,10 +292,11 @@ public class TileEntityMachineAssembler extends TileEntityMachineAssemblerBase i
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel(UpgradeType type) {
|
||||
if(type == UpgradeType.SPEED) return 3;
|
||||
if(type == UpgradeType.POWER) return 3;
|
||||
if(type == UpgradeType.OVERDRIVE) return 9;
|
||||
return 0;
|
||||
public HashMap<UpgradeType, Integer> getValidUpgrades() {
|
||||
HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
|
||||
upgrades.put(UpgradeType.SPEED, 3);
|
||||
upgrades.put(UpgradeType.POWER, 3);
|
||||
upgrades.put(UpgradeType.OVERDRIVE, 3);
|
||||
return upgrades;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
package com.hbm.tileentity.machine;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import com.hbm.blocks.BlockDummyable;
|
||||
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.fluid.Fluids;
|
||||
import com.hbm.inventory.fluid.tank.FluidTank;
|
||||
@ -31,15 +32,17 @@ import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public class TileEntityMachineAssemfac extends TileEntityMachineAssemblerBase implements IFluidStandardTransceiver, IUpgradeInfoProvider, IFluidCopiable {
|
||||
|
||||
|
||||
public AssemblerArm[] arms;
|
||||
|
||||
public FluidTank water;
|
||||
public FluidTank steam;
|
||||
|
||||
public UpgradeManagerNT upgradeManager = new UpgradeManagerNT();
|
||||
|
||||
public TileEntityMachineAssemfac() {
|
||||
super(14 * 8 + 4 + 1); //8 assembler groups with 14 slots, 4 upgrade slots, 1 battery slot
|
||||
|
||||
|
||||
arms = new AssemblerArm[6];
|
||||
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
|
||||
@ -57,7 +60,7 @@ public class TileEntityMachineAssemfac extends TileEntityMachineAssemblerBase im
|
||||
@Override
|
||||
public void setInventorySlotContents(int i, ItemStack stack) {
|
||||
super.setInventorySlotContents(i, stack);
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
@ -66,37 +69,37 @@ public class TileEntityMachineAssemfac extends TileEntityMachineAssemblerBase im
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
|
||||
|
||||
if(worldObj.getTotalWorldTime() % 20 == 0) {
|
||||
this.updateConnections();
|
||||
}
|
||||
|
||||
|
||||
this.speed = 100;
|
||||
this.consumption = 100;
|
||||
|
||||
UpgradeManager.eval(slots, 1, 4);
|
||||
|
||||
int speedLevel = Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 6);
|
||||
int powerLevel = Math.min(UpgradeManager.getLevel(UpgradeType.POWER), 3);
|
||||
int overLevel = UpgradeManager.getLevel(UpgradeType.OVERDRIVE);
|
||||
|
||||
upgradeManager.checkSlots(this, slots, 1, 4);
|
||||
|
||||
int speedLevel = upgradeManager.getLevel(UpgradeType.SPEED);
|
||||
int powerLevel = upgradeManager.getLevel(UpgradeType.POWER);
|
||||
int overLevel = upgradeManager.getLevel(UpgradeType.OVERDRIVE);
|
||||
|
||||
this.speed -= speedLevel * 15;
|
||||
this.consumption += speedLevel * 300;
|
||||
this.speed += powerLevel * 5;
|
||||
this.consumption -= powerLevel * 30;
|
||||
this.speed /= (overLevel + 1);
|
||||
this.consumption *= (overLevel + 1);
|
||||
|
||||
|
||||
for(DirPos pos : getConPos()) {
|
||||
this.sendFluid(steam, worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
|
||||
}
|
||||
|
||||
|
||||
this.networkPackNT(150);
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
for(AssemblerArm arm : arms) {
|
||||
arm.updateInterp();
|
||||
if(isProgressing) {
|
||||
@ -105,7 +108,7 @@ public class TileEntityMachineAssemfac extends TileEntityMachineAssemblerBase im
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void serialize(ByteBuf buf) {
|
||||
super.serialize(buf);
|
||||
@ -118,7 +121,7 @@ public class TileEntityMachineAssemfac extends TileEntityMachineAssemblerBase im
|
||||
water.serialize(buf);
|
||||
steam.serialize(buf);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void deserialize(ByteBuf buf) {
|
||||
super.deserialize(buf);
|
||||
@ -131,7 +134,7 @@ public class TileEntityMachineAssemfac extends TileEntityMachineAssemblerBase im
|
||||
water.deserialize(buf);
|
||||
steam.deserialize(buf);
|
||||
}
|
||||
|
||||
|
||||
private int getWaterRequired() {
|
||||
return 1000 / this.speed;
|
||||
}
|
||||
@ -147,19 +150,19 @@ public class TileEntityMachineAssemfac extends TileEntityMachineAssemblerBase im
|
||||
this.water.setFill(this.water.getFill() - getWaterRequired());
|
||||
this.steam.setFill(this.steam.getFill() + getWaterRequired());
|
||||
}
|
||||
|
||||
|
||||
private void updateConnections() {
|
||||
for(DirPos pos : getConPos()) {
|
||||
this.trySubscribe(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() {
|
||||
|
||||
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset);
|
||||
ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
|
||||
|
||||
|
||||
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 * 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)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static class AssemblerArm {
|
||||
public double[] angles = new double[4];
|
||||
public double[] prevAngles = new double[4];
|
||||
public double[] targetAngles = new double[4];
|
||||
public double[] speed = new double[4];
|
||||
|
||||
|
||||
Random rand = new Random();
|
||||
|
||||
|
||||
int actionMode;
|
||||
ArmActionState state;
|
||||
int actionDelay = 0;
|
||||
|
||||
|
||||
public AssemblerArm(int actionMode) {
|
||||
this.actionMode = actionMode;
|
||||
|
||||
|
||||
if(this.actionMode == 0) {
|
||||
speed[0] = 15; //Pivot
|
||||
speed[1] = 15; //Arm
|
||||
@ -198,19 +201,19 @@ public class TileEntityMachineAssemfac extends TileEntityMachineAssemblerBase im
|
||||
speed[2] = 1; //Piston
|
||||
speed[3] = 0.125; //Striker
|
||||
}
|
||||
|
||||
|
||||
state = ArmActionState.ASSUME_POSITION;
|
||||
chooseNewArmPoistion();
|
||||
actionDelay = rand.nextInt(20);
|
||||
}
|
||||
|
||||
|
||||
public void updateArm() {
|
||||
|
||||
|
||||
if(actionDelay > 0) {
|
||||
actionDelay--;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
switch(state) {
|
||||
//Move. If done moving, set a delay and progress to EXTEND
|
||||
case ASSUME_POSITION:
|
||||
@ -254,12 +257,12 @@ public class TileEntityMachineAssemfac extends TileEntityMachineAssemblerBase im
|
||||
state = ArmActionState.ASSUME_POSITION;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void chooseNewArmPoistion() {
|
||||
|
||||
|
||||
if(this.actionMode == 0) {
|
||||
targetAngles[0] = -rand.nextInt(50); //Pivot
|
||||
targetAngles[1] = -targetAngles[0]; //Arm
|
||||
@ -270,45 +273,45 @@ public class TileEntityMachineAssemfac extends TileEntityMachineAssemblerBase im
|
||||
targetAngles[2] = rand.nextInt(10) + 10; //Piston
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void updateInterp() {
|
||||
for(int i = 0; i < angles.length; i++) {
|
||||
prevAngles[i] = angles[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return True when it has finished moving
|
||||
*/
|
||||
private boolean move() {
|
||||
boolean didMove = false;
|
||||
|
||||
|
||||
for(int i = 0; i < angles.length; i++) {
|
||||
if(angles[i] == targetAngles[i])
|
||||
continue;
|
||||
|
||||
|
||||
didMove = true;
|
||||
|
||||
|
||||
double angle = angles[i];
|
||||
double target = targetAngles[i];
|
||||
double turn = speed[i];
|
||||
double delta = Math.abs(angle - target);
|
||||
|
||||
|
||||
if(delta <= turn) {
|
||||
angles[i] = targetAngles[i];
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if(angle < target) {
|
||||
angles[i] += turn;
|
||||
} else {
|
||||
angles[i] -= turn;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return !didMove;
|
||||
}
|
||||
|
||||
|
||||
public static enum ArmActionState {
|
||||
ASSUME_POSITION,
|
||||
EXTEND_STRIKER,
|
||||
@ -316,12 +319,12 @@ public class TileEntityMachineAssemfac extends TileEntityMachineAssemblerBase im
|
||||
RETRACT_STRIKER
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
AxisAlignedBB bb = null;
|
||||
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getRenderBoundingBox() {
|
||||
|
||||
|
||||
if(bb == null) {
|
||||
bb = AxisAlignedBB.getBoundingBox(
|
||||
xCoord - 5,
|
||||
@ -332,10 +335,10 @@ public class TileEntityMachineAssemfac extends TileEntityMachineAssemblerBase im
|
||||
zCoord + 5
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
return bb;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public double getMaxRenderDistanceSquared() {
|
||||
@ -364,42 +367,42 @@ public class TileEntityMachineAssemfac extends TileEntityMachineAssemblerBase im
|
||||
|
||||
DirPos[] inpos;
|
||||
DirPos[] outpos;
|
||||
|
||||
|
||||
@Override
|
||||
public DirPos[] getInputPositions() {
|
||||
|
||||
|
||||
if(inpos != null)
|
||||
return inpos;
|
||||
|
||||
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset);
|
||||
ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
|
||||
|
||||
|
||||
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 * 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 * 1 + rot.offsetX * 5, yCoord, zCoord + dir.offsetZ * 1 + rot.offsetZ * 5, rot)
|
||||
};
|
||||
|
||||
|
||||
return inpos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DirPos[] getOutputPositions() {
|
||||
|
||||
|
||||
if(outpos != null)
|
||||
return outpos;
|
||||
|
||||
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset);
|
||||
ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
|
||||
|
||||
|
||||
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 * 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 * 2 + rot.offsetX * 5, yCoord, zCoord - dir.offsetZ * 2 + rot.offsetZ * 5, rot)
|
||||
};
|
||||
|
||||
|
||||
return outpos;
|
||||
}
|
||||
|
||||
@ -456,11 +459,12 @@ public class TileEntityMachineAssemfac extends TileEntityMachineAssemblerBase im
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel(UpgradeType type) {
|
||||
if(type == UpgradeType.SPEED) return 6;
|
||||
if(type == UpgradeType.POWER) return 3;
|
||||
if(type == UpgradeType.OVERDRIVE) return 12;
|
||||
return 0;
|
||||
public HashMap<UpgradeType, Integer> getValidUpgrades() {
|
||||
HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
|
||||
upgrades.put(UpgradeType.SPEED, 6);
|
||||
upgrades.put(UpgradeType.POWER, 3);
|
||||
upgrades.put(UpgradeType.OVERDRIVE, 12);
|
||||
return upgrades;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1,12 +1,13 @@
|
||||
package com.hbm.tileentity.machine;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
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.gui.GUIMachineCentrifuge;
|
||||
import com.hbm.inventory.recipes.CentrifugeRecipes;
|
||||
@ -38,12 +39,12 @@ import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public class TileEntityMachineCentrifuge extends TileEntityMachineBase implements IEnergyReceiverMK2, IGUIProvider, IUpgradeInfoProvider, IInfoProviderEC, IConfigurableMachine{
|
||||
|
||||
|
||||
public int progress;
|
||||
public long power;
|
||||
public boolean isProgressing;
|
||||
private int audioDuration = 0;
|
||||
|
||||
|
||||
private AudioWrapper audio;
|
||||
|
||||
//configurable values
|
||||
@ -51,6 +52,8 @@ public class TileEntityMachineCentrifuge extends TileEntityMachineBase implement
|
||||
public static int processingSpeed = 200;
|
||||
public static int baseConsumption = 200;
|
||||
|
||||
public UpgradeManagerNT upgradeManager = new UpgradeManagerNT();
|
||||
|
||||
public String getConfigName() {
|
||||
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
|
||||
* 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.
|
||||
*/
|
||||
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() {
|
||||
super(8);
|
||||
}
|
||||
|
||||
|
||||
public String getName() {
|
||||
return "container.centrifuge";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemStack) {
|
||||
return i == 0;
|
||||
@ -126,7 +129,7 @@ public class TileEntityMachineCentrifuge extends TileEntityMachineBase implement
|
||||
return false;
|
||||
}
|
||||
ItemStack[] out = CentrifugeRecipes.getOutput(slots[0]);
|
||||
|
||||
|
||||
if(out == null) {
|
||||
return false;
|
||||
}
|
||||
@ -175,7 +178,7 @@ public class TileEntityMachineCentrifuge extends TileEntityMachineBase implement
|
||||
public boolean isProcessing() {
|
||||
return this.progress > 0;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
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);
|
||||
|
||||
power = Library.chargeTEFromItems(slots, 1, power, maxPower);
|
||||
|
||||
|
||||
int consumption = baseConsumption;
|
||||
int speed = 1;
|
||||
|
||||
UpgradeManager.eval(slots, 6, 7);
|
||||
speed += Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 3);
|
||||
consumption += Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 3) * baseConsumption;
|
||||
|
||||
speed *= (1 + Math.min(UpgradeManager.getLevel(UpgradeType.OVERDRIVE), 3) * 5);
|
||||
consumption += Math.min(UpgradeManager.getLevel(UpgradeType.OVERDRIVE), 3) * baseConsumption * 50;
|
||||
|
||||
consumption /= (1 + Math.min(UpgradeManager.getLevel(UpgradeType.POWER), 3));
|
||||
|
||||
upgradeManager.checkSlots(this, slots, 6, 7);
|
||||
speed += upgradeManager.getLevel(UpgradeType.SPEED);
|
||||
consumption += upgradeManager.getLevel(UpgradeType.SPEED) * baseConsumption;
|
||||
|
||||
speed *= (1 + upgradeManager.getLevel(UpgradeType.OVERDRIVE) * 5);
|
||||
consumption += upgradeManager.getLevel(UpgradeType.OVERDRIVE) * baseConsumption * 50;
|
||||
|
||||
consumption /= (1 + upgradeManager.getLevel(UpgradeType.POWER));
|
||||
|
||||
if(hasPower() && isProcessing()) {
|
||||
this.power -= consumption;
|
||||
@ -221,20 +224,20 @@ public class TileEntityMachineCentrifuge extends TileEntityMachineBase implement
|
||||
} else {
|
||||
progress = 0;
|
||||
}
|
||||
|
||||
|
||||
this.networkPackNT(50);
|
||||
} else {
|
||||
|
||||
|
||||
if(isProgressing) {
|
||||
audioDuration += 2;
|
||||
} else {
|
||||
audioDuration -= 3;
|
||||
}
|
||||
|
||||
|
||||
audioDuration = MathHelper.clamp_int(audioDuration, 0, 60);
|
||||
|
||||
|
||||
if(audioDuration > 10) {
|
||||
|
||||
|
||||
if(audio == null) {
|
||||
audio = createAudioLoop();
|
||||
audio.startSound();
|
||||
@ -244,9 +247,9 @@ public class TileEntityMachineCentrifuge extends TileEntityMachineBase implement
|
||||
|
||||
audio.updateVolume(getVolume(1F));
|
||||
audio.updatePitch((audioDuration - 10) / 100F + 0.5F);
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
if(audio != null) {
|
||||
audio.stopSound();
|
||||
audio = null;
|
||||
@ -254,7 +257,7 @@ public class TileEntityMachineCentrifuge extends TileEntityMachineBase implement
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void serialize(ByteBuf buf) {
|
||||
super.serialize(buf);
|
||||
@ -262,7 +265,7 @@ public class TileEntityMachineCentrifuge extends TileEntityMachineBase implement
|
||||
buf.writeInt(progress);
|
||||
buf.writeBoolean(isProgressing);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void deserialize(ByteBuf buf) {
|
||||
super.deserialize(buf);
|
||||
@ -295,12 +298,12 @@ public class TileEntityMachineCentrifuge extends TileEntityMachineBase implement
|
||||
audio = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
AxisAlignedBB bb = null;
|
||||
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getRenderBoundingBox() {
|
||||
|
||||
|
||||
if(bb == null) {
|
||||
bb = AxisAlignedBB.getBoundingBox(
|
||||
xCoord,
|
||||
@ -311,7 +314,7 @@ public class TileEntityMachineCentrifuge extends TileEntityMachineBase implement
|
||||
zCoord + 1
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
return bb;
|
||||
}
|
||||
|
||||
@ -369,11 +372,12 @@ public class TileEntityMachineCentrifuge extends TileEntityMachineBase implement
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel(UpgradeType type) {
|
||||
if(type == UpgradeType.SPEED) return 3;
|
||||
if(type == UpgradeType.POWER) return 3;
|
||||
if(type == UpgradeType.OVERDRIVE) return 3;
|
||||
return 0;
|
||||
public HashMap<UpgradeType, Integer> getValidUpgrades() {
|
||||
HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
|
||||
upgrades.put(UpgradeType.SPEED, 3);
|
||||
upgrades.put(UpgradeType.POWER, 3);
|
||||
upgrades.put(UpgradeType.OVERDRIVE, 3);
|
||||
return upgrades;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -381,4 +385,4 @@ public class TileEntityMachineCentrifuge extends TileEntityMachineBase implement
|
||||
data.setBoolean(CompatEnergyControl.B_ACTIVE, this.progress > 0);
|
||||
data.setInteger(CompatEnergyControl.B_ACTIVE, this.progress);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,12 +1,13 @@
|
||||
package com.hbm.tileentity.machine;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import com.hbm.blocks.BlockDummyable;
|
||||
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.fluid.Fluids;
|
||||
import com.hbm.inventory.fluid.tank.FluidTank;
|
||||
@ -33,7 +34,7 @@ import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public class TileEntityMachineChemfac extends TileEntityMachineChemplantBase implements IUpgradeInfoProvider, IFluidCopiable {
|
||||
|
||||
|
||||
float rotSpeed;
|
||||
public float rot;
|
||||
public float prevRot;
|
||||
@ -41,6 +42,8 @@ public class TileEntityMachineChemfac extends TileEntityMachineChemplantBase imp
|
||||
public FluidTank water;
|
||||
public FluidTank steam;
|
||||
|
||||
public UpgradeManagerNT upgradeManager = new UpgradeManagerNT();
|
||||
|
||||
public TileEntityMachineChemfac() {
|
||||
super(77);
|
||||
|
||||
@ -51,7 +54,7 @@ public class TileEntityMachineChemfac extends TileEntityMachineChemplantBase imp
|
||||
@Override
|
||||
public void setInventorySlotContents(int i, ItemStack stack) {
|
||||
super.setInventorySlotContents(i, stack);
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
@ -60,14 +63,14 @@ public class TileEntityMachineChemfac extends TileEntityMachineChemplantBase imp
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
|
||||
|
||||
if(worldObj.getTotalWorldTime() % 60 == 0) {
|
||||
|
||||
|
||||
for(DirPos pos : getConPos()) {
|
||||
this.trySubscribe(worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
|
||||
|
||||
|
||||
for(FluidTank tank : inTanks()) {
|
||||
if(tank.getTankType() != Fluids.NONE) {
|
||||
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()) {
|
||||
if(tank.getTankType() != Fluids.NONE && tank.getFill() > 0) {
|
||||
this.sendFluid(tank, worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.speed = 100;
|
||||
this.consumption = 100;
|
||||
|
||||
UpgradeManager.eval(slots, 1, 4);
|
||||
|
||||
int speedLevel = Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 6);
|
||||
int powerLevel = Math.min(UpgradeManager.getLevel(UpgradeType.POWER), 3);
|
||||
int overLevel = UpgradeManager.getLevel(UpgradeType.OVERDRIVE);
|
||||
|
||||
upgradeManager.checkSlots(this, slots, 1, 4);
|
||||
|
||||
int speedLevel = upgradeManager.getLevel(UpgradeType.SPEED);
|
||||
int powerLevel = upgradeManager.getLevel(UpgradeType.POWER);
|
||||
int overLevel = upgradeManager.getLevel(UpgradeType.OVERDRIVE);
|
||||
|
||||
this.speed -= speedLevel * 15;
|
||||
this.consumption += speedLevel * 300;
|
||||
this.speed += powerLevel * 5;
|
||||
this.consumption -= powerLevel * 20;
|
||||
this.speed /= (overLevel + 1);
|
||||
this.consumption *= (overLevel + 1);
|
||||
|
||||
|
||||
if(this.speed <= 0) {
|
||||
this.speed = 1;
|
||||
}
|
||||
|
||||
|
||||
this.networkPackNT(150);
|
||||
} else {
|
||||
|
||||
|
||||
float maxSpeed = 30F;
|
||||
|
||||
|
||||
if(isProgressing) {
|
||||
|
||||
|
||||
rotSpeed += 0.1;
|
||||
|
||||
|
||||
if(rotSpeed > maxSpeed)
|
||||
rotSpeed = maxSpeed;
|
||||
|
||||
|
||||
if(rotSpeed == maxSpeed && this.worldObj.getTotalWorldTime() % 5 == 0) {
|
||||
|
||||
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset).getOpposite();
|
||||
ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
|
||||
Random rand = worldObj.rand;
|
||||
|
||||
|
||||
double x = xCoord + 0.5 - rot.offsetX * 0.5;
|
||||
double y = yCoord + 3;
|
||||
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 * 0.5 + rand.nextGaussian() * 0.15, y, z - dir.offsetZ * 0.5 + rand.nextGaussian() * 0.15, 0.0, 0.15, 0.0);
|
||||
}
|
||||
} else {
|
||||
|
||||
|
||||
rotSpeed -= 0.1;
|
||||
|
||||
|
||||
if(rotSpeed < 0)
|
||||
rotSpeed = 0;
|
||||
}
|
||||
|
||||
|
||||
prevRot = rot;
|
||||
|
||||
|
||||
rot += rotSpeed;
|
||||
|
||||
|
||||
if(rot >= 360) {
|
||||
rot -= 360;
|
||||
prevRot -= 360;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void serialize(ByteBuf buf) {
|
||||
super.serialize(buf);
|
||||
@ -154,15 +157,15 @@ public class TileEntityMachineChemfac extends TileEntityMachineChemplantBase imp
|
||||
buf.writeInt(progress[i]);
|
||||
buf.writeInt(maxProgress[i]);
|
||||
}
|
||||
|
||||
|
||||
buf.writeBoolean(isProgressing);
|
||||
|
||||
|
||||
for(int i = 0; i < tanks.length; i++) tanks[i].serialize(buf);
|
||||
|
||||
|
||||
water.serialize(buf);
|
||||
steam.serialize(buf);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void deserialize(ByteBuf buf) {
|
||||
super.deserialize(buf);
|
||||
@ -171,15 +174,15 @@ public class TileEntityMachineChemfac extends TileEntityMachineChemplantBase imp
|
||||
progress[i] = buf.readInt();
|
||||
maxProgress[i] = buf.readInt();
|
||||
}
|
||||
|
||||
|
||||
isProgressing = buf.readBoolean();
|
||||
|
||||
|
||||
for(int i = 0; i < tanks.length; i++) tanks[i].deserialize(buf);
|
||||
|
||||
|
||||
water.deserialize(buf);
|
||||
steam.deserialize(buf);
|
||||
}
|
||||
|
||||
|
||||
private int getWaterRequired() {
|
||||
return 1000 / this.speed;
|
||||
}
|
||||
@ -201,19 +204,19 @@ public class TileEntityMachineChemfac extends TileEntityMachineChemplantBase imp
|
||||
public long getMaxPower() {
|
||||
return 10_000_000;
|
||||
}
|
||||
|
||||
|
||||
protected List<DirPos> conPos;
|
||||
|
||||
|
||||
protected List<DirPos> getConPos() {
|
||||
|
||||
|
||||
if(conPos != null && !conPos.isEmpty())
|
||||
return conPos;
|
||||
|
||||
|
||||
conPos = new ArrayList();
|
||||
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset).getOpposite();
|
||||
ForgeDirection rot = dir.getRotation(ForgeDirection.DOWN);
|
||||
|
||||
|
||||
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 * 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()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return conPos;
|
||||
}
|
||||
|
||||
@ -249,52 +252,52 @@ public class TileEntityMachineChemfac extends TileEntityMachineChemplantBase imp
|
||||
|
||||
DirPos[] inpos;
|
||||
DirPos[] outpos;
|
||||
|
||||
|
||||
@Override
|
||||
public DirPos[] getInputPositions() {
|
||||
|
||||
|
||||
if(inpos != null)
|
||||
return inpos;
|
||||
|
||||
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset);
|
||||
ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
|
||||
|
||||
|
||||
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 * 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 * 1 + rot.offsetX * 5, yCoord, zCoord + dir.offsetZ * 1 + rot.offsetZ * 5, rot)
|
||||
};
|
||||
|
||||
|
||||
return inpos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DirPos[] getOutputPositions() {
|
||||
|
||||
|
||||
if(outpos != null)
|
||||
return outpos;
|
||||
|
||||
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset);
|
||||
ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
|
||||
|
||||
|
||||
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 * 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 * 2 + rot.offsetX * 5, yCoord, zCoord - dir.offsetZ * 2 + rot.offsetZ * 5, rot)
|
||||
};
|
||||
|
||||
|
||||
return outpos;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
super.readFromNBT(nbt);
|
||||
water.readFromNBT(nbt, "w");
|
||||
steam.readFromNBT(nbt, "s");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
super.writeToNBT(nbt);
|
||||
@ -309,27 +312,27 @@ public class TileEntityMachineChemfac extends TileEntityMachineChemplantBase imp
|
||||
|
||||
@Override
|
||||
protected List<FluidTank> inTanks() {
|
||||
|
||||
|
||||
List<FluidTank> inTanks = super.inTanks();
|
||||
inTanks.add(water);
|
||||
|
||||
|
||||
return inTanks;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<FluidTank> outTanks() {
|
||||
|
||||
|
||||
List<FluidTank> outTanks = super.outTanks();
|
||||
outTanks.add(steam);
|
||||
|
||||
|
||||
return outTanks;
|
||||
}
|
||||
|
||||
|
||||
AxisAlignedBB bb = null;
|
||||
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getRenderBoundingBox() {
|
||||
|
||||
|
||||
if(bb == null) {
|
||||
bb = AxisAlignedBB.getBoundingBox(
|
||||
xCoord - 5,
|
||||
@ -340,10 +343,10 @@ public class TileEntityMachineChemfac extends TileEntityMachineChemplantBase imp
|
||||
zCoord + 5
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
return bb;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public double getMaxRenderDistanceSquared() {
|
||||
@ -383,11 +386,12 @@ public class TileEntityMachineChemfac extends TileEntityMachineChemplantBase imp
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel(UpgradeType type) {
|
||||
if(type == UpgradeType.SPEED) return 6;
|
||||
if(type == UpgradeType.POWER) return 3;
|
||||
if(type == UpgradeType.OVERDRIVE) return 12;
|
||||
return 0;
|
||||
public HashMap<UpgradeType, Integer> getValidUpgrades() {
|
||||
HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
|
||||
upgrades.put(UpgradeType.SPEED, 6);
|
||||
upgrades.put(UpgradeType.POWER, 3);
|
||||
upgrades.put(UpgradeType.OVERDRIVE, 12);
|
||||
return upgrades;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
package com.hbm.tileentity.machine;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import com.hbm.blocks.BlockDummyable;
|
||||
import com.hbm.blocks.ModBlocks;
|
||||
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.fluid.Fluids;
|
||||
import com.hbm.inventory.fluid.tank.FluidTank;
|
||||
@ -49,15 +50,17 @@ public class TileEntityMachineChemplant extends TileEntityMachineBase implements
|
||||
public int progress;
|
||||
public int maxProgress = 100;
|
||||
public boolean isProgressing;
|
||||
|
||||
|
||||
private AudioWrapper audio;
|
||||
|
||||
|
||||
public FluidTank[] tanks;
|
||||
|
||||
|
||||
//upgraded stats
|
||||
int consumption = 100;
|
||||
int speed = 100;
|
||||
|
||||
public UpgradeManagerNT upgradeManager = new UpgradeManagerNT();
|
||||
|
||||
public TileEntityMachineChemplant() {
|
||||
super(21);
|
||||
/*
|
||||
@ -71,7 +74,7 @@ public class TileEntityMachineChemplant extends TileEntityMachineBase implements
|
||||
* 17-18 FIn In
|
||||
* 19-20 FIn Out
|
||||
*/
|
||||
|
||||
|
||||
tanks = new FluidTank[4];
|
||||
for(int i = 0; i < 4; i++) {
|
||||
tanks[i] = new FluidTank(Fluids.NONE, 24_000);
|
||||
@ -82,7 +85,7 @@ public class TileEntityMachineChemplant extends TileEntityMachineBase implements
|
||||
public String getName() {
|
||||
return "container.chemplant";
|
||||
}
|
||||
|
||||
|
||||
// last successful load
|
||||
int lsl0 = 0;
|
||||
int lsl1 = 0;
|
||||
@ -91,23 +94,23 @@ public class TileEntityMachineChemplant extends TileEntityMachineBase implements
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
|
||||
|
||||
this.speed = 100;
|
||||
this.consumption = 100;
|
||||
|
||||
|
||||
this.isProgressing = false;
|
||||
this.power = Library.chargeTEFromItems(slots, 0, power, maxPower);
|
||||
|
||||
int fluidDelay = 40;
|
||||
|
||||
|
||||
if(lsu0 >= fluidDelay && tanks[0].loadTank(17, 19, slots)) lsl0 = 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(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[3].unloadTank(10, 12, slots);
|
||||
|
||||
@ -115,48 +118,48 @@ public class TileEntityMachineChemplant extends TileEntityMachineBase implements
|
||||
if(lsl1 < fluidDelay) lsl1++;
|
||||
if(lsu0 < fluidDelay) lsu0++;
|
||||
if(lsu1 < fluidDelay) lsu1++;
|
||||
|
||||
|
||||
loadItems();
|
||||
unloadItems();
|
||||
|
||||
|
||||
if(worldObj.getTotalWorldTime() % 20 == 0) {
|
||||
this.updateConnections();
|
||||
}
|
||||
|
||||
|
||||
for(DirPos pos : getConPos()) {
|
||||
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());
|
||||
}
|
||||
|
||||
UpgradeManager.eval(slots, 1, 3);
|
||||
|
||||
int speedLevel = Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 3);
|
||||
int powerLevel = Math.min(UpgradeManager.getLevel(UpgradeType.POWER), 3);
|
||||
int overLevel = UpgradeManager.getLevel(UpgradeType.OVERDRIVE);
|
||||
|
||||
upgradeManager.checkSlots(this, slots, 1, 3);
|
||||
|
||||
int speedLevel = upgradeManager.getLevel(UpgradeType.SPEED);
|
||||
int powerLevel = upgradeManager.getLevel(UpgradeType.POWER);
|
||||
int overLevel = upgradeManager.getLevel(UpgradeType.OVERDRIVE);
|
||||
|
||||
this.speed -= speedLevel * 25;
|
||||
this.consumption += speedLevel * 300;
|
||||
this.speed += powerLevel * 5;
|
||||
this.consumption -= powerLevel * 20;
|
||||
this.speed /= (overLevel + 1);
|
||||
this.consumption *= (overLevel + 1);
|
||||
|
||||
|
||||
if(this.speed <= 0) {
|
||||
this.speed = 1;
|
||||
}
|
||||
|
||||
|
||||
if(!canProcess()) {
|
||||
this.progress = 0;
|
||||
} else {
|
||||
isProgressing = true;
|
||||
process();
|
||||
}
|
||||
|
||||
|
||||
this.networkPackNT(150);
|
||||
} else {
|
||||
|
||||
|
||||
if(isProgressing && this.worldObj.getTotalWorldTime() % 3 == 0) {
|
||||
|
||||
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset).getOpposite();
|
||||
ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
|
||||
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;
|
||||
worldObj.spawnParticle("cloud", x, y, z, 0.0, 0.1, 0.0);
|
||||
}
|
||||
|
||||
|
||||
float volume = this.getVolume(1F);
|
||||
|
||||
|
||||
if(isProgressing && volume > 0) {
|
||||
|
||||
|
||||
if(audio == null) {
|
||||
audio = this.createAudioLoop();
|
||||
audio.updateVolume(volume);
|
||||
@ -177,9 +180,9 @@ public class TileEntityMachineChemplant extends TileEntityMachineBase implements
|
||||
audio = rebootAudio(audio);
|
||||
audio.updateVolume(volume);
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
if(audio != null) {
|
||||
audio.stopSound();
|
||||
audio = null;
|
||||
@ -199,7 +202,7 @@ public class TileEntityMachineChemplant extends TileEntityMachineBase implements
|
||||
for(int i = 0; i < tanks.length; i++)
|
||||
tanks[i].serialize(buf);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void deserialize(ByteBuf buf) {
|
||||
super.deserialize(buf);
|
||||
@ -211,7 +214,7 @@ public class TileEntityMachineChemplant extends TileEntityMachineBase implements
|
||||
for(int i = 0; i < tanks.length; i++)
|
||||
tanks[i].deserialize(buf);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public AudioWrapper createAudioLoop() {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void updateConnections() {
|
||||
|
||||
|
||||
for(DirPos pos : getConPos()) {
|
||||
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[1].getTankType(), worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public DirPos[] getConPos() {
|
||||
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset).getOpposite();
|
||||
ForgeDirection rot = dir.getRotation(ForgeDirection.DOWN);
|
||||
|
||||
|
||||
return new DirPos[] {
|
||||
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()),
|
||||
@ -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())
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
private boolean canProcess() {
|
||||
|
||||
|
||||
if(slots[4] == null || slots[4].getItem() != ModItems.chemistry_template)
|
||||
return false;
|
||||
|
||||
|
||||
ChemRecipe recipe = ChemplantRecipes.indexMapping.get(slots[4].getItemDamage());
|
||||
|
||||
|
||||
if(recipe == null)
|
||||
return false;
|
||||
|
||||
|
||||
setupTanks(recipe);
|
||||
|
||||
|
||||
if(this.power < this.consumption) return false;
|
||||
if(!hasRequiredFluids(recipe)) return false;
|
||||
if(!hasSpaceForFluids(recipe)) return false;
|
||||
if(!hasRequiredItems(recipe)) return false;
|
||||
if(!hasSpaceForItems(recipe)) return false;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
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[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[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) {
|
||||
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;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
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[1] != null && tanks[3].getFill() + recipe.outputFluids[1].fill > tanks[3].getMaxFill()) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private boolean hasRequiredItems(ChemRecipe recipe) {
|
||||
return InventoryUtil.doesArrayHaveIngredients(slots, 13, 16, recipe.inputs);
|
||||
}
|
||||
|
||||
|
||||
private boolean hasSpaceForItems(ChemRecipe recipe) {
|
||||
return InventoryUtil.doesArrayHaveSpace(slots, 5, 8, recipe.outputs);
|
||||
}
|
||||
|
||||
|
||||
private void process() {
|
||||
|
||||
|
||||
this.power -= this.consumption;
|
||||
this.progress++;
|
||||
|
||||
|
||||
if(slots[0] != null && slots[0].getItem() == ModItems.meteorite_sword_machined)
|
||||
slots[0] = new ItemStack(ModItems.meteorite_sword_treated); //fisfndmoivndlmgindgifgjfdnblfm
|
||||
|
||||
|
||||
ChemRecipe recipe = ChemplantRecipes.indexMapping.get(slots[4].getItemDamage());
|
||||
|
||||
|
||||
this.maxProgress = recipe.getDuration() * this.speed / 100;
|
||||
|
||||
|
||||
if(maxProgress <= 0) maxProgress = 1;
|
||||
|
||||
|
||||
if(this.progress >= this.maxProgress) {
|
||||
consumeFluids(recipe);
|
||||
produceFluids(recipe);
|
||||
@ -330,81 +333,81 @@ public class TileEntityMachineChemplant extends TileEntityMachineBase implements
|
||||
this.markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void consumeFluids(ChemRecipe recipe) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
private void produceFluids(ChemRecipe recipe) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
private void consumeItems(ChemRecipe recipe) {
|
||||
|
||||
|
||||
for(AStack in : recipe.inputs) {
|
||||
if(in != null)
|
||||
InventoryUtil.tryConsumeAStack(slots, 13, 16, in);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void produceItems(ChemRecipe recipe) {
|
||||
|
||||
|
||||
for(ItemStack out : recipe.outputs) {
|
||||
if(out != null)
|
||||
InventoryUtil.tryAddItemToInventory(slots, 5, 8, out.copy());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//TODO: move this into a util class
|
||||
private void loadItems() {
|
||||
|
||||
|
||||
if(slots[4] == null || slots[4].getItem() != ModItems.chemistry_template)
|
||||
return;
|
||||
|
||||
|
||||
ChemRecipe recipe = ChemplantRecipes.indexMapping.get(slots[4].getItemDamage());
|
||||
|
||||
|
||||
if(recipe != null) {
|
||||
|
||||
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset).getOpposite();
|
||||
|
||||
int x = xCoord - dir.offsetX * 2;
|
||||
int z = zCoord - dir.offsetZ * 2;
|
||||
|
||||
|
||||
TileEntity te = worldObj.getTileEntity(x, yCoord, z);
|
||||
|
||||
|
||||
if(te instanceof IInventory) {
|
||||
|
||||
|
||||
IInventory inv = (IInventory) te;
|
||||
ISidedInventory sided = inv instanceof ISidedInventory ? (ISidedInventory) inv : null;
|
||||
int[] access = sided != null ? sided.getAccessibleSlotsFromSide(dir.ordinal()) : null;
|
||||
|
||||
|
||||
for(AStack ingredient : recipe.inputs) {
|
||||
|
||||
|
||||
outer:
|
||||
while(!InventoryUtil.doesArrayHaveIngredients(slots, 13, 16, ingredient)) {
|
||||
|
||||
|
||||
boolean found = false;
|
||||
|
||||
|
||||
for(int i = 0; i < (access != null ? access.length : inv.getSizeInventory()); i++) {
|
||||
|
||||
int slot = access != null ? access[i] : i;
|
||||
ItemStack stack = inv.getStackInSlot(slot);
|
||||
|
||||
|
||||
if(ingredient.matchesRecipe(stack, true) && (sided == null || sided.canExtractItem(slot, stack, 0))) {
|
||||
|
||||
|
||||
for(int j = 13; j <= 16; j++) {
|
||||
|
||||
|
||||
if(slots[j] != null && slots[j].stackSize < slots[j].getMaxStackSize() & InventoryUtil.doesStackDataMatch(slots[j], stack)) {
|
||||
inv.decrStackSize(slot, 1);
|
||||
slots[j].stackSize++;
|
||||
continue outer;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for(int j = 13; j <= 16; j++) {
|
||||
|
||||
|
||||
if(slots[j] == null) {
|
||||
slots[j] = stack.copy();
|
||||
slots[j].stackSize = 1;
|
||||
@ -421,43 +424,43 @@ public class TileEntityMachineChemplant extends TileEntityMachineBase implements
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void unloadItems() {
|
||||
|
||||
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset).getOpposite();
|
||||
ForgeDirection rot = dir.getRotation(ForgeDirection.DOWN);
|
||||
|
||||
int x = xCoord + dir.offsetX * 3 + rot.offsetX;
|
||||
int z = zCoord + dir.offsetZ * 3 + rot.offsetZ;
|
||||
|
||||
|
||||
TileEntity te = worldObj.getTileEntity(x, yCoord, z);
|
||||
|
||||
|
||||
if(te instanceof IInventory) {
|
||||
|
||||
|
||||
IInventory inv = (IInventory) te;
|
||||
ISidedInventory sided = inv instanceof ISidedInventory ? (ISidedInventory) inv : null;
|
||||
int[] access = sided != null ? sided.getAccessibleSlotsFromSide(dir.ordinal()) : null;
|
||||
|
||||
|
||||
boolean shouldOutput = true;
|
||||
|
||||
|
||||
while(shouldOutput) {
|
||||
shouldOutput = false;
|
||||
outer:
|
||||
for(int i = 5; i <= 8; i++) {
|
||||
|
||||
|
||||
ItemStack out = slots[i];
|
||||
|
||||
|
||||
if(out != null) {
|
||||
|
||||
|
||||
for(int j = 0; j < (access != null ? access.length : inv.getSizeInventory()); j++) {
|
||||
|
||||
|
||||
int slot = access != null ? access[j] : j;
|
||||
|
||||
|
||||
if(!inv.isItemValidForSlot(slot, out))
|
||||
continue;
|
||||
|
||||
|
||||
ItemStack target = inv.getStackInSlot(slot);
|
||||
|
||||
|
||||
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);
|
||||
this.decrStackSize(i, toDec);
|
||||
@ -466,14 +469,14 @@ public class TileEntityMachineChemplant extends TileEntityMachineBase implements
|
||||
break outer;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for(int j = 0; j < (access != null ? access.length : inv.getSizeInventory()); j++) {
|
||||
|
||||
|
||||
int slot = access != null ? access[j] : j;
|
||||
|
||||
|
||||
if(!inv.isItemValidForSlot(slot, out))
|
||||
continue;
|
||||
|
||||
|
||||
if(inv.getStackInSlot(slot) == null && (sided != null ? sided.canInsertItem(slot, out, dir.ordinal()) : inv.isItemValidForSlot(slot, out))) {
|
||||
ItemStack copy = out.copy();
|
||||
copy.stackSize = 1;
|
||||
@ -503,36 +506,36 @@ public class TileEntityMachineChemplant extends TileEntityMachineBase implements
|
||||
public long getMaxPower() {
|
||||
return maxPower;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
super.readFromNBT(nbt);
|
||||
|
||||
|
||||
this.power = nbt.getLong("power");
|
||||
this.progress = nbt.getInteger("progress");
|
||||
|
||||
|
||||
for(int i = 0; i < tanks.length; i++) {
|
||||
tanks[i].readFromNBT(nbt, "t" + i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
super.writeToNBT(nbt);
|
||||
|
||||
|
||||
nbt.setLong("power", power);
|
||||
nbt.setInteger("progress", progress);
|
||||
|
||||
|
||||
for(int i = 0; i < tanks.length; i++) {
|
||||
tanks[i].writeToNBT(nbt, "t" + i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
AxisAlignedBB bb = null;
|
||||
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getRenderBoundingBox() {
|
||||
|
||||
|
||||
if(bb == null) {
|
||||
bb = AxisAlignedBB.getBoundingBox(
|
||||
xCoord - 2,
|
||||
@ -543,10 +546,10 @@ public class TileEntityMachineChemplant extends TileEntityMachineBase implements
|
||||
zCoord + 3
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
return bb;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public double getMaxRenderDistanceSquared() {
|
||||
@ -601,10 +604,11 @@ public class TileEntityMachineChemplant extends TileEntityMachineBase implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel(UpgradeType type) {
|
||||
if(type == UpgradeType.SPEED) return 3;
|
||||
if(type == UpgradeType.POWER) return 3;
|
||||
if(type == UpgradeType.OVERDRIVE) return 9;
|
||||
return 0;
|
||||
public HashMap<UpgradeType, Integer> getValidUpgrades() {
|
||||
HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
|
||||
upgrades.put(UpgradeType.SPEED, 3);
|
||||
upgrades.put(UpgradeType.POWER, 3);
|
||||
upgrades.put(UpgradeType.OVERDRIVE, 9);
|
||||
return upgrades;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
package com.hbm.tileentity.machine;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import com.hbm.blocks.BlockDummyable;
|
||||
import com.hbm.blocks.ModBlocks;
|
||||
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.fluid.Fluids;
|
||||
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.lib.Library;
|
||||
import com.hbm.main.MainRegistry;
|
||||
import com.hbm.tileentity.IFluidCopiable;
|
||||
import com.hbm.tileentity.IGUIProvider;
|
||||
import com.hbm.tileentity.IUpgradeInfoProvider;
|
||||
import com.hbm.tileentity.TileEntityMachineBase;
|
||||
import com.hbm.tileentity.*;
|
||||
import com.hbm.util.BobMathUtil;
|
||||
import com.hbm.util.I18nUtil;
|
||||
import com.hbm.util.Tuple.Pair;
|
||||
@ -39,7 +37,7 @@ import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public class TileEntityMachineCompressor extends TileEntityMachineBase implements IGUIProvider, IControlReceiver, IEnergyReceiverMK2, IFluidStandardTransceiver, IUpgradeInfoProvider, IFluidCopiable {
|
||||
|
||||
|
||||
public FluidTank[] tanks;
|
||||
public long power;
|
||||
public static final long maxPower = 100_000;
|
||||
@ -49,13 +47,15 @@ public class TileEntityMachineCompressor extends TileEntityMachineBase implement
|
||||
public static final int processTimeBase = 100;
|
||||
public int powerRequirement;
|
||||
public static final int powerRequirementBase = 2_500;
|
||||
|
||||
|
||||
public float fanSpin;
|
||||
public float prevFanSpin;
|
||||
public float piston;
|
||||
public float prevPiston;
|
||||
public boolean pistonDir;
|
||||
|
||||
public UpgradeManagerNT upgradeManager = new UpgradeManagerNT();
|
||||
|
||||
public TileEntityMachineCompressor() {
|
||||
super(4);
|
||||
this.tanks = new FluidTank[2];
|
||||
@ -70,23 +70,23 @@ public class TileEntityMachineCompressor extends TileEntityMachineBase implement
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
|
||||
|
||||
if(worldObj.getTotalWorldTime() % 20 == 0) {
|
||||
this.updateConnections();
|
||||
}
|
||||
|
||||
|
||||
this.power = Library.chargeTEFromItems(slots, 1, power, maxPower);
|
||||
this.tanks[0].setType(0, slots);
|
||||
this.setupTanks();
|
||||
|
||||
UpgradeManager.eval(slots, 1, 3);
|
||||
|
||||
int speedLevel = Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 3);
|
||||
int powerLevel = Math.min(UpgradeManager.getLevel(UpgradeType.POWER), 3);
|
||||
int overLevel = UpgradeManager.getLevel(UpgradeType.OVERDRIVE);
|
||||
|
||||
upgradeManager.checkSlots(this, slots, 1, 3);
|
||||
|
||||
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()));
|
||||
int timeBase = this.processTimeBase;
|
||||
if(rec != null) timeBase = rec.duration;
|
||||
@ -98,44 +98,44 @@ public class TileEntityMachineCompressor extends TileEntityMachineBase implement
|
||||
this.powerRequirement = this.powerRequirementBase / (powerLevel + 1);
|
||||
this.processTime = this.processTime / (overLevel + 1);
|
||||
this.powerRequirement = this.powerRequirement * ((overLevel * 2) + 1);
|
||||
|
||||
|
||||
if(processTime <= 0) processTime = 1;
|
||||
|
||||
|
||||
if(canProcess()) {
|
||||
this.progress++;
|
||||
this.isOn = true;
|
||||
this.power -= powerRequirement;
|
||||
|
||||
|
||||
if(progress >= this.processTime) {
|
||||
progress = 0;
|
||||
this.process();
|
||||
this.markChanged();
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
this.progress = 0;
|
||||
this.isOn = false;
|
||||
}
|
||||
|
||||
|
||||
for(DirPos pos : getConPos()) {
|
||||
this.sendFluid(tanks[1], worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
|
||||
}
|
||||
|
||||
this.networkPackNT(100);
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
this.prevFanSpin = this.fanSpin;
|
||||
this.prevPiston = this.piston;
|
||||
|
||||
|
||||
if(this.isOn) {
|
||||
this.fanSpin += 15;
|
||||
|
||||
|
||||
if(this.fanSpin >= 360) {
|
||||
this.prevFanSpin -= 360;
|
||||
this.fanSpin -= 360;
|
||||
}
|
||||
|
||||
|
||||
if(this.pistonDir) {
|
||||
this.piston -= randSpeed;
|
||||
if(this.piston <= 0) {
|
||||
@ -149,12 +149,12 @@ public class TileEntityMachineCompressor extends TileEntityMachineBase implement
|
||||
this.pistonDir = !this.pistonDir;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.piston = MathHelper.clamp_float(this.piston, 0F, 1F);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private float randSpeed = 0.1F;
|
||||
|
||||
@Override
|
||||
@ -180,42 +180,42 @@ public class TileEntityMachineCompressor extends TileEntityMachineBase implement
|
||||
tanks[1].deserialize(buf);
|
||||
this.isOn = buf.readBoolean();
|
||||
}
|
||||
|
||||
|
||||
private void updateConnections() {
|
||||
for(DirPos pos : getConPos()) {
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public DirPos[] getConPos() {
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset);
|
||||
ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
|
||||
|
||||
|
||||
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.getOpposite()),
|
||||
new DirPos(xCoord - dir.offsetX * 2, yCoord, zCoord - dir.offsetZ * 2, dir.getOpposite()),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public boolean canProcess() {
|
||||
|
||||
|
||||
if(this.power <= powerRequirement) return false;
|
||||
|
||||
|
||||
CompressorRecipe recipe = CompressorRecipes.recipes.get(new Pair(tanks[0].getTankType(), tanks[0].getPressure()));
|
||||
|
||||
|
||||
if(recipe == null) {
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
public void process() {
|
||||
|
||||
|
||||
CompressorRecipe recipe = CompressorRecipes.recipes.get(new Pair(tanks[0].getTankType(), tanks[0].getPressure()));
|
||||
|
||||
|
||||
if(recipe == null) {
|
||||
tanks[0].setFill(tanks[0].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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void setupTanks() {
|
||||
|
||||
|
||||
CompressorRecipe recipe = CompressorRecipes.recipes.get(new Pair(tanks[0].getTankType(), tanks[0].getPressure()));
|
||||
|
||||
|
||||
if(recipe == null) {
|
||||
tanks[1].withPressure(tanks[0].getPressure() + 1).setTankType(tanks[0].getTankType());
|
||||
} else {
|
||||
tanks[1].withPressure(recipe.output.pressure).setTankType(recipe.output.type);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
super.readFromNBT(nbt);
|
||||
@ -244,7 +244,7 @@ public class TileEntityMachineCompressor extends TileEntityMachineBase implement
|
||||
tanks[0].readFromNBT(nbt, "0");
|
||||
tanks[1].readFromNBT(nbt, "1");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
super.writeToNBT(nbt);
|
||||
@ -273,18 +273,18 @@ public class TileEntityMachineCompressor extends TileEntityMachineBase implement
|
||||
@Override
|
||||
public void receiveControl(NBTTagCompound data) {
|
||||
int compression = data.getInteger("compression");
|
||||
|
||||
|
||||
if(compression != tanks[0].getPressure()) {
|
||||
tanks[0].withPressure(compression);
|
||||
|
||||
|
||||
CompressorRecipe recipe = CompressorRecipes.recipes.get(new Pair(tanks[0].getTankType(), compression));
|
||||
|
||||
|
||||
if(recipe == null) {
|
||||
tanks[1].withPressure(compression + 1);
|
||||
} else {
|
||||
tanks[1].withPressure(recipe.output.pressure).setTankType(recipe.output.type);
|
||||
}
|
||||
|
||||
|
||||
this.markChanged();
|
||||
}
|
||||
}
|
||||
@ -318,12 +318,12 @@ public class TileEntityMachineCompressor extends TileEntityMachineBase implement
|
||||
public FluidTank[] getReceivingTanks() {
|
||||
return new FluidTank[] {tanks[0]};
|
||||
}
|
||||
|
||||
|
||||
AxisAlignedBB bb = null;
|
||||
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getRenderBoundingBox() {
|
||||
|
||||
|
||||
if(bb == null) {
|
||||
bb = AxisAlignedBB.getBoundingBox(
|
||||
xCoord - 2,
|
||||
@ -334,10 +334,10 @@ public class TileEntityMachineCompressor extends TileEntityMachineBase implement
|
||||
zCoord + 3
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
return bb;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public double getMaxRenderDistanceSquared() {
|
||||
@ -365,11 +365,12 @@ public class TileEntityMachineCompressor extends TileEntityMachineBase implement
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel(UpgradeType type) {
|
||||
if(type == UpgradeType.SPEED) return 3;
|
||||
if(type == UpgradeType.POWER) return 3;
|
||||
if(type == UpgradeType.OVERDRIVE) return 9;
|
||||
return 0;
|
||||
public HashMap<UpgradeType, Integer> getValidUpgrades() {
|
||||
HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
|
||||
upgrades.put(UpgradeType.SPEED, 3);
|
||||
upgrades.put(UpgradeType.POWER, 3);
|
||||
upgrades.put(UpgradeType.OVERDRIVE, 9);
|
||||
return upgrades;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
package com.hbm.tileentity.machine;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import com.hbm.blocks.ModBlocks;
|
||||
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.fluid.Fluids;
|
||||
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.lib.Library;
|
||||
import com.hbm.main.MainRegistry;
|
||||
import com.hbm.tileentity.IFluidCopiable;
|
||||
import com.hbm.tileentity.IGUIProvider;
|
||||
import com.hbm.tileentity.IUpgradeInfoProvider;
|
||||
import com.hbm.tileentity.TileEntityMachineBase;
|
||||
import com.hbm.tileentity.*;
|
||||
import com.hbm.util.BobMathUtil;
|
||||
import com.hbm.util.I18nUtil;
|
||||
import com.hbm.util.fauxpointtwelve.DirPos;
|
||||
@ -40,19 +38,21 @@ import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public class TileEntityMachineCrystallizer extends TileEntityMachineBase implements IEnergyReceiverMK2, IFluidStandardReceiver, IGUIProvider, IUpgradeInfoProvider, IFluidCopiable {
|
||||
|
||||
|
||||
public long power;
|
||||
public static final long maxPower = 1000000;
|
||||
public static final int demand = 1000;
|
||||
public short progress;
|
||||
public short duration = 600;
|
||||
public boolean isOn;
|
||||
|
||||
|
||||
public float angle;
|
||||
public float prevAngle;
|
||||
|
||||
|
||||
public FluidTank tank;
|
||||
|
||||
public UpgradeManagerNT upgradeManager = new UpgradeManagerNT();
|
||||
|
||||
public TileEntityMachineCrystallizer() {
|
||||
super(8);
|
||||
tank = new FluidTank(Fluids.PEROXIDE, 8000);
|
||||
@ -65,76 +65,76 @@ public class TileEntityMachineCrystallizer extends TileEntityMachineBase impleme
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
|
||||
|
||||
this.isOn = false;
|
||||
|
||||
|
||||
this.updateConnections();
|
||||
|
||||
|
||||
power = Library.chargeTEFromItems(slots, 1, power, maxPower);
|
||||
tank.setType(7, slots);
|
||||
tank.loadTank(3, 4, slots);
|
||||
|
||||
UpgradeManager.eval(slots, 5, 6);
|
||||
|
||||
|
||||
upgradeManager.checkSlots(this, slots, 5, 6);
|
||||
|
||||
for(int i = 0; i < getCycleCount(); i++) {
|
||||
|
||||
|
||||
if(canProcess()) {
|
||||
|
||||
|
||||
progress++;
|
||||
power -= getPowerRequired();
|
||||
isOn = true;
|
||||
|
||||
|
||||
if(progress > getDuration()) {
|
||||
progress = 0;
|
||||
processItem();
|
||||
|
||||
|
||||
this.markDirty();
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
progress = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.networkPackNT(25);
|
||||
} else {
|
||||
|
||||
|
||||
prevAngle = angle;
|
||||
|
||||
|
||||
if(isOn) {
|
||||
angle += 5F * this.getCycleCount();
|
||||
|
||||
|
||||
if(angle >= 360) {
|
||||
angle -= 360;
|
||||
prevAngle -= 360;
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10);
|
||||
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));
|
||||
|
||||
|
||||
for(EntityPlayer player : players) {
|
||||
HbmPlayerProps props = HbmPlayerProps.getData(player);
|
||||
props.isOnLadder = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void updateConnections() {
|
||||
|
||||
|
||||
for(DirPos pos : getConPos()) {
|
||||
this.trySubscribe(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() {
|
||||
|
||||
return new DirPos[] {
|
||||
@ -148,7 +148,7 @@ public class TileEntityMachineCrystallizer extends TileEntityMachineBase impleme
|
||||
new DirPos(xCoord - 1, yCoord, zCoord - 2, Library.NEG_Z)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void serialize(ByteBuf buf) {
|
||||
super.serialize(buf);
|
||||
@ -158,7 +158,7 @@ public class TileEntityMachineCrystallizer extends TileEntityMachineBase impleme
|
||||
buf.writeBoolean(isOn);
|
||||
tank.serialize(buf);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void deserialize(ByteBuf buf) {
|
||||
super.deserialize(buf);
|
||||
@ -168,103 +168,103 @@ public class TileEntityMachineCrystallizer extends TileEntityMachineBase impleme
|
||||
isOn = buf.readBoolean();
|
||||
tank.deserialize(buf);
|
||||
}
|
||||
|
||||
|
||||
private void processItem() {
|
||||
|
||||
CrystallizerRecipe result = CrystallizerRecipes.getOutput(slots[0], tank.getTankType());
|
||||
|
||||
|
||||
if(result == null) //never happens but you can't be sure enough
|
||||
return;
|
||||
|
||||
|
||||
ItemStack stack = result.output.copy();
|
||||
|
||||
|
||||
if(slots[2] == null)
|
||||
slots[2] = stack;
|
||||
else if(slots[2].stackSize + stack.stackSize <= slots[2].getMaxStackSize())
|
||||
slots[2].stackSize += stack.stackSize;
|
||||
|
||||
|
||||
tank.setFill(tank.getFill() - getRequiredAcid(result.acidAmount));
|
||||
|
||||
|
||||
float freeChance = this.getFreeChance();
|
||||
|
||||
|
||||
if(freeChance == 0 || freeChance < worldObj.rand.nextFloat())
|
||||
this.decrStackSize(0, result.itemAmount);
|
||||
}
|
||||
|
||||
|
||||
private boolean canProcess() {
|
||||
|
||||
|
||||
//Is there no input?
|
||||
if(slots[0] == null)
|
||||
return false;
|
||||
|
||||
|
||||
if(power < getPowerRequired())
|
||||
return false;
|
||||
|
||||
|
||||
CrystallizerRecipe result = CrystallizerRecipes.getOutput(slots[0], tank.getTankType());
|
||||
|
||||
|
||||
//Or output?
|
||||
if(result == null)
|
||||
return false;
|
||||
|
||||
|
||||
//Not enough of the input item?
|
||||
if(slots[0].stackSize < result.itemAmount)
|
||||
return false;
|
||||
|
||||
|
||||
if(tank.getFill() < getRequiredAcid(result.acidAmount)) return false;
|
||||
|
||||
|
||||
ItemStack stack = result.output.copy();
|
||||
|
||||
|
||||
//Does the output not match?
|
||||
if(slots[2] != null && (slots[2].getItem() != stack.getItem() || slots[2].getItemDamage() != stack.getItemDamage()))
|
||||
return false;
|
||||
|
||||
|
||||
//Or is the output slot already full?
|
||||
if(slots[2] != null && slots[2].stackSize + stack.stackSize > slots[2].getMaxStackSize())
|
||||
return false;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public int getRequiredAcid(int base) {
|
||||
int efficiency = Math.min(UpgradeManager.getLevel(UpgradeType.EFFECT), 3);
|
||||
int efficiency = upgradeManager.getLevel(UpgradeType.EFFECT);
|
||||
if(efficiency > 0) {
|
||||
return base * (efficiency + 2);
|
||||
}
|
||||
return base;
|
||||
}
|
||||
|
||||
|
||||
public float getFreeChance() {
|
||||
int efficiency = Math.min(UpgradeManager.getLevel(UpgradeType.EFFECT), 3);
|
||||
int efficiency = upgradeManager.getLevel(UpgradeType.EFFECT);
|
||||
if(efficiency > 0) {
|
||||
return Math.min(efficiency * 0.05F, 0.15F);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
public short getDuration() {
|
||||
CrystallizerRecipe result = CrystallizerRecipes.getOutput(slots[0], tank.getTankType());
|
||||
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) {
|
||||
return (short) Math.ceil((base * Math.max(1F - 0.25F * speed, 0.25F)));
|
||||
}
|
||||
return (short) base;
|
||||
}
|
||||
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
public float getCycleCount() {
|
||||
int speed = UpgradeManager.getLevel(UpgradeType.OVERDRIVE);
|
||||
int speed = upgradeManager.getLevel(UpgradeType.OVERDRIVE);
|
||||
return Math.min(1 + speed * 2, 7);
|
||||
}
|
||||
|
||||
|
||||
public long getPowerScaled(int i) {
|
||||
return (power * i) / maxPower;
|
||||
}
|
||||
|
||||
|
||||
public int getProgressScaled(int i) {
|
||||
return (progress * i) / duration;
|
||||
}
|
||||
@ -283,34 +283,34 @@ public class TileEntityMachineCrystallizer extends TileEntityMachineBase impleme
|
||||
public long getMaxPower() {
|
||||
return maxPower;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
super.readFromNBT(nbt);
|
||||
|
||||
|
||||
power = nbt.getLong("power");
|
||||
tank.readFromNBT(nbt, "tank");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
super.writeToNBT(nbt);
|
||||
|
||||
|
||||
nbt.setLong("power", power);
|
||||
tank.writeToNBT(nbt, "tank");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemStack) {
|
||||
|
||||
|
||||
CrystallizerRecipe recipe = CrystallizerRecipes.getOutput(itemStack, tank.getTankType());
|
||||
if(i == 0 && recipe != null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
if(i == 1 && itemStack.getItem() instanceof IBatteryItem)
|
||||
return true;
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -321,15 +321,15 @@ public class TileEntityMachineCrystallizer extends TileEntityMachineBase impleme
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsFromSide(int side) {
|
||||
|
||||
|
||||
return side == 0 ? new int[] { 2 } : new int[] { 0, 2 };
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getRenderBoundingBox() {
|
||||
return TileEntity.INFINITE_EXTENT_AABB;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public double getMaxRenderDistanceSquared() {
|
||||
@ -339,7 +339,7 @@ public class TileEntityMachineCrystallizer extends TileEntityMachineBase impleme
|
||||
@Override
|
||||
public void setInventorySlotContents(int i, ItemStack stack) {
|
||||
super.setInventorySlotContents(i, stack);
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
@ -388,11 +388,12 @@ public class TileEntityMachineCrystallizer extends TileEntityMachineBase impleme
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel(UpgradeType type) {
|
||||
if(type == UpgradeType.SPEED) return 3;
|
||||
if(type == UpgradeType.EFFECT) return 3;
|
||||
if(type == UpgradeType.OVERDRIVE) return 3;
|
||||
return 0;
|
||||
public HashMap<UpgradeType, Integer> getValidUpgrades() {
|
||||
HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
|
||||
upgrades.put(UpgradeType.SPEED, 3);
|
||||
upgrades.put(UpgradeType.EFFECT, 3);
|
||||
upgrades.put(UpgradeType.OVERDRIVE, 3);
|
||||
return upgrades;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
package com.hbm.tileentity.machine;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
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.ComparableStack;
|
||||
import com.hbm.inventory.container.ContainerMachineCyclotron;
|
||||
@ -39,21 +40,23 @@ import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public class TileEntityMachineCyclotron extends TileEntityMachineBase implements IEnergyReceiverMK2, IFluidStandardTransceiver, IGUIProvider, IConditionalInvAccess, IUpgradeInfoProvider, IInfoProviderEC, IFluidCopiable {
|
||||
|
||||
|
||||
public long power;
|
||||
public static final long maxPower = 100000000;
|
||||
public static int consumption = 1_000_000;
|
||||
|
||||
private byte plugs;
|
||||
|
||||
|
||||
private byte plugs;
|
||||
|
||||
public int progress;
|
||||
public static final int duration = 690;
|
||||
|
||||
|
||||
public FluidTank[] tanks;
|
||||
|
||||
public UpgradeManagerNT upgradeManager = new UpgradeManagerNT();
|
||||
|
||||
public TileEntityMachineCyclotron() {
|
||||
super(12);
|
||||
|
||||
|
||||
this.tanks = new FluidTank[3];
|
||||
this.tanks[0] = new FluidTank(Fluids.WATER, 32000);
|
||||
this.tanks[1] = new FluidTank(Fluids.SPENTSTEAM, 32000);
|
||||
@ -67,67 +70,67 @@ public class TileEntityMachineCyclotron extends TileEntityMachineBase implements
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
|
||||
|
||||
this.updateConnections();
|
||||
|
||||
this.power = Library.chargeTEFromItems(slots, 9, power, maxPower);
|
||||
|
||||
UpgradeManager.eval(slots, 10, 11);
|
||||
|
||||
|
||||
upgradeManager.checkSlots(this, slots, 10, 11);
|
||||
|
||||
if(canProcess()) {
|
||||
progress += getSpeed();
|
||||
power -= getConsumption();
|
||||
|
||||
|
||||
int convert = getCoolantConsumption();
|
||||
tanks[0].setFill(tanks[0].getFill() - convert);
|
||||
tanks[1].setFill(tanks[1].getFill() + convert);
|
||||
|
||||
|
||||
if(progress >= duration) {
|
||||
process();
|
||||
progress = 0;
|
||||
this.markDirty();
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
progress = 0;
|
||||
}
|
||||
|
||||
|
||||
this.sendFluid();
|
||||
this.networkPackNT(25);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void serialize(ByteBuf buf) {
|
||||
super.serialize(buf);
|
||||
buf.writeLong(power);
|
||||
buf.writeInt(progress);
|
||||
buf.writeByte(plugs);
|
||||
|
||||
|
||||
for(int i = 0; i < 3; i++)
|
||||
tanks[i].serialize(buf);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void deserialize(ByteBuf buf) {
|
||||
super.deserialize(buf);
|
||||
power = buf.readLong();
|
||||
progress = buf.readInt();
|
||||
plugs = buf.readByte();
|
||||
|
||||
|
||||
for(int i = 0; i < 3; i++)
|
||||
tanks[i].deserialize(buf);
|
||||
}
|
||||
|
||||
|
||||
private void updateConnections() {
|
||||
for(DirPos pos : getConPos()) {
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void sendFluid() {
|
||||
for(int i = 1; i < 3; i++) {
|
||||
if(tanks[i].getFill() > 0) {
|
||||
@ -137,7 +140,7 @@ public class TileEntityMachineCyclotron extends TileEntityMachineBase implements
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public DirPos[] getConPos() {
|
||||
return new DirPos[] {
|
||||
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)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public boolean canProcess() {
|
||||
|
||||
|
||||
if(power < getConsumption())
|
||||
return false;
|
||||
|
||||
|
||||
int convert = getCoolantConsumption();
|
||||
|
||||
|
||||
if(tanks[0].getFill() < convert)
|
||||
return false;
|
||||
|
||||
|
||||
if(tanks[1].getFill() + convert > tanks[1].getMaxFill())
|
||||
return false;
|
||||
|
||||
|
||||
for(int i = 0; i < 3; i++) {
|
||||
|
||||
|
||||
Object[] res = CyclotronRecipes.getOutput(slots[i + 3], slots[i]);
|
||||
|
||||
|
||||
if(res == null)
|
||||
continue;
|
||||
|
||||
|
||||
ItemStack out = (ItemStack)res[0];
|
||||
|
||||
|
||||
if(out == null)
|
||||
continue;
|
||||
|
||||
|
||||
if(slots[i + 6] == null)
|
||||
return true;
|
||||
|
||||
|
||||
if(slots[i + 6].getItem() == out.getItem() && slots[i + 6].getItemDamage() == out.getItemDamage() && slots[i + 6].stackSize < out.getMaxStackSize())
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public void process() {
|
||||
|
||||
|
||||
for(int i = 0; i < 3; i++) {
|
||||
|
||||
|
||||
Object[] res = CyclotronRecipes.getOutput(slots[i + 3], slots[i]);
|
||||
|
||||
|
||||
if(res == null)
|
||||
continue;
|
||||
|
||||
|
||||
ItemStack out = (ItemStack)res[0];
|
||||
|
||||
|
||||
if(out == null)
|
||||
continue;
|
||||
|
||||
|
||||
if(slots[i + 6] == null) {
|
||||
|
||||
|
||||
this.decrStackSize(i, 1);
|
||||
this.decrStackSize(i + 3, 1);
|
||||
slots[i + 6] = out;
|
||||
|
||||
|
||||
this.tanks[2].setFill(this.tanks[2].getFill() + (Integer)res[1]);
|
||||
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
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 + 3, 1);
|
||||
slots[i + 6].stackSize++;
|
||||
|
||||
|
||||
this.tanks[2].setFill(this.tanks[2].getFill() + (Integer)res[1]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(this.tanks[2].getFill() > this.tanks[2].getMaxFill())
|
||||
this.tanks[2].setFill(this.tanks[2].getMaxFill());
|
||||
}
|
||||
|
||||
|
||||
public int getSpeed() {
|
||||
return Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 3) + 1;
|
||||
return upgradeManager.getLevel(UpgradeType.SPEED) + 1;
|
||||
}
|
||||
|
||||
|
||||
public int getConsumption() {
|
||||
int efficiency = Math.min(UpgradeManager.getLevel(UpgradeType.POWER), 3);
|
||||
|
||||
int efficiency = upgradeManager.getLevel(UpgradeType.POWER);
|
||||
|
||||
return consumption - 100_000 * efficiency;
|
||||
}
|
||||
|
||||
|
||||
public int getCoolantConsumption() {
|
||||
int efficiency = Math.min(UpgradeManager.getLevel(UpgradeType.EFFECT), 3);
|
||||
int efficiency = upgradeManager.getLevel(UpgradeType.EFFECT);
|
||||
//half a small tower's worth
|
||||
return 500 / (efficiency + 1) * getSpeed();
|
||||
}
|
||||
@ -248,67 +251,67 @@ public class TileEntityMachineCyclotron extends TileEntityMachineBase implements
|
||||
public int getProgressScaled(int i) {
|
||||
return (progress * i) / duration;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getRenderBoundingBox() {
|
||||
return AxisAlignedBB.getBoundingBox(xCoord - 2, yCoord, zCoord - 2, xCoord + 3, yCoord + 4, zCoord + 3);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public double getMaxRenderDistanceSquared() {
|
||||
return 65536.0D;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
super.readFromNBT(nbt);
|
||||
|
||||
|
||||
for(int i = 0; i < 3; i++)
|
||||
tanks[i].readFromNBT(nbt, "t" + i);
|
||||
|
||||
|
||||
this.progress = nbt.getInteger("progress");
|
||||
this.power = nbt.getLong("power");
|
||||
this.plugs = nbt.getByte("plugs");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
super.writeToNBT(nbt);
|
||||
|
||||
|
||||
for(int i = 0; i < 3; i++)
|
||||
tanks[i].writeToNBT(nbt, "t" + i);
|
||||
|
||||
|
||||
nbt.setInteger("progress", progress);
|
||||
nbt.setLong("power", power);
|
||||
nbt.setByte("plugs", plugs);
|
||||
}
|
||||
|
||||
|
||||
public void setPlug(int index) {
|
||||
this.plugs |= (1 << index);
|
||||
this.markDirty();
|
||||
}
|
||||
|
||||
|
||||
public boolean getPlug(int index) {
|
||||
return (this.plugs & (1 << index)) > 0;
|
||||
}
|
||||
|
||||
|
||||
public static Item getItemForPlug(int i) {
|
||||
|
||||
|
||||
switch(i) {
|
||||
case 0: return ModItems.powder_balefire;
|
||||
case 1: return ModItems.book_of_;
|
||||
case 2: return ModItems.diamond_gavel;
|
||||
case 3: return ModItems.coin_maskman;
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int i, ItemStack stack) {
|
||||
super.setInventorySlotContents(i, stack);
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
@ -356,7 +359,7 @@ public class TileEntityMachineCyclotron extends TileEntityMachineBase implements
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int x, int y, int z, int slot, ItemStack stack) {
|
||||
|
||||
|
||||
if(slot < 3) {
|
||||
for(Entry<Pair<ComparableStack, AStack>, Pair<ItemStack, Integer>> entry : CyclotronRecipes.recipes.entrySet()) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -383,7 +386,7 @@ public class TileEntityMachineCyclotron extends TileEntityMachineBase implements
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsFromSide(int x, int y, int z, int side) {
|
||||
|
||||
|
||||
for(int i = 2; i < 6; i++) {
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(i);
|
||||
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 - rot.offsetX && z == zCoord + dir.offsetZ * 2 - rot.offsetZ) return new int[] {2, 5, 6, 7, 8};
|
||||
}
|
||||
|
||||
|
||||
return new int[] {6, 7, 8};
|
||||
}
|
||||
|
||||
@ -417,11 +420,12 @@ public class TileEntityMachineCyclotron extends TileEntityMachineBase implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel(UpgradeType type) {
|
||||
if(type == UpgradeType.SPEED) return 3;
|
||||
if(type == UpgradeType.POWER) return 3;
|
||||
if(type == UpgradeType.EFFECT) return 3;
|
||||
return 0;
|
||||
public HashMap<UpgradeType, Integer> getValidUpgrades() {
|
||||
HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
|
||||
upgrades.put(UpgradeType.SPEED, 3);
|
||||
upgrades.put(UpgradeType.POWER, 3);
|
||||
upgrades.put(UpgradeType.EFFECT, 3);
|
||||
return upgrades;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
package com.hbm.tileentity.machine;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
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.gui.GUIMachineEPress;
|
||||
import com.hbm.inventory.recipes.PressRecipes;
|
||||
@ -44,9 +45,11 @@ public class TileEntityMachineEPress extends TileEntityMachineBase implements IE
|
||||
public final static int maxPress = 200;
|
||||
boolean isRetracting = false;
|
||||
private int delay;
|
||||
|
||||
|
||||
public ItemStack syncStack;
|
||||
|
||||
|
||||
public UpgradeManagerNT upgradeManager = new UpgradeManagerNT();
|
||||
|
||||
public TileEntityMachineEPress() {
|
||||
super(5);
|
||||
}
|
||||
@ -55,39 +58,39 @@ public class TileEntityMachineEPress extends TileEntityMachineBase implements IE
|
||||
public String getName() {
|
||||
return "container.epress";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
|
||||
|
||||
this.updateConnections();
|
||||
power = Library.chargeTEFromItems(slots, 0, power, maxPower);
|
||||
|
||||
|
||||
boolean canProcess = this.canProcess();
|
||||
|
||||
|
||||
if((canProcess || this.isRetracting || this.delay > 0) && power >= 100) {
|
||||
|
||||
|
||||
power -= 100;
|
||||
|
||||
|
||||
if(delay <= 0) {
|
||||
|
||||
UpgradeManager.eval(slots, 4, 4);
|
||||
int speed = 1 + Math.min(3, UpgradeManager.getLevel(UpgradeType.SPEED));
|
||||
|
||||
|
||||
upgradeManager.checkSlots(this, slots, 4, 4);
|
||||
int speed = 1 + upgradeManager.getLevel(UpgradeType.SPEED);
|
||||
|
||||
int stampSpeed = this.isRetracting ? 20 : 45;
|
||||
stampSpeed *= (1D + (double) speed / 4D);
|
||||
|
||||
|
||||
if(this.isRetracting) {
|
||||
this.press -= stampSpeed;
|
||||
|
||||
|
||||
if(this.press <= 0) {
|
||||
this.isRetracting = false;
|
||||
this.delay = 5 - speed + 1;
|
||||
}
|
||||
} else if(canProcess) {
|
||||
this.press += stampSpeed;
|
||||
|
||||
|
||||
if(this.press >= this.maxPress) {
|
||||
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]);
|
||||
@ -97,17 +100,17 @@ public class TileEntityMachineEPress extends TileEntityMachineBase implements IE
|
||||
slots[3].stackSize += output.stackSize;
|
||||
}
|
||||
this.decrStackSize(2, 1);
|
||||
|
||||
|
||||
if(slots[1].getMaxDamage() != 0) {
|
||||
slots[1].setItemDamage(slots[1].getItemDamage() + 1);
|
||||
if(slots[1].getItemDamage() >= slots[1].getMaxDamage()) {
|
||||
slots[1] = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.isRetracting = true;
|
||||
this.delay = 5 - speed + 1;
|
||||
|
||||
|
||||
this.markDirty();
|
||||
}
|
||||
} else if(this.press > 0){
|
||||
@ -117,14 +120,14 @@ public class TileEntityMachineEPress extends TileEntityMachineBase implements IE
|
||||
delay--;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.networkPackNT(50);
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
// approach-based interpolation, GO!
|
||||
this.lastPress = this.renderPress;
|
||||
|
||||
|
||||
if(this.turnProgress > 0) {
|
||||
this.renderPress = this.renderPress + ((this.syncPress - this.renderPress) / (double) this.turnProgress);
|
||||
--this.turnProgress;
|
||||
@ -156,35 +159,35 @@ public class TileEntityMachineEPress extends TileEntityMachineBase implements IE
|
||||
|
||||
this.turnProgress = 2;
|
||||
}
|
||||
|
||||
|
||||
public boolean canProcess() {
|
||||
if(power < 100) return false;
|
||||
if(slots[1] == null || slots[2] == null) return false;
|
||||
|
||||
|
||||
ItemStack output = PressRecipes.getOutput(slots[2], slots[1]);
|
||||
|
||||
|
||||
if(output == null) return false;
|
||||
|
||||
|
||||
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;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private void updateConnections() {
|
||||
|
||||
|
||||
for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
|
||||
this.trySubscribe(worldObj, xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ, dir);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack stack) {
|
||||
|
||||
|
||||
if(stack.getItem() instanceof ItemStamp)
|
||||
return i == 1;
|
||||
|
||||
|
||||
return i == 2;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsFromSide(int side) {
|
||||
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) {
|
||||
return i == 3;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
super.readFromNBT(nbt);
|
||||
|
||||
|
||||
press = nbt.getInteger("press");
|
||||
power = nbt.getInteger("power");
|
||||
isRetracting = nbt.getBoolean("ret");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
super.writeToNBT(nbt);
|
||||
@ -221,7 +224,7 @@ public class TileEntityMachineEPress extends TileEntityMachineBase implements IE
|
||||
@Override
|
||||
public void setPower(long i) {
|
||||
power = i;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -233,19 +236,19 @@ public class TileEntityMachineEPress extends TileEntityMachineBase implements IE
|
||||
public long getMaxPower() {
|
||||
return maxPower;
|
||||
}
|
||||
|
||||
|
||||
AxisAlignedBB aabb;
|
||||
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getRenderBoundingBox() {
|
||||
|
||||
|
||||
if(aabb != null)
|
||||
return aabb;
|
||||
|
||||
|
||||
aabb = AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 3, zCoord + 1);
|
||||
return aabb;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public double getMaxRenderDistanceSquared() {
|
||||
@ -277,9 +280,10 @@ public class TileEntityMachineEPress extends TileEntityMachineBase implements IE
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel(UpgradeType type) {
|
||||
if(type == UpgradeType.SPEED) return 3;
|
||||
return 0;
|
||||
public HashMap<UpgradeType, Integer> getValidUpgrades() {
|
||||
HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
|
||||
upgrades.put(UpgradeType.SPEED, 3);
|
||||
return upgrades;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1,12 +1,13 @@
|
||||
package com.hbm.tileentity.machine;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import com.hbm.blocks.ModBlocks;
|
||||
import com.hbm.blocks.machine.MachineElectricFurnace;
|
||||
import com.hbm.handler.pollution.PollutionHandler;
|
||||
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.gui.GUIMachineElectricFurnace;
|
||||
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 };
|
||||
|
||||
public UpgradeManagerNT upgradeManager = new UpgradeManagerNT();
|
||||
|
||||
public TileEntityMachineElectricFurnace() {
|
||||
super(4);
|
||||
}
|
||||
@ -69,7 +72,7 @@ public class TileEntityMachineElectricFurnace extends TileEntityMachineBase impl
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
super.readFromNBT(nbt);
|
||||
|
||||
|
||||
this.power = nbt.getLong("power");
|
||||
this.progress = nbt.getInteger("progress");
|
||||
}
|
||||
@ -114,7 +117,7 @@ public class TileEntityMachineElectricFurnace extends TileEntityMachineBase impl
|
||||
}
|
||||
|
||||
public boolean canProcess() {
|
||||
|
||||
|
||||
if(slots[1] == null || cooldown > 0) {
|
||||
return false;
|
||||
}
|
||||
@ -167,7 +170,7 @@ public class TileEntityMachineElectricFurnace extends TileEntityMachineBase impl
|
||||
boolean markDirty = false;
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
|
||||
|
||||
if(cooldown > 0) {
|
||||
cooldown--;
|
||||
}
|
||||
@ -179,16 +182,16 @@ public class TileEntityMachineElectricFurnace extends TileEntityMachineBase impl
|
||||
this.consumption = 50;
|
||||
this.maxProgress = 100;
|
||||
|
||||
UpgradeManager.eval(slots, 3, 3);
|
||||
upgradeManager.checkSlots(this, slots, 3, 3);
|
||||
|
||||
int speedLevel = UpgradeManager.getLevel(UpgradeType.SPEED);
|
||||
int powerLevel = UpgradeManager.getLevel(UpgradeType.POWER);
|
||||
int speedLevel = upgradeManager.getLevel(UpgradeType.SPEED);
|
||||
int powerLevel = upgradeManager.getLevel(UpgradeType.POWER);
|
||||
|
||||
maxProgress -= speedLevel * 25;
|
||||
consumption += speedLevel * 50;
|
||||
maxProgress += powerLevel * 10;
|
||||
consumption -= powerLevel * 15;
|
||||
|
||||
|
||||
if(!hasPower()) {
|
||||
cooldown = 20;
|
||||
}
|
||||
@ -197,7 +200,7 @@ public class TileEntityMachineElectricFurnace extends TileEntityMachineBase impl
|
||||
progress++;
|
||||
|
||||
power -= consumption;
|
||||
|
||||
|
||||
if(worldObj.getTotalWorldTime() % 20 == 0) PollutionHandler.incrementPollution(worldObj, xCoord, yCoord, zCoord, PollutionType.SOOT, PollutionHandler.SOOT_PER_SECOND);
|
||||
|
||||
if(this.progress >= maxProgress) {
|
||||
@ -219,7 +222,7 @@ public class TileEntityMachineElectricFurnace extends TileEntityMachineBase impl
|
||||
markDirty = true;
|
||||
MachineElectricFurnace.updateBlockState(this.progress > 0, this.worldObj, this.xCoord, this.yCoord, this.zCoord);
|
||||
}
|
||||
|
||||
|
||||
this.networkPackNT(50);
|
||||
|
||||
|
||||
@ -228,7 +231,7 @@ public class TileEntityMachineElectricFurnace extends TileEntityMachineBase impl
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void serialize(ByteBuf buf) {
|
||||
super.serialize(buf);
|
||||
@ -236,7 +239,7 @@ public class TileEntityMachineElectricFurnace extends TileEntityMachineBase impl
|
||||
buf.writeInt(maxProgress);
|
||||
buf.writeInt(progress);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void deserialize(ByteBuf buf) {
|
||||
super.deserialize(buf);
|
||||
@ -244,7 +247,7 @@ public class TileEntityMachineElectricFurnace extends TileEntityMachineBase impl
|
||||
maxProgress = buf.readInt();
|
||||
progress = buf.readInt();
|
||||
}
|
||||
|
||||
|
||||
private void updateConnections() {
|
||||
|
||||
for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
|
||||
@ -298,9 +301,10 @@ public class TileEntityMachineElectricFurnace extends TileEntityMachineBase impl
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel(UpgradeType type) {
|
||||
if(type == UpgradeType.SPEED) return 3;
|
||||
if(type == UpgradeType.POWER) return 3;
|
||||
return 0;
|
||||
public HashMap<UpgradeType, Integer> getValidUpgrades() {
|
||||
HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
|
||||
upgrades.put(UpgradeType.SPEED, 3);
|
||||
upgrades.put(UpgradeType.POWER, 3);
|
||||
return upgrades;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,10 +1,7 @@
|
||||
package com.hbm.tileentity.machine;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.*;
|
||||
|
||||
import com.hbm.blocks.BlockDummyable;
|
||||
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.entity.item.EntityMovingItem;
|
||||
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.fluid.Fluids;
|
||||
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 long power;
|
||||
public boolean operational = false;
|
||||
|
||||
|
||||
public boolean enableDrill = false;
|
||||
public boolean enableCrusher = false;
|
||||
public boolean enableWalling = false;
|
||||
public boolean enableVeinMiner = false;
|
||||
public boolean enableSilkTouch = false;
|
||||
|
||||
|
||||
protected int ticksWorked = 0;
|
||||
protected int targetDepth = 0; //0 is the first block below null position
|
||||
protected boolean bedrockDrilling = false;
|
||||
@ -83,13 +80,15 @@ public class TileEntityMachineExcavator extends TileEntityMachineBase implements
|
||||
public float crusherRotation = 0F;
|
||||
public float prevCrusherRotation = 0F;
|
||||
public int chuteTimer = 0;
|
||||
|
||||
|
||||
public double speed = 1.0D;
|
||||
public final long baseConsumption = 10_000L;
|
||||
public long consumption = baseConsumption;
|
||||
|
||||
|
||||
public FluidTank tank;
|
||||
|
||||
public UpgradeManagerNT upgradeManager = new UpgradeManagerNT();
|
||||
|
||||
public TileEntityMachineExcavator() {
|
||||
super(14);
|
||||
this.tank = new FluidTank(Fluids.SULFURIC_ACID, 16_000);
|
||||
@ -102,48 +101,48 @@ public class TileEntityMachineExcavator extends TileEntityMachineBase implements
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
|
||||
|
||||
//needs to happen on client too for GUI rendering
|
||||
UpgradeManager.eval(slots, 2, 3);
|
||||
int speedLevel = Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 3);
|
||||
int powerLevel = Math.min(UpgradeManager.getLevel(UpgradeType.POWER), 3);
|
||||
|
||||
upgradeManager.checkSlots(this, slots, 2, 3);
|
||||
int speedLevel = upgradeManager.getLevel(UpgradeType.SPEED);
|
||||
int powerLevel = upgradeManager.getLevel(UpgradeType.POWER);
|
||||
|
||||
consumption = baseConsumption * (1 + speedLevel);
|
||||
consumption /= (1 + powerLevel);
|
||||
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
|
||||
|
||||
this.tank.setType(1, slots);
|
||||
|
||||
|
||||
if(worldObj.getTotalWorldTime() % 20 == 0) {
|
||||
tryEjectBuffer();
|
||||
|
||||
|
||||
for(DirPos pos : getConPos()) {
|
||||
this.trySubscribe(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--;
|
||||
|
||||
|
||||
this.power = Library.chargeTEFromItems(slots, 0, this.getPower(), this.getMaxPower());
|
||||
this.operational = false;
|
||||
int radiusLevel = Math.min(UpgradeManager.getLevel(UpgradeType.EFFECT), 3);
|
||||
|
||||
int radiusLevel = upgradeManager.getLevel(UpgradeType.EFFECT);
|
||||
|
||||
EnumDrillType type = this.getInstalledDrill();
|
||||
if(this.enableDrill && type != null && this.power >= this.getPowerConsumption()) {
|
||||
|
||||
|
||||
operational = true;
|
||||
this.power -= this.getPowerConsumption();
|
||||
|
||||
|
||||
this.speed = type.speed;
|
||||
this.speed *= (1 + speedLevel / 2D);
|
||||
|
||||
|
||||
int maxDepth = this.yCoord - 4;
|
||||
|
||||
if((bedrockDrilling || targetDepth <= maxDepth) && tryDrill(1 + radiusLevel * 2)) {
|
||||
targetDepth++;
|
||||
|
||||
|
||||
if(targetDepth > maxDepth) {
|
||||
this.enableDrill = false;
|
||||
}
|
||||
@ -151,17 +150,17 @@ public class TileEntityMachineExcavator extends TileEntityMachineBase implements
|
||||
} else {
|
||||
this.targetDepth = 0;
|
||||
}
|
||||
|
||||
|
||||
this.networkPackNT(150);
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
this.prevDrillExtension = this.drillExtension;
|
||||
|
||||
|
||||
if(this.drillExtension != this.targetDepth) {
|
||||
float diff = Math.abs(this.drillExtension - this.targetDepth);
|
||||
float speed = Math.max(0.15F, diff / 10F);
|
||||
|
||||
|
||||
if(diff <= speed) {
|
||||
this.drillExtension = this.targetDepth;
|
||||
} else {
|
||||
@ -172,31 +171,31 @@ public class TileEntityMachineExcavator extends TileEntityMachineBase implements
|
||||
|
||||
this.prevDrillRotation = this.drillRotation;
|
||||
this.prevCrusherRotation = this.crusherRotation;
|
||||
|
||||
|
||||
if(this.operational) {
|
||||
this.drillRotation += 15F;
|
||||
|
||||
|
||||
if(this.enableCrusher) {
|
||||
this.crusherRotation += 15F;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(this.drillRotation >= 360F) {
|
||||
this.drillRotation -= 360F;
|
||||
this.prevDrillRotation -= 360F;
|
||||
}
|
||||
|
||||
|
||||
if(this.crusherRotation >= 360F) {
|
||||
this.crusherRotation -= 360F;
|
||||
this.prevCrusherRotation -= 360F;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected DirPos[] getConPos() {
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset);
|
||||
ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
|
||||
|
||||
|
||||
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),
|
||||
@ -204,7 +203,7 @@ public class TileEntityMachineExcavator extends TileEntityMachineBase implements
|
||||
new DirPos(xCoord - rot.offsetX * 4, yCoord + 1, zCoord - rot.offsetZ * 4, rot.getOpposite())
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void serialize(ByteBuf buf) {
|
||||
super.serialize(buf);
|
||||
@ -219,7 +218,7 @@ public class TileEntityMachineExcavator extends TileEntityMachineBase implements
|
||||
buf.writeLong(power);
|
||||
tank.serialize(buf);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void deserialize(ByteBuf buf) {
|
||||
super.deserialize(buf);
|
||||
@ -234,11 +233,11 @@ public class TileEntityMachineExcavator extends TileEntityMachineBase implements
|
||||
power = buf.readLong();
|
||||
tank.deserialize(buf);
|
||||
}
|
||||
|
||||
|
||||
protected int getY() {
|
||||
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. */
|
||||
protected boolean tryDrill(int radius) {
|
||||
int y = getY();
|
||||
@ -246,22 +245,22 @@ public class TileEntityMachineExcavator extends TileEntityMachineBase implements
|
||||
if(targetDepth == 0 || y == 0) {
|
||||
radius = 1;
|
||||
}
|
||||
|
||||
|
||||
for(int ring = 1; ring <= radius; ring++) {
|
||||
|
||||
|
||||
boolean ignoreAll = true;
|
||||
float combinedHardness = 0F;
|
||||
BlockPos bedrockOre = null;
|
||||
bedrockDrilling = false;
|
||||
|
||||
|
||||
for(int x = xCoord - ring; x <= xCoord + ring; x++) {
|
||||
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 */
|
||||
if(ring == 1 || (x == xCoord - ring || x == xCoord + ring || z == zCoord - ring || z == zCoord + ring)) {
|
||||
|
||||
|
||||
Block b = worldObj.getBlock(x, y, z);
|
||||
|
||||
|
||||
if(b == ModBlocks.ore_bedrock) {
|
||||
combinedHardness = 5 * 60 * 20;
|
||||
bedrockOre = new BlockPos(x, y, z);
|
||||
@ -270,23 +269,23 @@ public class TileEntityMachineExcavator extends TileEntityMachineBase implements
|
||||
ignoreAll = false;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if(shouldIgnoreBlock(b, x, y ,z)) continue;
|
||||
|
||||
|
||||
ignoreAll = false;
|
||||
|
||||
|
||||
combinedHardness += b.getBlockHardness(worldObj, x, y, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(!ignoreAll) {
|
||||
ticksWorked++;
|
||||
|
||||
|
||||
int ticksToWork = (int) Math.ceil(combinedHardness / this.speed);
|
||||
|
||||
|
||||
if(ticksWorked >= ticksToWork) {
|
||||
|
||||
|
||||
if(bedrockOre == null) {
|
||||
breakBlocks(ring);
|
||||
buildWall(ring + 1, ring == radius && this.enableWalling);
|
||||
@ -297,7 +296,7 @@ public class TileEntityMachineExcavator extends TileEntityMachineBase implements
|
||||
}
|
||||
ticksWorked = 0;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
} else {
|
||||
tryCollect(radius + 1);
|
||||
@ -308,26 +307,26 @@ public class TileEntityMachineExcavator extends TileEntityMachineBase implements
|
||||
ticksWorked = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
protected void collectBedrock(BlockPos pos) {
|
||||
TileEntity oreTile = Compat.getTileStandard(worldObj, pos.getX(), pos.getY(), pos.getZ());
|
||||
|
||||
|
||||
if(oreTile instanceof TileEntityBedrockOre) {
|
||||
TileEntityBedrockOre ore = (TileEntityBedrockOre) oreTile;
|
||||
|
||||
|
||||
if(ore.resource == null) return;
|
||||
if(ore.tier > this.getInstalledDrill().tier) return;
|
||||
if(ore.acidRequirement != null) {
|
||||
|
||||
|
||||
if(ore.acidRequirement.type != tank.getTankType() || ore.acidRequirement.fill > tank.getFill()) return;
|
||||
|
||||
|
||||
tank.setFill(tank.getFill() - ore.acidRequirement.fill);
|
||||
}
|
||||
|
||||
|
||||
ItemStack stack = ore.resource.copy();
|
||||
List<ItemStack> stacks = new ArrayList();
|
||||
stacks.add(stack);
|
||||
|
||||
|
||||
if(stack.getItem() == ModItems.bedrock_ore_base) {
|
||||
ItemBedrockOreBase.setOreAmount(stack, pos.getX(), pos.getZ());
|
||||
}
|
||||
@ -337,63 +336,63 @@ public class TileEntityMachineExcavator extends TileEntityMachineBase implements
|
||||
int x = xCoord + dir.offsetX * 4;
|
||||
int y = yCoord - 3;
|
||||
int z = zCoord + dir.offsetZ * 4;
|
||||
|
||||
|
||||
/* try to insert into a valid container */
|
||||
TileEntity tile = worldObj.getTileEntity(x, y, z);
|
||||
if(tile instanceof IInventory) {
|
||||
supplyContainer((IInventory) tile, stacks, dir.getOpposite());
|
||||
}
|
||||
|
||||
|
||||
if(stack.stackSize <= 0) return;
|
||||
|
||||
|
||||
/* try to place on conveyor belt */
|
||||
Block b = worldObj.getBlock(x, y, z);
|
||||
if(b instanceof IConveyorBelt) {
|
||||
supplyConveyor((IConveyorBelt) b, stacks, x, y, z);
|
||||
}
|
||||
|
||||
|
||||
if(stack.stackSize <= 0) return;
|
||||
|
||||
|
||||
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])) {
|
||||
int toAdd = Math.min(slots[i].getMaxStackSize() - slots[i].stackSize, stack.stackSize);
|
||||
slots[i].stackSize += toAdd;
|
||||
stack.stackSize -= toAdd;
|
||||
|
||||
|
||||
chuteTimer = 40;
|
||||
|
||||
|
||||
if(stack.stackSize <= 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* add leftovers to empty slots */
|
||||
for(int i = 5; i < 14; i++) {
|
||||
|
||||
|
||||
if(slots[i] == null) {
|
||||
|
||||
|
||||
chuteTimer = 40;
|
||||
|
||||
|
||||
slots[i] = stack.copy();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** breaks and drops all blocks in the specified ring */
|
||||
protected void breakBlocks(int ring) {
|
||||
int y = getY();
|
||||
|
||||
|
||||
for(int x = xCoord - ring; x <= xCoord + ring; x++) {
|
||||
for(int z = zCoord - ring; z <= zCoord + ring; z++) {
|
||||
|
||||
|
||||
if(ring == 1 || (x == xCoord - ring || x == xCoord + ring || z == zCoord - ring || z == zCoord + ring)) {
|
||||
|
||||
|
||||
Block b = worldObj.getBlock(x, y, z);
|
||||
|
||||
|
||||
if(!this.shouldIgnoreBlock(b, 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) {
|
||||
|
||||
Block b = worldObj.getBlock(x, y, z);
|
||||
|
||||
|
||||
if(this.enableVeinMiner && this.getInstalledDrill().vein) {
|
||||
|
||||
|
||||
if(isOre(x, y, z, b)) {
|
||||
minX = x;
|
||||
minY = y;
|
||||
@ -417,51 +416,51 @@ public class TileEntityMachineExcavator extends TileEntityMachineBase implements
|
||||
maxZ = z;
|
||||
breakRecursively(x, y, z, 10);
|
||||
recursionBrake.clear();
|
||||
|
||||
|
||||
/* 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));
|
||||
for(EntityItem item : items) item.setPosition(x + 0.5, y + 0.5, z + 0.5);
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
breakSingleBlock(b, x, y, z);
|
||||
}
|
||||
|
||||
|
||||
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 */
|
||||
Item blockItem = Item.getItemFromBlock(b);
|
||||
|
||||
|
||||
if(blockItem != null) {
|
||||
List<String> names = ItemStackUtil.getOreDictNames(new ItemStack(blockItem));
|
||||
|
||||
|
||||
for(String name : names) {
|
||||
if(name.startsWith("ore")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private HashSet<BlockPos> recursionBrake = new HashSet();
|
||||
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) {
|
||||
|
||||
|
||||
if(depth < 0) return;
|
||||
BlockPos pos = new BlockPos(x, y, z);
|
||||
if(recursionBrake.contains(pos)) return;
|
||||
recursionBrake.add(pos);
|
||||
|
||||
|
||||
Block b = worldObj.getBlock(x, y, z);
|
||||
|
||||
|
||||
for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
int ix = x + dir.offsetX;
|
||||
int iy = y + dir.offsetY;
|
||||
int iz = z + dir.offsetZ;
|
||||
|
||||
|
||||
if(worldObj.getBlock(ix, iy, iz) == b) {
|
||||
breakRecursively(ix, iy, iz, depth - 1);
|
||||
}
|
||||
@ -475,36 +474,36 @@ public class TileEntityMachineExcavator extends TileEntityMachineBase implements
|
||||
if(y > maxY) maxY = y;
|
||||
if(z < minZ) minZ = z;
|
||||
if(z > maxZ) maxZ = z;
|
||||
|
||||
|
||||
if(this.enableWalling) {
|
||||
worldObj.setBlock(x, y, z, ModBlocks.barricade);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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());
|
||||
|
||||
|
||||
if(this.canSilkTouch()) {
|
||||
|
||||
|
||||
try {
|
||||
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));
|
||||
|
||||
|
||||
if(result != null) {
|
||||
items.clear();
|
||||
items.add(result.copy());
|
||||
}
|
||||
} catch(Exception ex) { }
|
||||
}
|
||||
|
||||
|
||||
if(this.enableCrusher) {
|
||||
|
||||
|
||||
List<ItemStack> list = new ArrayList();
|
||||
|
||||
|
||||
for(ItemStack stack : items) {
|
||||
ItemStack crushed = ShredderRecipes.getShredderResult(stack).copy();
|
||||
|
||||
|
||||
if(crushed.getItem() == ModItems.scrap || crushed.getItem() == ModItems.dust) {
|
||||
list.add(stack);
|
||||
} else {
|
||||
@ -512,36 +511,36 @@ public class TileEntityMachineExcavator extends TileEntityMachineBase implements
|
||||
list.add(crushed);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
items = list;
|
||||
}
|
||||
|
||||
|
||||
if(b == ModBlocks.barricade)
|
||||
items.clear();
|
||||
|
||||
|
||||
for(ItemStack item : items) {
|
||||
worldObj.spawnEntityInWorld(new EntityItem(worldObj, x + 0.5, y + 0.5, z + 0.5, item));
|
||||
}
|
||||
|
||||
|
||||
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 */
|
||||
protected void buildWall(int ring, boolean wallEverything) {
|
||||
int y = getY();
|
||||
|
||||
|
||||
for(int x = xCoord - ring; x <= xCoord + ring; x++) {
|
||||
for(int z = zCoord - ring; z <= zCoord + ring; z++) {
|
||||
|
||||
|
||||
Block b = worldObj.getBlock(x, y, z);
|
||||
|
||||
|
||||
if(x == xCoord - ring || x == xCoord + ring || z == zCoord - ring || z == zCoord + ring) {
|
||||
|
||||
|
||||
if(b.isReplaceable(worldObj, x, y, z) && (wallEverything || b.getMaterial().isLiquid())) {
|
||||
worldObj.setBlock(x, y, z, ModBlocks.barricade);
|
||||
}
|
||||
} else {
|
||||
|
||||
|
||||
if(b.getMaterial().isLiquid()) {
|
||||
worldObj.setBlockToAir(x, y, z);
|
||||
continue;
|
||||
@ -552,14 +551,14 @@ public class TileEntityMachineExcavator extends TileEntityMachineBase implements
|
||||
}
|
||||
protected void mineOuterOres(int ring) {
|
||||
int y = getY();
|
||||
|
||||
|
||||
for(int x = xCoord - ring; x <= xCoord + ring; x++) {
|
||||
for(int z = zCoord - ring; z <= zCoord + ring; z++) {
|
||||
|
||||
|
||||
if(ring == 1 || (x == xCoord - ring || x == xCoord + ring || z == zCoord - ring || z == zCoord + ring)) {
|
||||
|
||||
|
||||
Block b = worldObj.getBlock(x, y, z);
|
||||
|
||||
|
||||
if(!this.shouldIgnoreBlock(b, x, y, z) && this.isOre(x, y, z, b)) {
|
||||
tryMineAtLocation(x, y, z);
|
||||
}
|
||||
@ -567,7 +566,7 @@ public class TileEntityMachineExcavator extends TileEntityMachineBase implements
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void tryEjectBuffer() {
|
||||
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10);
|
||||
@ -575,32 +574,32 @@ public class TileEntityMachineExcavator extends TileEntityMachineBase implements
|
||||
int x = xCoord + dir.offsetX * 4;
|
||||
int y = yCoord - 3;
|
||||
int z = zCoord + dir.offsetZ * 4;
|
||||
|
||||
|
||||
List<ItemStack> items = new ArrayList();
|
||||
|
||||
for(int i = 5; i < 14; i++) {
|
||||
ItemStack stack = slots[i];
|
||||
|
||||
|
||||
if(stack != null) {
|
||||
items.add(stack.copy());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TileEntity tile = worldObj.getTileEntity(x, y, z);
|
||||
if(tile instanceof IInventory) {
|
||||
supplyContainer((IInventory) tile, items, dir.getOpposite());
|
||||
}
|
||||
|
||||
|
||||
Block b = worldObj.getBlock(x, y, z);
|
||||
if(b instanceof IConveyorBelt) {
|
||||
supplyConveyor((IConveyorBelt) b, items, x, y, z);
|
||||
}
|
||||
|
||||
|
||||
items.removeIf(i -> i == null || i.stackSize <= 0);
|
||||
|
||||
for(int i = 5; i < 14; i++) {
|
||||
int index = i - 5;
|
||||
|
||||
|
||||
if(items.size() > index) {
|
||||
slots[i] = items.get(index).copy();
|
||||
} 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 */
|
||||
protected void tryCollect(int radius) {
|
||||
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));
|
||||
|
||||
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10);
|
||||
|
||||
int x = xCoord + dir.offsetX * 4;
|
||||
int y = yCoord - 3;
|
||||
int z = zCoord + dir.offsetZ * 4;
|
||||
|
||||
|
||||
List<ItemStack> stacks = new ArrayList();
|
||||
items.forEach(i -> stacks.add(i.getEntityItem()));
|
||||
|
||||
|
||||
/* try to insert into a valid container */
|
||||
TileEntity tile = worldObj.getTileEntity(x, y, z);
|
||||
if(tile instanceof IInventory) {
|
||||
supplyContainer((IInventory) tile, stacks, dir.getOpposite());
|
||||
}
|
||||
|
||||
|
||||
/* try to place on conveyor belt */
|
||||
Block b = worldObj.getBlock(x, y, z);
|
||||
if(b instanceof IConveyorBelt) {
|
||||
supplyConveyor((IConveyorBelt) b, stacks, x, y, z);
|
||||
}
|
||||
|
||||
|
||||
items.removeIf(i -> i.isDead || i.getEntityItem().stackSize <= 0);
|
||||
|
||||
|
||||
/* collect remaining items in internal buffer */
|
||||
outer:
|
||||
for(EntityItem item : items) {
|
||||
|
||||
|
||||
ItemStack stack = item.getEntityItem();
|
||||
|
||||
|
||||
/* adding items to existing stacks */
|
||||
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])) {
|
||||
int toAdd = Math.min(slots[i].getMaxStackSize() - slots[i].stackSize, stack.stackSize);
|
||||
slots[i].stackSize += toAdd;
|
||||
stack.stackSize -= toAdd;
|
||||
|
||||
|
||||
chuteTimer = 40;
|
||||
|
||||
|
||||
if(stack.stackSize <= 0) {
|
||||
item.setDead();
|
||||
continue outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* add leftovers to empty slots */
|
||||
for(int i = 5; i < 14; i++) {
|
||||
|
||||
|
||||
if(slots[i] == null) {
|
||||
|
||||
|
||||
chuteTimer = 40;
|
||||
|
||||
|
||||
slots[i] = stack.copy();
|
||||
item.setDead();
|
||||
break;
|
||||
@ -675,60 +674,60 @@ public class TileEntityMachineExcavator extends TileEntityMachineBase implements
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** places all items into a connected container, if possible */
|
||||
protected void supplyContainer(IInventory inv, List<ItemStack> items, ForgeDirection dir) {
|
||||
|
||||
|
||||
int side = dir.ordinal();
|
||||
int[] access = null;
|
||||
|
||||
|
||||
if(inv instanceof ISidedInventory) {
|
||||
ISidedInventory sided = (ISidedInventory) inv;
|
||||
access = InventoryUtil.masquerade(sided, dir.ordinal());
|
||||
}
|
||||
|
||||
|
||||
for(ItemStack item : items) {
|
||||
|
||||
|
||||
if(item.stackSize <= 0) continue;
|
||||
|
||||
|
||||
CraneInserter.addToInventory(inv, access, item, side);
|
||||
chuteTimer = 40;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** moves all items onto a connected conveyor belt */
|
||||
protected void supplyConveyor(IConveyorBelt belt, List<ItemStack> items, int x, int y, int z) {
|
||||
|
||||
|
||||
Random rand = worldObj.rand;
|
||||
|
||||
|
||||
for(ItemStack item : items) {
|
||||
|
||||
|
||||
if(item.stackSize <= 0) continue;
|
||||
|
||||
|
||||
Vec3 base = Vec3.createVectorHelper(x + rand.nextDouble(), y + 0.5, z + rand.nextDouble());
|
||||
Vec3 vec = belt.getClosestSnappingPosition(worldObj, x, y, z, base);
|
||||
|
||||
|
||||
EntityMovingItem moving = new EntityMovingItem(worldObj);
|
||||
moving.setPosition(base.xCoord, vec.yCoord, base.zCoord);
|
||||
moving.setItemStack(item.copy());
|
||||
worldObj.spawnEntityInWorld(moving);
|
||||
item.stackSize = 0;
|
||||
|
||||
|
||||
chuteTimer = 40;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public long getPowerConsumption() {
|
||||
return consumption;
|
||||
}
|
||||
|
||||
|
||||
public int getFortuneLevel() {
|
||||
EnumDrillType type = getInstalledDrill();
|
||||
|
||||
|
||||
if(type != null) return type.fortune;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
@ -740,32 +739,32 @@ public class TileEntityMachineExcavator extends TileEntityMachineBase implements
|
||||
if(data.hasKey("walling")) this.enableWalling = !this.enableWalling;
|
||||
if(data.hasKey("veinminer")) this.enableVeinMiner = !this.enableVeinMiner;
|
||||
if(data.hasKey("silktouch")) this.enableSilkTouch = !this.enableSilkTouch;
|
||||
|
||||
|
||||
this.markChanged();
|
||||
}
|
||||
|
||||
|
||||
public EnumDrillType getInstalledDrill() {
|
||||
if(slots[4] != null && slots[4].getItem() instanceof ItemDrillbit) {
|
||||
return EnumUtil.grabEnumSafely(EnumDrillType.class, slots[4].getItemDamage());
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public boolean canVeinMine() {
|
||||
EnumDrillType type = getInstalledDrill();
|
||||
return this.enableVeinMiner && type != null && type.vein;
|
||||
}
|
||||
|
||||
|
||||
public boolean canSilkTouch() {
|
||||
EnumDrillType type = getInstalledDrill();
|
||||
return this.enableSilkTouch && type != null && type.silk;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
super.readFromNBT(nbt);
|
||||
|
||||
|
||||
this.enableDrill = nbt.getBoolean("d");
|
||||
this.enableCrusher = nbt.getBoolean("c");
|
||||
this.enableWalling = nbt.getBoolean("w");
|
||||
@ -775,11 +774,11 @@ public class TileEntityMachineExcavator extends TileEntityMachineBase implements
|
||||
this.power = nbt.getLong("p");
|
||||
this.tank.readFromNBT(nbt, "tank");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
super.writeToNBT(nbt);
|
||||
|
||||
|
||||
nbt.setBoolean("d", enableDrill);
|
||||
nbt.setBoolean("c", enableCrusher);
|
||||
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) {
|
||||
return new GUIMachineExcavator(player.inventory, this);
|
||||
}
|
||||
|
||||
|
||||
AxisAlignedBB bb = null;
|
||||
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getRenderBoundingBox() {
|
||||
|
||||
|
||||
if(bb == null) {
|
||||
bb = AxisAlignedBB.getBoundingBox(
|
||||
xCoord - 3,
|
||||
@ -821,10 +820,10 @@ public class TileEntityMachineExcavator extends TileEntityMachineBase implements
|
||||
zCoord + 4
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
return bb;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public double getMaxRenderDistanceSquared() {
|
||||
@ -874,10 +873,11 @@ public class TileEntityMachineExcavator extends TileEntityMachineBase implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel(UpgradeType type) {
|
||||
if(type == UpgradeType.SPEED) return 3;
|
||||
if(type == UpgradeType.POWER) return 3;
|
||||
return 0;
|
||||
public HashMap<UpgradeType, Integer> getValidUpgrades() {
|
||||
HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
|
||||
upgrades.put(UpgradeType.SPEED, 3);
|
||||
upgrades.put(UpgradeType.POWER, 3);
|
||||
return upgrades;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
package com.hbm.tileentity.machine;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
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.gui.GUIMachineExposureChamber;
|
||||
import com.hbm.inventory.recipes.ExposureChamberRecipes;
|
||||
@ -31,10 +32,10 @@ import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public class TileEntityMachineExposureChamber extends TileEntityMachineBase implements IGUIProvider, IEnergyReceiverMK2, IUpgradeInfoProvider {
|
||||
|
||||
|
||||
public long power;
|
||||
public static final long maxPower = 1_000_000;
|
||||
|
||||
|
||||
public int progress;
|
||||
public static final int processTimeBase = 200;
|
||||
public int processTime = processTimeBase;
|
||||
@ -45,7 +46,9 @@ public class TileEntityMachineExposureChamber extends TileEntityMachineBase impl
|
||||
public boolean isOn = false;
|
||||
public float rotation;
|
||||
public float prevRotation;
|
||||
|
||||
|
||||
public UpgradeManagerNT upgradeManager = new UpgradeManagerNT();
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
super.readFromNBT(nbt);
|
||||
@ -53,7 +56,7 @@ public class TileEntityMachineExposureChamber extends TileEntityMachineBase impl
|
||||
this.power = nbt.getLong("power");
|
||||
this.savedParticles = nbt.getInteger("savedParticles");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
super.writeToNBT(nbt);
|
||||
@ -82,39 +85,39 @@ public class TileEntityMachineExposureChamber extends TileEntityMachineBase impl
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
|
||||
|
||||
this.isOn = false;
|
||||
this.power = Library.chargeTEFromItems(slots, 5, power, maxPower);
|
||||
|
||||
|
||||
if(worldObj.getTotalWorldTime() % 20 == 0) {
|
||||
for(DirPos pos : getConPos()) this.trySubscribe(worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
|
||||
}
|
||||
|
||||
UpgradeManager.eval(slots, 6, 7);
|
||||
int speedLevel = Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 3);
|
||||
int powerLevel = Math.min(UpgradeManager.getLevel(UpgradeType.POWER), 3);
|
||||
int overdriveLevel = Math.min(UpgradeManager.getLevel(UpgradeType.OVERDRIVE), 3);
|
||||
|
||||
|
||||
upgradeManager.checkSlots(this, slots, 6, 7);
|
||||
int speedLevel = upgradeManager.getLevel(UpgradeType.SPEED);
|
||||
int powerLevel = upgradeManager.getLevel(UpgradeType.POWER);
|
||||
int overdriveLevel = upgradeManager.getLevel(UpgradeType.OVERDRIVE);
|
||||
|
||||
this.consumption = this.consumptionBase;
|
||||
|
||||
|
||||
this.processTime = this.processTimeBase - this.processTimeBase / 4 * speedLevel;
|
||||
this.consumption *= (speedLevel / 2 + 1);
|
||||
this.processTime *= (powerLevel / 2 + 1);
|
||||
this.consumption /= (powerLevel + 1);
|
||||
this.processTime /= (overdriveLevel + 1);
|
||||
this.consumption *= (overdriveLevel * 2 + 1);
|
||||
|
||||
|
||||
if(slots[1] == null && slots[0] != null && slots[3] != null && this.savedParticles <= 0) {
|
||||
ExposureChamberRecipe recipe = this.getRecipe(slots[0], slots[3]);
|
||||
|
||||
|
||||
if(recipe != null) {
|
||||
|
||||
|
||||
ItemStack container = slots[0].getItem().getContainerItem(slots[0]);
|
||||
|
||||
|
||||
boolean canStore = false;
|
||||
|
||||
|
||||
if(container == null) {
|
||||
canStore = true;
|
||||
} else if(slots[2] == null) {
|
||||
@ -124,7 +127,7 @@ public class TileEntityMachineExposureChamber extends TileEntityMachineBase impl
|
||||
slots[2].stackSize++;
|
||||
canStore = true;
|
||||
}
|
||||
|
||||
|
||||
if(canStore) {
|
||||
slots[1] = slots[0].copy();
|
||||
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) {
|
||||
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()))) {
|
||||
this.progress++;
|
||||
this.power -= this.consumption;
|
||||
this.isOn = true;
|
||||
|
||||
|
||||
if(this.progress >= this.processTime) {
|
||||
this.progress = 0;
|
||||
this.savedParticles--;
|
||||
this.decrStackSize(3, 1);
|
||||
|
||||
|
||||
if(slots[4] == null) {
|
||||
slots[4] = recipe.output.copy();
|
||||
} else {
|
||||
slots[4].stackSize += recipe.output.stackSize;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
this.progress = 0;
|
||||
}
|
||||
} else {
|
||||
this.progress = 0;
|
||||
}
|
||||
|
||||
|
||||
if(this.savedParticles <= 0) {
|
||||
slots[1] = null;
|
||||
}
|
||||
|
||||
|
||||
this.networkPackNT(50);
|
||||
} else {
|
||||
|
||||
|
||||
this.prevRotation = this.rotation;
|
||||
|
||||
|
||||
if(this.isOn) {
|
||||
|
||||
|
||||
this.rotation += 10D;
|
||||
|
||||
|
||||
if(this.rotation >= 720D) {
|
||||
this.rotation -= 720D;
|
||||
this.prevRotation -= 720D;
|
||||
@ -181,7 +184,7 @@ public class TileEntityMachineExposureChamber extends TileEntityMachineBase impl
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public DirPos[] getConPos() {
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10);
|
||||
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)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public ExposureChamberRecipe getRecipe(ItemStack particle, ItemStack ingredient) {
|
||||
return ExposureChamberRecipes.getRecipe(particle, ingredient);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack stack) {
|
||||
|
||||
|
||||
//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
|
||||
if(i == 0 && slots[0] != null) return true;
|
||||
if(i == 3 && slots[3] != null) return true;
|
||||
|
||||
|
||||
//if there's no particle stored, use the un-consumed capsule for reference
|
||||
ItemStack particle = slots[1] != null ? slots[1] : slots[0];
|
||||
|
||||
|
||||
//if no particle is loaded and an ingot is present
|
||||
if(i == 0 && particle == null && slots[3] != null) {
|
||||
ExposureChamberRecipe recipe = getRecipe(stack, slots[3]);
|
||||
return recipe != null;
|
||||
}
|
||||
|
||||
|
||||
//if a particle is loaded but no ingot present
|
||||
if(i == 3 && particle != null && slots[3] == null) {
|
||||
ExposureChamberRecipe recipe = getRecipe(slots[0], stack);
|
||||
return recipe != null;
|
||||
}
|
||||
|
||||
|
||||
//if there's nothing at all, find a reference recipe and see if the item matches anything
|
||||
if(particle == null && slots[3] == null) {
|
||||
|
||||
|
||||
for(ExposureChamberRecipe recipe : ExposureChamberRecipes.recipes) {
|
||||
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;
|
||||
}
|
||||
|
||||
@ -253,7 +256,7 @@ public class TileEntityMachineExposureChamber extends TileEntityMachineBase impl
|
||||
buf.writeLong(this.power);
|
||||
buf.writeByte((byte) this.savedParticles);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void deserialize(ByteBuf buf) {
|
||||
this.isOn = buf.readBoolean();
|
||||
@ -280,10 +283,10 @@ public class TileEntityMachineExposureChamber extends TileEntityMachineBase impl
|
||||
}
|
||||
|
||||
AxisAlignedBB bb = null;
|
||||
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getRenderBoundingBox() {
|
||||
|
||||
|
||||
if(bb == null) {
|
||||
bb = AxisAlignedBB.getBoundingBox(
|
||||
xCoord - 8,
|
||||
@ -294,10 +297,10 @@ public class TileEntityMachineExposureChamber extends TileEntityMachineBase impl
|
||||
zCoord + 9
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
return bb;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public double getMaxRenderDistanceSquared() {
|
||||
@ -337,10 +340,11 @@ public class TileEntityMachineExposureChamber extends TileEntityMachineBase impl
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel(UpgradeType type) {
|
||||
if(type == UpgradeType.SPEED) return 3;
|
||||
if(type == UpgradeType.POWER) return 3;
|
||||
if(type == UpgradeType.OVERDRIVE) return 3;
|
||||
return 0;
|
||||
public HashMap<UpgradeType, Integer> getValidUpgrades() {
|
||||
HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
|
||||
upgrades.put(UpgradeType.SPEED, 3);
|
||||
upgrades.put(UpgradeType.POWER, 3);
|
||||
upgrades.put(UpgradeType.OVERDRIVE, 3);
|
||||
return upgrades;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
package com.hbm.tileentity.machine;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
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.fluid.Fluids;
|
||||
import com.hbm.inventory.fluid.tank.FluidTank;
|
||||
@ -69,6 +70,8 @@ public class TileEntityMachineMiningLaser extends TileEntityMachineBase implemen
|
||||
boolean lock = false;
|
||||
double breakProgress;
|
||||
|
||||
public UpgradeManagerNT upgradeManager = new UpgradeManagerNT();
|
||||
|
||||
public TileEntityMachineMiningLaser() {
|
||||
|
||||
//slot 0: battery
|
||||
@ -112,14 +115,14 @@ public class TileEntityMachineMiningLaser extends TileEntityMachineBase implemen
|
||||
|
||||
if(isOn) {
|
||||
|
||||
UpgradeManager.eval(slots, 1, 8);
|
||||
int cycles = 1 + UpgradeManager.getLevel(UpgradeType.OVERDRIVE);
|
||||
int speed = 1 + Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 12);
|
||||
int range = 1 + Math.min(UpgradeManager.getLevel(UpgradeType.EFFECT) * 2, 24);
|
||||
int fortune = Math.min(UpgradeManager.getLevel(UpgradeType.FORTUNE), 3);
|
||||
upgradeManager.checkSlots(this, slots, 1, 8);
|
||||
int cycles = 1 + upgradeManager.getLevel(UpgradeType.OVERDRIVE);
|
||||
int speed = 1 + upgradeManager.getLevel(UpgradeType.SPEED);
|
||||
int range = 1 + upgradeManager.getLevel(UpgradeType.EFFECT) * 2;
|
||||
int fortune = upgradeManager.getLevel(UpgradeType.FORTUNE);
|
||||
int consumption = this.consumption
|
||||
- (this.consumption * Math.min(UpgradeManager.getLevel(UpgradeType.POWER), 12) / 16)
|
||||
+ (this.consumption * Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 12) / 16);
|
||||
- (this.consumption * upgradeManager.getLevel(UpgradeType.POWER) / 16)
|
||||
+ (this.consumption * upgradeManager.getLevel(UpgradeType.SPEED) / 16);
|
||||
|
||||
for(int i = 0; i < cycles; i++) {
|
||||
|
||||
@ -678,12 +681,13 @@ public class TileEntityMachineMiningLaser extends TileEntityMachineBase implemen
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel(UpgradeType type) {
|
||||
if(type == UpgradeType.SPEED) return 12;
|
||||
if(type == UpgradeType.POWER) return 12;
|
||||
if(type == UpgradeType.EFFECT) return 12;
|
||||
if(type == UpgradeType.FORTUNE) return 3;
|
||||
if(type == UpgradeType.OVERDRIVE) return 9;
|
||||
return 0;
|
||||
public HashMap<UpgradeType, Integer> getValidUpgrades() {
|
||||
HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
|
||||
upgrades.put(UpgradeType.SPEED, 12);
|
||||
upgrades.put(UpgradeType.POWER, 12);
|
||||
upgrades.put(UpgradeType.EFFECT, 12);
|
||||
upgrades.put(UpgradeType.FORTUNE, 3);
|
||||
upgrades.put(UpgradeType.OVERDRIVE, 9);
|
||||
return upgrades;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
package com.hbm.tileentity.machine;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import com.hbm.blocks.ModBlocks;
|
||||
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.fluid.Fluids;
|
||||
import com.hbm.inventory.fluid.tank.FluidTank;
|
||||
@ -32,21 +33,23 @@ import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class TileEntityMachineMixer extends TileEntityMachineBase implements IControlReceiver, IGUIProvider, IEnergyReceiverMK2, IFluidStandardTransceiver, IUpgradeInfoProvider, IFluidCopiable {
|
||||
|
||||
|
||||
public long power;
|
||||
public static final long maxPower = 10_000;
|
||||
public int progress;
|
||||
public int processTime;
|
||||
public int recipeIndex;
|
||||
|
||||
|
||||
public float rotation;
|
||||
public float prevRotation;
|
||||
public boolean wasOn = false;
|
||||
|
||||
private int consumption = 50;
|
||||
|
||||
|
||||
public FluidTank[] tanks;
|
||||
|
||||
public UpgradeManagerNT upgradeManager = new UpgradeManagerNT();
|
||||
|
||||
public TileEntityMachineMixer() {
|
||||
super(5);
|
||||
this.tanks = new FluidTank[3];
|
||||
@ -62,53 +65,53 @@ public class TileEntityMachineMixer extends TileEntityMachineBase implements ICo
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
|
||||
|
||||
this.power = Library.chargeTEFromItems(slots, 0, power, maxPower);
|
||||
tanks[2].setType(2, slots);
|
||||
|
||||
UpgradeManager.eval(slots, 3, 4);
|
||||
int speedLevel = Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 3);
|
||||
int powerLevel = Math.min(UpgradeManager.getLevel(UpgradeType.POWER), 3);
|
||||
int overLevel = UpgradeManager.getLevel(UpgradeType.OVERDRIVE);
|
||||
|
||||
|
||||
upgradeManager.checkSlots(this, slots, 3, 4);
|
||||
int speedLevel = upgradeManager.getLevel(UpgradeType.SPEED);
|
||||
int powerLevel = upgradeManager.getLevel(UpgradeType.POWER);
|
||||
int overLevel = upgradeManager.getLevel(UpgradeType.OVERDRIVE);
|
||||
|
||||
this.consumption = 50;
|
||||
|
||||
this.consumption += speedLevel * 150;
|
||||
this.consumption -= this.consumption * powerLevel * 0.25;
|
||||
this.consumption *= (overLevel * 3 + 1);
|
||||
|
||||
|
||||
for(DirPos pos : getConPos()) {
|
||||
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[1].getTankType() != Fluids.NONE) this.trySubscribe(tanks[1].getTankType(), worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
|
||||
}
|
||||
|
||||
|
||||
this.wasOn = this.canProcess();
|
||||
|
||||
|
||||
if(this.wasOn) {
|
||||
this.progress++;
|
||||
this.power -= this.getConsumption();
|
||||
|
||||
|
||||
this.processTime -= this.processTime * speedLevel / 4;
|
||||
this.processTime /= (overLevel + 1);
|
||||
|
||||
|
||||
if(processTime <= 0) this.processTime = 1;
|
||||
|
||||
|
||||
if(this.progress >= this.processTime) {
|
||||
this.process();
|
||||
this.progress = 0;
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
this.progress = 0;
|
||||
}
|
||||
|
||||
|
||||
for(DirPos pos : getConPos()) {
|
||||
if(tanks[2].getFill() > 0) this.sendFluid(tanks[2], worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
|
||||
}
|
||||
|
||||
|
||||
NBTTagCompound data = new NBTTagCompound();
|
||||
data.setLong("power", power);
|
||||
data.setInteger("processTime", processTime);
|
||||
@ -119,22 +122,22 @@ public class TileEntityMachineMixer extends TileEntityMachineBase implements ICo
|
||||
tanks[i].writeToNBT(data, i + "");
|
||||
}
|
||||
this.networkPackNT(50);
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
this.prevRotation = this.rotation;
|
||||
|
||||
|
||||
if(this.wasOn) {
|
||||
this.rotation += 20F;
|
||||
}
|
||||
|
||||
|
||||
if(this.rotation >= 360) {
|
||||
this.rotation -= 360;
|
||||
this.prevRotation -= 360;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void serialize(ByteBuf buf) {
|
||||
super.serialize(buf);
|
||||
@ -143,10 +146,10 @@ public class TileEntityMachineMixer extends TileEntityMachineBase implements ICo
|
||||
buf.writeInt(progress);
|
||||
buf.writeInt(recipeIndex);
|
||||
buf.writeBoolean(wasOn);
|
||||
|
||||
|
||||
for(int i = 0; i < tanks.length; i++) tanks[i].serialize(buf);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void deserialize(ByteBuf buf) {
|
||||
super.deserialize(buf);
|
||||
@ -155,10 +158,10 @@ public class TileEntityMachineMixer extends TileEntityMachineBase implements ICo
|
||||
progress = buf.readInt();
|
||||
recipeIndex = buf.readInt();
|
||||
wasOn = buf.readBoolean();
|
||||
|
||||
|
||||
for(int i = 0; i < tanks.length; i++) tanks[i].deserialize(buf);
|
||||
}
|
||||
|
||||
|
||||
public boolean canProcess() {
|
||||
|
||||
MixerRecipe[] recipes = MixerRecipes.getOutput(tanks[2].getTankType());
|
||||
@ -166,38 +169,38 @@ public class TileEntityMachineMixer extends TileEntityMachineBase implements ICo
|
||||
this.recipeIndex = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
this.recipeIndex = this.recipeIndex % recipes.length;
|
||||
MixerRecipe recipe = recipes[this.recipeIndex];
|
||||
if(recipe == null) {
|
||||
this.recipeIndex = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
tanks[0].setTankType(recipe.input1 != null ? recipe.input1.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.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 */
|
||||
if(this.power < getConsumption()) return false;
|
||||
|
||||
|
||||
if(recipe.output + tanks[2].getFill() > tanks[2].getMaxFill()) return false;
|
||||
|
||||
|
||||
if(recipe.solidInput != null) {
|
||||
|
||||
|
||||
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;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
protected void process() {
|
||||
|
||||
|
||||
MixerRecipe[] recipes = MixerRecipes.getOutput(tanks[2].getTankType());
|
||||
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);
|
||||
tanks[2].setFill(tanks[2].getFill() + recipe.output);
|
||||
}
|
||||
|
||||
|
||||
public int getConsumption() {
|
||||
return consumption;
|
||||
}
|
||||
|
||||
|
||||
protected DirPos[] getConPos() {
|
||||
return new DirPos[] {
|
||||
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),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsFromSide(int meta) {
|
||||
return new int[] { 1 };
|
||||
@ -228,16 +231,16 @@ public class TileEntityMachineMixer extends TileEntityMachineBase implements ICo
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemStack) {
|
||||
|
||||
|
||||
MixerRecipe[] recipes = MixerRecipes.getOutput(tanks[2].getTankType());
|
||||
if(recipes == null || recipes.length <= 0) return false;
|
||||
|
||||
|
||||
MixerRecipe recipe = recipes[this.recipeIndex % recipes.length];
|
||||
if(recipe == null || recipe.solidInput == null) return false;
|
||||
|
||||
|
||||
return recipe.solidInput.matchesRecipe(itemStack, true);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
super.readFromNBT(nbt);
|
||||
@ -248,11 +251,11 @@ public class TileEntityMachineMixer extends TileEntityMachineBase implements ICo
|
||||
this.recipeIndex = nbt.getInteger("recipe");
|
||||
for(int i = 0; i < 3; i++) this.tanks[i].readFromNBT(nbt, i + "");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
super.writeToNBT(nbt);
|
||||
|
||||
|
||||
nbt.setLong("power", power);
|
||||
nbt.setInteger("progress", progress);
|
||||
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) {
|
||||
return new GUIMixer(player.inventory, this);
|
||||
}
|
||||
|
||||
|
||||
AxisAlignedBB aabb;
|
||||
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getRenderBoundingBox() {
|
||||
|
||||
|
||||
if(aabb != null)
|
||||
return aabb;
|
||||
|
||||
|
||||
aabb = AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 3, zCoord + 1);
|
||||
return aabb;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public double getMaxRenderDistanceSquared() {
|
||||
@ -350,11 +353,12 @@ public class TileEntityMachineMixer extends TileEntityMachineBase implements ICo
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel(UpgradeType type) {
|
||||
if(type == UpgradeType.SPEED) return 3;
|
||||
if(type == UpgradeType.POWER) return 3;
|
||||
if(type == UpgradeType.OVERDRIVE) return 6;
|
||||
return 0;
|
||||
public HashMap<UpgradeType, Integer> getValidUpgrades() {
|
||||
HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
|
||||
upgrades.put(UpgradeType.SPEED, 3);
|
||||
upgrades.put(UpgradeType.POWER, 3);
|
||||
upgrades.put(UpgradeType.OVERDRIVE, 6);
|
||||
return upgrades;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
package com.hbm.tileentity.machine;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
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.fluid.FluidType;
|
||||
import com.hbm.inventory.fluid.Fluids;
|
||||
@ -47,18 +48,18 @@ import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public class TileEntityMachineOreSlopper extends TileEntityMachineBase implements IEnergyReceiverMK2, IFluidStandardTransceiver, IGUIProvider, IUpgradeInfoProvider, IFluidCopiable {
|
||||
|
||||
|
||||
public long power;
|
||||
public static final long maxPower = 100_000;
|
||||
|
||||
|
||||
public static final int waterUsedBase = 1_000;
|
||||
public int waterUsed = waterUsedBase;
|
||||
public static final long consumptionBase = 200;
|
||||
public long consumption = consumptionBase;
|
||||
|
||||
|
||||
public float progress;
|
||||
public boolean processing;
|
||||
|
||||
|
||||
public SlopperAnimation animation = SlopperAnimation.LOWERING;
|
||||
public float slider;
|
||||
public float prevSlider;
|
||||
@ -69,10 +70,12 @@ public class TileEntityMachineOreSlopper extends TileEntityMachineBase implement
|
||||
public float fan;
|
||||
public float prevFan;
|
||||
public int delay;
|
||||
|
||||
|
||||
public FluidTank[] tanks;
|
||||
public double[] ores = new double[BedrockOreType.values().length];
|
||||
|
||||
public UpgradeManagerNT upgradeManager = new UpgradeManagerNT();
|
||||
|
||||
public TileEntityMachineOreSlopper() {
|
||||
super(11);
|
||||
tanks = new FluidTank[2];
|
||||
@ -84,75 +87,75 @@ public class TileEntityMachineOreSlopper extends TileEntityMachineBase implement
|
||||
public String getName() {
|
||||
return "container.machineOreSlopper";
|
||||
}
|
||||
|
||||
|
||||
public static enum SlopperAnimation {
|
||||
LOWERING, LIFTING, MOVE_SHREDDER, DUMPING, MOVE_BUCKET
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
|
||||
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10);
|
||||
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
|
||||
|
||||
this.power = Library.chargeTEFromItems(slots, 0, power, maxPower);
|
||||
|
||||
|
||||
tanks[0].setType(1, slots);
|
||||
FluidType conversion = this.getFluidOutput(tanks[0].getTankType());
|
||||
if(conversion != null) tanks[1].setTankType(conversion);
|
||||
|
||||
|
||||
for(DirPos pos : getConPos()) {
|
||||
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());
|
||||
if(tanks[1].getFill() > 0) this.sendFluid(tanks[1], worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
|
||||
}
|
||||
|
||||
|
||||
this.processing = false;
|
||||
|
||||
UpgradeManager.eval(slots, 9, 10);
|
||||
int speed = Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 3);
|
||||
int efficiency = Math.min(UpgradeManager.getLevel(UpgradeType.EFFECT), 3);
|
||||
|
||||
|
||||
upgradeManager.checkSlots(this, slots, 9, 10);
|
||||
int speed = upgradeManager.getLevel(UpgradeType.SPEED);
|
||||
int efficiency = upgradeManager.getLevel(UpgradeType.EFFECT);
|
||||
|
||||
this.consumption = this.consumptionBase + (this.consumptionBase * speed) / 2 + (this.consumptionBase * efficiency);
|
||||
|
||||
|
||||
if(canSlop()) {
|
||||
this.power -= this.consumption;
|
||||
this.progress += 1F / (600 - speed * 150);
|
||||
this.processing = true;
|
||||
boolean markDirty = false;
|
||||
|
||||
|
||||
while(progress >= 1F && canSlop()) {
|
||||
progress -= 1F;
|
||||
|
||||
|
||||
for(BedrockOreType type : BedrockOreType.values()) {
|
||||
ores[type.ordinal()] += (ItemBedrockOreBase.getOreAmount(slots[2], type) * (1D + efficiency * 0.1));
|
||||
}
|
||||
|
||||
|
||||
this.decrStackSize(2, 1);
|
||||
this.tanks[0].setFill(this.tanks[0].getFill() - waterUsed);
|
||||
this.tanks[1].setFill(this.tanks[1].getFill() + waterUsed);
|
||||
markDirty = true;
|
||||
}
|
||||
|
||||
|
||||
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));
|
||||
|
||||
|
||||
for(Entity e : entities) {
|
||||
e.attackEntityFrom(ModDamageSource.turbofan, 1000F);
|
||||
|
||||
|
||||
if(!e.isEntityAlive() && e instanceof EntityLivingBase) {
|
||||
NBTTagCompound vdat = new NBTTagCompound();
|
||||
vdat.setString("type", "giblets");
|
||||
vdat.setInteger("ent", e.getEntityId());
|
||||
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));
|
||||
|
||||
|
||||
worldObj.playSoundEffect(e.posX, e.posY, e.posZ, "mob.zombie.woodbreak", 2.0F, 0.95F + worldObj.rand.nextFloat() * 0.2F);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
this.progress = 0;
|
||||
}
|
||||
@ -169,31 +172,31 @@ public class TileEntityMachineOreSlopper extends TileEntityMachineBase implement
|
||||
break outer;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.networkPackNT(150);
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
this.prevSlider = this.slider;
|
||||
this.prevBucket = this.bucket;
|
||||
this.prevBlades = this.blades;
|
||||
this.prevFan = this.fan;
|
||||
|
||||
|
||||
if(this.processing) {
|
||||
|
||||
|
||||
this.blades += 15F;
|
||||
this.fan += 35F;
|
||||
|
||||
|
||||
if(blades >= 360) {
|
||||
blades -= 360;
|
||||
prevBlades -= 360;
|
||||
}
|
||||
|
||||
|
||||
if(fan >= 360) {
|
||||
fan -= 360;
|
||||
prevFan -= 360;
|
||||
}
|
||||
|
||||
|
||||
if(animation == animation.DUMPING && MainRegistry.proxy.me().getDistance(xCoord + 0.5, yCoord + 4, zCoord + 0.5) <= 50) {
|
||||
NBTTagCompound data = new NBTTagCompound();
|
||||
data.setString("type", "vanillaExt");
|
||||
@ -205,12 +208,12 @@ public class TileEntityMachineOreSlopper extends TileEntityMachineBase implement
|
||||
data.setDouble("mY", -0.2D);
|
||||
MainRegistry.proxy.effectNT(data);
|
||||
}
|
||||
|
||||
|
||||
if(delay > 0) {
|
||||
delay--;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
switch(animation) {
|
||||
case LOWERING:
|
||||
this.bucket += 1F/40F;
|
||||
@ -250,11 +253,11 @@ public class TileEntityMachineOreSlopper extends TileEntityMachineBase implement
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public DirPos[] getConPos() {
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10);
|
||||
ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
|
||||
|
||||
|
||||
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.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};
|
||||
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsFromSide(int side) {
|
||||
return slot_access;
|
||||
@ -293,7 +296,7 @@ public class TileEntityMachineOreSlopper extends TileEntityMachineBase implement
|
||||
tanks[0].serialize(buf);
|
||||
tanks[1].serialize(buf);
|
||||
}
|
||||
|
||||
|
||||
@Override public void deserialize(ByteBuf buf) {
|
||||
super.deserialize(buf);
|
||||
this.power = buf.readLong();
|
||||
@ -303,7 +306,7 @@ public class TileEntityMachineOreSlopper extends TileEntityMachineBase implement
|
||||
tanks[0].deserialize(buf);
|
||||
tanks[1].deserialize(buf);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
super.readFromNBT(nbt);
|
||||
@ -312,7 +315,7 @@ public class TileEntityMachineOreSlopper extends TileEntityMachineBase implement
|
||||
tanks[0].readFromNBT(nbt, "water");
|
||||
tanks[1].readFromNBT(nbt, "slop");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
super.writeToNBT(nbt);
|
||||
@ -321,16 +324,16 @@ public class TileEntityMachineOreSlopper extends TileEntityMachineBase implement
|
||||
tanks[0].writeToNBT(nbt, "water");
|
||||
tanks[1].writeToNBT(nbt, "slop");
|
||||
}
|
||||
|
||||
|
||||
public boolean canSlop() {
|
||||
if(this.getFluidOutput(tanks[0].getTankType()) == null) return false;
|
||||
if(tanks[0].getFill() < waterUsed) return false;
|
||||
if(tanks[1].getFill() + waterUsed > tanks[1].getMaxFill()) return false;
|
||||
if(power < consumption) return false;
|
||||
|
||||
|
||||
return slots[2] != null && slots[2].getItem() == ModItems.bedrock_ore_base;
|
||||
}
|
||||
|
||||
|
||||
public FluidType getFluidOutput(FluidType input) {
|
||||
if(input == Fluids.WATER) return Fluids.SLOP;
|
||||
return null;
|
||||
@ -343,12 +346,12 @@ public class TileEntityMachineOreSlopper extends TileEntityMachineBase implement
|
||||
@Override public FluidTank[] getAllTanks() { return tanks; }
|
||||
@Override public FluidTank[] getSendingTanks() { return new FluidTank[] {tanks[1]}; }
|
||||
@Override public FluidTank[] getReceivingTanks() { return new FluidTank[] {tanks[0]}; }
|
||||
|
||||
|
||||
AxisAlignedBB bb = null;
|
||||
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getRenderBoundingBox() {
|
||||
|
||||
|
||||
if(bb == null) {
|
||||
bb = AxisAlignedBB.getBoundingBox(
|
||||
xCoord - 3,
|
||||
@ -359,10 +362,10 @@ public class TileEntityMachineOreSlopper extends TileEntityMachineBase implement
|
||||
zCoord + 4
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
return bb;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public double getMaxRenderDistanceSquared() {
|
||||
@ -399,9 +402,10 @@ public class TileEntityMachineOreSlopper extends TileEntityMachineBase implement
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel(UpgradeType type) {
|
||||
if(type == UpgradeType.SPEED) return 3;
|
||||
if(type == UpgradeType.EFFECT) return 3;
|
||||
return 0;
|
||||
public HashMap<UpgradeType, Integer> getValidUpgrades() {
|
||||
HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
|
||||
upgrades.put(UpgradeType.SPEED, 3);
|
||||
upgrades.put(UpgradeType.EFFECT, 3);
|
||||
return upgrades;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
package com.hbm.tileentity.machine;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import com.hbm.blocks.ModBlocks;
|
||||
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.container.ContainerMachineSolderingStation;
|
||||
import com.hbm.inventory.fluid.Fluids;
|
||||
@ -53,6 +54,8 @@ public class TileEntityMachineSolderingStation extends TileEntityMachineBase imp
|
||||
public FluidTank tank;
|
||||
public ItemStack display;
|
||||
|
||||
public UpgradeManagerNT upgradeManager = new UpgradeManagerNT();
|
||||
|
||||
public TileEntityMachineSolderingStation() {
|
||||
super(11);
|
||||
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]});
|
||||
long intendedMaxPower;
|
||||
|
||||
UpgradeManager.eval(slots, 9, 10);
|
||||
int redLevel = Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 3);
|
||||
int blueLevel = Math.min(UpgradeManager.getLevel(UpgradeType.POWER), 3);
|
||||
upgradeManager.checkSlots(this, slots, 9, 10);
|
||||
int redLevel = upgradeManager.getLevel(UpgradeType.SPEED);
|
||||
int blueLevel = upgradeManager.getLevel(UpgradeType.POWER);
|
||||
|
||||
if(recipe != null) {
|
||||
this.processTime = recipe.duration - (recipe.duration * redLevel / 6) + (recipe.duration * blueLevel / 3);
|
||||
@ -374,10 +377,11 @@ public class TileEntityMachineSolderingStation extends TileEntityMachineBase imp
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel(UpgradeType type) {
|
||||
if(type == UpgradeType.SPEED) return 3;
|
||||
if(type == UpgradeType.POWER) return 3;
|
||||
return 0;
|
||||
public HashMap<UpgradeType, Integer> getValidUpgrades() {
|
||||
HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
|
||||
upgrades.put(UpgradeType.SPEED, 3);
|
||||
upgrades.put(UpgradeType.POWER, 3);
|
||||
return upgrades;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
package com.hbm.tileentity.machine;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import com.hbm.blocks.BlockDummyable;
|
||||
import com.hbm.blocks.ModBlocks;
|
||||
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.fluid.Fluids;
|
||||
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 FluidTank tank;
|
||||
public FluidTank blood;
|
||||
|
||||
|
||||
public int afterburner;
|
||||
public boolean wasOn;
|
||||
public boolean showBlood = false;
|
||||
@ -64,9 +65,11 @@ public class TileEntityMachineTurbofan extends TileEntityMachinePolluting implem
|
||||
public float spin;
|
||||
public float lastSpin;
|
||||
public int momentum = 0;
|
||||
|
||||
|
||||
private AudioWrapper audio;
|
||||
|
||||
public UpgradeManagerNT upgradeManager = new UpgradeManagerNT();
|
||||
|
||||
public TileEntityMachineTurbofan() {
|
||||
super(5, 150);
|
||||
tank = new FluidTank(Fluids.KEROSENE, 24000);
|
||||
@ -91,7 +94,7 @@ public class TileEntityMachineTurbofan extends TileEntityMachinePolluting implem
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
super.writeToNBT(nbt);
|
||||
|
||||
|
||||
nbt.setLong("powerTime", power);
|
||||
tank.writeToNBT(nbt, "fuel");
|
||||
blood.writeToNBT(nbt, "blood");
|
||||
@ -101,12 +104,12 @@ public class TileEntityMachineTurbofan extends TileEntityMachinePolluting implem
|
||||
public long getPowerScaled(long i) {
|
||||
return (power * i) / maxPower;
|
||||
}
|
||||
|
||||
|
||||
protected DirPos[] getConPos() {
|
||||
|
||||
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10).getRotation(ForgeDirection.UP);
|
||||
ForgeDirection rot = dir.getRotation(ForgeDirection.DOWN);
|
||||
|
||||
|
||||
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 - dir.offsetX, this.yCoord, this.zCoord + rot.offsetZ * 2 - dir.offsetZ, rot),
|
||||
@ -117,12 +120,12 @@ public class TileEntityMachineTurbofan extends TileEntityMachinePolluting implem
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
|
||||
|
||||
this.output = 0;
|
||||
this.consumption = 0;
|
||||
|
||||
|
||||
//meta below 12 means that it's an old multiblock configuration
|
||||
if(this.getBlockMetadata() < 12) {
|
||||
//get old direction
|
||||
@ -144,54 +147,54 @@ public class TileEntityMachineTurbofan extends TileEntityMachinePolluting implem
|
||||
worldObj.getTileEntity(xCoord, yCoord, zCoord).readFromNBT(data);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
tank.setType(4, slots);
|
||||
tank.loadTank(0, 1, slots);
|
||||
blood.setTankType(Fluids.BLOOD);
|
||||
|
||||
|
||||
this.wasOn = false;
|
||||
|
||||
UpgradeManager.eval(slots, 2, 2);
|
||||
this.afterburner = UpgradeManager.getLevel(UpgradeType.AFTERBURN);
|
||||
|
||||
|
||||
upgradeManager.checkSlots(this, slots, 2, 2);
|
||||
this.afterburner = upgradeManager.getLevel(UpgradeType.AFTERBURN);
|
||||
|
||||
if(slots[2] != null && slots[2].getItem() == ModItems.flame_pony)
|
||||
this.afterburner = 100;
|
||||
|
||||
|
||||
long burnValue = 0;
|
||||
int amount = 1 + this.afterburner;
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
int amountToBurn = Math.min(amount, this.tank.getFill());
|
||||
|
||||
|
||||
if(amountToBurn > 0) {
|
||||
this.wasOn = true;
|
||||
this.tank.setFill(this.tank.getFill() - amountToBurn);
|
||||
this.output = (int) (burnValue * amountToBurn * (1 + Math.min(this.afterburner / 3D, 4)));
|
||||
this.power += this.output;
|
||||
this.consumption = amountToBurn;
|
||||
|
||||
|
||||
if(worldObj.getTotalWorldTime() % 20 == 0) super.pollute(tank.getTankType(), FluidTrait.FluidReleaseType.BURN, amountToBurn * 5);;
|
||||
}
|
||||
|
||||
|
||||
power = Library.chargeItemsFromTE(slots, 3, power, power);
|
||||
|
||||
|
||||
for(DirPos pos : getConPos()) {
|
||||
this.tryProvide(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());
|
||||
this.sendSmoke(pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
|
||||
}
|
||||
|
||||
|
||||
if(burnValue > 0 && amountToBurn > 0) {
|
||||
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10).getRotation(ForgeDirection.UP);
|
||||
ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
|
||||
|
||||
|
||||
if(this.afterburner > 0) {
|
||||
|
||||
|
||||
for(int i = 0; i < 2; i++) {
|
||||
double speed = 2 + worldObj.rand.nextDouble() * 3;
|
||||
double deviation = worldObj.rand.nextGaussian() * 0.2;
|
||||
@ -202,15 +205,15 @@ public class TileEntityMachineTurbofan extends TileEntityMachinePolluting implem
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
/*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);
|
||||
}*/
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
if(this.afterburner > 90) {
|
||||
NBTTagCompound data = new NBTTagCompound();
|
||||
data.setString("type", "gasfire");
|
||||
@ -223,16 +226,16 @@ public class TileEntityMachineTurbofan extends TileEntityMachinePolluting implem
|
||||
), new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 150));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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 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;
|
||||
|
||||
|
||||
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) {
|
||||
|
||||
|
||||
if(this.afterburner > 0) {
|
||||
e.setFire(5);
|
||||
e.attackEntityFrom(DamageSource.onFire, 5F);
|
||||
@ -240,40 +243,40 @@ public class TileEntityMachineTurbofan extends TileEntityMachinePolluting implem
|
||||
e.motionX -= dir.offsetX * 0.2;
|
||||
e.motionZ -= dir.offsetZ * 0.2;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
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;
|
||||
|
||||
|
||||
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) {
|
||||
e.motionX -= dir.offsetX * 0.2;
|
||||
e.motionZ -= dir.offsetZ * 0.2;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
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;
|
||||
|
||||
|
||||
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) {
|
||||
e.attackEntityFrom(ModDamageSource.turbofan, 1000);
|
||||
e.setInWeb();
|
||||
|
||||
|
||||
if(!e.isEntityAlive() && e instanceof EntityLivingBase) {
|
||||
NBTTagCompound vdat = new NBTTagCompound();
|
||||
vdat.setString("type", "giblets");
|
||||
vdat.setInteger("ent", e.getEntityId());
|
||||
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));
|
||||
|
||||
|
||||
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()) {
|
||||
blood.setFill(blood.getMaxFill());
|
||||
}
|
||||
@ -281,17 +284,17 @@ public class TileEntityMachineTurbofan extends TileEntityMachinePolluting implem
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(this.power > this.maxPower) {
|
||||
this.power = this.maxPower;
|
||||
}
|
||||
|
||||
this.networkPackNT(150);
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
this.lastSpin = this.spin;
|
||||
|
||||
|
||||
if(wasOn) {
|
||||
if(this.momentum < 100F)
|
||||
this.momentum++;
|
||||
@ -299,16 +302,16 @@ public class TileEntityMachineTurbofan extends TileEntityMachinePolluting implem
|
||||
if(this.momentum > 0)
|
||||
this.momentum--;
|
||||
}
|
||||
|
||||
|
||||
this.spin += momentum / 2;
|
||||
|
||||
|
||||
if(this.spin >= 360) {
|
||||
this.spin -= 360F;
|
||||
this.lastSpin -= 360F;
|
||||
}
|
||||
|
||||
if(momentum > 0) {
|
||||
|
||||
|
||||
if(audio == null) {
|
||||
audio = createAudioLoop();
|
||||
audio.startSound();
|
||||
@ -319,9 +322,9 @@ public class TileEntityMachineTurbofan extends TileEntityMachinePolluting implem
|
||||
audio.keepAlive();
|
||||
audio.updateVolume(getVolume(momentum / 50F));
|
||||
audio.updatePitch(momentum / 200F + 0.5F + this.afterburner * 0.16F);
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
if(audio != null) {
|
||||
audio.stopSound();
|
||||
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 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;
|
||||
|
||||
|
||||
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) {
|
||||
if(e == MainRegistry.proxy.me()) {
|
||||
e.motionX -= dir.offsetX * 0.2;
|
||||
e.motionZ -= dir.offsetZ * 0.2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
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;
|
||||
|
||||
|
||||
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) {
|
||||
if(e == MainRegistry.proxy.me()) {
|
||||
e.motionX -= dir.offsetX * 0.2;
|
||||
e.motionZ -= dir.offsetZ * 0.2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
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;
|
||||
|
||||
|
||||
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) {
|
||||
if(e == MainRegistry.proxy.me()) {
|
||||
e.setInWeb();
|
||||
@ -401,7 +404,7 @@ public class TileEntityMachineTurbofan extends TileEntityMachinePolluting implem
|
||||
tank.deserialize(buf);
|
||||
blood.deserialize(buf);
|
||||
}
|
||||
|
||||
|
||||
public AudioWrapper createAudioLoop() {
|
||||
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) {
|
||||
this.power = i;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getRenderBoundingBox() {
|
||||
return TileEntity.INFINITE_EXTENT_AABB;
|
||||
@ -493,9 +496,10 @@ public class TileEntityMachineTurbofan extends TileEntityMachinePolluting implem
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel(UpgradeType type) {
|
||||
if(type == UpgradeType.AFTERBURN) return 3;
|
||||
return 0;
|
||||
public HashMap<UpgradeType, Integer> getValidUpgrades() {
|
||||
HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
|
||||
upgrades.put(UpgradeType.AFTERBURN, 3);
|
||||
return upgrades;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
package com.hbm.tileentity.machine.oil;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import com.hbm.blocks.ModBlocks;
|
||||
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.fluid.Fluids;
|
||||
import com.hbm.inventory.fluid.tank.FluidTank;
|
||||
@ -52,6 +53,8 @@ public class TileEntityMachineGasFlare extends TileEntityMachineBase implements
|
||||
protected int fluidUsed = 0;
|
||||
protected int output = 0;
|
||||
|
||||
public UpgradeManagerNT upgradeManager = new UpgradeManagerNT();
|
||||
|
||||
public TileEntityMachineGasFlare() {
|
||||
super(6);
|
||||
tank = new FluidTank(Fluids.GAS, 64000);
|
||||
@ -117,9 +120,9 @@ public class TileEntityMachineGasFlare extends TileEntityMachineBase implements
|
||||
|
||||
if(isOn && tank.getFill() > 0) {
|
||||
|
||||
UpgradeManager.eval(slots, 4, 5);
|
||||
int burn = Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 3);
|
||||
int yield = Math.min(UpgradeManager.getLevel(UpgradeType.EFFECT), 3);
|
||||
upgradeManager.checkSlots(this, slots, 4, 5);
|
||||
int burn = upgradeManager.getLevel(UpgradeType.SPEED);
|
||||
int yield = upgradeManager.getLevel(UpgradeType.EFFECT);
|
||||
|
||||
maxVent += maxVent * burn;
|
||||
maxBurn += maxBurn * burn;
|
||||
@ -319,10 +322,11 @@ public class TileEntityMachineGasFlare extends TileEntityMachineBase implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel(UpgradeType type) {
|
||||
if(type == UpgradeType.SPEED) return 3;
|
||||
if(type == UpgradeType.EFFECT) return 3;
|
||||
return 0;
|
||||
public HashMap<UpgradeType, Integer> getValidUpgrades() {
|
||||
HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
|
||||
upgrades.put(UpgradeType.SPEED, 3);
|
||||
upgrades.put(UpgradeType.EFFECT, 3);
|
||||
return upgrades;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
package com.hbm.tileentity.machine.oil;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import com.hbm.blocks.ModBlocks;
|
||||
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.fluid.Fluids;
|
||||
import com.hbm.inventory.fluid.tank.FluidTank;
|
||||
@ -44,9 +45,11 @@ public class TileEntityMachineLiquefactor extends TileEntityMachineBase implemen
|
||||
public int progress;
|
||||
public static final int processTimeBase = 100;
|
||||
public int processTime;
|
||||
|
||||
|
||||
public FluidTank tank;
|
||||
|
||||
|
||||
public UpgradeManagerNT upgradeManager = new UpgradeManagerNT();
|
||||
|
||||
public TileEntityMachineLiquefactor() {
|
||||
super(4);
|
||||
tank = new FluidTank(Fluids.NONE, 24_000);
|
||||
@ -59,42 +62,42 @@ public class TileEntityMachineLiquefactor extends TileEntityMachineBase implemen
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
this.power = Library.chargeTEFromItems(slots, 1, power, maxPower);
|
||||
|
||||
|
||||
this.updateConnections();
|
||||
|
||||
UpgradeManager.eval(slots, 2, 3);
|
||||
int speed = Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 3);
|
||||
int power = Math.min(UpgradeManager.getLevel(UpgradeType.POWER), 3);
|
||||
upgradeManager.checkSlots(this, slots, 2, 3);
|
||||
int speed = upgradeManager.getLevel(UpgradeType.SPEED);
|
||||
int power = upgradeManager.getLevel(UpgradeType.POWER);
|
||||
|
||||
this.processTime = processTimeBase - (processTimeBase / 4) * speed;
|
||||
this.usage = (usageBase + (usageBase * speed)) / (power + 1);
|
||||
|
||||
|
||||
if(this.canProcess())
|
||||
this.process();
|
||||
else
|
||||
this.progress = 0;
|
||||
|
||||
|
||||
this.sendFluid();
|
||||
|
||||
this.networkPackNT(50);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void updateConnections() {
|
||||
for(DirPos pos : getConPos()) {
|
||||
this.trySubscribe(worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void sendFluid() {
|
||||
for(DirPos pos : getConPos()) {
|
||||
this.sendFluid(tank, worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private DirPos[] getConPos() {
|
||||
return new DirPos[] {
|
||||
new DirPos(xCoord, yCoord + 4, zCoord, Library.POS_Y),
|
||||
@ -115,36 +118,36 @@ public class TileEntityMachineLiquefactor extends TileEntityMachineBase implemen
|
||||
public int[] getAccessibleSlotsFromSide(int side) {
|
||||
return new int[] { 0 };
|
||||
}
|
||||
|
||||
|
||||
public boolean canProcess() {
|
||||
|
||||
|
||||
if(this.power < usage) return false;
|
||||
if(slots[0] == null) return false;
|
||||
|
||||
|
||||
FluidStack out = LiquefactionRecipes.getOutput(slots[0]);
|
||||
|
||||
|
||||
if(out == null) return false;
|
||||
if(out.type != tank.getTankType() && tank.getFill() > 0) return false;
|
||||
if(out.fill + tank.getFill() > tank.getMaxFill()) return false;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public void process() {
|
||||
|
||||
|
||||
this.power -= usage;
|
||||
|
||||
|
||||
progress++;
|
||||
|
||||
|
||||
if(progress >= processTime) {
|
||||
|
||||
|
||||
FluidStack out = LiquefactionRecipes.getOutput(slots[0]);
|
||||
tank.setTankType(out.type);
|
||||
tank.setFill(tank.getFill() + out.fill);
|
||||
this.decrStackSize(0, 1);
|
||||
|
||||
|
||||
progress = 0;
|
||||
|
||||
|
||||
this.markDirty();
|
||||
}
|
||||
}
|
||||
@ -168,13 +171,13 @@ public class TileEntityMachineLiquefactor extends TileEntityMachineBase implemen
|
||||
this.processTime = buf.readInt();
|
||||
tank.deserialize(buf);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
super.readFromNBT(nbt);
|
||||
tank.readFromNBT(nbt, "tank");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
super.writeToNBT(nbt);
|
||||
@ -197,10 +200,10 @@ public class TileEntityMachineLiquefactor extends TileEntityMachineBase implemen
|
||||
}
|
||||
|
||||
AxisAlignedBB bb = null;
|
||||
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getRenderBoundingBox() {
|
||||
|
||||
|
||||
if(bb == null) {
|
||||
bb = AxisAlignedBB.getBoundingBox(
|
||||
xCoord - 1,
|
||||
@ -211,10 +214,10 @@ public class TileEntityMachineLiquefactor extends TileEntityMachineBase implemen
|
||||
zCoord + 2
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
return bb;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public double getMaxRenderDistanceSquared() {
|
||||
@ -260,10 +263,11 @@ public class TileEntityMachineLiquefactor extends TileEntityMachineBase implemen
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel(UpgradeType type) {
|
||||
if(type == UpgradeType.SPEED) return 3;
|
||||
if(type == UpgradeType.POWER) return 3;
|
||||
return 0;
|
||||
public HashMap<UpgradeType, Integer> getValidUpgrades() {
|
||||
HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
|
||||
upgrades.put(UpgradeType.SPEED, 3);
|
||||
upgrades.put(UpgradeType.POWER, 3);
|
||||
return upgrades;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
package com.hbm.tileentity.machine.oil;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import com.hbm.blocks.ModBlocks;
|
||||
import com.hbm.handler.pollution.PollutionHandler;
|
||||
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.fluid.Fluids;
|
||||
import com.hbm.inventory.fluid.tank.FluidTank;
|
||||
@ -40,21 +41,23 @@ import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public class TileEntityMachinePyroOven extends TileEntityMachinePolluting implements IEnergyReceiverMK2, IFluidStandardTransceiver, IGUIProvider, IUpgradeInfoProvider, IFluidCopiable {
|
||||
|
||||
|
||||
public long power;
|
||||
public static final long maxPower = 10_000_000;
|
||||
public boolean isVenting;
|
||||
public boolean isProgressing;
|
||||
public float progress;
|
||||
public static int consumption = 10_000;
|
||||
|
||||
|
||||
public int prevAnim;
|
||||
public int anim = 0;
|
||||
|
||||
|
||||
public FluidTank[] tanks;
|
||||
|
||||
|
||||
private AudioWrapper audio;
|
||||
|
||||
public UpgradeManagerNT upgradeManager = new UpgradeManagerNT();
|
||||
|
||||
public TileEntityMachinePyroOven() {
|
||||
super(6, 50);
|
||||
tanks = new FluidTank[2];
|
||||
@ -65,7 +68,7 @@ public class TileEntityMachinePyroOven extends TileEntityMachinePolluting implem
|
||||
@Override
|
||||
public void setInventorySlotContents(int i, ItemStack stack) {
|
||||
super.setInventorySlotContents(i, stack);
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
@ -78,12 +81,12 @@ public class TileEntityMachinePyroOven extends TileEntityMachinePolluting implem
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
|
||||
|
||||
this.power = Library.chargeTEFromItems(slots, 0, power, maxPower);
|
||||
tanks[0].setType(3, slots);
|
||||
|
||||
|
||||
for(DirPos pos : getConPos()) {
|
||||
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());
|
||||
@ -93,50 +96,50 @@ public class TileEntityMachinePyroOven extends TileEntityMachinePolluting implem
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10);
|
||||
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);
|
||||
|
||||
UpgradeManager.eval(slots, 4, 5);
|
||||
int speed = Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 3);
|
||||
int powerSaving = Math.min(UpgradeManager.getLevel(UpgradeType.POWER), 3);
|
||||
int overdrive = Math.min(UpgradeManager.getLevel(UpgradeType.OVERDRIVE), 3);
|
||||
|
||||
|
||||
upgradeManager.checkSlots(this, slots, 4, 5);
|
||||
int speed = upgradeManager.getLevel(UpgradeType.SPEED);
|
||||
int powerSaving = upgradeManager.getLevel(UpgradeType.POWER);
|
||||
int overdrive = upgradeManager.getLevel(UpgradeType.OVERDRIVE);
|
||||
|
||||
this.isProgressing = false;
|
||||
this.isVenting = false;
|
||||
|
||||
|
||||
if(this.canProcess()) {
|
||||
PyroOvenRecipe recipe = getMatchingRecipe();
|
||||
this.progress += 1F / Math.max((recipe.duration - speed * (recipe.duration / 4)) / (overdrive * 2 + 1), 1);
|
||||
this.isProgressing = true;
|
||||
this.power -= this.getConsumption(speed + overdrive * 2, powerSaving);
|
||||
|
||||
|
||||
if(progress >= 1F) {
|
||||
this.progress = 0F;
|
||||
this.finishRecipe(recipe);
|
||||
this.markDirty();
|
||||
}
|
||||
|
||||
|
||||
this.pollute(PollutionType.SOOT, PollutionHandler.SOOT_PER_SECOND);
|
||||
|
||||
|
||||
} else {
|
||||
this.progress = 0F;
|
||||
}
|
||||
|
||||
|
||||
this.networkPackNT(50);
|
||||
} else {
|
||||
|
||||
|
||||
this.prevAnim = this.anim;
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10);
|
||||
ForgeDirection rot = dir.getRotation(ForgeDirection.DOWN);
|
||||
|
||||
|
||||
if(isProgressing) {
|
||||
this.anim++;
|
||||
|
||||
|
||||
if(audio == null) {
|
||||
audio = createAudioLoop();
|
||||
audio.startSound();
|
||||
} else if(!audio.isPlaying()) {
|
||||
audio = rebootAudio(audio);
|
||||
}
|
||||
|
||||
|
||||
audio.keepAlive();
|
||||
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 * 2.375, yCoord + 3, zCoord + 0.5 - rot.offsetZ + dir.offsetZ * 2.375, 0.0, 0.05, 0.0);
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
if(audio != null) {
|
||||
audio.stopSound();
|
||||
audio = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(this.isVenting) {
|
||||
|
||||
if(worldObj.getTotalWorldTime() % 2 == 0) {
|
||||
@ -173,29 +176,29 @@ public class TileEntityMachinePyroOven extends TileEntityMachinePolluting implem
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static int getConsumption(int speed, int powerSaving) {
|
||||
return (int) (consumption * Math.pow(speed + 1, 2)) / (powerSaving + 1);
|
||||
}
|
||||
|
||||
|
||||
protected PyroOvenRecipe lastValidRecipe;
|
||||
|
||||
|
||||
public PyroOvenRecipe getMatchingRecipe() {
|
||||
|
||||
|
||||
if(lastValidRecipe != null && doesRecipeMatch(lastValidRecipe)) return lastValidRecipe;
|
||||
|
||||
|
||||
for(PyroOvenRecipe rec : PyroOvenRecipes.recipes) {
|
||||
if(doesRecipeMatch(rec)) {
|
||||
lastValidRecipe = rec;
|
||||
return rec;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public boolean doesRecipeMatch(PyroOvenRecipe recipe) {
|
||||
|
||||
|
||||
if(recipe.inputFluid != null) {
|
||||
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 {
|
||||
if(slots[1] != null) return false; // recipe does not need item, but item is present
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public boolean canProcess() {
|
||||
int speed = Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 3);
|
||||
int powerSaving = Math.min(UpgradeManager.getLevel(UpgradeType.POWER), 3);
|
||||
int speed = upgradeManager.getLevel(UpgradeType.SPEED);
|
||||
int powerSaving = upgradeManager.getLevel(UpgradeType.POWER);
|
||||
if(power < this.getConsumption(speed, powerSaving)) return false; // not enough power
|
||||
|
||||
|
||||
PyroOvenRecipe recipe = this.getMatchingRecipe();
|
||||
if(recipe == null) return false; // no matching recipe
|
||||
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.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
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public void finishRecipe(PyroOvenRecipe recipe) {
|
||||
if(recipe.outputItem != null) {
|
||||
if(slots[2] == null) {
|
||||
@ -245,11 +248,11 @@ public class TileEntityMachinePyroOven extends TileEntityMachinePolluting implem
|
||||
tanks[0].setFill(tanks[0].getFill() - recipe.inputFluid.fill);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected DirPos[] getConPos() {
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10);
|
||||
ForgeDirection rot = dir.getRotation(ForgeDirection.DOWN);
|
||||
|
||||
|
||||
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 * 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.writeFloat(progress);
|
||||
}
|
||||
|
||||
|
||||
@Override public void deserialize(ByteBuf buf) {
|
||||
super.deserialize(buf);
|
||||
tanks[0].deserialize(buf);
|
||||
@ -278,7 +281,7 @@ public class TileEntityMachinePyroOven extends TileEntityMachinePolluting implem
|
||||
isProgressing = buf.readBoolean();
|
||||
progress = buf.readFloat();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
super.readFromNBT(nbt);
|
||||
@ -287,7 +290,7 @@ public class TileEntityMachinePyroOven extends TileEntityMachinePolluting implem
|
||||
this.progress = nbt.getFloat("prog");
|
||||
this.power = nbt.getLong("power");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
super.writeToNBT(nbt);
|
||||
@ -296,18 +299,18 @@ public class TileEntityMachinePyroOven extends TileEntityMachinePolluting implem
|
||||
nbt.setFloat("prog", progress);
|
||||
nbt.setLong("power", power);
|
||||
}
|
||||
|
||||
|
||||
@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 canExtractItem(int i, ItemStack itemStack, int j) { return i == 2; }
|
||||
|
||||
|
||||
@Override
|
||||
public void pollute(PollutionType type, float amount) {
|
||||
FluidTank tank = type == PollutionType.SOOT ? smoke : type == PollutionType.HEAVYMETAL ? smoke_leaded : smoke_poison;
|
||||
|
||||
|
||||
int fluidAmount = (int) Math.ceil(amount * 100);
|
||||
tank.setFill(tank.getFill() + fluidAmount);
|
||||
|
||||
|
||||
if(tank.getFill() > tank.getMaxFill()) {
|
||||
int overflow = tank.getFill() - tank.getMaxFill();
|
||||
tank.setFill(tank.getMaxFill());
|
||||
@ -319,7 +322,7 @@ public class TileEntityMachinePyroOven extends TileEntityMachinePolluting implem
|
||||
@Override public AudioWrapper createAudioLoop() {
|
||||
return MainRegistry.proxy.getLoopedSound("hbm:block.pyroOperate", xCoord, yCoord, zCoord, 1.0F, 15F, 1.0F, 20);
|
||||
}
|
||||
|
||||
|
||||
@Override public void onChunkUnload() {
|
||||
if(audio != null) { audio.stopSound(); audio = null; }
|
||||
}
|
||||
@ -328,15 +331,15 @@ public class TileEntityMachinePyroOven extends TileEntityMachinePolluting implem
|
||||
super.invalidate();
|
||||
if(audio != null) { audio.stopSound(); audio = null; }
|
||||
}
|
||||
|
||||
|
||||
AxisAlignedBB bb = null;
|
||||
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getRenderBoundingBox() {
|
||||
if(bb == null) bb = AxisAlignedBB.getBoundingBox(xCoord - 3, yCoord, zCoord - 3, xCoord + 4, yCoord + 3.5, zCoord + 4);
|
||||
return bb;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public double getMaxRenderDistanceSquared() {
|
||||
@ -375,10 +378,11 @@ public class TileEntityMachinePyroOven extends TileEntityMachinePolluting implem
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel(UpgradeType type) {
|
||||
if(type == UpgradeType.SPEED) return 3;
|
||||
if(type == UpgradeType.POWER) return 3;
|
||||
if(type == UpgradeType.OVERDRIVE) return 3;
|
||||
return 0;
|
||||
public HashMap<UpgradeType, Integer> getValidUpgrades() {
|
||||
HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
|
||||
upgrades.put(UpgradeType.SPEED, 3);
|
||||
upgrades.put(UpgradeType.POWER, 3);
|
||||
upgrades.put(UpgradeType.OVERDRIVE, 3);
|
||||
return upgrades;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
package com.hbm.tileentity.machine.oil;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
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.fluid.Fluids;
|
||||
import com.hbm.inventory.fluid.tank.FluidTank;
|
||||
@ -43,9 +44,11 @@ public class TileEntityMachineSolidifier extends TileEntityMachineBase implement
|
||||
public int progress;
|
||||
public static final int processTimeBase = 100;
|
||||
public int processTime;
|
||||
|
||||
|
||||
public FluidTank tank;
|
||||
|
||||
public UpgradeManagerNT upgradeManager = new UpgradeManagerNT();
|
||||
|
||||
public TileEntityMachineSolidifier() {
|
||||
super(5);
|
||||
tank = new FluidTank(Fluids.NONE, 24_000);
|
||||
@ -58,20 +61,20 @@ public class TileEntityMachineSolidifier extends TileEntityMachineBase implement
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
this.power = Library.chargeTEFromItems(slots, 1, power, maxPower);
|
||||
tank.setType(4, slots);
|
||||
|
||||
this.updateConnections();
|
||||
|
||||
UpgradeManager.eval(slots, 2, 3);
|
||||
int speed = Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 3);
|
||||
int power = Math.min(UpgradeManager.getLevel(UpgradeType.POWER), 3);
|
||||
upgradeManager.checkSlots(this, slots, 2, 3);
|
||||
int speed = upgradeManager.getLevel(UpgradeType.SPEED);
|
||||
int power = upgradeManager.getLevel(UpgradeType.POWER);
|
||||
|
||||
this.processTime = processTimeBase - (processTimeBase / 4) * speed;
|
||||
this.usage = (usageBase + (usageBase * speed)) / (power + 1);
|
||||
|
||||
|
||||
if(this.canProcess())
|
||||
this.process();
|
||||
else
|
||||
@ -80,14 +83,14 @@ public class TileEntityMachineSolidifier extends TileEntityMachineBase implement
|
||||
this.networkPackNT(50);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void updateConnections() {
|
||||
for(DirPos pos : getConPos()) {
|
||||
this.trySubscribe(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() {
|
||||
return new DirPos[] {
|
||||
new DirPos(xCoord, yCoord + 4, zCoord, Library.POS_Y),
|
||||
@ -108,59 +111,59 @@ public class TileEntityMachineSolidifier extends TileEntityMachineBase implement
|
||||
public int[] getAccessibleSlotsFromSide(int side) {
|
||||
return new int[] { 0 };
|
||||
}
|
||||
|
||||
|
||||
public boolean canProcess() {
|
||||
|
||||
|
||||
if(this.power < usage)
|
||||
return false;
|
||||
|
||||
|
||||
Pair<Integer, ItemStack> out = SolidificationRecipes.getOutput(tank.getTankType());
|
||||
|
||||
|
||||
if(out == null)
|
||||
return false;
|
||||
|
||||
|
||||
int req = out.getKey();
|
||||
ItemStack stack = out.getValue();
|
||||
|
||||
|
||||
if(req > tank.getFill())
|
||||
return false;
|
||||
|
||||
|
||||
if(slots[0] != null) {
|
||||
|
||||
|
||||
if(slots[0].getItem() != stack.getItem())
|
||||
return false;
|
||||
|
||||
|
||||
if(slots[0].getItemDamage() != stack.getItemDamage())
|
||||
return false;
|
||||
|
||||
|
||||
if(slots[0].stackSize + stack.stackSize > slots[0].getMaxStackSize())
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public void process() {
|
||||
|
||||
|
||||
this.power -= usage;
|
||||
|
||||
|
||||
progress++;
|
||||
|
||||
|
||||
if(progress >= processTime) {
|
||||
|
||||
|
||||
Pair<Integer, ItemStack> out = SolidificationRecipes.getOutput(tank.getTankType());
|
||||
int req = out.getKey();
|
||||
ItemStack stack = out.getValue();
|
||||
tank.setFill(tank.getFill() - req);
|
||||
|
||||
|
||||
if(slots[0] == null) {
|
||||
slots[0] = stack.copy();
|
||||
} else {
|
||||
slots[0].stackSize += stack.stackSize;
|
||||
}
|
||||
|
||||
|
||||
progress = 0;
|
||||
|
||||
|
||||
this.markDirty();
|
||||
}
|
||||
}
|
||||
@ -184,13 +187,13 @@ public class TileEntityMachineSolidifier extends TileEntityMachineBase implement
|
||||
this.processTime = buf.readInt();
|
||||
tank.deserialize(buf);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
super.readFromNBT(nbt);
|
||||
tank.readFromNBT(nbt, "tank");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
super.writeToNBT(nbt);
|
||||
@ -211,12 +214,12 @@ public class TileEntityMachineSolidifier extends TileEntityMachineBase implement
|
||||
public long getMaxPower() {
|
||||
return maxPower;
|
||||
}
|
||||
|
||||
|
||||
AxisAlignedBB bb = null;
|
||||
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getRenderBoundingBox() {
|
||||
|
||||
|
||||
if(bb == null) {
|
||||
bb = AxisAlignedBB.getBoundingBox(
|
||||
xCoord - 1,
|
||||
@ -227,10 +230,10 @@ public class TileEntityMachineSolidifier extends TileEntityMachineBase implement
|
||||
zCoord + 2
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
return bb;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public double getMaxRenderDistanceSquared() {
|
||||
@ -276,10 +279,11 @@ public class TileEntityMachineSolidifier extends TileEntityMachineBase implement
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel(UpgradeType type) {
|
||||
if(type == UpgradeType.SPEED) return 3;
|
||||
if(type == UpgradeType.POWER) return 3;
|
||||
return 0;
|
||||
public HashMap<UpgradeType, Integer> getValidUpgrades() {
|
||||
HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
|
||||
upgrades.put(UpgradeType.SPEED, 3);
|
||||
upgrades.put(UpgradeType.POWER, 3);
|
||||
return upgrades;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
package com.hbm.tileentity.machine.oil;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
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.tank.FluidTank;
|
||||
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 int indicator = 0;
|
||||
|
||||
|
||||
public long power;
|
||||
|
||||
|
||||
public FluidTank[] tanks;
|
||||
|
||||
public UpgradeManagerNT upgradeManager = new UpgradeManagerNT();
|
||||
|
||||
public TileEntityOilDrillBase() {
|
||||
super(8);
|
||||
tanks = new FluidTank[2];
|
||||
tanks[0] = new FluidTank(Fluids.OIL, 64_000);
|
||||
tanks[1] = new FluidTank(Fluids.GAS, 64_000);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
super.readFromNBT(nbt);
|
||||
|
||||
|
||||
this.power = nbt.getLong("power");
|
||||
for(int i = 0; i < this.tanks.length; i++)
|
||||
this.tanks[i].readFromNBT(nbt, "t" + i);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
super.writeToNBT(nbt);
|
||||
|
||||
|
||||
nbt.setLong("power", power);
|
||||
for(int i = 0; i < this.tanks.length; i++)
|
||||
this.tanks[i].writeToNBT(nbt, "t" + i);
|
||||
@ -62,10 +65,10 @@ public abstract class TileEntityOilDrillBase extends TileEntityMachineBase imple
|
||||
|
||||
@Override
|
||||
public void writeNBT(NBTTagCompound nbt) {
|
||||
|
||||
|
||||
boolean empty = power == 0;
|
||||
for(FluidTank tank : tanks) if(tank.getFill() > 0) empty = false;
|
||||
|
||||
|
||||
if(!empty) {
|
||||
nbt.setLong("power", power);
|
||||
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[1].unloadTank(3, 4, slots);
|
||||
|
||||
UpgradeManager.eval(slots, 5, 7);
|
||||
this.speedLevel = Math.min(UpgradeManager.getLevel(UpgradeType.SPEED), 3);
|
||||
this.energyLevel = Math.min(UpgradeManager.getLevel(UpgradeType.POWER), 3);
|
||||
this.overLevel = Math.min(UpgradeManager.getLevel(UpgradeType.OVERDRIVE), 3) + 1;
|
||||
int abLevel = Math.min(UpgradeManager.getLevel(UpgradeType.AFTERBURN), 3);
|
||||
upgradeManager.checkSlots(this, slots, 5, 7);
|
||||
this.speedLevel = upgradeManager.getLevel(UpgradeType.SPEED);
|
||||
this.energyLevel = upgradeManager.getLevel(UpgradeType.POWER);
|
||||
this.overLevel = upgradeManager.getLevel(UpgradeType.OVERDRIVE) + 1;
|
||||
int abLevel = upgradeManager.getLevel(UpgradeType.AFTERBURN);
|
||||
|
||||
int toBurn = Math.min(tanks[1].getFill(), abLevel * 10);
|
||||
|
||||
@ -169,7 +172,7 @@ public abstract class TileEntityOilDrillBase extends TileEntityMachineBase imple
|
||||
this.indicator = buf.readInt();
|
||||
for (FluidTank tank : tanks) tank.deserialize(buf);
|
||||
}
|
||||
|
||||
|
||||
public boolean canPump() {
|
||||
return true;
|
||||
}
|
||||
@ -177,27 +180,27 @@ public abstract class TileEntityOilDrillBase extends TileEntityMachineBase imple
|
||||
@Override
|
||||
public void setInventorySlotContents(int i, ItemStack stack) {
|
||||
super.setInventorySlotContents(i, stack);
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
public int getPowerReqEff() {
|
||||
int req = this.getPowerReq();
|
||||
return (req + (req / 4 * this.speedLevel) - (req / 4 * this.energyLevel)) * this.overLevel;
|
||||
}
|
||||
|
||||
|
||||
public int getDelayEff() {
|
||||
int delay = getDelay();
|
||||
return Math.max((delay - (delay / 4 * this.speedLevel) + (delay / 10 * this.energyLevel)) / this.overLevel, 1);
|
||||
}
|
||||
|
||||
|
||||
public abstract int getPowerReq();
|
||||
public abstract int getDelay();
|
||||
|
||||
|
||||
public void tryDrill(int y) {
|
||||
Block b = worldObj.getBlock(xCoord, y, zCoord);
|
||||
|
||||
|
||||
if(b.getExplosionResistance(null) < 1000) {
|
||||
onDrill(y);
|
||||
worldObj.setBlock(xCoord, y, zCoord, ModBlocks.oil_pipe);
|
||||
@ -205,72 +208,72 @@ public abstract class TileEntityOilDrillBase extends TileEntityMachineBase imple
|
||||
this.indicator = 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void onDrill(int y) { }
|
||||
|
||||
|
||||
public int getDrillDepth() {
|
||||
return 5;
|
||||
}
|
||||
|
||||
|
||||
public boolean trySuck(int y) {
|
||||
|
||||
|
||||
Block b = worldObj.getBlock(xCoord, y, zCoord);
|
||||
|
||||
|
||||
if(!canSuckBlock(b))
|
||||
return false;
|
||||
|
||||
|
||||
if(!this.canPump())
|
||||
return true;
|
||||
|
||||
|
||||
trace.clear();
|
||||
|
||||
|
||||
return suckRec(xCoord, y, zCoord, 0);
|
||||
}
|
||||
|
||||
|
||||
public boolean canSuckBlock(Block b) {
|
||||
return b == ModBlocks.ore_oil || b == ModBlocks.ore_oil_empty;
|
||||
}
|
||||
|
||||
|
||||
protected HashSet<Tuple.Triplet<Integer, Integer, Integer>> trace = new HashSet();
|
||||
|
||||
|
||||
public boolean suckRec(int x, int y, int z, int layer) {
|
||||
|
||||
|
||||
Triplet<Integer, Integer, Integer> pos = new Triplet(x, y, z);
|
||||
|
||||
|
||||
if(trace.contains(pos))
|
||||
return false;
|
||||
|
||||
|
||||
trace.add(pos);
|
||||
|
||||
|
||||
if(layer > 64)
|
||||
return false;
|
||||
|
||||
|
||||
Block b = worldObj.getBlock(x, y, z);
|
||||
|
||||
|
||||
if(b == ModBlocks.ore_oil || b == ModBlocks.ore_bedrock_oil) {
|
||||
doSuck(x, y, z);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
if(b == ModBlocks.ore_oil_empty) {
|
||||
ForgeDirection[] dirs = BobMathUtil.getShuffledDirs();
|
||||
|
||||
|
||||
for(ForgeDirection dir : dirs) {
|
||||
if(suckRec(x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ, layer + 1))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public void doSuck(int x, int y, int z) {
|
||||
|
||||
|
||||
if(worldObj.getBlock(x, y, z) == ModBlocks.ore_oil) {
|
||||
onSuck(x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public abstract void onSuck(int x, int y, int z);
|
||||
|
||||
@Override
|
||||
@ -308,7 +311,7 @@ public abstract class TileEntityOilDrillBase extends TileEntityMachineBase imple
|
||||
public FluidTank[] getAllTanks() {
|
||||
return tanks;
|
||||
}
|
||||
|
||||
|
||||
public abstract DirPos[] getConPos();
|
||||
|
||||
protected void updateConnections() {
|
||||
@ -323,12 +326,13 @@ public abstract class TileEntityOilDrillBase extends TileEntityMachineBase imple
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel(UpgradeType type) {
|
||||
if(type == UpgradeType.SPEED) return 3;
|
||||
if(type == UpgradeType.POWER) return 3;
|
||||
if(type == UpgradeType.AFTERBURN) return 3;
|
||||
if(type == UpgradeType.OVERDRIVE) return 3;
|
||||
return 0;
|
||||
public HashMap<UpgradeType, Integer> getValidUpgrades() {
|
||||
HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
|
||||
upgrades.put(UpgradeType.SPEED, 3);
|
||||
upgrades.put(UpgradeType.POWER, 3);
|
||||
upgrades.put(UpgradeType.AFTERBURN, 3);
|
||||
upgrades.put(UpgradeType.OVERDRIVE, 3);
|
||||
return upgrades;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package com.hbm.tileentity.turret;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import com.hbm.blocks.ModBlocks;
|
||||
@ -97,13 +98,14 @@ public class TileEntityTurretMaxwell extends TileEntityTurretBaseNT implements I
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel(UpgradeType type) {
|
||||
if(type == UpgradeType.SPEED) return 27;
|
||||
if(type == UpgradeType.POWER) return 27;
|
||||
if(type == UpgradeType.EFFECT) return 27;
|
||||
if(type == UpgradeType.AFTERBURN) return 27;
|
||||
if(type == UpgradeType.OVERDRIVE) return 27;
|
||||
return 0;
|
||||
public HashMap<UpgradeType, Integer> getValidUpgrades() {
|
||||
HashMap<UpgradeType, Integer> upgrades = new HashMap<>();
|
||||
upgrades.put(UpgradeType.SPEED, 27);
|
||||
upgrades.put(UpgradeType.POWER, 27);
|
||||
upgrades.put(UpgradeType.EFFECT, 27);
|
||||
upgrades.put(UpgradeType.AFTERBURN, 27);
|
||||
upgrades.put(UpgradeType.OVERDRIVE, 27);
|
||||
return upgrades;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user