New modes for Fluid Filter

This commit is contained in:
DEMOOH 2017-02-12 12:23:42 +02:00 committed by GitHub
parent 64ddbfef6e
commit 244d54edfd

View file

@ -18,13 +18,31 @@ import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo; import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidContainerItem; import net.minecraftforge.fluids.IFluidContainerItem;
import net.minecraftforge.fluids.IFluidHandler; import net.minecraftforge.fluids.IFluidHandler;
import java.util.logging.Logger;
import gregtech.api.util.GT_Log;
public class GT_Cover_Fluidfilter public class GT_Cover_Fluidfilter
extends GT_CoverBehavior { extends GT_CoverBehavior {
public int doCoverThings(byte aSide, byte aInputRedstone, int aCoverID, int aCoverVariable, ICoverable aTileEntity, long aTimer) { public int doCoverThings(byte aSide, byte aInputRedstone, int aCoverID, int aCoverVariable, ICoverable aTileEntity, long aTimer) {
return aCoverVariable; return aCoverVariable;
} }
public int onCoverScrewdriverclick(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) {
int aFilterMode = aCoverVariable & 7;
aCoverVariable ^=aFilterMode;
aFilterMode = (aFilterMode + (aPlayer.isSneaking()? -1 : 1)) % 4;
if(aFilterMode < 0){aFilterMode = 3;}
switch(aFilterMode) {
case 0: GT_Utility.sendChatToPlayer(aPlayer, "Allow input, no output"); break;
case 1: GT_Utility.sendChatToPlayer(aPlayer, "Deny input, no output"); break;
case 2: GT_Utility.sendChatToPlayer(aPlayer, "Allow input, permit any output"); break;
case 3: GT_Utility.sendChatToPlayer(aPlayer, "Deny input, permit any output"); break;
}
aCoverVariable|=aFilterMode;
return aCoverVariable;
}
public boolean onCoverRightclick(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { public boolean onCoverRightclick(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) {
//System.out.println("rightclick"); //System.out.println("rightclick");
if (((aX > 0.375D) && (aX < 0.625D)) || ((aSide > 3) && (((aY > 0.375D) && (aY < 0.625D)) || ((aSide < 2) && (((aZ > 0.375D) && (aZ < 0.625D)) || (aSide == 2) || (aSide == 3)))))) { if (((aX > 0.375D) && (aX < 0.625D)) || ((aSide > 3) && (((aY > 0.375D) && (aY < 0.625D)) || ((aSide < 2) && (((aZ > 0.375D) && (aZ < 0.625D)) || (aSide == 2) || (aSide == 3)))))) {
@ -33,17 +51,18 @@ public class GT_Cover_Fluidfilter
FluidStack tFluid = FluidContainerRegistry.getFluidForFilledItem(tStack); FluidStack tFluid = FluidContainerRegistry.getFluidForFilledItem(tStack);
if(tFluid!=null){ if(tFluid!=null){
//System.out.println(tFluid.getLocalizedName()+" "+tFluid.getFluidID()); //System.out.println(tFluid.getLocalizedName()+" "+tFluid.getFluidID());
aCoverVariable = tFluid.getFluidID(); int aFluid = tFluid.getFluidID();
aCoverVariable = (aCoverVariable & 7) | (aFluid << 3);
aTileEntity.setCoverDataAtSide(aSide, aCoverVariable); aTileEntity.setCoverDataAtSide(aSide, aCoverVariable);
FluidStack sFluid = new FluidStack(FluidRegistry.getFluid(aCoverVariable),1000); FluidStack sFluid = new FluidStack(FluidRegistry.getFluid(aFluid),1000);
GT_Utility.sendChatToPlayer(aPlayer, "Filter Fluid: " + sFluid.getLocalizedName()); GT_Utility.sendChatToPlayer(aPlayer, "Filter Fluid: " + sFluid.getLocalizedName());
}else if(tStack.getItem() instanceof IFluidContainerItem){ }else if(tStack.getItem() instanceof IFluidContainerItem){
IFluidContainerItem tContainer = (IFluidContainerItem)tStack.getItem(); IFluidContainerItem tContainer = (IFluidContainerItem)tStack.getItem();
if(tContainer.getFluid(tStack) != null) { if(tContainer.getFluid(tStack) != null) {
aCoverVariable = tContainer.getFluid(tStack).getFluidID(); int aFluid = tContainer.getFluid(tStack).getFluidID();
aCoverVariable = (aCoverVariable & 7) | (aFluid << 3);
aTileEntity.setCoverDataAtSide(aSide, aCoverVariable); aTileEntity.setCoverDataAtSide(aSide, aCoverVariable);
//System.out.println("fluidcontainer " + aCoverVariable); FluidStack sFluid = new FluidStack(FluidRegistry.getFluid(aFluid),1000);
FluidStack sFluid = new FluidStack(FluidRegistry.getFluid(aCoverVariable), 1000);
GT_Utility.sendChatToPlayer(aPlayer, "Filter Fluid: " + sFluid.getLocalizedName()); GT_Utility.sendChatToPlayer(aPlayer, "Filter Fluid: " + sFluid.getLocalizedName());
} }
} }
@ -56,13 +75,15 @@ public class GT_Cover_Fluidfilter
@Override @Override
public boolean letsFluidIn(byte aSide, int aCoverID, int aCoverVariable, Fluid aFluid, ICoverable aTileEntity) { public boolean letsFluidIn(byte aSide, int aCoverID, int aCoverVariable, Fluid aFluid, ICoverable aTileEntity) {
if(aFluid==null){return true;} if(aFluid==null){return true;}
return aFluid.getID() == aCoverVariable; int aFilterMode = aCoverVariable & 7;
int aFilterFluid = aCoverVariable >>> 3;
return aFluid.getID() == aFilterFluid ? (aFilterMode == 0 || aFilterMode == 2 ? true : false) : (aFilterMode == 1 || aFilterMode == 3 ? true : false);
} }
@Override @Override
public boolean letsFluidOut(byte aSide, int aCoverID, int aCoverVariable, Fluid aFluid, ICoverable aTileEntity) { public boolean letsFluidOut(byte aSide, int aCoverID, int aCoverVariable, Fluid aFluid, ICoverable aTileEntity) {
if(aFluid==null) return false; int aFilterMode = aCoverVariable & 7;
return aFluid.getID() == aCoverVariable; return aFilterMode == 0 || aFilterMode == 1 ? false : true;
} }
public boolean alwaysLookConnected(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { public boolean alwaysLookConnected(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) {