Use Generics to reduce annoying casts in Pipe

This commit is contained in:
CovertJaguar 2013-07-24 01:17:55 -07:00
parent 1f80338819
commit 28c3b15c58
19 changed files with 46 additions and 50 deletions

View file

@ -34,11 +34,11 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
public abstract class Pipe implements IPipe, IDropControlInventory {
public abstract class Pipe<T extends PipeTransport> implements IPipe, IDropControlInventory {
public int[] signalStrength = new int[]{0, 0, 0, 0};
public TileGenericPipe container;
public final PipeTransport transport;
public final T transport;
public final int itemID;
private boolean internalUpdateScheduled = false;
public boolean[] wireSet = new boolean[]{false, false, false, false};
@ -47,7 +47,7 @@ public abstract class Pipe implements IPipe, IDropControlInventory {
private static Map<Class, TilePacketWrapper> networkWrappers = new HashMap<Class, TilePacketWrapper>();
public SafeTimeTracker actionTracker = new SafeTimeTracker();
public Pipe(PipeTransport transport, int itemID) {
public Pipe(T transport, int itemID) {
this.transport = transport;
this.itemID = itemID;

View file

@ -8,7 +8,6 @@
package buildcraft.transport.pipes;
import buildcraft.transport.PipeIconProvider;
import buildcraft.transport.PipeTransportFluids;
/**
*
@ -22,7 +21,7 @@ public class PipeFluidsEmerald extends PipeFluidsWood {
standardIconIndex = PipeIconProvider.TYPE.PipeFluidsEmerald_Standard.ordinal();
solidIconIndex = PipeIconProvider.TYPE.PipeAllEmerald_Solid.ordinal();
((PipeTransportFluids) transport).flowRate = 40;
((PipeTransportFluids) transport).travelDelay = 4;
transport.flowRate = 40;
transport.travelDelay = 4;
}
}

View file

@ -16,13 +16,13 @@ import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraftforge.common.ForgeDirection;
public class PipeFluidsGold extends Pipe {
public class PipeFluidsGold extends Pipe<PipeTransportFluids> {
public PipeFluidsGold(int itemID) {
super(new PipeTransportFluids(), itemID);
((PipeTransportFluids) transport).flowRate = 40;
((PipeTransportFluids) transport).travelDelay = 4;
transport.flowRate = 40;
transport.travelDelay = 4;
}
@Override

View file

@ -19,7 +19,7 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.IFluidHandler;
public class PipeFluidsIron extends Pipe {
public class PipeFluidsIron extends Pipe<PipeTransportFluids> {
protected int standardIconIndex = PipeIconProvider.TYPE.PipeFluidsIron_Standard.ordinal();
protected int solidIconIndex = PipeIconProvider.TYPE.PipeAllIron_Solid.ordinal();

View file

@ -20,7 +20,7 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.FluidStack;
public class PipeFluidsSandstone extends Pipe implements IPipeTransportFluidsHook {
public class PipeFluidsSandstone extends Pipe<PipeTransportFluids> implements IPipeTransportFluidsHook {
public PipeFluidsSandstone(int itemID) {
super(new PipeTransportFluids(), itemID);
@ -42,7 +42,7 @@ public class PipeFluidsSandstone extends Pipe implements IPipeTransportFluidsHoo
if (!(container.getTile(from) instanceof TileGenericPipe))
return 0;
return ((PipeTransportFluids) transport).internalTanks[from.ordinal()].fill(resource, doFill);
return transport.internalTanks[from.ordinal()].fill(resource, doFill);
}
@Override

View file

@ -9,7 +9,6 @@ package buildcraft.transport.pipes;
import buildcraft.BuildCraftTransport;
import buildcraft.api.core.IIconProvider;
import buildcraft.api.core.Position;
import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerHandler;
import buildcraft.api.power.PowerHandler.PowerReceiver;
@ -29,7 +28,7 @@ import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidHandler;
public class PipeFluidsWood extends Pipe implements IPowerReceptor {
public class PipeFluidsWood extends Pipe<PipeTransportFluids> implements IPowerReceptor {
public @TileNetworkData
int liquidToExtract;
@ -121,13 +120,13 @@ public class PipeFluidsWood extends Pipe implements IPowerReceptor {
if (tile instanceof IFluidHandler) {
IFluidHandler fluidHandler = (IFluidHandler) tile;
int flowRate = ((PipeTransportFluids) transport).flowRate;
int flowRate = transport.flowRate;
FluidStack extracted = fluidHandler.drain(side.getOpposite(), liquidToExtract > flowRate ? flowRate : liquidToExtract, false);
int inserted = 0;
if (extracted != null) {
inserted = ((PipeTransportFluids) transport).fill(side, extracted, true);
inserted = transport.fill(side, extracted, true);
fluidHandler.drain(side.getOpposite(), inserted, true);
}

View file

@ -35,7 +35,7 @@ import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.ForgeDirection;
public class PipeItemsDiamond extends Pipe implements IPipeTransportItemsHook, IClientState {
public class PipeItemsDiamond extends Pipe<PipeTransportItems> implements IPipeTransportItemsHook, IClientState {
private SimpleInventory filters = new SimpleInventory(54, "Filters", 1);
@ -130,7 +130,7 @@ public class PipeItemsDiamond extends Pipe implements IPipeTransportItemsHook, I
@Override
public void readjustSpeed(IPipedItem item) {
((PipeTransportItems) transport).defaultReajustSpeed(item);
transport.defaultReajustSpeed(item);
}
/* SAVING & LOADING */

View file

@ -21,7 +21,7 @@ import net.minecraft.inventory.IInventory;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
public class PipeItemsIron extends Pipe {
public class PipeItemsIron extends Pipe<PipeTransportItems> {
private int standardIconIndex = PipeIconProvider.TYPE.PipeItemsIron_Standard.ordinal();
private int solidIconIndex = PipeIconProvider.TYPE.PipeAllIron_Solid.ordinal();
@ -46,7 +46,7 @@ public class PipeItemsIron extends Pipe {
public PipeItemsIron(int itemID) {
super(new PipeTransportItems(), itemID);
((PipeTransportItems) transport).allowBouncing = true;
transport.allowBouncing = true;
}
@Override

View file

@ -33,11 +33,11 @@ import net.minecraft.item.Item;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
public class PipeItemsLapis extends Pipe implements IItemTravelingHook, IPipeTransportItemsHook {
public class PipeItemsLapis extends Pipe<PipeTransportItems> implements IItemTravelingHook, IPipeTransportItemsHook {
public PipeItemsLapis(int itemID) {
super(new PipeTransportItems(), itemID);
((PipeTransportItems) transport).travelHook = this;
transport.travelHook = this;
}
@Override

View file

@ -34,7 +34,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.common.ForgeDirection;
public class PipeItemsObsidian extends Pipe implements IPowerReceptor {
public class PipeItemsObsidian extends Pipe<PipeTransportItems> implements IPowerReceptor {
private PowerHandler powerHandler;
private int[] entitiesDropped;
@ -250,7 +250,7 @@ public class PipeItemsObsidian extends Pipe implements IPowerReceptor {
passive.setSpeed((float) speed);
((PipeTransportItems) transport).entityEntering(passive, orientation);
transport.entityEntering(passive, orientation);
}
}

View file

@ -19,11 +19,11 @@ import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
public class PipeItemsVoid extends Pipe implements IItemTravelingHook {
public class PipeItemsVoid extends Pipe<PipeTransportItems> implements IItemTravelingHook {
public PipeItemsVoid(int itemID) {
super(new PipeTransportItems(), itemID);
((PipeTransportItems) transport).travelHook = this;
transport.travelHook = this;
}
@Override
@ -46,7 +46,7 @@ public class PipeItemsVoid extends Pipe implements IItemTravelingHook {
// This is called when the void pipe is connected to multiple pipes
@Override
public void centerReached(PipeTransportItems pipe, EntityData data) {
((PipeTransportItems) transport).scheduleRemoval(data.item);
transport.scheduleRemoval(data.item);
}
@Override

View file

@ -32,7 +32,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
public class PipeItemsWood extends Pipe implements IPowerReceptor {
public class PipeItemsWood extends Pipe<PipeTransportItems> implements IPowerReceptor {
protected PowerHandler powerHandler;
protected int standardIconIndex = PipeIconProvider.TYPE.PipeItemsWood_Standard.ordinal();
@ -139,7 +139,7 @@ public class PipeItemsWood extends Pipe implements IPowerReceptor {
IPipedItem entity = new EntityPassiveItem(container.worldObj, entityPos.x, entityPos.y, entityPos.z, stack);
((PipeTransportItems) transport).entityEntering(entity, entityPos.orientation);
transport.entityEntering(entity, entityPos.orientation);
}
}
}

View file

@ -16,11 +16,11 @@ import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraftforge.common.ForgeDirection;
public class PipePowerCobblestone extends Pipe {
public class PipePowerCobblestone extends Pipe<PipeTransportPower> {
public PipePowerCobblestone(int itemID) {
super(new PipeTransportPower(), itemID);
((PipeTransportPower) transport).initFromPipe(getClass());
transport.initFromPipe(getClass());
}
@Override

View file

@ -16,11 +16,11 @@ import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraftforge.common.ForgeDirection;
public class PipePowerDiamond extends Pipe {
public class PipePowerDiamond extends Pipe<PipeTransportPower> {
public PipePowerDiamond(int itemID) {
super(new PipeTransportPower(), itemID);
((PipeTransportPower) transport).initFromPipe(getClass());
transport.initFromPipe(getClass());
}
@Override

View file

@ -16,11 +16,11 @@ import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraftforge.common.ForgeDirection;
public class PipePowerGold extends Pipe {
public class PipePowerGold extends Pipe<PipeTransportPower> {
public PipePowerGold(int itemID) {
super(new PipeTransportPower(), itemID);
((PipeTransportPower) transport).initFromPipe(getClass());
transport.initFromPipe(getClass());
}
@Override

View file

@ -16,11 +16,11 @@ import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraftforge.common.ForgeDirection;
public class PipePowerQuartz extends Pipe {
public class PipePowerQuartz extends Pipe<PipeTransportPower> {
public PipePowerQuartz(int itemID) {
super(new PipeTransportPower(), itemID);
((PipeTransportPower) transport).initFromPipe(getClass());
transport.initFromPipe(getClass());
}
@Override

View file

@ -16,11 +16,11 @@ import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraftforge.common.ForgeDirection;
public class PipePowerStone extends Pipe {
public class PipePowerStone extends Pipe<PipeTransportPower> {
public PipePowerStone(int itemID) {
super(new PipeTransportPower(), itemID);
((PipeTransportPower) transport).initFromPipe(getClass());
transport.initFromPipe(getClass());
}
@Override

View file

@ -21,7 +21,7 @@ import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.ForgeDirection;
public class PipePowerWood extends Pipe implements IPowerReceptor {
public class PipePowerWood extends Pipe<PipeTransportPower> implements IPowerReceptor {
private PowerHandler powerHandler;
protected int standardIconIndex = PipeIconProvider.TYPE.PipePowerWood_Standard.ordinal();
@ -34,7 +34,7 @@ public class PipePowerWood extends Pipe implements IPowerReceptor {
powerHandler = new PowerHandler(this, Type.PIPE);
initPowerProvider();
((PipeTransportPower) transport).initFromPipe(getClass());
transport.initFromPipe(getClass());
}
private void initPowerProvider() {
@ -101,15 +101,13 @@ public class PipePowerWood extends Pipe implements IPowerReceptor {
}
energyToRemove /= (float) sources;
PipeTransportPower trans = (PipeTransportPower) transport;
for (ForgeDirection o : ForgeDirection.VALID_DIRECTIONS) {
if (!powerSources[o.ordinal()])
continue;
float energyUsable = powerHandler.useEnergy(0, energyToRemove, false);
float energySend = trans.receiveEnergy(o, energyUsable);
float energySend = transport.receiveEnergy(o, energyUsable);
if (energySend > 0) {
powerHandler.useEnergy(0, energySend, true);
}

View file

@ -262,8 +262,8 @@ public class RenderPipe extends TileEntitySpecialRenderer {
}
private void renderPower(Pipe pipe, double x, double y, double z) {
PipeTransportPower pow = (PipeTransportPower) pipe.transport;
private void renderPower(Pipe<PipeTransportPower> pipe, double x, double y, double z) {
PipeTransportPower pow = pipe.transport;
GL11.glPushMatrix();
GL11.glDisable(2896 /* GL_LIGHTING */);
@ -299,8 +299,8 @@ public class RenderPipe extends TileEntitySpecialRenderer {
GL11.glPopMatrix();
}
private void renderFluids(Pipe pipe, double x, double y, double z) {
PipeTransportFluids liq = (PipeTransportFluids) pipe.transport;
private void renderFluids(Pipe<PipeTransportFluids> pipe, double x, double y, double z) {
PipeTransportFluids liq = pipe.transport;
GL11.glPushMatrix();
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
@ -403,14 +403,14 @@ public class RenderPipe extends TileEntitySpecialRenderer {
return getDisplayFluidLists(liquidId, world);
}
private void renderSolids(Pipe pipe, double x, double y, double z) {
private void renderSolids(Pipe<PipeTransportItems> pipe, double x, double y, double z) {
GL11.glPushMatrix();
GL11.glDisable(2896 /* GL_LIGHTING */);
float light = pipe.container.worldObj.getLightBrightness(pipe.container.xCoord, pipe.container.yCoord, pipe.container.zCoord);
int count = 0;
for (EntityData itemData : ((PipeTransportItems) pipe.transport).travelingEntities.values()) {
for (EntityData itemData : pipe.transport.travelingEntities.values()) {
if (count >= MAX_ITEMS_TO_RENDER) {
break;
}