revert RF API, add anti-fakeplayer measures to engine overheat wrenching
This commit is contained in:
parent
6b9d5d8330
commit
e0c96aa7d6
15 changed files with 83 additions and 125 deletions
17
api/buildcraft/api/power/IRedstoneEnergyReceiver.java
Normal file
17
api/buildcraft/api/power/IRedstoneEnergyReceiver.java
Normal file
|
@ -0,0 +1,17 @@
|
|||
package buildcraft.api.power;
|
||||
|
||||
/**
|
||||
* Use this class for IEnergyHandlers which wish to receive
|
||||
* Redstone Engine power.
|
||||
*
|
||||
* Please note, however, that BuildCraft's design does NOT
|
||||
* want you to allow this for any block. Redstone engines
|
||||
* generally emit 0.625 RF/t in pulses.
|
||||
*
|
||||
* Please consult us before having your tile entity
|
||||
* implement this. We're making the interface public as
|
||||
* an act of good will.
|
||||
*/
|
||||
public interface IRedstoneEnergyReceiver {
|
||||
boolean canReceiveRedstoneEnergy();
|
||||
}
|
|
@ -6,6 +6,6 @@ public class CoFHAPIProps {
|
|||
|
||||
}
|
||||
|
||||
public static final String VERSION = "1.7.10R1.0.1";
|
||||
public static final String VERSION = "1.7.10R1.0.0";
|
||||
|
||||
}
|
||||
|
|
|
@ -87,8 +87,8 @@ public class EnergyStorage implements IEnergyStorage {
|
|||
}
|
||||
|
||||
/**
|
||||
* This function is included to allow for server -> client sync. Do not call this externally to the containing Tile Entity, as not all IEnergyHandlers
|
||||
* are guaranteed to have it.
|
||||
* This function is included to allow for server -> client sync. Do not call this externally to the containing Tile Entity, as not all IEnergyHandlers are
|
||||
* guaranteed to have it.
|
||||
*
|
||||
* @param energy
|
||||
*/
|
||||
|
|
|
@ -5,7 +5,7 @@ import net.minecraftforge.common.util.ForgeDirection;
|
|||
/**
|
||||
* Implement this interface on TileEntities which should connect to energy transportation blocks. This is intended for blocks which generate energy but do not
|
||||
* accept it; otherwise just use IEnergyHandler.
|
||||
* <p>
|
||||
*
|
||||
* Note that {@link IEnergyHandler} is an extension of this.
|
||||
*
|
||||
* @author King Lemming
|
||||
|
|
|
@ -4,7 +4,7 @@ import net.minecraft.item.ItemStack;
|
|||
|
||||
/**
|
||||
* Implement this interface on Item classes that support external manipulation of their internal energy storages.
|
||||
* <p>
|
||||
*
|
||||
* A reference implementation is provided {@link ItemEnergyContainer}.
|
||||
*
|
||||
* @author King Lemming
|
||||
|
|
|
@ -4,19 +4,17 @@ import net.minecraftforge.common.util.ForgeDirection;
|
|||
|
||||
/**
|
||||
* Implement this interface on Tile Entities which should handle energy, generally storing it in one or more internal {@link IEnergyStorage} objects.
|
||||
* <p>
|
||||
*
|
||||
* A reference implementation is provided {@link TileEnergyHandler}.
|
||||
*
|
||||
*
|
||||
* @author King Lemming
|
||||
*
|
||||
*
|
||||
*/
|
||||
public interface IEnergyHandler extends IEnergyProvider, IEnergyReceiver {
|
||||
|
||||
// merely a convenience interface (remove these methods in 1.8; provided here for back-compat via compiler doing things)
|
||||
public interface IEnergyHandler extends IEnergyConnection {
|
||||
|
||||
/**
|
||||
* Add energy to an IEnergyReceiver, internal distribution is left entirely to the IEnergyReceiver.
|
||||
*
|
||||
* Add energy to an IEnergyHandler, internal distribution is left entirely to the IEnergyHandler.
|
||||
*
|
||||
* @param from
|
||||
* Orientation the energy is received from.
|
||||
* @param maxReceive
|
||||
|
@ -25,12 +23,11 @@ public interface IEnergyHandler extends IEnergyProvider, IEnergyReceiver {
|
|||
* If TRUE, the charge will only be simulated.
|
||||
* @return Amount of energy that was (or would have been, if simulated) received.
|
||||
*/
|
||||
@Override
|
||||
int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate);
|
||||
|
||||
/**
|
||||
* Remove energy from an IEnergyProvider, internal distribution is left entirely to the IEnergyProvider.
|
||||
*
|
||||
* Remove energy from an IEnergyHandler, internal distribution is left entirely to the IEnergyHandler.
|
||||
*
|
||||
* @param from
|
||||
* Orientation the energy is extracted from.
|
||||
* @param maxExtract
|
||||
|
@ -39,20 +36,16 @@ public interface IEnergyHandler extends IEnergyProvider, IEnergyReceiver {
|
|||
* If TRUE, the extraction will only be simulated.
|
||||
* @return Amount of energy that was (or would have been, if simulated) extracted.
|
||||
*/
|
||||
@Override
|
||||
int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the amount of energy currently stored.
|
||||
*/
|
||||
@Override
|
||||
int getEnergyStored(ForgeDirection from);
|
||||
|
||||
/**
|
||||
* Returns the maximum amount of energy that can be stored.
|
||||
*/
|
||||
@Override
|
||||
int getMaxEnergyStored(ForgeDirection from);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
package cofh.api.energy;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
/**
|
||||
* Implement this interface on Tile Entities which should provide energy, generally storing it in one or more internal {@link IEnergyStorage} objects.
|
||||
* <p>
|
||||
* A reference implementation is provided {@link TileEnergyHandler}.
|
||||
*
|
||||
* @author King Lemming
|
||||
*
|
||||
*/
|
||||
public interface IEnergyProvider extends IEnergyConnection {
|
||||
|
||||
/**
|
||||
* Remove energy from an IEnergyProvider, internal distribution is left entirely to the IEnergyProvider.
|
||||
*
|
||||
* @param from
|
||||
* Orientation the energy is extracted from.
|
||||
* @param maxExtract
|
||||
* Maximum amount of energy to extract.
|
||||
* @param simulate
|
||||
* If TRUE, the extraction will only be simulated.
|
||||
* @return Amount of energy that was (or would have been, if simulated) extracted.
|
||||
*/
|
||||
int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate);
|
||||
|
||||
/**
|
||||
* Returns the amount of energy currently stored.
|
||||
*/
|
||||
int getEnergyStored(ForgeDirection from);
|
||||
|
||||
/**
|
||||
* Returns the maximum amount of energy that can be stored.
|
||||
*/
|
||||
int getMaxEnergyStored(ForgeDirection from);
|
||||
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
package cofh.api.energy;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
/**
|
||||
* Implement this interface on Tile Entities which should receive energy, generally storing it in one or more internal {@link IEnergyStorage} objects.
|
||||
* <p>
|
||||
* A reference implementation is provided {@link TileEnergyHandler}.
|
||||
*
|
||||
* @author King Lemming
|
||||
*
|
||||
*/
|
||||
public interface IEnergyReceiver extends IEnergyConnection {
|
||||
|
||||
/**
|
||||
* Add energy to an IEnergyReceiver, internal distribution is left entirely to the IEnergyReceiver.
|
||||
*
|
||||
* @param from
|
||||
* Orientation the energy is received from.
|
||||
* @param maxReceive
|
||||
* Maximum amount of energy to receive.
|
||||
* @param simulate
|
||||
* If TRUE, the charge will only be simulated.
|
||||
* @return Amount of energy that was (or would have been, if simulated) received.
|
||||
*/
|
||||
int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate);
|
||||
|
||||
/**
|
||||
* Returns the amount of energy currently stored.
|
||||
*/
|
||||
int getEnergyStored(ForgeDirection from);
|
||||
|
||||
/**
|
||||
* Returns the maximum amount of energy that can be stored.
|
||||
*/
|
||||
int getMaxEnergyStored(ForgeDirection from);
|
||||
|
||||
}
|
|
@ -1,9 +1,8 @@
|
|||
package cofh.api.energy;
|
||||
|
||||
/**
|
||||
* An energy storage is the unit of interaction with Energy inventories.<br>
|
||||
* This is not to be implemented on TileEntities. This is for internal use only.
|
||||
* <p>
|
||||
* An energy storage is the unit of interaction with Energy inventories.
|
||||
*
|
||||
* A reference implementation can be found at {@link EnergyStorage}.
|
||||
*
|
||||
* @author King Lemming
|
||||
|
|
|
@ -6,9 +6,9 @@ import net.minecraftforge.common.util.ForgeDirection;
|
|||
|
||||
/**
|
||||
* Reference implementation of {@link IEnergyHandler}. Use/extend this or implement your own.
|
||||
*
|
||||
*
|
||||
* @author King Lemming
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class TileEnergyHandler extends TileEntity implements IEnergyHandler {
|
||||
|
||||
|
@ -28,28 +28,25 @@ public class TileEnergyHandler extends TileEntity implements IEnergyHandler {
|
|||
storage.writeToNBT(nbt);
|
||||
}
|
||||
|
||||
/* IEnergyConnection */
|
||||
/* IEnergyHandler */
|
||||
@Override
|
||||
public boolean canConnectEnergy(ForgeDirection from) {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/* IEnergyReceiver */
|
||||
@Override
|
||||
public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate) {
|
||||
|
||||
return storage.receiveEnergy(maxReceive, simulate);
|
||||
}
|
||||
|
||||
/* IEnergyProvider */
|
||||
@Override
|
||||
public int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate) {
|
||||
|
||||
return storage.extractEnergy(maxExtract, simulate);
|
||||
}
|
||||
|
||||
/* IEnergyReceiver and IEnergyProvider */
|
||||
@Override
|
||||
public int getEnergyStored(ForgeDirection from) {
|
||||
|
||||
|
|
9
api/cofh/api/package-info.java
Normal file
9
api/cofh/api/package-info.java
Normal file
|
@ -0,0 +1,9 @@
|
|||
/**
|
||||
* (C) 2014 Team CoFH / CoFH / Cult of the Full Hub
|
||||
* http://www.teamcofh.com
|
||||
*/
|
||||
@API(apiVersion = CoFHAPIProps.VERSION, owner = "CoFHLib", provides = "CoFHAPI")
|
||||
package cofh.api;
|
||||
|
||||
import cpw.mods.fml.common.API;
|
||||
|
|
@ -21,6 +21,7 @@ import io.netty.buffer.Unpooled;
|
|||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
@ -34,6 +35,7 @@ import net.minecraft.world.World;
|
|||
|
||||
import cpw.mods.fml.common.network.internal.FMLProxyPacket;
|
||||
|
||||
import net.minecraftforge.common.util.FakePlayer;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import buildcraft.api.core.IAreaProvider;
|
||||
|
@ -345,6 +347,20 @@ public final class Utils {
|
|||
}
|
||||
}
|
||||
|
||||
public static boolean isFakePlayer(EntityPlayer player) {
|
||||
if (player instanceof FakePlayer) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Tip donated by skyboy - addedToChunk must be set to false by a fake player
|
||||
// or it becomes a chunk-loading entity.
|
||||
if (!player.addedToChunk) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean checkPipesConnections(TileEntity tile1, TileEntity tile2) {
|
||||
if (tile1 == null || tile2 == null) {
|
||||
return false;
|
||||
|
|
|
@ -15,8 +15,8 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import cofh.api.energy.IEnergyProvider;
|
||||
import cofh.api.energy.IEnergyReceiver;
|
||||
import cofh.api.energy.IEnergyConnection;
|
||||
import cofh.api.energy.IEnergyHandler;
|
||||
import buildcraft.BuildCraftEnergy;
|
||||
import buildcraft.api.power.IEngine;
|
||||
import buildcraft.api.tiles.IHeatable;
|
||||
|
@ -27,9 +27,10 @@ import buildcraft.api.transport.IPipeTile.PipeType;
|
|||
import buildcraft.core.DefaultProps;
|
||||
import buildcraft.core.TileBuildCraft;
|
||||
import buildcraft.core.utils.MathUtils;
|
||||
import buildcraft.core.utils.Utils;
|
||||
import buildcraft.energy.gui.ContainerEngine;
|
||||
|
||||
public abstract class TileEngine extends TileBuildCraft implements IPipeConnection, IEnergyProvider, IEngine, IHeatable {
|
||||
public abstract class TileEngine extends TileBuildCraft implements IPipeConnection, IEnergyHandler, IEngine, IHeatable {
|
||||
// Index corresponds to metadata
|
||||
public static final ResourceLocation[] BASE_TEXTURES = new ResourceLocation[]{
|
||||
new ResourceLocation(DefaultProps.TEXTURE_PATH_BLOCKS + "/base_wood.png"),
|
||||
|
@ -119,7 +120,7 @@ public abstract class TileEngine extends TileBuildCraft implements IPipeConnecti
|
|||
player.getCurrentEquippedItem().getItem() instanceof IToolWrench) {
|
||||
IToolWrench wrench = (IToolWrench) player.getCurrentEquippedItem().getItem();
|
||||
if (wrench.canWrench(player, xCoord, yCoord, zCoord)) {
|
||||
if (getEnergyStage() == EnergyStage.OVERHEAT) {
|
||||
if (getEnergyStage() == EnergyStage.OVERHEAT && !Utils.isFakePlayer(player)) {
|
||||
energyStage = computeEnergyStage();
|
||||
sendNetworkUpdate();
|
||||
}
|
||||
|
@ -290,8 +291,8 @@ public abstract class TileEngine extends TileBuildCraft implements IPipeConnecti
|
|||
orientation.getOpposite(),
|
||||
this.energy, true);
|
||||
return extractEnergy(maxEnergy, false);
|
||||
} else if (tile instanceof IEnergyReceiver) {
|
||||
IEnergyReceiver handler = (IEnergyReceiver) tile;
|
||||
} else if (tile instanceof IEnergyHandler) {
|
||||
IEnergyHandler handler = (IEnergyHandler) tile;
|
||||
|
||||
int maxEnergy = handler.receiveEnergy(
|
||||
orientation.getOpposite(),
|
||||
|
@ -320,8 +321,8 @@ public abstract class TileEngine extends TileBuildCraft implements IPipeConnecti
|
|||
extracted, false);
|
||||
|
||||
extractEnergy(neededRF, true);
|
||||
} else if (tile instanceof IEnergyReceiver) {
|
||||
IEnergyReceiver handler = (IEnergyReceiver) tile;
|
||||
} else if (tile instanceof IEnergyHandler) {
|
||||
IEnergyHandler handler = (IEnergyHandler) tile;
|
||||
int neededRF = handler.receiveEnergy(
|
||||
orientation.getOpposite(),
|
||||
extracted, false);
|
||||
|
@ -510,8 +511,8 @@ public abstract class TileEngine extends TileBuildCraft implements IPipeConnecti
|
|||
return false;
|
||||
} else if (tile instanceof IEngine) {
|
||||
return ((IEngine) tile).canReceiveFromEngine(side.getOpposite());
|
||||
} else if (tile instanceof IEnergyReceiver) {
|
||||
return ((IEnergyReceiver) tile).canConnectEnergy(side.getOpposite());
|
||||
} else if (tile instanceof IEnergyHandler) {
|
||||
return ((IEnergyConnection) tile).canConnectEnergy(side.getOpposite());
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import net.minecraft.util.ResourceLocation;
|
|||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import buildcraft.api.transport.IPipeTile;
|
||||
import buildcraft.api.transport.IPipeTile.PipeType;
|
||||
import buildcraft.factory.TilePump;
|
||||
|
||||
public class TileEngineWood extends TileEngine {
|
||||
|
||||
|
@ -123,8 +124,10 @@ public class TileEngineWood extends TileEngine {
|
|||
hasSent = true;
|
||||
|
||||
TileEntity tile = getTile(orientation);
|
||||
|
||||
if (tile instanceof IPipeTile && ((IPipeTile) tile).getPipeType() != PipeType.POWER) {
|
||||
|
||||
// TODO: Make a proper API out of this
|
||||
if (tile instanceof TilePump ||
|
||||
(tile instanceof IPipeTile && ((IPipeTile) tile).getPipeType() != PipeType.POWER)) {
|
||||
super.sendPower();
|
||||
} else {
|
||||
this.energy = 0;
|
||||
|
|
|
@ -16,8 +16,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import cofh.api.energy.IEnergyConnection;
|
||||
import cofh.api.energy.IEnergyProvider;
|
||||
import cofh.api.energy.IEnergyReceiver;
|
||||
import cofh.api.energy.IEnergyHandler;
|
||||
import buildcraft.BuildCraftCore;
|
||||
import buildcraft.BuildCraftTransport;
|
||||
import buildcraft.api.core.SafeTimeTracker;
|
||||
|
@ -100,7 +99,7 @@ public class PipeTransportPower extends PipeTransport {
|
|||
// Disregard engines for this.
|
||||
return false;
|
||||
}
|
||||
if (tile instanceof IEnergyReceiver) {
|
||||
if (tile instanceof IEnergyHandler) {
|
||||
IEnergyConnection handler = (IEnergyConnection) tile;
|
||||
if (handler.canConnectEnergy(side.getOpposite())) {
|
||||
return true;
|
||||
|
@ -119,7 +118,7 @@ public class PipeTransportPower extends PipeTransport {
|
|||
return false;
|
||||
}
|
||||
// Disregard tiles which are consumers but NOT providers
|
||||
return (tile instanceof IEngine) || !(tile instanceof IEnergyReceiver && !(tile instanceof IEnergyProvider));
|
||||
return (tile instanceof IEngine) || (tile instanceof IEnergyHandler);
|
||||
} else {
|
||||
// Disregard tiles which can't connect either, I guess.
|
||||
return false;
|
||||
|
@ -218,8 +217,8 @@ public class PipeTransportPower extends PipeTransport {
|
|||
ForgeDirection.VALID_DIRECTIONS[out].getOpposite(),
|
||||
powerConsumed);
|
||||
tilePowered = true;
|
||||
} else if (tiles[out] instanceof IEnergyReceiver) {
|
||||
IEnergyReceiver handler = (IEnergyReceiver) tiles[out];
|
||||
} else if (tiles[out] instanceof IEnergyHandler) {
|
||||
IEnergyHandler handler = (IEnergyHandler) tiles[out];
|
||||
|
||||
if (handler.canConnectEnergy(ForgeDirection.VALID_DIRECTIONS[out].getOpposite())) {
|
||||
// Transmit power to an RF energy handler
|
||||
|
@ -286,8 +285,8 @@ public class PipeTransportPower extends PipeTransport {
|
|||
continue;
|
||||
}
|
||||
|
||||
if (tile instanceof IEnergyReceiver) {
|
||||
IEnergyReceiver handler = (IEnergyReceiver) tile;
|
||||
if (tile instanceof IEnergyHandler) {
|
||||
IEnergyHandler handler = (IEnergyHandler) tile;
|
||||
if (handler.canConnectEnergy(dir.getOpposite())) {
|
||||
int request = handler.receiveEnergy(dir.getOpposite(), this.maxPower, true);
|
||||
|
||||
|
|
Loading…
Reference in a new issue