diff options
Diffstat (limited to 'src/main/java/gregtech')
-rw-r--r-- | src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Muffler.java | 130 |
1 files changed, 72 insertions, 58 deletions
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Muffler.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Muffler.java index 4c48fe09f1..e651df066b 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Muffler.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Muffler.java @@ -1,11 +1,14 @@ package gregtech.api.metatileentity.implementations; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; import gregtech.GT_Mod; import gregtech.api.enums.Textures; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_LanguageManager; import gregtech.common.GT_Pollution; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; @@ -16,34 +19,36 @@ import java.util.Arrays; import static gregtech.api.objects.XSTR.XSTR_INSTANCE; +@SuppressWarnings("unused") // Unused API is expected within scope public class GT_MetaTileEntity_Hatch_Muffler extends GT_MetaTileEntity_Hatch { + private static final String localizedDescFormat = GT_LanguageManager.addStringLocalization( + "gt.blockmachines.hatch.muffler.desc.format", + "Outputs the Pollution (Might cause ... things)%n" + + "DO NOT OBSTRUCT THE OUTPUT!%n" + + "Reduces Pollution to %d%%%n" + + "Recovers %d%% of CO2/CO/SO2"); + private final int pollutionReduction = calculatePollutionReduction(100); + private final int pollutionRecover = 100 - pollutionReduction; + private final String[] description = String.format(localizedDescFormat, pollutionReduction, pollutionRecover) + .split("\\R"); + private final boolean[] facings = new boolean[ForgeDirection.VALID_DIRECTIONS.length]; + public GT_MetaTileEntity_Hatch_Muffler(int aID, String aName, String aNameRegional, int aTier) { super(aID, aName, aNameRegional, aTier, 0, ""); } public GT_MetaTileEntity_Hatch_Muffler(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { - super(aName, aTier, 0, aDescription, aTextures); + this(aName, aTier, new String[]{aDescription}, aTextures); } public GT_MetaTileEntity_Hatch_Muffler(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) { super(aName, aTier, 0, aDescription, aTextures); - } - - private int[] mFacings; - - /*private void init()*/ { setInValidFacings(ForgeDirection.DOWN); } @Override public String[] getDescription() { - int pollutionReduction = calculatePollutionReduction(100); - return new String[]{ - "Outputs the Pollution (Might cause ... things)", - "DO NOT OBSTRUCT THE OUTPUT!", - "Reduces Pollution to " + pollutionReduction + "%", - "Recovers " + (100 - pollutionReduction) + "% of CO2/CO/SO2" - }; + return description; } @Override @@ -61,28 +66,18 @@ public class GT_MetaTileEntity_Hatch_Muffler extends GT_MetaTileEntity_Hatch { return true; } - //API Code, BartWorks/TecTech based EBF relies on this. It's marked here, not anywhere else. - public void setInValidFacings(ForgeDirection... aFacings) { - mFacings = Arrays.stream(aFacings).mapToInt(Enum::ordinal).toArray(); - } - @Override - public boolean isFacingValid(byte aFacing) { - for (int x : mFacings) { - if (x == aFacing) { - return true; - } - } + public boolean isValidSlot(int aIndex) { return false; } @Override - public boolean isAccessAllowed(EntityPlayer aPlayer) { - return true; + public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return false; } @Override - public boolean isValidSlot(int aIndex) { + public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { return false; } @@ -91,48 +86,28 @@ public class GT_MetaTileEntity_Hatch_Muffler extends GT_MetaTileEntity_Hatch { return new GT_MetaTileEntity_Hatch_Muffler(mName, mTier, mDescriptionArray, mTextures); } - //MetaTileEntity is passed so newer muffler hatches can do wacky things with the multis - public boolean polluteEnvironment(MetaTileEntity mte) { - if (getBaseMetaTileEntity().getAirAtSide(getBaseMetaTileEntity().getFrontFacing())) { - GT_Pollution.addPollution(getBaseMetaTileEntity(), calculatePollutionReduction(10000)); - return true; - } - return false; - } - - @Deprecated - public boolean polluteEnvironment() { - return polluteEnvironment(null); - } - - public int calculatePollutionReduction(int aPollution) { - if ((float) mTier < 2) { - return aPollution; - } - return (int) ((float) aPollution * ((100F - (12.5F * ((float) mTier - 1F))) / 100F)); - } - @Override - public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { - return false; + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + if (aBaseMetaTileEntity.isClientSide() && this.getBaseMetaTileEntity().isActive()) { + pollutionParticles(this.getBaseMetaTileEntity().getWorld(), "largesmoke"); + } } @Override - public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { - return false; + public boolean isFacingValid(byte aFacing) { + return facings[aFacing]; } @Override - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - super.onPostTick(aBaseMetaTileEntity, aTick); - if (aBaseMetaTileEntity.isClientSide() && this.getBaseMetaTileEntity().isActive()) { - pollutionParticles(this.getBaseMetaTileEntity().getWorld(), "largesmoke"); - } + public boolean isAccessAllowed(EntityPlayer aPlayer) { + return true; } + @SideOnly(Side.CLIENT) public void pollutionParticles(World aWorld, String name) { boolean chk1, chk2, chk3; - float ran1 = XSTR_INSTANCE.nextFloat(), ran2 = 0, ran3 = 0; + float ran1 = XSTR_INSTANCE.nextFloat(), ran2, ran3; chk1 = ran1 * 100 < calculatePollutionReduction(100); if (GT_Pollution.getPollution(getBaseMetaTileEntity()) >= GT_Mod.gregtechproxy.mPollutionSmogLimit) { ran2 = XSTR_INSTANCE.nextFloat(); @@ -142,6 +117,7 @@ public class GT_MetaTileEntity_Hatch_Muffler extends GT_MetaTileEntity_Hatch { if (!(chk1 || chk2 || chk3)) return; } else { if (!chk1) return; + ran2 = ran3 = 0.0F; chk2 = chk3 = false; } @@ -173,4 +149,42 @@ public class GT_MetaTileEntity_Hatch_Muffler extends GT_MetaTileEntity_Hatch { if (chk3) aWorld.spawnParticle(name, xPos + ran3 * 0.5F, yPos + XSTR_INSTANCE.nextFloat() * 0.5F, zPos + XSTR_INSTANCE.nextFloat() * 0.5F, xSpd, ySpd, zSpd); } + + public int calculatePollutionReduction(int aPollution) { + if (mTier < 2) { + return aPollution; + } + return (int) ((float) aPollution * ((100F - 12.5F * ((float) mTier - 1F)) / 100F)); + } + + /** + * @return pollution success + * @deprecated replaced by {@link .polluteEnvironment(MetaTileEntity)} + */ + @Deprecated + public boolean polluteEnvironment() { + return polluteEnvironment(null); + } + + /** + * @param mte The multi-block controller's {@link MetaTileEntity} + * MetaTileEntity is passed so newer muffler hatches can do wacky things with the multis + * @return pollution success + */ + public boolean polluteEnvironment(MetaTileEntity mte) { + if (getBaseMetaTileEntity().getAirAtSide(getBaseMetaTileEntity().getFrontFacing())) { + GT_Pollution.addPollution(getBaseMetaTileEntity(), calculatePollutionReduction(10000)); + return true; + } + return false; + } + + /** + * @param aFacings the {@link ForgeDirection} invalid facings + * @apiNote API Code, BartWorks/TecTech based EBF relies on this. It's marked here, not anywhere else. + */ + public void setInValidFacings(ForgeDirection... aFacings) { + Arrays.fill(facings, true); + Arrays.stream(aFacings).forEach(face -> facings[face.ordinal()] = false); + } } |