diff options
Diffstat (limited to 'src/main/java/GoodGenerator/Blocks/TEs')
4 files changed, 290 insertions, 38 deletions
diff --git a/src/main/java/GoodGenerator/Blocks/TEs/MetaTE/NeutronAccelerator.java b/src/main/java/GoodGenerator/Blocks/TEs/MetaTE/NeutronAccelerator.java index b6f087eba7..d8853e4f02 100644 --- a/src/main/java/GoodGenerator/Blocks/TEs/MetaTE/NeutronAccelerator.java +++ b/src/main/java/GoodGenerator/Blocks/TEs/MetaTE/NeutronAccelerator.java @@ -21,7 +21,7 @@ public class NeutronAccelerator extends GT_MetaTileEntity_Hatch_Energy { } public int getMaxEUConsume() { - return (int)(V[mTier] * 10 / 8); + return (int)(V[mTier] * 8 / 10); } @Override @@ -47,7 +47,7 @@ public class NeutronAccelerator extends GT_MetaTileEntity_Hatch_Energy { "Input EU to Accelerate the Neutron!", "Max EU input: " + this.maxEUInput(), "Max EU consumption: " + this.getMaxEUConsume(), - "Every EU can be transformed into 0.1~0.2 KeV Neutron Kinetic Energy." + "Every EU can be transformed into 10~20 eV Neutron Kinetic Energy." }; } diff --git a/src/main/java/GoodGenerator/Blocks/TEs/MetaTE/NeutronSensor.java b/src/main/java/GoodGenerator/Blocks/TEs/MetaTE/NeutronSensor.java index 640859b9f0..593b3b738c 100644 --- a/src/main/java/GoodGenerator/Blocks/TEs/MetaTE/NeutronSensor.java +++ b/src/main/java/GoodGenerator/Blocks/TEs/MetaTE/NeutronSensor.java @@ -23,6 +23,7 @@ public class NeutronSensor extends GT_MetaTileEntity_Hatch { private static final IIconContainer textureFont_Glow = new Textures.BlockIcons.CustomIcon("icons/NeutronSensorFont_GLOW"); protected String texts = ""; + boolean isOn = false; public NeutronSensor(int aID, String aName, String aNameRegional, int aTier) { super(aID, aName, aNameRegional, aTier, 0, "Detect Neutron Kinetic Energy."); @@ -102,6 +103,18 @@ public class NeutronSensor extends GT_MetaTileEntity_Hatch { texts = text == null ? "" : text; } + public String getText() { + return texts == null ? "" : texts; + } + + public void outputRedstoneSignal(){ + isOn = true; + } + + public void stopOutputRedstoneSignal(){ + isOn = false; + } + @Override public ITexture[] getTexturesActive(ITexture aBaseTexture) { return new ITexture[] { @@ -120,6 +133,24 @@ public class NeutronSensor extends GT_MetaTileEntity_Hatch { } @Override + public boolean allowGeneralRedstoneOutput(){ + return true; + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + if (isOn) { + for (byte i = 0; i < 6; i ++) + aBaseMetaTileEntity.setInternalOutputRedstoneSignal(i, (byte) 15); + } + else { + for (byte i = 0; i < 6; i ++) + aBaseMetaTileEntity.setInternalOutputRedstoneSignal(i, (byte) 0); + } + super.onPostTick(aBaseMetaTileEntity, aTick); + } + + @Override public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { return new NeutronSensor(mName, mTier, mDescriptionArray, mTextures); } @@ -134,9 +165,4 @@ public class NeutronSensor extends GT_MetaTileEntity_Hatch { return false; } - @Override - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - super.onPostTick(aBaseMetaTileEntity, aTick); - //if (aTick % 100 == 0) GT_Log.out.print(texts + "\n"); - } } diff --git a/src/main/java/GoodGenerator/Blocks/TEs/NeutronActivator.java b/src/main/java/GoodGenerator/Blocks/TEs/NeutronActivator.java index 2498f81d2a..9291310c13 100644 --- a/src/main/java/GoodGenerator/Blocks/TEs/NeutronActivator.java +++ b/src/main/java/GoodGenerator/Blocks/TEs/NeutronActivator.java @@ -2,53 +2,201 @@ package GoodGenerator.Blocks.TEs; import GoodGenerator.Blocks.TEs.MetaTE.NeutronAccelerator; import GoodGenerator.Blocks.TEs.MetaTE.NeutronSensor; +import GoodGenerator.Client.GUI.NeutronActivatorGUIClient; +import GoodGenerator.Common.Container.NeutronActivatorGUIContainer; +import GoodGenerator.Loader.Loaders; +import GoodGenerator.util.CharExchanger; +import GoodGenerator.util.DescTextLocalization; +import GoodGenerator.util.ItemRefer; +import GoodGenerator.util.MyRecipeAdder; +import com.github.technus.tectech.mechanics.constructable.IConstructable; import com.github.technus.tectech.mechanics.structure.IStructureDefinition; import com.github.technus.tectech.mechanics.structure.StructureDefinition; import com.github.technus.tectech.thing.metaTileEntity.multi.base.GT_MetaTileEntity_MultiblockBase_EM; import gregtech.api.GregTech_API; import gregtech.api.enums.Materials; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch; +import gregtech.api.render.TextureFactory; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; import ic2.core.Ic2Items; import net.minecraft.block.Block; +import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.StatCollector; +import net.minecraftforge.fluids.FluidStack; +import org.lwjgl.input.Keyboard; import java.util.ArrayList; +import java.util.Collection; import static GoodGenerator.util.StructureHelper.addFrame; import static com.github.technus.tectech.mechanics.structure.StructureUtility.*; import static org.apache.commons.lang3.RandomUtils.nextInt; -public class NeutronActivator extends GT_MetaTileEntity_MultiblockBase_EM { +public class NeutronActivator extends GT_MetaTileEntity_MultiblockBase_EM implements IConstructable { protected IStructureDefinition<NeutronActivator> multiDefinition = null; protected final ArrayList<NeutronAccelerator> mNeutronAccelerator = new ArrayList<>(); protected final ArrayList<NeutronSensor> mNeutronSensor = new ArrayList<>(); protected int casingAmount = 0; - protected int KeV; + protected int eV = 0; + + private static final IIconContainer textureFontOn = new Textures.BlockIcons.CustomIcon("icons/NeutronActivator_On"); + private static final IIconContainer textureFontOn_Glow = new Textures.BlockIcons.CustomIcon("icons/NeutronActivator_On_GLOW"); + private static final IIconContainer textureFontOff = new Textures.BlockIcons.CustomIcon("icons/NeutronActivator_Off"); + private static final IIconContainer textureFontOff_Glow = new Textures.BlockIcons.CustomIcon("icons/NeutronActivator_Off_GLOW"); public NeutronActivator(String name) { super(name); } public NeutronActivator(int id, String name, String nameRegional) { - super(id,name,nameRegional); + super(id, name, nameRegional); + } + + @Override + public boolean checkRecipe_EM(ItemStack aStack) { + this.mEfficiency = 10000; + + ArrayList<FluidStack> tFluids = getStoredFluids(); + ArrayList<ItemStack> tItems = getStoredInputs(); + Collection<GT_Recipe> tRecipes = MyRecipeAdder.instance.NA.mRecipeList; + + for (int i = 0; i < tFluids.size() - 1; i++) { + for (int j = i + 1; j < tFluids.size(); j++) { + if (GT_Utility.areFluidsEqual(tFluids.get(i), tFluids.get(j))) { + if ((tFluids.get(i)).amount >= (tFluids.get(j)).amount) { + tFluids.remove(j--); + } else { + tFluids.remove(i--); + break; + } + } + } + } + + for (int i = 0; i < tItems.size() - 1; i++) { + for (int j = i + 1; j < tItems.size(); j++) { + if (GT_Utility.areStacksEqual(tItems.get(i), tItems.get(j))) { + if ((tItems.get(i)).stackSize >= (tItems.get(j)).stackSize) { + tItems.remove(j--); + } else { + tItems.remove(i--); + break; + } + } + } + } + + FluidStack[] inFluids = tFluids.toArray(new FluidStack[0]); + ItemStack[] inItems = tItems.toArray(new ItemStack[0]); + int minNKE, maxNKE; + + for (GT_Recipe recipe : tRecipes) { + minNKE = (recipe.mSpecialValue % 10000) * 1000000; + maxNKE = (recipe.mSpecialValue / 10000) * 1000000; + if (recipe.isRecipeInputEqual(true, inFluids, inItems)) { + mMaxProgresstime = recipe.mDuration; + if (eV <= maxNKE && eV >= minNKE) { + this.mOutputFluids = recipe.mFluidOutputs; + this.mOutputItems = recipe.mOutputs; + } + else { + this.mOutputFluids = null; + this.mOutputItems = new ItemStack[]{ItemRefer.Radioactive_Waste.get(4)}; + } + } + return true; + } + return false; + } + + @Override + public int getMaxEfficiency(ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerTick(ItemStack aStack) { + return 0; + } + + @Override + public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new NeutronActivatorGUIClient(aPlayerInventory, aBaseMetaTileEntity, getLocalName(), "EMDisplay.png"); + } + + @Override + public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new NeutronActivatorGUIContainer(aPlayerInventory, aBaseMetaTileEntity); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + eV = aNBT.getInteger("mKeV"); + super.loadNBTData(aNBT); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setInteger("mKeV", eV); + super.saveNBTData(aNBT); + } + + @Override + public String[] getDescription() { + final GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType("Neutron Activator") + .addInfo("Controller block for the Neutron Activator") + .addInfo("Superluminal-velocity Motion.") + .addInfo("You need to input energy to the Neutron Accelerator to get it running.") + .addInfo("It will output correct products with Specific Neutron Kinetic Energy.") + .addInfo("Otherwise it will output trash.") + .addInfo("The Neutron Kinetic Energy will decrease 72KeV/s when no Neutron Accelerator is running.") + .addInfo("It will explode when the Neutron Kinetic Energy is over" + EnumChatFormatting.RED + " 300MeV" + EnumChatFormatting.GRAY + ".") + .addInfo("The structure is too complex!") + .addInfo("Follow the" + EnumChatFormatting.DARK_BLUE + " Tec" + EnumChatFormatting.BLUE + "Tech" + EnumChatFormatting.GRAY + " blueprint to build the main structure.") + .addSeparator() + .beginStructureBlock(5, 6, 5, false) + .addController("Front bottom") + .addInputHatch("Hint block with dot 1") + .addInputBus("Hint block with dot 1") + .addOutputHatch("Hint block with dot 2") + .addOutputBus("Hint block with dot 2") + .addMaintenanceHatch("Hint block with dot 2") + .addOtherStructurePart("Neutron Accelerator", "Hint block with dot 2") + .addOtherStructurePart("Neutron Sensor", "Hint block with dot 2") + .addCasingInfo("Clean Stainless Steel Machine Casing", 7) + .toolTipFinisher("Good Generator"); + if (!Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) { + return tt.getInformation(); + } else { + return tt.getStructureInformation(); + } } @Override public IStructureDefinition<NeutronActivator> getStructure_EM() { - if(multiDefinition == null) { + if (multiDefinition == null) { multiDefinition = StructureDefinition .<NeutronActivator>builder() .addShape(mName, transpose(new String[][]{ - {"CCCCC","CDDDC","CDDDC","CDDDC","CCCCC"}, - {"F F"," GGG "," GPG "," GGG ","F F"}, - {"F F"," GGG "," GPG "," GGG ","F F"}, - {"F F"," GGG "," GPG "," GGG ","F F"}, - {"F F"," GGG "," GPG "," GGG ","F F"}, - {"XX~XX","XDDDX","XDDDX","XDDDX","XXXXX"}, + {"CCCCC", "CDDDC", "CDDDC", "CDDDC", "CCCCC"}, + {"F F", " GGG ", " GPG ", " GGG ", "F F"}, + {"F F", " GGG ", " GPG ", " GGG ", "F F"}, + {"F F", " GGG ", " GPG ", " GGG ", "F F"}, + {"F F", " GGG ", " GPG ", " GGG ", "F F"}, + {"XX~XX", "XDDDX", "XDDDX", "XDDDX", "XXXXX"}, }) ) .addElement( @@ -59,7 +207,7 @@ public class NeutronActivator extends GT_MetaTileEntity_MultiblockBase_EM { 1 ), onElementPass( - x -> x.casingAmount ++, + x -> x.casingAmount++, ofBlock( GregTech_API.sBlockCasings4, 1 ) @@ -87,7 +235,7 @@ public class NeutronActivator extends GT_MetaTileEntity_MultiblockBase_EM { .addElement( 'P', ofBlock( - GregTech_API.sBlockCasings2, 13 + Loaders.speedingPipe, 0 ) ) .addElement( @@ -102,11 +250,11 @@ public class NeutronActivator extends GT_MetaTileEntity_MultiblockBase_EM { 2 ), ofHatchAdder( - NeutronActivator::addAccelerator, 49, + NeutronActivator::addAcceleratorAndSensor, 49, 2 ), onElementPass( - x -> x.casingAmount ++, + x -> x.casingAmount++, ofBlock( GregTech_API.sBlockCasings4, 1 ) @@ -126,24 +274,28 @@ public class NeutronActivator extends GT_MetaTileEntity_MultiblockBase_EM { return structureCheck_EM(mName, 2, 5, 0) && casingAmount >= 7; } - public final boolean addAccelerator(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + public final boolean addAcceleratorAndSensor(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { if (aTileEntity == null) { return false; } else { IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); - if (aMetaTileEntity instanceof NeutronAccelerator){ - ((GT_MetaTileEntity_Hatch)aMetaTileEntity).updateTexture(aBaseCasingIndex); - return this.mNeutronAccelerator.add((NeutronAccelerator)aMetaTileEntity); - } else if (aMetaTileEntity instanceof NeutronSensor){ - ((GT_MetaTileEntity_Hatch)aMetaTileEntity).updateTexture(aBaseCasingIndex); - return this.mNeutronSensor.add((NeutronSensor)aMetaTileEntity); + if (aMetaTileEntity instanceof NeutronAccelerator) { + ((GT_MetaTileEntity_Hatch) aMetaTileEntity).updateTexture(aBaseCasingIndex); + return this.mNeutronAccelerator.add((NeutronAccelerator) aMetaTileEntity); + } else if (aMetaTileEntity instanceof NeutronSensor) { + ((GT_MetaTileEntity_Hatch) aMetaTileEntity).updateTexture(aBaseCasingIndex); + return this.mNeutronSensor.add((NeutronSensor) aMetaTileEntity); } } return false; } public int maxNeutronKineticEnergy() { - return 10000000; + return 300000000; + } + + public int getCurrentNeutronKineticEnergy() { + return eV; } @Override @@ -157,21 +309,95 @@ public class NeutronActivator extends GT_MetaTileEntity_MultiblockBase_EM { boolean anyWorking = false; if (this.getBaseMetaTileEntity().isServerSide()) { for (NeutronAccelerator tHatch : mNeutronAccelerator) { - if (tHatch.isRunning) { + if (tHatch.isRunning && this.getRepairStatus() == this.getIdealStatus()) { anyWorking = true; - this.KeV += nextInt(tHatch.getMaxEUConsume(), tHatch.getMaxEUConsume() * 2 + 1) / 10; + this.eV += nextInt(tHatch.getMaxEUConsume(), tHatch.getMaxEUConsume() * 2 + 1) * 10; } } if (!anyWorking) { - if (this.KeV >= 80 && aTick % 20 == 0) { - this.KeV -= 80; + if (this.eV >= 72000 && aTick % 20 == 0) { + this.eV -= 72000; + } else if (this.eV > 0 && aTick % 20 == 0) { + this.eV = 0; + } + } + if (this.eV < 0) this.eV = 0; + if (this.eV > maxNeutronKineticEnergy()) doExplosion(4 * 32); + + for (NeutronSensor tHatch : mNeutronSensor) { + String tText = tHatch.getText(); + if (CharExchanger.isValidCompareExpress(rawProcessExp(tText))) { + if (CharExchanger.compareExpression(rawProcessExp(tText), eV)) { + tHatch.outputRedstoneSignal(); + } else tHatch.stopOutputRedstoneSignal(); } - else if (this.KeV > 0 && aTick % 20 == 0) { - this.KeV = 0; + } + } + } + + protected String rawProcessExp(String exp) { + StringBuilder ret = new StringBuilder(); + for (char c : exp.toCharArray()) { + if (exp.length() - ret.length() == 3) { + if (Character.isDigit(c)) ret.append(c); + else { + if (c == 'K' || c == 'k') { + ret.append("000"); + } + if (c == 'M' || c == 'm') { + ret.append("000000"); + } } + break; } - if (this.KeV < 0) this.KeV = 0; - if (this.KeV > maxNeutronKineticEnergy()) doExplosion(4 * 32); + ret.append(c); + } + return ret.toString(); + } + + @Override + public void construct(ItemStack itemStack, boolean b) { + structureBuild_EM(mName, 2, 5, 0, b, itemStack); + } + + @Override + public String[] getStructureDescription(ItemStack itemStack) { + return DescTextLocalization.addText("NeutronActivator.hint", 7); + } + + @Override + public String[] getInfoData() { + int currentNKEInput = 0; + boolean anyWorking = false; + for (NeutronAccelerator tHatch : mNeutronAccelerator) { + if (tHatch.isRunning) { + currentNKEInput += nextInt(tHatch.getMaxEUConsume(), tHatch.getMaxEUConsume() * 2 + 1) * 10; + anyWorking = true; + } + } + if (!anyWorking) currentNKEInput = -72000; + return new String[] { + "Progress:", + EnumChatFormatting.GREEN + Integer.toString(this.mProgresstime / 20) + EnumChatFormatting.RESET + " s / " + EnumChatFormatting.YELLOW + this.mMaxProgresstime / 20 + EnumChatFormatting.RESET + " s", + "Current Neutron Kinetic Energy Input: " + EnumChatFormatting.GREEN + GT_Utility.formatNumbers(currentNKEInput) + EnumChatFormatting.RESET + "eV", + StatCollector.translateToLocal("scanner.info.NA") + " " + EnumChatFormatting.LIGHT_PURPLE + GT_Utility.formatNumbers(getCurrentNeutronKineticEnergy()) + EnumChatFormatting.RESET + "eV" + }; + } + + @Override + public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, boolean aActive, boolean aRedstone) { + if(aSide == aFacing) { + if(aActive) return new ITexture[]{ + Textures.BlockIcons.getCasingTextureForId(49), + TextureFactory.of(textureFontOn), + TextureFactory.builder().addIcon(textureFontOn_Glow).glow().build() + }; + else return new ITexture[]{ + Textures.BlockIcons.getCasingTextureForId(49), + TextureFactory.of(textureFontOff), + TextureFactory.builder().addIcon(textureFontOff_Glow).glow().build() + }; } + return new ITexture[]{Textures.BlockIcons.getCasingTextureForId(49)}; } } diff --git a/src/main/java/GoodGenerator/Blocks/TEs/UniversalChemicalFuelEngine.java b/src/main/java/GoodGenerator/Blocks/TEs/UniversalChemicalFuelEngine.java index 382a0e10d1..9f589db8bb 100644 --- a/src/main/java/GoodGenerator/Blocks/TEs/UniversalChemicalFuelEngine.java +++ b/src/main/java/GoodGenerator/Blocks/TEs/UniversalChemicalFuelEngine.java @@ -201,7 +201,7 @@ public class UniversalChemicalFuelEngine extends GT_MetaTileEntity_MultiblockBas .addInfo("The efficiency is determined by the proportion of Combustion Promoter to fuel.") .addInfo("The proportion is bigger, and the efficiency will be higher.") .addInfo("It creates sqrt(Current Output Power) pollution every second") - .addInfo("If you forge to supply Combustion Promoter, this engine will swallow all the fuel " + EnumChatFormatting.YELLOW + "without outputting energy" + EnumChatFormatting.GRAY + ".") + .addInfo("If you forget to supply Combustion Promoter, this engine will swallow all the fuel " + EnumChatFormatting.YELLOW + "without outputting energy" + EnumChatFormatting.GRAY + ".") .addInfo("The efficiency is up to 150%.") .addInfo("The structure is too complex!") .addInfo("Follow the" + EnumChatFormatting.DARK_BLUE + " Tec" + EnumChatFormatting.BLUE + "Tech" + EnumChatFormatting.GRAY + " blueprint to build the main structure.") |