Initiated migration of filler to the new builder API (#1492)
Started experiments with simplified energy API (#1498)
This commit is contained in:
parent
909b28a6df
commit
86188e560e
19 changed files with 461 additions and 351 deletions
|
@ -8,10 +8,11 @@
|
|||
*/
|
||||
package buildcraft.api.filler;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import buildcraft.api.core.IBox;
|
||||
import buildcraft.core.Box;
|
||||
import buildcraft.core.blueprints.BptBuilderTemplate;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
|
@ -19,19 +20,10 @@ public interface IFillerPattern {
|
|||
|
||||
public String getUniqueTag();
|
||||
|
||||
/**
|
||||
* Creates the object that does the pattern iteration. This object may be
|
||||
* state-full and will be used until the pattern is done or changes.
|
||||
*
|
||||
* @param tile the Filler
|
||||
* @param box the area to fill
|
||||
* @param orientation not currently used, but may be in the future (the filler needs some orientation code)
|
||||
* @return
|
||||
*/
|
||||
public IPatternIterator createPatternIterator(TileEntity tile, IBox box, ForgeDirection orientation);
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getIcon();
|
||||
|
||||
public String getDisplayName();
|
||||
|
||||
public BptBuilderTemplate getBlueprint (Box box, World world, ForgeDirection orientation);
|
||||
}
|
||||
|
|
38
common/buildcraft/api/mj/MjBattery.java
Executable file
38
common/buildcraft/api/mj/MjBattery.java
Executable file
|
@ -0,0 +1,38 @@
|
|||
/**
|
||||
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
|
||||
* http://www.mod-buildcraft.com
|
||||
*
|
||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public
|
||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||
*/
|
||||
package buildcraft.api.mj;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Inherited;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* This annotation is used for tiles that need to interface with BuildCraft
|
||||
* energy framework, a.k.a MinecraftJoule or MJ. In order to receive power,
|
||||
* tiles, need to declare a *public* double field, with the annotation
|
||||
* MjBattery. BuildCraft machines able to provide power will then connect to
|
||||
* these tiles, and feed energy up to max capacity. It's the responsibilty
|
||||
* of the implementer to manually decrease the value of the energy, as he
|
||||
* simulates energy consumption. On each cycle, per power input, machines can
|
||||
* receive up to "maxReceivedPerCyle" units of energy. As an optional behavior,
|
||||
* the system can have a minimum amount of energy consumed even if the system
|
||||
* is at max capacity, modelized by the "minimumConsumption" value.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
@Inherited
|
||||
public @interface MjBattery {
|
||||
|
||||
public double maxCapacity () default 100.0;
|
||||
public double maxReceivedPerCycle () default 10.0;
|
||||
public double miniumConsumption () default 0.1;
|
||||
|
||||
}
|
|
@ -23,6 +23,7 @@ public class BuilderProxyClient extends BuilderProxy {
|
|||
super.registerBlockRenderers();
|
||||
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileArchitect.class, new RenderBoxProvider());
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileFiller.class, new RenderBoxProvider());
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileBuilder.class, new RenderBoxProvider());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,28 +13,27 @@ import io.netty.buffer.ByteBuf;
|
|||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import buildcraft.BuildCraftCore;
|
||||
import buildcraft.api.blueprints.SchematicToBuild;
|
||||
import buildcraft.api.core.IAreaProvider;
|
||||
import buildcraft.api.filler.FillerManager;
|
||||
import buildcraft.api.filler.IFillerPattern;
|
||||
import buildcraft.api.filler.IPatternIterator;
|
||||
import buildcraft.api.gates.IAction;
|
||||
import buildcraft.api.gates.IActionReceptor;
|
||||
import buildcraft.api.power.IPowerReceptor;
|
||||
import buildcraft.api.power.PowerHandler;
|
||||
import buildcraft.api.power.PowerHandler.PowerReceiver;
|
||||
import buildcraft.api.power.PowerHandler.Type;
|
||||
import buildcraft.api.mj.MjBattery;
|
||||
import buildcraft.builders.filler.pattern.PatternFill;
|
||||
import buildcraft.builders.triggers.ActionFiller;
|
||||
import buildcraft.core.Box;
|
||||
import buildcraft.core.IBoxProvider;
|
||||
import buildcraft.core.IBuilderInventory;
|
||||
import buildcraft.core.IMachine;
|
||||
import buildcraft.core.TileBuildCraft;
|
||||
import buildcraft.core.inventory.InventoryIterator;
|
||||
import buildcraft.core.inventory.InventoryIterator.IInvSlot;
|
||||
import buildcraft.core.blueprints.BptBuilderTemplate;
|
||||
import buildcraft.core.blueprints.BptContext;
|
||||
import buildcraft.core.inventory.SimpleInventory;
|
||||
import buildcraft.core.network.IGuiReturnHandler;
|
||||
import buildcraft.core.network.PacketPayload;
|
||||
|
@ -44,26 +43,24 @@ import buildcraft.core.triggers.ActionMachineControl;
|
|||
import buildcraft.core.triggers.ActionMachineControl.Mode;
|
||||
import buildcraft.core.utils.Utils;
|
||||
|
||||
public class TileFiller extends TileBuildCraft implements IInventory, IPowerReceptor, IMachine, IActionReceptor, IGuiReturnHandler {
|
||||
public class TileFiller extends TileBuildCraft implements IBuilderInventory, IMachine, IActionReceptor, IGuiReturnHandler, IBoxProvider {
|
||||
|
||||
public IFillerPattern currentPattern = PatternFill.INSTANCE;
|
||||
|
||||
private BptBuilderTemplate currentTemplate;
|
||||
private BptContext context;
|
||||
|
||||
private static int POWER_USAGE = 25;
|
||||
private final Box box = new Box();
|
||||
private boolean done = false;
|
||||
private IPatternIterator patternIterator;
|
||||
private PowerHandler powerHandler;
|
||||
private ActionMachineControl.Mode lastMode = ActionMachineControl.Mode.Unknown;
|
||||
private SimpleInventory inv = new SimpleInventory(27, "Filler", 64);
|
||||
|
||||
@MjBattery (maxReceivedPerCycle = 25)
|
||||
public double mjStored = 0;
|
||||
|
||||
public TileFiller() {
|
||||
inv.addListener(this);
|
||||
powerHandler = new PowerHandler(this, Type.MACHINE);
|
||||
initPowerProvider();
|
||||
}
|
||||
|
||||
private void initPowerProvider() {
|
||||
powerHandler.configure(30, POWER_USAGE * 2, POWER_USAGE, POWER_USAGE * 4);
|
||||
powerHandler.configurePowerPerdition(1, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -88,30 +85,42 @@ public class TileFiller extends TileBuildCraft implements IInventory, IPowerRece
|
|||
@Override
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
|
||||
if (worldObj.isRemote) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (done) {
|
||||
if (lastMode == Mode.Loop) {
|
||||
done = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doWork(PowerHandler workProvider) {
|
||||
if (worldObj.isRemote)
|
||||
return;
|
||||
if (done)
|
||||
return;
|
||||
if (lastMode == Mode.Off)
|
||||
return;
|
||||
if (powerHandler.useEnergy(POWER_USAGE, POWER_USAGE, false) != POWER_USAGE)
|
||||
return;
|
||||
if (!box.isInitialized())
|
||||
if (lastMode == Mode.Off) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (patternIterator == null)
|
||||
patternIterator = currentPattern.createPatternIterator(this, box, ForgeDirection.NORTH);
|
||||
if (!box.isInitialized()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack stackToUse = null;
|
||||
if (mjStored > POWER_USAGE) {
|
||||
mjStored -= POWER_USAGE;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentPattern != null && currentTemplate == null) {
|
||||
currentTemplate = currentPattern.getBlueprint(box, getWorld(), ForgeDirection.NORTH);
|
||||
context = currentTemplate.getContext();
|
||||
}
|
||||
|
||||
if (currentTemplate != null) {
|
||||
SchematicToBuild s = currentTemplate.getNextBlock(getWorld(), this);
|
||||
s.schematic.writeToWorld(context, s.x, s.y, s.z);
|
||||
}
|
||||
|
||||
/*ItemStack stackToUse = null;
|
||||
int slotNum = 0;
|
||||
|
||||
for (IInvSlot slot : InventoryIterator.getIterable(inv, ForgeDirection.UNKNOWN)) {
|
||||
|
@ -123,19 +132,14 @@ public class TileFiller extends TileBuildCraft implements IInventory, IPowerRece
|
|||
}
|
||||
}
|
||||
|
||||
done = patternIterator.iteratePattern(stackToUse);
|
||||
powerHandler.useEnergy(POWER_USAGE, POWER_USAGE, true);
|
||||
|
||||
if (stackToUse != null && stackToUse.stackSize <= 0) {
|
||||
setInventorySlotContents(slotNum, null);
|
||||
}
|
||||
|
||||
if (done) {
|
||||
patternIterator = null;
|
||||
sendNetworkUpdate();
|
||||
} else if (powerHandler.getEnergyStored() >= POWER_USAGE) {
|
||||
doWork(workProvider);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -174,14 +178,17 @@ public class TileFiller extends TileBuildCraft implements IInventory, IPowerRece
|
|||
|
||||
inv.readFromNBT(nbt);
|
||||
|
||||
if (nbt.hasKey("pattern"))
|
||||
if (nbt.hasKey("pattern")) {
|
||||
currentPattern = FillerManager.registry.getPattern(nbt.getString("pattern"));
|
||||
}
|
||||
|
||||
if (currentPattern == null)
|
||||
if (currentPattern == null) {
|
||||
currentPattern = PatternFill.INSTANCE;
|
||||
}
|
||||
|
||||
if (nbt.hasKey("box"))
|
||||
if (nbt.hasKey("box")) {
|
||||
box.initialize(nbt.getCompoundTag("box"));
|
||||
}
|
||||
|
||||
done = nbt.getBoolean("done");
|
||||
lastMode = Mode.values()[nbt.getByte("lastMode")];
|
||||
|
@ -193,8 +200,9 @@ public class TileFiller extends TileBuildCraft implements IInventory, IPowerRece
|
|||
|
||||
inv.writeToNBT(nbt);
|
||||
|
||||
if (currentPattern != null)
|
||||
if (currentPattern != null) {
|
||||
nbt.setString("pattern", currentPattern.getUniqueTag());
|
||||
}
|
||||
|
||||
NBTTagCompound boxStore = new NBTTagCompound();
|
||||
box.writeToNBT(boxStore);
|
||||
|
@ -211,8 +219,9 @@ public class TileFiller extends TileBuildCraft implements IInventory, IPowerRece
|
|||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer entityplayer) {
|
||||
if (worldObj.getTileEntity(xCoord, yCoord, zCoord) != this)
|
||||
if (worldObj.getTileEntity(xCoord, yCoord, zCoord) != this) {
|
||||
return false;
|
||||
}
|
||||
return entityplayer.getDistanceSq(xCoord + 0.5D, yCoord + 0.5D, zCoord + 0.5D) <= 64D;
|
||||
}
|
||||
|
||||
|
@ -225,7 +234,6 @@ public class TileFiller extends TileBuildCraft implements IInventory, IPowerRece
|
|||
public void setPattern(IFillerPattern pattern) {
|
||||
if (pattern != null && currentPattern != pattern) {
|
||||
currentPattern = pattern;
|
||||
patternIterator = null;
|
||||
done = false;
|
||||
sendNetworkUpdate();
|
||||
}
|
||||
|
@ -264,11 +272,6 @@ public class TileFiller extends TileBuildCraft implements IInventory, IPowerRece
|
|||
handlePacketPayload(((PacketPayloadStream) packet.payload).stream);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PowerReceiver getPowerReceiver(ForgeDirection side) {
|
||||
return powerHandler.getPowerReceiver();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return !done && lastMode != Mode.Off;
|
||||
|
@ -330,4 +333,19 @@ public class TileFiller extends TileBuildCraft implements IInventory, IPowerRece
|
|||
public boolean hasCustomInventoryName() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Box getBox() {
|
||||
return box;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getRenderBoundingBox() {
|
||||
return new Box (this).extendToEncompass(box).getBoundingBox();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBuildingMaterial(int i) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,16 +14,10 @@ import java.util.TreeMap;
|
|||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import buildcraft.BuildCraftBuilders;
|
||||
import buildcraft.api.core.IBox;
|
||||
import buildcraft.api.filler.IFillerPattern;
|
||||
import buildcraft.api.filler.IPatternIterator;
|
||||
import buildcraft.core.Box;
|
||||
import buildcraft.core.blueprints.BptBuilderTemplate;
|
||||
import buildcraft.core.proxy.CoreProxy;
|
||||
import buildcraft.core.utils.BlockUtil;
|
||||
import buildcraft.core.utils.StringUtils;
|
||||
|
@ -39,22 +33,6 @@ public abstract class FillerPattern implements IFillerPattern {
|
|||
patterns.put(getUniqueTag (), this);
|
||||
}
|
||||
|
||||
/**
|
||||
* stackToPlace contains the next item that can be place in the world. Null
|
||||
* if there is none. IteratePattern is responsible to decrementing the stack
|
||||
* size if needed. Return true when the iteration process is finished.
|
||||
*/
|
||||
public boolean iteratePattern(TileEntity tile, IBox box, ItemStack stackToPlace) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: This should be based on templates!!!!!
|
||||
*/
|
||||
public BptBuilderTemplate getBlueprint (Box box, World world) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return StringUtils.localize("fillerpattern." + tag);
|
||||
|
@ -79,27 +57,6 @@ public abstract class FillerPattern implements IFillerPattern {
|
|||
return "Pattern: " + getUniqueTag();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPatternIterator createPatternIterator(TileEntity tile, IBox box, ForgeDirection orientation) {
|
||||
return new PatternIterator(tile, box);
|
||||
}
|
||||
|
||||
protected class PatternIterator implements IPatternIterator {
|
||||
|
||||
private final IBox box;
|
||||
private final TileEntity tile;
|
||||
|
||||
public PatternIterator(TileEntity tile, IBox box) {
|
||||
this.box = box;
|
||||
this.tile = tile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean iteratePattern(ItemStack stackToPlace) {
|
||||
return FillerPattern.this.iteratePattern(tile, box, stackToPlace);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to fill blocks in the area.
|
||||
*
|
||||
|
|
|
@ -8,9 +8,11 @@
|
|||
*/
|
||||
package buildcraft.builders.filler.pattern;
|
||||
|
||||
import buildcraft.api.core.IBox;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import buildcraft.core.Box;
|
||||
import buildcraft.core.blueprints.BptBuilderTemplate;
|
||||
|
||||
|
||||
public class PatternBox extends FillerPattern {
|
||||
|
||||
|
@ -19,6 +21,12 @@ public class PatternBox extends FillerPattern {
|
|||
}
|
||||
|
||||
@Override
|
||||
public BptBuilderTemplate getBlueprint(Box box, World world,
|
||||
ForgeDirection orientation) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/*@Override
|
||||
public boolean iteratePattern(TileEntity tile, IBox box, ItemStack stackToPlace) {
|
||||
int xMin = (int) box.pMin().x;
|
||||
int yMin = (int) box.pMin().y;
|
||||
|
@ -47,5 +55,5 @@ public class PatternBox extends FillerPattern {
|
|||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
|
|
@ -8,10 +8,8 @@
|
|||
*/
|
||||
package buildcraft.builders.filler.pattern;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import buildcraft.api.core.IBox;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import buildcraft.core.Box;
|
||||
import buildcraft.core.blueprints.BptBuilderTemplate;
|
||||
import buildcraft.core.blueprints.Template;
|
||||
|
@ -22,7 +20,7 @@ public class PatternClear extends FillerPattern {
|
|||
super("clear");
|
||||
}
|
||||
|
||||
@Override
|
||||
/*@Override
|
||||
public boolean iteratePattern(TileEntity tile, IBox box, ItemStack stackToPlace) {
|
||||
int xMin = (int) box.pMin().x;
|
||||
int yMin = (int) box.pMin().y;
|
||||
|
@ -33,10 +31,10 @@ public class PatternClear extends FillerPattern {
|
|||
int zMax = (int) box.pMax().z;
|
||||
|
||||
return !empty(xMin, yMin, zMin, xMax, yMax, zMax, tile.getWorldObj());
|
||||
}
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public BptBuilderTemplate getBlueprint (Box box, World world) {
|
||||
public BptBuilderTemplate getBlueprint (Box box, World world, ForgeDirection orientation) {
|
||||
int xMin = (int) box.pMin().x;
|
||||
int yMin = (int) box.pMin().y;
|
||||
int zMin = (int) box.pMin().z;
|
||||
|
|
|
@ -8,115 +8,134 @@
|
|||
*/
|
||||
package buildcraft.builders.filler.pattern;
|
||||
|
||||
import buildcraft.api.core.IBox;
|
||||
import buildcraft.api.core.Position;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import buildcraft.core.Box;
|
||||
import buildcraft.core.blueprints.BptBuilderTemplate;
|
||||
|
||||
public class PatternCylinder extends FillerPattern {
|
||||
|
||||
public PatternCylinder() {
|
||||
super("cylinder");
|
||||
}
|
||||
public PatternCylinder() {
|
||||
super("cylinder");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean iteratePattern(TileEntity tile, IBox box, ItemStack stackToPlace) {
|
||||
int xMin = (int)box.pMin().x;
|
||||
int yMin = (int)box.pMin().y;
|
||||
int zMin = (int)box.pMin().z;
|
||||
/*@Override
|
||||
public boolean iteratePattern(TileEntity tile, IBox box,
|
||||
ItemStack stackToPlace) {
|
||||
int xMin = (int) box.pMin().x;
|
||||
int yMin = (int) box.pMin().y;
|
||||
int zMin = (int) box.pMin().z;
|
||||
|
||||
int xMax = (int)box.pMax().x;
|
||||
int yMax = (int)box.pMax().y;
|
||||
int zMax = (int)box.pMax().z;
|
||||
int xMax = (int) box.pMax().x;
|
||||
int yMax = (int) box.pMax().y;
|
||||
int zMax = (int) box.pMax().z;
|
||||
|
||||
int xFix = (xMax-xMin)%2;
|
||||
int zFix = (zMax-zMin)%2;
|
||||
int xFix = (xMax - xMin) % 2;
|
||||
int zFix = (zMax - zMin) % 2;
|
||||
|
||||
int xCenter = (xMax+xMin)/2 + (xMax+xMin<0 && xFix==1 ? -1 : 0);
|
||||
int zCenter = (zMax+zMin)/2 + (zMax+zMin<0 && zFix==1 ? -1 : 0);
|
||||
int xCenter = (xMax + xMin) / 2
|
||||
+ (xMax + xMin < 0 && xFix == 1 ? -1 : 0);
|
||||
int zCenter = (zMax + zMin) / 2
|
||||
+ (zMax + zMin < 0 && zFix == 1 ? -1 : 0);
|
||||
|
||||
int xRadius = (xMax-xMin)/2;
|
||||
int zRadius = (zMax-zMin)/2;
|
||||
int xRadius = (xMax - xMin) / 2;
|
||||
int zRadius = (zMax - zMin) / 2;
|
||||
|
||||
if(xRadius == 0 || zRadius == 0) {
|
||||
return !fill(xMin, yMin, zMin, xMax, yMax, zMax, stackToPlace, tile.getWorldObj());
|
||||
}
|
||||
if (xRadius == 0 || zRadius == 0) {
|
||||
return !fill(xMin, yMin, zMin, xMax, yMax, zMax, stackToPlace,
|
||||
tile.getWorldObj());
|
||||
}
|
||||
|
||||
int dx = xRadius, dz = 0;
|
||||
int xChange = zRadius*zRadius*(1-2*xRadius);
|
||||
int zChange = xRadius*xRadius;
|
||||
int ellipseError = 0;
|
||||
int twoASquare = 2*xRadius*xRadius;
|
||||
int twoBSquare = 2*zRadius*zRadius;
|
||||
int stoppingX = twoBSquare*xRadius;
|
||||
int stoppingZ = 0;
|
||||
int dx = xRadius, dz = 0;
|
||||
int xChange = zRadius * zRadius * (1 - 2 * xRadius);
|
||||
int zChange = xRadius * xRadius;
|
||||
int ellipseError = 0;
|
||||
int twoASquare = 2 * xRadius * xRadius;
|
||||
int twoBSquare = 2 * zRadius * zRadius;
|
||||
int stoppingX = twoBSquare * xRadius;
|
||||
int stoppingZ = 0;
|
||||
|
||||
while(stoppingX >= stoppingZ) {
|
||||
if(!fillFourColumns(xCenter,zCenter,dx,dz,xFix,zFix,yMin,yMax,stackToPlace,tile.getWorldObj()))
|
||||
return false;
|
||||
++dz;
|
||||
stoppingZ += twoASquare;
|
||||
ellipseError += zChange;
|
||||
zChange += twoASquare;
|
||||
if(2*ellipseError + xChange > 0) {
|
||||
--dx;
|
||||
stoppingX -= twoBSquare;
|
||||
ellipseError += xChange;
|
||||
xChange += twoBSquare;
|
||||
}
|
||||
}
|
||||
while (stoppingX >= stoppingZ) {
|
||||
if (!fillFourColumns(xCenter, zCenter, dx, dz, xFix, zFix, yMin,
|
||||
yMax, stackToPlace, tile.getWorldObj())) {
|
||||
return false;
|
||||
}
|
||||
++dz;
|
||||
stoppingZ += twoASquare;
|
||||
ellipseError += zChange;
|
||||
zChange += twoASquare;
|
||||
if (2 * ellipseError + xChange > 0) {
|
||||
--dx;
|
||||
stoppingX -= twoBSquare;
|
||||
ellipseError += xChange;
|
||||
xChange += twoBSquare;
|
||||
}
|
||||
}
|
||||
|
||||
dx = 0;
|
||||
dz = zRadius;
|
||||
xChange = zRadius*zRadius;
|
||||
zChange = xRadius*xRadius*(1-2*zRadius);
|
||||
ellipseError = 0;
|
||||
stoppingX = 0;
|
||||
stoppingZ = twoASquare*zRadius;
|
||||
dx = 0;
|
||||
dz = zRadius;
|
||||
xChange = zRadius * zRadius;
|
||||
zChange = xRadius * xRadius * (1 - 2 * zRadius);
|
||||
ellipseError = 0;
|
||||
stoppingX = 0;
|
||||
stoppingZ = twoASquare * zRadius;
|
||||
|
||||
while(stoppingX <= stoppingZ) {
|
||||
if(!fillFourColumns(xCenter,zCenter,dx,dz,xFix,zFix,yMin,yMax,stackToPlace,tile.getWorldObj()))
|
||||
return false;
|
||||
++dx;
|
||||
stoppingX += twoBSquare;
|
||||
ellipseError += xChange;
|
||||
xChange += twoBSquare;
|
||||
if(2*ellipseError + zChange > 0) {
|
||||
--dz;
|
||||
stoppingZ -= twoASquare;
|
||||
ellipseError += zChange;
|
||||
zChange += twoASquare;
|
||||
}
|
||||
}
|
||||
while (stoppingX <= stoppingZ) {
|
||||
if (!fillFourColumns(xCenter, zCenter, dx, dz, xFix, zFix, yMin,
|
||||
yMax, stackToPlace, tile.getWorldObj())) {
|
||||
return false;
|
||||
}
|
||||
++dx;
|
||||
stoppingX += twoBSquare;
|
||||
ellipseError += xChange;
|
||||
xChange += twoBSquare;
|
||||
if (2 * ellipseError + zChange > 0) {
|
||||
--dz;
|
||||
stoppingZ -= twoASquare;
|
||||
ellipseError += zChange;
|
||||
zChange += twoASquare;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean fillFourColumns(int xCenter, int zCenter, int dx, int dz, int xFix, int zFix, int yMin, int yMax, ItemStack stackToPlace, World world) {
|
||||
int x,z;
|
||||
private boolean fillFourColumns(int xCenter, int zCenter, int dx, int dz,
|
||||
int xFix, int zFix, int yMin, int yMax, ItemStack stackToPlace,
|
||||
World world) {
|
||||
int x, z;
|
||||
|
||||
x = xCenter + dx + xFix;
|
||||
z = zCenter + dz + zFix;
|
||||
if(fill(x,yMin,z,x,yMax,z,stackToPlace,world))
|
||||
return false;
|
||||
x = xCenter + dx + xFix;
|
||||
z = zCenter + dz + zFix;
|
||||
if (fill(x, yMin, z, x, yMax, z, stackToPlace, world)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
x = xCenter - dx;
|
||||
z = zCenter + dz + zFix;
|
||||
if(fill(x,yMin,z,x,yMax,z,stackToPlace,world))
|
||||
return false;
|
||||
x = xCenter - dx;
|
||||
z = zCenter + dz + zFix;
|
||||
if (fill(x, yMin, z, x, yMax, z, stackToPlace, world)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
x = xCenter - dx;
|
||||
z = zCenter - dz;
|
||||
if(fill(x,yMin,z,x,yMax,z,stackToPlace,world))
|
||||
return false;
|
||||
x = xCenter - dx;
|
||||
z = zCenter - dz;
|
||||
if (fill(x, yMin, z, x, yMax, z, stackToPlace, world)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
x = xCenter + dx + xFix;
|
||||
z = zCenter - dz;
|
||||
if(fill(x,yMin,z,x,yMax,z,stackToPlace,world))
|
||||
return false;
|
||||
x = xCenter + dx + xFix;
|
||||
z = zCenter - dz;
|
||||
if (fill(x, yMin, z, x, yMax, z, stackToPlace, world)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public BptBuilderTemplate getBlueprint(Box box, World world,
|
||||
ForgeDirection orientation) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,11 +9,9 @@
|
|||
package buildcraft.builders.filler.pattern;
|
||||
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import buildcraft.api.blueprints.SchematicRegistry;
|
||||
import buildcraft.api.core.IBox;
|
||||
import buildcraft.core.Box;
|
||||
import buildcraft.core.blueprints.BptBuilderTemplate;
|
||||
import buildcraft.core.blueprints.Template;
|
||||
|
@ -27,20 +25,7 @@ public class PatternFill extends FillerPattern {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean iteratePattern(TileEntity tile, IBox box, ItemStack stackToPlace) {
|
||||
int xMin = (int) box.pMin().x;
|
||||
int yMin = (int) box.pMin().y;
|
||||
int zMin = (int) box.pMin().z;
|
||||
|
||||
int xMax = (int) box.pMax().x;
|
||||
int yMax = (int) box.pMax().y;
|
||||
int zMax = (int) box.pMax().z;
|
||||
|
||||
return !fill(xMin, yMin, zMin, xMax, yMax, zMax, stackToPlace, tile.getWorldObj());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BptBuilderTemplate getBlueprint (Box box, World world) {
|
||||
public BptBuilderTemplate getBlueprint (Box box, World world, ForgeDirection orientation) {
|
||||
int xMin = (int) box.pMin().x;
|
||||
int yMin = (int) box.pMin().y;
|
||||
int zMin = (int) box.pMin().z;
|
||||
|
|
|
@ -9,11 +9,9 @@
|
|||
package buildcraft.builders.filler.pattern;
|
||||
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import buildcraft.api.blueprints.SchematicRegistry;
|
||||
import buildcraft.api.core.IBox;
|
||||
import buildcraft.core.Box;
|
||||
import buildcraft.core.blueprints.BptBuilderTemplate;
|
||||
import buildcraft.core.blueprints.Template;
|
||||
|
@ -24,7 +22,7 @@ public class PatternFlatten extends FillerPattern {
|
|||
super("flatten");
|
||||
}
|
||||
|
||||
@Override
|
||||
/*@Override
|
||||
public boolean iteratePattern(TileEntity tile, IBox box, ItemStack stackToPlace) {
|
||||
int xMin = (int) box.pMin().x;
|
||||
int yMin = (int) box.pMin().y;
|
||||
|
@ -38,10 +36,10 @@ public class PatternFlatten extends FillerPattern {
|
|||
return false;
|
||||
}
|
||||
return !empty(xMin, yMin, zMin, xMax, yMax, zMax, tile.getWorldObj());
|
||||
}
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public BptBuilderTemplate getBlueprint (Box box, World world) {
|
||||
public BptBuilderTemplate getBlueprint (Box box, World world, ForgeDirection orientation) {
|
||||
int xMin = (int) box.pMin().x;
|
||||
int yMin = 1;
|
||||
int zMin = (int) box.pMin().z;
|
||||
|
@ -64,4 +62,11 @@ public class PatternFlatten extends FillerPattern {
|
|||
|
||||
return new BptBuilderTemplate(bpt, world, box.xMin, 1, box.zMin);
|
||||
}
|
||||
|
||||
/*@Override
|
||||
public BptBuilderTemplate getBlueprint(Box box, World world,
|
||||
) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}*/
|
||||
}
|
||||
|
|
|
@ -8,9 +8,10 @@
|
|||
*/
|
||||
package buildcraft.builders.filler.pattern;
|
||||
|
||||
import buildcraft.api.core.IBox;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import buildcraft.core.Box;
|
||||
import buildcraft.core.blueprints.BptBuilderTemplate;
|
||||
|
||||
public class PatternHorizon extends FillerPattern {
|
||||
|
||||
|
@ -18,7 +19,7 @@ public class PatternHorizon extends FillerPattern {
|
|||
super("horizon");
|
||||
}
|
||||
|
||||
@Override
|
||||
/*@Override
|
||||
public boolean iteratePattern(TileEntity tile, IBox box, ItemStack stackToPlace) {
|
||||
int xMin = (int) box.pMin().x;
|
||||
int yMin = (int) box.pMin().y;
|
||||
|
@ -31,5 +32,11 @@ public class PatternHorizon extends FillerPattern {
|
|||
return false;
|
||||
}
|
||||
return !empty(xMin, yMin, zMin, xMax, tile.getWorldObj().getActualHeight(), zMax, tile.getWorldObj());
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public BptBuilderTemplate getBlueprint(Box box, World world,
|
||||
ForgeDirection orientation) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,11 +9,9 @@
|
|||
package buildcraft.builders.filler.pattern;
|
||||
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import buildcraft.api.blueprints.SchematicRegistry;
|
||||
import buildcraft.api.core.IBox;
|
||||
import buildcraft.core.Box;
|
||||
import buildcraft.core.blueprints.BptBuilderTemplate;
|
||||
import buildcraft.core.blueprints.Template;
|
||||
|
@ -24,7 +22,7 @@ public class PatternPyramid extends FillerPattern {
|
|||
super("pyramid");
|
||||
}
|
||||
|
||||
@Override
|
||||
/*@Override
|
||||
public boolean iteratePattern(TileEntity tile, IBox box, ItemStack stackToPlace) {
|
||||
int xMin = (int) box.pMin().x;
|
||||
int yMin = (int) box.pMin().y;
|
||||
|
@ -64,10 +62,10 @@ public class PatternPyramid extends FillerPattern {
|
|||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public BptBuilderTemplate getBlueprint (Box box, World world) {
|
||||
public BptBuilderTemplate getBlueprint (Box box, World world, ForgeDirection orientation) {
|
||||
int xMin = (int) box.pMin().x;
|
||||
int yMin = (int) box.pMin().y;
|
||||
int zMin = (int) box.pMin().z;
|
||||
|
|
|
@ -8,9 +8,11 @@
|
|||
*/
|
||||
package buildcraft.builders.filler.pattern;
|
||||
|
||||
import buildcraft.api.core.IBox;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import buildcraft.core.Box;
|
||||
import buildcraft.core.blueprints.BptBuilderTemplate;
|
||||
|
||||
|
||||
public class PatternStairs extends FillerPattern {
|
||||
|
||||
|
@ -19,6 +21,12 @@ public class PatternStairs extends FillerPattern {
|
|||
}
|
||||
|
||||
@Override
|
||||
public BptBuilderTemplate getBlueprint(Box box, World world,
|
||||
ForgeDirection orientation) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/*@Override
|
||||
public boolean iteratePattern(TileEntity tile, IBox box, ItemStack stackToPlace) {
|
||||
int xMin = (int) box.pMin().x;
|
||||
int yMin = (int) box.pMin().y;
|
||||
|
@ -188,5 +196,5 @@ public class PatternStairs extends FillerPattern {
|
|||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
package buildcraft.core;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ReflectAPI {
|
||||
|
||||
public static String KEY_MJ_STORED = "_MJ_STORED";
|
||||
static Map <Class, Field> MAP_MJ_STORED = new HashMap <Class, Field> ();
|
||||
|
||||
public static Field get_MJ_STORED (Class c) {
|
||||
if (!MAP_MJ_STORED.containsKey(c)) {
|
||||
for (Field f : c.getFields()) {
|
||||
if (f.getName().equals(KEY_MJ_STORED)) {
|
||||
return MAP_MJ_STORED.put(c, f);
|
||||
}
|
||||
}
|
||||
|
||||
return MAP_MJ_STORED.put(c, null);
|
||||
} else {
|
||||
return MAP_MJ_STORED.get(c);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
64
common/buildcraft/core/ReflectMjAPI.java
Executable file
64
common/buildcraft/core/ReflectMjAPI.java
Executable file
|
@ -0,0 +1,64 @@
|
|||
package buildcraft.core;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import buildcraft.api.mj.MjBattery;
|
||||
|
||||
public class ReflectMjAPI {
|
||||
|
||||
public static class BatteryField {
|
||||
public Field field;
|
||||
public MjBattery battery;
|
||||
|
||||
public double getEnergyRequested (Object obj) {
|
||||
try {
|
||||
double contained = field.getDouble(obj);
|
||||
|
||||
double left = contained + battery.maxReceivedPerCycle() > battery
|
||||
.maxCapacity() ? battery.maxCapacity() - contained : battery
|
||||
.maxReceivedPerCycle();
|
||||
|
||||
if (left > 0) {
|
||||
return left;
|
||||
} else {
|
||||
return battery.miniumConsumption();
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static Map <Class, BatteryField> MjBatteries = new HashMap <Class, BatteryField> ();
|
||||
|
||||
public static BatteryField getMjBattery (Class c) {
|
||||
if (!MjBatteries.containsKey(c)) {
|
||||
for (Field f : c.getFields()) {
|
||||
MjBattery battery = f.getAnnotation (MjBattery.class);
|
||||
|
||||
if (battery != null) {
|
||||
if (!f.getType().equals(double.class)) {
|
||||
throw new RuntimeException("MjBattery need to be of type double");
|
||||
} else {
|
||||
BatteryField bField = new BatteryField();
|
||||
bField.field = f;
|
||||
bField.battery = battery;
|
||||
|
||||
return MjBatteries.put(c, bField);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return MjBatteries.put(c, null);
|
||||
} else {
|
||||
return MjBatteries.get(c);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -16,7 +16,6 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import buildcraft.BuildCraftBuilders;
|
||||
import buildcraft.BuildCraftEnergy;
|
||||
import buildcraft.api.gates.IOverrideDefaultTriggers;
|
||||
import buildcraft.api.gates.ITrigger;
|
||||
|
@ -29,10 +28,11 @@ import buildcraft.api.transport.IPipeConnection;
|
|||
import buildcraft.api.transport.IPipeTile;
|
||||
import buildcraft.api.transport.IPipeTile.PipeType;
|
||||
import buildcraft.core.DefaultProps;
|
||||
import buildcraft.core.ReflectMjAPI;
|
||||
import buildcraft.core.ReflectMjAPI.BatteryField;
|
||||
import buildcraft.core.TileBuffer;
|
||||
import buildcraft.core.TileBuildCraft;
|
||||
import buildcraft.core.network.NetworkData;
|
||||
import buildcraft.core.proxy.CoreProxy;
|
||||
import buildcraft.energy.gui.ContainerEngine;
|
||||
|
||||
public abstract class TileEngine extends TileBuildCraft implements IPowerReceptor, IPowerEmitter, IOverrideDefaultTriggers, IPipeConnection {
|
||||
|
@ -45,7 +45,7 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
|
|||
BLUE, GREEN, YELLOW, RED, OVERHEAT;
|
||||
public static final EnergyStage[] VALUES = values();
|
||||
}
|
||||
|
||||
|
||||
public static final float MIN_HEAT = 20;
|
||||
public static final float IDEAL_HEAT = 100;
|
||||
public static final float MAX_HEAT = 250;
|
||||
|
@ -92,22 +92,24 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
|
|||
|
||||
protected EnergyStage computeEnergyStage() {
|
||||
float energyLevel = getHeatLevel();
|
||||
if (energyLevel < 0.25f)
|
||||
if (energyLevel < 0.25f) {
|
||||
return EnergyStage.BLUE;
|
||||
else if (energyLevel < 0.5f)
|
||||
} else if (energyLevel < 0.5f) {
|
||||
return EnergyStage.GREEN;
|
||||
else if (energyLevel < 0.75f)
|
||||
} else if (energyLevel < 0.75f) {
|
||||
return EnergyStage.YELLOW;
|
||||
else if (energyLevel < 1f)
|
||||
} else if (energyLevel < 1f) {
|
||||
return EnergyStage.RED;
|
||||
else
|
||||
} else {
|
||||
return EnergyStage.OVERHEAT;
|
||||
}
|
||||
}
|
||||
|
||||
public final EnergyStage getEnergyStage() {
|
||||
if (!worldObj.isRemote) {
|
||||
if (energyStage == EnergyStage.OVERHEAT)
|
||||
if (energyStage == EnergyStage.OVERHEAT) {
|
||||
return energyStage;
|
||||
}
|
||||
EnergyStage newStage = computeEnergyStage();
|
||||
|
||||
if (energyStage != newStage) {
|
||||
|
@ -139,7 +141,7 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
|
|||
if (!worldObj.isRemote) {
|
||||
return Math.max(0.16f * getHeatLevel(), 0.01f);
|
||||
}
|
||||
|
||||
|
||||
switch (getEnergyStage()) {
|
||||
case BLUE:
|
||||
return 0.02F;
|
||||
|
@ -175,7 +177,7 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
|
|||
|
||||
if (checkOrienation) {
|
||||
checkOrienation = false;
|
||||
|
||||
|
||||
if (!isOrientationValid()) {
|
||||
switchOrientation(true);
|
||||
}
|
||||
|
@ -228,21 +230,50 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
|
|||
|
||||
private double getPowerToExtract() {
|
||||
TileEntity tile = getTileBuffer(orientation).getTile();
|
||||
PowerReceiver receptor = ((IPowerReceptor) tile).getPowerReceiver(orientation.getOpposite());
|
||||
return extractEnergy(receptor.getMinEnergyReceived(), receptor.getMaxEnergyReceived(), false); // Comment out for constant power
|
||||
// return extractEnergy(0, getActualOutput(), false); // Uncomment for constant power
|
||||
|
||||
if (tile instanceof IPowerReceptor) {
|
||||
PowerReceiver receptor = ((IPowerReceptor) tile)
|
||||
.getPowerReceiver(orientation.getOpposite());
|
||||
|
||||
return extractEnergy(receptor.getMinEnergyReceived(),
|
||||
receptor.getMaxEnergyReceived(), false);
|
||||
} else {
|
||||
return extractEnergy(0, ReflectMjAPI.getMjBattery(tile.getClass())
|
||||
.getEnergyRequested(tile), false);
|
||||
}
|
||||
}
|
||||
|
||||
private void sendPower() {
|
||||
TileEntity tile = getTileBuffer(orientation).getTile();
|
||||
if (isPoweredTile(tile, orientation)) {
|
||||
PowerReceiver receptor = ((IPowerReceptor) tile).getPowerReceiver(orientation.getOpposite());
|
||||
|
||||
double extracted = getPowerToExtract();
|
||||
if (extracted > 0) {
|
||||
double needed = receptor.receiveEnergy(PowerHandler.Type.ENGINE, extracted, orientation.getOpposite());
|
||||
extractEnergy(receptor.getMinEnergyReceived(), needed, true); // Comment out for constant power
|
||||
// currentOutput = extractEnergy(0, needed, true); // Uncomment for constant power
|
||||
|
||||
if (tile instanceof IPowerReceptor) {
|
||||
PowerReceiver receptor = ((IPowerReceptor) tile)
|
||||
.getPowerReceiver(orientation.getOpposite());
|
||||
|
||||
if (extracted > 0) {
|
||||
double needed = receptor.receiveEnergy(
|
||||
PowerHandler.Type.ENGINE, extracted,
|
||||
orientation.getOpposite());
|
||||
|
||||
extractEnergy(receptor.getMinEnergyReceived(), needed, true);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
BatteryField f = ReflectMjAPI.getMjBattery(tile.getClass());
|
||||
|
||||
f.field.set(
|
||||
tile,
|
||||
f.field.getDouble(tile)
|
||||
+ extractEnergy(0,
|
||||
extracted + f.battery.miniumConsumption(),
|
||||
true) - f.battery.miniumConsumption());
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -256,12 +287,13 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
|
|||
}
|
||||
|
||||
protected void engineUpdate() {
|
||||
if (!isRedstonePowered)
|
||||
if (!isRedstonePowered) {
|
||||
if (energy >= 1) {
|
||||
energy -= 1;
|
||||
} else if (energy < 1) {
|
||||
energy = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
|
@ -279,14 +311,14 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
|
|||
|
||||
public boolean isOrientationValid() {
|
||||
TileEntity tile = getTileBuffer(orientation).getTile();
|
||||
|
||||
|
||||
return isPoweredTile(tile, orientation);
|
||||
}
|
||||
|
||||
public boolean switchOrientation(boolean preferPipe) {
|
||||
if (preferPipe && switchOrientation_do(true)) {
|
||||
return true;
|
||||
} else {
|
||||
} else {
|
||||
return switchOrientation_do(false);
|
||||
}
|
||||
}
|
||||
|
@ -305,7 +337,7 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
|
|||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -313,7 +345,7 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
|
|||
if (tileCache == null) {
|
||||
tileCache = TileBuffer.makeBuffer(worldObj, xCoord, yCoord, zCoord, false);
|
||||
}
|
||||
|
||||
|
||||
return tileCache[side.ordinal()];
|
||||
}
|
||||
|
||||
|
@ -334,17 +366,17 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
|
|||
@Override
|
||||
public void readFromNBT(NBTTagCompound data) {
|
||||
super.readFromNBT(data);
|
||||
|
||||
|
||||
orientation = ForgeDirection.getOrientation(data.getInteger("orientation"));
|
||||
progress = data.getFloat("progress");
|
||||
energy = data.getDouble("energy");
|
||||
heat = data.getFloat("heat");
|
||||
heat = data.getFloat("heat");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound data) {
|
||||
super.writeToNBT(data);
|
||||
|
||||
|
||||
data.setInteger("orientation", orientation.ordinal());
|
||||
data.setFloat("progress", progress);
|
||||
data.setDouble("energy", energy);
|
||||
|
@ -432,13 +464,13 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
|
|||
|
||||
if (energy >= actualMax) {
|
||||
extracted = actualMax;
|
||||
|
||||
|
||||
if (doExtract) {
|
||||
energy -= actualMax;
|
||||
}
|
||||
} else {
|
||||
extracted = energy;
|
||||
|
||||
|
||||
if (doExtract) {
|
||||
energy = 0;
|
||||
}
|
||||
|
@ -448,8 +480,12 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
|
|||
}
|
||||
|
||||
public boolean isPoweredTile(TileEntity tile, ForgeDirection side) {
|
||||
if (tile instanceof IPowerReceptor) {
|
||||
if (tile == null) {
|
||||
return false;
|
||||
} else if (tile instanceof IPowerReceptor) {
|
||||
return ((IPowerReceptor) tile).getPowerReceiver(side.getOpposite()) != null;
|
||||
} else if (ReflectMjAPI.getMjBattery(tile.getClass()) != null) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
@ -489,7 +525,7 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
|
|||
public ConnectOverride overridePipeConnection(PipeType type, ForgeDirection with) {
|
||||
if (type == PipeType.POWER) {
|
||||
return ConnectOverride.DEFAULT;
|
||||
} else if (with == orientation) {
|
||||
} else if (with == orientation) {
|
||||
return ConnectOverride.DISCONNECT;
|
||||
} else {
|
||||
return ConnectOverride.DEFAULT;
|
||||
|
|
|
@ -14,13 +14,13 @@ public interface IPipeTransportPowerHook {
|
|||
|
||||
/**
|
||||
* Override default behavior on receiving energy into the pipe.
|
||||
*
|
||||
*
|
||||
* @return The amount of power used, or -1 for default behavior.
|
||||
*/
|
||||
public float receiveEnergy(ForgeDirection from, float val);
|
||||
public double receiveEnergy(ForgeDirection from, double val);
|
||||
|
||||
/**
|
||||
* Override default requested power.
|
||||
*/
|
||||
public float requestEnergy(ForgeDirection from, float amount);
|
||||
public double requestEnergy(ForgeDirection from, double amount);
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
*/
|
||||
package buildcraft.transport;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
@ -26,7 +25,8 @@ import buildcraft.api.power.PowerHandler.PowerReceiver;
|
|||
import buildcraft.api.power.PowerHandler.Type;
|
||||
import buildcraft.api.transport.IPipeTile.PipeType;
|
||||
import buildcraft.core.DefaultProps;
|
||||
import buildcraft.core.ReflectAPI;
|
||||
import buildcraft.core.ReflectMjAPI;
|
||||
import buildcraft.core.ReflectMjAPI.BatteryField;
|
||||
import buildcraft.transport.network.PacketPowerUpdate;
|
||||
import buildcraft.transport.pipes.PipePowerCobblestone;
|
||||
import buildcraft.transport.pipes.PipePowerDiamond;
|
||||
|
@ -94,25 +94,28 @@ public class PipeTransportPower extends PipeTransport {
|
|||
public boolean canPipeConnect(TileEntity tile, ForgeDirection side) {
|
||||
if (tile instanceof TileGenericPipe) {
|
||||
Pipe pipe2 = ((TileGenericPipe) tile).pipe;
|
||||
if (BlockGenericPipe.isValid(pipe2) && !(pipe2.transport instanceof PipeTransportPower))
|
||||
if (BlockGenericPipe.isValid(pipe2) && !(pipe2.transport instanceof PipeTransportPower)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (tile instanceof IPowerReceptor) {
|
||||
IPowerReceptor receptor = (IPowerReceptor) tile;
|
||||
PowerReceiver receiver = receptor.getPowerReceiver(side.getOpposite());
|
||||
if (receiver != null && receiver.getType().canReceiveFromPipes())
|
||||
if (receiver != null && receiver.getType().canReceiveFromPipes()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (container.pipe instanceof PipePowerWood && tile instanceof IPowerEmitter) {
|
||||
IPowerEmitter emitter = (IPowerEmitter) tile;
|
||||
if (emitter.canEmitPowerFrom(side.getOpposite()))
|
||||
if (emitter.canEmitPowerFrom(side.getOpposite())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (ReflectAPI.get_MJ_STORED(tile.getClass()) != null) {
|
||||
if (ReflectMjAPI.getMjBattery(tile.getClass()) != null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -173,23 +176,24 @@ public class PipeTransportPower extends PipeTransport {
|
|||
float totalPowerQuery = 0;
|
||||
|
||||
for (int j = 0; j < 6; ++j) {
|
||||
if (j != i && powerQuery[j] > 0)
|
||||
if (j != i && powerQuery[j] > 0) {
|
||||
if (tiles[j] != null
|
||||
&& (tiles[j] instanceof TileGenericPipe
|
||||
|| tiles[j] instanceof IPowerReceptor || ReflectAPI
|
||||
.get_MJ_STORED(tiles[j].getClass()) != null)) {
|
||||
|| tiles[j] instanceof IPowerReceptor || ReflectMjAPI
|
||||
.getMjBattery(tiles[j].getClass()) != null)) {
|
||||
totalPowerQuery += powerQuery[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int j = 0; j < 6; ++j) {
|
||||
if (j != i && powerQuery[j] > 0) {
|
||||
float watts = 0.0F;
|
||||
double watts = 0.0F;
|
||||
|
||||
PowerReceiver prov = getReceiverOnSide(ForgeDirection.VALID_DIRECTIONS[j]);
|
||||
if (prov != null && prov.powerRequest() > 0) {
|
||||
watts = (internalPower[i] / totalPowerQuery) * powerQuery[j];
|
||||
watts = (float) prov.receiveEnergy(Type.PIPE, watts, ForgeDirection.VALID_DIRECTIONS[j].getOpposite());
|
||||
watts = prov.receiveEnergy(Type.PIPE, watts, ForgeDirection.VALID_DIRECTIONS[j].getOpposite());
|
||||
internalPower[i] -= watts;
|
||||
} else if (tiles[j] instanceof TileGenericPipe) {
|
||||
watts = (internalPower[i] / totalPowerQuery) * powerQuery[j];
|
||||
|
@ -202,16 +206,17 @@ public class PipeTransportPower extends PipeTransport {
|
|||
} else if (tiles[j] != null) {
|
||||
// Look for the simplified power framework
|
||||
|
||||
Field f = ReflectAPI.get_MJ_STORED(tiles [j].getClass());
|
||||
BatteryField f = ReflectMjAPI.getMjBattery(tiles [j].getClass());
|
||||
|
||||
try {
|
||||
if (f != null) {
|
||||
watts = (internalPower[i] / totalPowerQuery) * powerQuery[j];
|
||||
|
||||
float energy = f.getFloat(tiles[j]);
|
||||
double energy = f.field.getDouble (tiles[j]);
|
||||
|
||||
if (energy < 100) {
|
||||
energy += watts;
|
||||
f.setFloat(tiles [j], energy);
|
||||
f.field.setDouble(tiles [j], energy);
|
||||
internalPower[i] -= watts;
|
||||
}
|
||||
}
|
||||
|
@ -262,22 +267,10 @@ public class PipeTransportPower extends PipeTransport {
|
|||
}
|
||||
|
||||
if (tile != null) {
|
||||
Field f = ReflectAPI.get_MJ_STORED(tile.getClass());
|
||||
BatteryField f = ReflectMjAPI.getMjBattery(tile.getClass());
|
||||
|
||||
try {
|
||||
if (f != null) {
|
||||
float energy = f.getFloat(tile);
|
||||
|
||||
if (energy < 100) {
|
||||
requestEnergy(dir, 100);
|
||||
}
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
if (f != null) {
|
||||
requestEnergy(dir, f.getEnergyRequested(tile));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -335,14 +328,17 @@ public class PipeTransportPower extends PipeTransport {
|
|||
|
||||
private PowerReceiver getReceiverOnSide(ForgeDirection side) {
|
||||
TileEntity tile = tiles[side.ordinal()];
|
||||
if (!(tile instanceof IPowerReceptor))
|
||||
if (!(tile instanceof IPowerReceptor)) {
|
||||
return null;
|
||||
}
|
||||
IPowerReceptor receptor = (IPowerReceptor) tile;
|
||||
PowerReceiver receiver = receptor.getPowerReceiver(side.getOpposite());
|
||||
if (receiver == null)
|
||||
if (receiver == null) {
|
||||
return null;
|
||||
if (!receiver.getType().canReceiveFromPipes())
|
||||
}
|
||||
if (!receiver.getType().canReceiveFromPipes()) {
|
||||
return null;
|
||||
}
|
||||
return receiver;
|
||||
}
|
||||
|
||||
|
@ -379,29 +375,32 @@ public class PipeTransportPower extends PipeTransport {
|
|||
* All power input MUST go through designated input pipes, such as Wooden
|
||||
* Power Pipes or a subclass thereof.
|
||||
*/
|
||||
public float receiveEnergy(ForgeDirection from, float val) {
|
||||
public double receiveEnergy(ForgeDirection from, double val) {
|
||||
step();
|
||||
if (this.container.pipe instanceof IPipeTransportPowerHook) {
|
||||
float ret = ((IPipeTransportPowerHook) this.container.pipe).receiveEnergy(from, val);
|
||||
if (ret >= 0)
|
||||
double ret = ((IPipeTransportPowerHook) this.container.pipe).receiveEnergy(from, val);
|
||||
if (ret >= 0) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
int side = from.ordinal();
|
||||
if (internalNextPower[side] > maxPower)
|
||||
if (internalNextPower[side] > maxPower) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
internalNextPower[side] += val;
|
||||
|
||||
if (internalNextPower[side] > maxPower) {
|
||||
val -= internalNextPower[side] - maxPower;
|
||||
internalNextPower[side] = maxPower;
|
||||
if (val < 0)
|
||||
if (val < 0) {
|
||||
val = 0;
|
||||
}
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
public void requestEnergy(ForgeDirection from, float amount) {
|
||||
public void requestEnergy(ForgeDirection from, double amount) {
|
||||
step();
|
||||
|
||||
if (this.container.pipe instanceof IPipeTransportPowerHook) {
|
||||
|
|
|
@ -8,6 +8,9 @@
|
|||
*/
|
||||
package buildcraft.transport.pipes;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import buildcraft.BuildCraftTransport;
|
||||
import buildcraft.api.core.IIconProvider;
|
||||
import buildcraft.api.power.IPowerReceptor;
|
||||
|
@ -21,9 +24,6 @@ import buildcraft.transport.PipeIconProvider;
|
|||
import buildcraft.transport.PipeTransportPower;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public class PipePowerWood extends Pipe<PipeTransportPower> implements IPowerReceptor, IPipeTransportPowerHook {
|
||||
|
||||
|
@ -69,11 +69,13 @@ public class PipePowerWood extends Pipe<PipeTransportPower> implements IPowerRec
|
|||
@Override
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
if (container.getWorldObj().isRemote)
|
||||
if (container.getWorldObj().isRemote) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (powerHandler.getEnergyStored() <= 0)
|
||||
if (powerHandler.getEnergyStored() <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
int sources = 0;
|
||||
for (ForgeDirection o : ForgeDirection.VALID_DIRECTIONS) {
|
||||
|
@ -103,15 +105,16 @@ public class PipePowerWood extends Pipe<PipeTransportPower> implements IPowerRec
|
|||
} else {
|
||||
energyToRemove = 1;
|
||||
}
|
||||
energyToRemove /= (float) sources;
|
||||
energyToRemove /= sources;
|
||||
|
||||
for (ForgeDirection o : ForgeDirection.VALID_DIRECTIONS) {
|
||||
if (!powerSources[o.ordinal()])
|
||||
if (!powerSources[o.ordinal()]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
float energyUsable = (float) powerHandler.useEnergy(0, energyToRemove, false);
|
||||
|
||||
float energySent = transport.receiveEnergy(o, energyUsable);
|
||||
double energySent = transport.receiveEnergy(o, energyUsable);
|
||||
if (energySent > 0) {
|
||||
powerHandler.useEnergy(0, energySent, true);
|
||||
}
|
||||
|
@ -150,12 +153,12 @@ public class PipePowerWood extends Pipe<PipeTransportPower> implements IPowerRec
|
|||
}
|
||||
|
||||
@Override
|
||||
public float receiveEnergy(ForgeDirection from, float val) {
|
||||
public double receiveEnergy(ForgeDirection from, double val) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float requestEnergy(ForgeDirection from, float amount) {
|
||||
public double requestEnergy(ForgeDirection from, double amount) {
|
||||
if (container.getTile(from) instanceof IPipeTile) {
|
||||
return amount;
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue