Added IBlockDefaultTriggers.

Prevent DefaultTriggerProvider from adding triggers, but allow other
providers to add their own. This is a more friendly version of
IOverrideDefaultTriggers.
This commit is contained in:
SandGrainOne 2015-11-09 23:44:30 +01:00
parent 16831f6947
commit 99ee6ab927
5 changed files with 53 additions and 36 deletions

View file

@ -0,0 +1,23 @@
/**
* Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* The BuildCraft API is distributed under the terms of the MIT License.
* Please check the contents of the license, which should be located
* as "LICENSE.API" in the BuildCraft source code distribution.
*/
package buildcraft.api.statements;
import net.minecraftforge.common.util.ForgeDirection;
/**
* A tile entity implementing this interface will be able to prevent BuildCraft from
* adding default triggers.
*
* This does not block other statement providers from adding triggers or actions.
* See IOverrideDefaultStatements for a more aggressive approach.
*/
public interface IBlockDefaultTriggers {
boolean blockInventoryTriggers(ForgeDirection side);
boolean blockFluidHandlerTriggers(ForgeDirection side);
}

View file

@ -88,16 +88,16 @@ public final class StatementManager {
}
public static List<IActionExternal> getExternalActions(ForgeDirection side, TileEntity entity) {
List<IActionExternal> result = new LinkedList<IActionExternal>();
List<IActionExternal> result;
if (entity instanceof IOverrideDefaultStatements) {
result = ((IOverrideDefaultStatements) entity).overrideActions();
if (result != null) {
return result;
} else {
result = new LinkedList<IActionExternal>();
}
}
result = new LinkedList<IActionExternal>();
for (IActionProvider provider : actionProviders) {
Collection<IActionExternal> toAdd = provider.getExternalActions(side, entity);

View file

@ -19,6 +19,8 @@ import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import buildcraft.BuildCraftCore;
import buildcraft.api.statements.IBlockDefaultTriggers;
import buildcraft.api.statements.IStatementContainer;
import buildcraft.api.statements.ITriggerExternal;
import buildcraft.api.statements.ITriggerInternal;
@ -31,7 +33,15 @@ public class DefaultTriggerProvider implements ITriggerProvider {
public LinkedList<ITriggerExternal> getExternalTriggers(ForgeDirection side, TileEntity tile) {
LinkedList<ITriggerExternal> res = new LinkedList<ITriggerExternal>();
if (tile instanceof IInventory) {
boolean blockInventoryTriggers = false;
boolean blockFluidHandlerTriggers = false;
if (tile instanceof IBlockDefaultTriggers) {
blockInventoryTriggers = ((IBlockDefaultTriggers) tile).blockInventoryTriggers(side);
blockFluidHandlerTriggers = ((IBlockDefaultTriggers) tile).blockFluidHandlerTriggers(side);
}
if (!blockInventoryTriggers && tile instanceof IInventory) {
boolean isSided = tile instanceof ISidedInventory;
boolean addTriggers = false;
@ -51,7 +61,7 @@ public class DefaultTriggerProvider implements ITriggerProvider {
}
}
if (tile instanceof IFluidHandler) {
if (!blockFluidHandlerTriggers && tile instanceof IFluidHandler) {
FluidTankInfo[] tanks = ((IFluidHandler) tile).getTankInfo(side.getOpposite());
if (tanks != null && tanks.length > 0) {
res.add(BuildCraftCore.triggerEmptyFluid);

View file

@ -8,9 +8,6 @@
*/
package buildcraft.energy;
import java.util.LinkedList;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ICrafting;
@ -26,7 +23,6 @@ import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import buildcraft.BuildCraftCore;
import buildcraft.BuildCraftEnergy;
import buildcraft.api.core.StackKey;
@ -34,9 +30,7 @@ import buildcraft.api.fuels.BuildcraftFuelRegistry;
import buildcraft.api.fuels.ICoolant;
import buildcraft.api.fuels.IFuel;
import buildcraft.api.fuels.ISolidCoolant;
import buildcraft.api.statements.IActionExternal;
import buildcraft.api.statements.IOverrideDefaultStatements;
import buildcraft.api.statements.ITriggerExternal;
import buildcraft.api.statements.IBlockDefaultTriggers;
import buildcraft.api.transport.IItemPipe;
import buildcraft.core.GuiIds;
@ -46,7 +40,7 @@ import buildcraft.core.lib.fluids.TankManager;
import buildcraft.core.lib.fluids.TankUtils;
import buildcraft.core.lib.inventory.InvUtils;
public class TileEngineIron extends TileEngineWithInventory implements IFluidHandler, IOverrideDefaultStatements {
public class TileEngineIron extends TileEngineWithInventory implements IFluidHandler, IBlockDefaultTriggers {
public static int MAX_LIQUID = FluidContainerRegistry.BUCKET_VOLUME * 10;
public static float HEAT_PER_RF = 0.00023F;
@ -477,31 +471,12 @@ public class TileEngineIron extends TileEngineWithInventory implements IFluidHan
}
@Override
public List<ITriggerExternal> overrideTriggers() {
List<ITriggerExternal> triggers = new LinkedList<ITriggerExternal>();
triggers.add(BuildCraftCore.triggerEmptyInventory);
triggers.add(BuildCraftCore.triggerContainsInventory);
triggers.add(BuildCraftCore.triggerSpaceInventory);
triggers.add(BuildCraftCore.triggerFullInventory);
triggers.add(BuildCraftEnergy.triggerBlueEngineHeat);
triggers.add(BuildCraftEnergy.triggerGreenEngineHeat);
triggers.add(BuildCraftEnergy.triggerYellowEngineHeat);
triggers.add(BuildCraftEnergy.triggerRedEngineHeat);
triggers.add(BuildCraftEnergy.triggerEngineOverheat);
triggers.add(BuildCraftEnergy.triggerCoolantBelow25);
triggers.add(BuildCraftEnergy.triggerCoolantBelow50);
triggers.add(BuildCraftEnergy.triggerFuelBelow25);
triggers.add(BuildCraftEnergy.triggerFuelBelow50);
return triggers;
public boolean blockInventoryTriggers(ForgeDirection side) {
return false;
}
@Override
public List<IActionExternal> overrideActions() {
return null;
public boolean blockFluidHandlerTriggers(ForgeDirection side) {
return true;
}
}

View file

@ -21,6 +21,7 @@ import buildcraft.api.statements.ITriggerExternal;
import buildcraft.api.statements.ITriggerInternal;
import buildcraft.api.statements.ITriggerProvider;
import buildcraft.core.lib.engines.TileEngineBase;
import buildcraft.energy.TileEngineIron;
public class EnergyStatementProvider implements ITriggerProvider {
@ -41,6 +42,14 @@ public class EnergyStatementProvider implements ITriggerProvider {
triggers.add(BuildCraftEnergy.triggerEngineOverheat);
}
if (tile instanceof TileEngineIron) {
triggers.add(BuildCraftEnergy.triggerCoolantBelow25);
triggers.add(BuildCraftEnergy.triggerCoolantBelow50);
triggers.add(BuildCraftEnergy.triggerFuelBelow25);
triggers.add(BuildCraftEnergy.triggerFuelBelow50);
}
return triggers;
}