Pollution basework

This commit is contained in:
Blood-Asp 2016-07-03 18:31:06 +02:00
parent d21357bd84
commit 57deb3b3e1
16 changed files with 108 additions and 2 deletions

View file

@ -5,10 +5,12 @@ import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.util.GT_Recipe;
import gregtech.api.util.GT_Recipe.GT_Recipe_Map;
import gregtech.common.GT_Pollution;
import gregtech.api.util.GT_Utility;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.world.ChunkPosition;
import net.minecraftforge.fluids.FluidStack;
import java.util.Collection;
@ -177,6 +179,7 @@ public abstract class GT_MetaTileEntity_BasicGenerator extends GT_MetaTileEntity
@Override
public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
if (aBaseMetaTileEntity.isServerSide() && aBaseMetaTileEntity.isAllowedToWork() && aTick % 10 == 0) {
long tProducedEU = 0;
if (mFluid == null) {
if (aBaseMetaTileEntity.getUniversalEnergyStored() < maxEUOutput() + getMinimumStoredEU()) {
mInventory[getStackDisplaySlot()] = null;
@ -190,6 +193,7 @@ public abstract class GT_MetaTileEntity_BasicGenerator extends GT_MetaTileEntity
if (tFuelValue > 0 && tConsumed > 0 && mFluid.amount > tConsumed) {
long tFluidAmountToUse = Math.min(mFluid.amount / tConsumed, (maxEUOutput() * 20 + getMinimumStoredEU() - aBaseMetaTileEntity.getUniversalEnergyStored()) / tFuelValue);
if (tFluidAmountToUse > 0 && aBaseMetaTileEntity.increaseStoredEnergyUnits(tFluidAmountToUse * tFuelValue, true))
tProducedEU = tFluidAmountToUse * tFuelValue;
mFluid.amount -= tFluidAmountToUse * tConsumed;
}
}
@ -200,15 +204,22 @@ public abstract class GT_MetaTileEntity_BasicGenerator extends GT_MetaTileEntity
if (aBaseMetaTileEntity.addStackToSlot(getOutputSlot(), tEmptyContainer)) {
aBaseMetaTileEntity.increaseStoredEnergyUnits(tFuelValue, true);
aBaseMetaTileEntity.decrStackSize(getInputSlot(), 1);
tProducedEU = tFuelValue;
}
}
}
if(tProducedEU>0&&getPollution()>0){
GT_Pollution.addPollution(new ChunkPosition(this.getBaseMetaTileEntity().getXCoord(), this.getBaseMetaTileEntity().getYCoord(), this.getBaseMetaTileEntity().getZCoord()),
(int) ((tProducedEU * getPollution()/500)+1));
}
}
if (aBaseMetaTileEntity.isServerSide())
aBaseMetaTileEntity.setActive(aBaseMetaTileEntity.isAllowedToWork() && aBaseMetaTileEntity.getUniversalEnergyStored() >= maxEUOutput() + getMinimumStoredEU());
}
public abstract int getPollution();
public abstract GT_Recipe_Map getRecipes();
public abstract int getEfficiency();

View file

@ -5,8 +5,10 @@ import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.objects.GT_RenderedTexture;
import gregtech.common.GT_Pollution;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.ChunkPosition;
public class GT_MetaTileEntity_Hatch_Muffler extends GT_MetaTileEntity_Hatch {
public GT_MetaTileEntity_Hatch_Muffler(int aID, String aName, String aNameRegional, int aTier) {
@ -58,6 +60,7 @@ public class GT_MetaTileEntity_Hatch_Muffler extends GT_MetaTileEntity_Hatch {
}
public boolean polluteEnvironment() {
GT_Pollution.addPollution(new ChunkPosition(this.getBaseMetaTileEntity().getXCoord(), this.getBaseMetaTileEntity().getYCoord(), this.getBaseMetaTileEntity().getZCoord()), 1000 - (95*mTier));
return (mTier > 1 && getBaseMetaTileEntity().getRandomNumber(mTier) != 0) || getBaseMetaTileEntity().getAirAtSide(getBaseMetaTileEntity().getFrontFacing());
}

View file

@ -1532,15 +1532,17 @@ public class GT_Utility {
}
int tAmount = (int) (Math.pow(amount, 5) / 100);
ChunkPosition tPos = new ChunkPosition(aX/16, 1, aZ/16);
int[] tInts = new int[2];
if(GT_Proxy.chunkData.containsKey(tPos)){
int[] tInts = GT_Proxy.chunkData.get(tPos);
tInts = GT_Proxy.chunkData.get(tPos);
if(tInts.length>0){
if(tInts[0]>=0){tAmount = tInts[0];}
}
GT_Proxy.chunkData.remove(tPos);
}
tAmount = tAmount - 5;
GT_Proxy.chunkData.put(tPos, new int[]{tAmount});
tInts[0] = tAmount;
GT_Proxy.chunkData.put(tPos, tInts);
return new FluidStack(tFluid, tAmount);
}

View file

@ -0,0 +1,28 @@
package gregtech.common;
import net.minecraft.world.ChunkPosition;
public class GT_Pollution {
// List<ChunkPosition> list = new ArrayList<ChunkPosition>(chunkData.keySet());
public static void onWorldTick(int aTick){
}
public static void addPollution(ChunkPosition aPos, int aPollution){
int[] tData = new int[2];
if(GT_Proxy.chunkData.containsKey(aPos)){
tData = GT_Proxy.chunkData.get(aPos);
if(tData.length>1){
tData[1] += aPollution;
}
GT_Proxy.chunkData.replace(aPos, tData);
}else{
tData[1] += aPollution;
GT_Proxy.chunkData.put(aPos, tData);
}
}
}

View file

@ -10,9 +10,11 @@ import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.objects.GT_RenderedTexture;
import gregtech.api.util.GT_ModHandler;
import gregtech.api.util.GT_OreDictUnificator;
import gregtech.common.GT_Pollution;
import gregtech.common.gui.GT_Container_Boiler;
import gregtech.common.gui.GT_GUIContainer_Boiler;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.world.ChunkPosition;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidHandler;
@ -138,6 +140,9 @@ public class GT_MetaTileEntity_Boiler_Bronze
this.mProcessingEnergy -= 1;
this.mTemperature += 1;
}
if(this.mProcessingEnergy>0 && (aTick % 20L == 0L)){
GT_Pollution.addPollution(new ChunkPosition(this.getBaseMetaTileEntity().getXCoord(), this.getBaseMetaTileEntity().getYCoord(), this.getBaseMetaTileEntity().getZCoord()), 30);
}
aBaseMetaTileEntity.setActive(this.mProcessingEnergy > 0);
}
}

View file

@ -10,9 +10,11 @@ import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.objects.GT_RenderedTexture;
import gregtech.api.util.GT_ModHandler;
import gregtech.api.util.GT_OreDictUnificator;
import gregtech.common.GT_Pollution;
import gregtech.common.gui.GT_Container_Boiler;
import gregtech.common.gui.GT_GUIContainer_Boiler;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.world.ChunkPosition;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidHandler;
@ -116,6 +118,10 @@ public class GT_MetaTileEntity_Boiler_Lava
this.mProcessingEnergy -= 3;
this.mTemperature += 1;
}
if(this.mProcessingEnergy>0 && (aTick % 20L == 0L)){
GT_Pollution.addPollution(new ChunkPosition(this.getBaseMetaTileEntity().getXCoord(), this.getBaseMetaTileEntity().getYCoord(), this.getBaseMetaTileEntity().getZCoord()), 30);
}
aBaseMetaTileEntity.setActive(this.mProcessingEnergy > 0);
}
}

View file

@ -10,9 +10,11 @@ import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.objects.GT_RenderedTexture;
import gregtech.api.util.GT_ModHandler;
import gregtech.api.util.GT_OreDictUnificator;
import gregtech.common.GT_Pollution;
import gregtech.common.gui.GT_Container_Boiler;
import gregtech.common.gui.GT_GUIContainer_Boiler;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.world.ChunkPosition;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidHandler;
@ -143,6 +145,9 @@ public class GT_MetaTileEntity_Boiler_Steel
this.mProcessingEnergy -= 2;
this.mTemperature += 1;
}
if(this.mProcessingEnergy>0 && (aTick % 20L == 0L)){
GT_Pollution.addPollution(new ChunkPosition(this.getBaseMetaTileEntity().getXCoord(), this.getBaseMetaTileEntity().getYCoord(), this.getBaseMetaTileEntity().getZCoord()), 30);
}
aBaseMetaTileEntity.setActive(this.mProcessingEnergy > 0);
}
}

View file

@ -100,4 +100,9 @@ public class GT_MetaTileEntity_DieselGenerator
public ITexture[] getSidesActive(byte aColor) {
return new ITexture[]{super.getSidesActive(aColor)[0], new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_SIDE_ACTIVE)};
}
@Override
public int getPollution() {
return 10;
}
}

View file

@ -87,4 +87,9 @@ public class GT_MetaTileEntity_FluidNaquadahReactor
public ITexture[] getSidesActive(byte aColor) {
return new ITexture[]{super.getSidesActive(aColor)[0], new GT_RenderedTexture(Textures.BlockIcons.NAQUADAH_REACTOR_FLUID_SIDE_ACTIVE)};
}
@Override
public int getPollution() {
return 0;
}
}

View file

@ -89,4 +89,9 @@ public class GT_MetaTileEntity_GasTurbine
public ITexture[] getSidesActive(byte aColor) {
return new ITexture[]{super.getSidesActive(aColor)[0], new GT_RenderedTexture(Textures.BlockIcons.GAS_TURBINE_SIDE_ACTIVE)};
}
@Override
public int getPollution() {
return 5;
}
}

View file

@ -89,4 +89,9 @@ public class GT_MetaTileEntity_MagicEnergyConverter
public ITexture[] getSidesActive(byte aColor) {
return new ITexture[]{super.getSidesActive(aColor)[0], new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_MAGIC_ACTIVE)};
}
@Override
public int getPollution() {
return 0;
}
}

View file

@ -283,4 +283,9 @@ public class GT_MetaTileEntity_MagicalEnergyAbsorber extends GT_MetaTileEntity_B
public ITexture[] getSidesActive(byte aColor) {
return new ITexture[]{super.getSidesActive(aColor)[0], new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_MAGIC_ACTIVE)};
}
@Override
public int getPollution() {
return 0;
}
}

View file

@ -89,4 +89,9 @@ public class GT_MetaTileEntity_PlasmaGenerator
public ITexture[] getSidesActive(byte aColor) {
return new ITexture[]{super.getSidesActive(aColor)[0], new GT_RenderedTexture(Textures.BlockIcons.MACHINE_CASING_FUSION_GLASS_YELLOW)};
}
@Override
public int getPollution() {
return 0;
}
}

View file

@ -87,4 +87,9 @@ public class GT_MetaTileEntity_SolidNaquadahReactor
public ITexture[] getSidesActive(byte aColor) {
return new ITexture[]{super.getSidesActive(aColor)[0], new GT_RenderedTexture(Textures.BlockIcons.NAQUADAH_REACTOR_SOLID_SIDE_ACTIVE)};
}
@Override
public int getPollution() {
return 0;
}
}

View file

@ -104,4 +104,9 @@ public class GT_MetaTileEntity_SteamTurbine extends GT_MetaTileEntity_BasicGener
public ITexture[] getSidesActive(byte aColor) {
return new ITexture[]{super.getSidesActive(aColor)[0], new GT_RenderedTexture(Textures.BlockIcons.STEAM_TURBINE_SIDE_ACTIVE)};
}
@Override
public int getPollution() {
return 0;
}
}

View file

@ -12,6 +12,7 @@ import gregtech.api.objects.GT_ItemStack;
import gregtech.api.objects.GT_RenderedTexture;
import gregtech.api.util.GT_OreDictUnificator;
import gregtech.api.util.GT_Utility;
import gregtech.common.GT_Pollution;
import gregtech.common.gui.GT_Container_BronzeBlastFurnace;
import gregtech.common.gui.GT_GUIContainer_BronzeBlastFurnace;
import net.minecraft.entity.player.EntityPlayer;
@ -20,6 +21,7 @@ import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.ChunkPosition;
import net.minecraftforge.common.util.ForgeDirection;
public class GT_MetaTileEntity_BronzeBlastFurnace
@ -208,6 +210,10 @@ public class GT_MetaTileEntity_BronzeBlastFurnace
checkRecipe();
}
}
if(this.mMaxProgresstime>0 && (aTimer % 20L == 0L)){
GT_Pollution.addPollution(new ChunkPosition(this.getBaseMetaTileEntity().getXCoord(), this.getBaseMetaTileEntity().getYCoord(), this.getBaseMetaTileEntity().getZCoord()), 200);
}
aBaseMetaTileEntity.setActive((this.mMaxProgresstime > 0) && (this.mMachine));
if (aBaseMetaTileEntity.isActive()) {
if (aBaseMetaTileEntity.getAir(aBaseMetaTileEntity.getOffsetX(aBaseMetaTileEntity.getBackFacing(), 1), aBaseMetaTileEntity.getYCoord(), aBaseMetaTileEntity.getOffsetZ(aBaseMetaTileEntity.getBackFacing(), 1))) {