From e8e899fb8ec40fc2a8094e3a1f65527af23b11e4 Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Tue, 2 Apr 2019 14:47:39 +1000 Subject: + Added some basis for new redstone things. --- .../core/util/minecraft/InventoryUtils.java | 82 +++++++++++----------- 1 file changed, 40 insertions(+), 42 deletions(-) (limited to 'src/Java/gtPlusPlus/core/util') diff --git a/src/Java/gtPlusPlus/core/util/minecraft/InventoryUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/InventoryUtils.java index 0d4394d773..8f12d20494 100644 --- a/src/Java/gtPlusPlus/core/util/minecraft/InventoryUtils.java +++ b/src/Java/gtPlusPlus/core/util/minecraft/InventoryUtils.java @@ -7,54 +7,52 @@ import net.minecraft.entity.item.EntityItem; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; public class InventoryUtils { private final static Random mRandom = new Random(); - public static void dropInventoryItems(World world, int x, int y, int z, Block block){ - Object tileentity = world.getTileEntity(x, y, z); - - if (tileentity != null) - { - for (int i1 = 0; i1 < ((IInventory) tileentity).getSizeInventory(); ++i1) - { - ItemStack itemstack = ((IInventory) tileentity).getStackInSlot(i1); - - if (itemstack != null) - { - float f = mRandom.nextFloat() * 0.8F + 0.1F; - float f1 = mRandom.nextFloat() * 0.8F + 0.1F; - EntityItem entityitem; - - for (float f2 = mRandom.nextFloat() * 0.8F + 0.1F; itemstack.stackSize > 0; world.spawnEntityInWorld(entityitem)) - { - int j1 = mRandom.nextInt(21) + 10; - - if (j1 > itemstack.stackSize) - { - j1 = itemstack.stackSize; - } - - itemstack.stackSize -= j1; - entityitem = new EntityItem(world, x + f, y + f1, z + f2, new ItemStack(itemstack.getItem(), j1, itemstack.getItemDamage())); - float f3 = 0.05F; - entityitem.motionX = (float)mRandom.nextGaussian() * f3; - entityitem.motionY = (float)mRandom.nextGaussian() * f3 + 0.2F; - entityitem.motionZ = (float)mRandom.nextGaussian() * f3; - - if (itemstack.hasTagCompound()) - { - entityitem.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy()); - } - } - } - } - - world.func_147453_f(x, y, z, block); - } - + public static void dropInventoryItems(World world, int x, int y, int z, Block block) { + TileEntity tileentity = world.getTileEntity(x, y, z); + + if (tileentity != null && tileentity instanceof IInventory + && ((IInventory) tileentity).getSizeInventory() > 0) { + for (int i1 = 0; i1 < ((IInventory) tileentity).getSizeInventory(); ++i1) { + ItemStack itemstack = ((IInventory) tileentity).getStackInSlot(i1); + + if (itemstack != null) { + float f = mRandom.nextFloat() * 0.8F + 0.1F; + float f1 = mRandom.nextFloat() * 0.8F + 0.1F; + EntityItem entityitem; + + for (float f2 = mRandom.nextFloat() * 0.8F + 0.1F; itemstack.stackSize > 0; world.spawnEntityInWorld(entityitem)) { + int j1 = mRandom.nextInt(21) + 10; + + if (j1 > itemstack.stackSize) { + j1 = itemstack.stackSize; + } + + itemstack.stackSize -= j1; + entityitem = new EntityItem(world, x + f, y + f1, z + f2, + new ItemStack(itemstack.getItem(), j1, itemstack.getItemDamage())); + float f3 = 0.05F; + entityitem.motionX = (float) mRandom.nextGaussian() * f3; + entityitem.motionY = (float) mRandom.nextGaussian() * f3 + 0.2F; + entityitem.motionZ = (float) mRandom.nextGaussian() * f3; + + if (itemstack.hasTagCompound()) { + entityitem.getEntityItem() + .setTagCompound((NBTTagCompound) itemstack.getTagCompound().copy()); + } + } + } + } + + world.func_147453_f(x, y, z, block); + } + } } -- cgit From 70a0df8a68725c16f0c0b959639b8e82cbbcf3a0 Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Tue, 2 Apr 2019 17:44:13 +1000 Subject: % Work work --- src/Java/gtPlusPlus/core/block/ModBlocks.java | 4 +- .../general/redstone/BlockGenericRedstone.java | 24 ++- .../redstone/BlockGenericRedstoneDetector.java | 10 + .../general/redstone/BlockGenericRedstoneTest.java | 205 +++++++++++++++++++++ .../core/tileentities/ModTileEntities.java | 1 - .../redstone/TileEntityRedstoneHandler.java | 36 +++- .../gtPlusPlus/core/util/minecraft/ItemUtils.java | 61 ++++++ 7 files changed, 319 insertions(+), 22 deletions(-) create mode 100644 src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstoneTest.java (limited to 'src/Java/gtPlusPlus/core/util') diff --git a/src/Java/gtPlusPlus/core/block/ModBlocks.java b/src/Java/gtPlusPlus/core/block/ModBlocks.java index 8471c13351..b904b04556 100644 --- a/src/Java/gtPlusPlus/core/block/ModBlocks.java +++ b/src/Java/gtPlusPlus/core/block/ModBlocks.java @@ -12,6 +12,7 @@ import gtPlusPlus.core.block.general.MiningExplosives; import gtPlusPlus.core.block.general.PlayerDoors; import gtPlusPlus.core.block.general.antigrief.BlockWitherProof; import gtPlusPlus.core.block.general.redstone.BlockGenericRedstoneDetector; +import gtPlusPlus.core.block.general.redstone.BlockGenericRedstoneTest; import gtPlusPlus.core.block.machine.CircuitProgrammer; import gtPlusPlus.core.block.machine.DecayablesChest; import gtPlusPlus.core.block.machine.FishTrap; @@ -141,8 +142,9 @@ public final class ModBlocks { blockCustomJukebox = new Machine_SuperJukebox(); blockPooCollector = new Machine_PooCollector(); - + new BlockGenericRedstoneDetector(); + new BlockGenericRedstoneTest(); } diff --git a/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstone.java b/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstone.java index 3197d149c8..a021a39ac8 100644 --- a/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstone.java +++ b/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstone.java @@ -10,10 +10,12 @@ import cpw.mods.fml.common.registry.LanguageRegistry; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import gregtech.common.items.GT_MetaGenerated_Tool_01; +import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.creative.AddToCreativeTab; import gtPlusPlus.core.item.base.itemblock.ItemBlockMeta; import gtPlusPlus.core.tileentities.general.redstone.TileEntityRedstoneHandler; import gtPlusPlus.core.util.minecraft.InventoryUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; import gtPlusPlus.core.util.minecraft.PlayerUtils; import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; @@ -86,20 +88,22 @@ public abstract class BlockGenericRedstone extends BlockContainer { final Item mHandItem = mHandStack.getItem(); if (mHandItem instanceof GT_MetaGenerated_Tool_01) { + Logger.INFO("Found Tool in players hand!"); + final TileEntityRedstoneHandler tile = (TileEntityRedstoneHandler) world.getTileEntity(x, y, z); if (tile != null) { - if (tile.isScrewdriverable()) { - if ((mHandItem.getDamage(mHandStack) == 22) || (mHandItem.getDamage(mHandStack) == 150)){ + if (tile.isScrewdriverable() || player.capabilities.isCreativeMode) { + if (ItemUtils.isToolScrewdriver(mHandStack)){ mDidTool = tile.onScrewdriverRMB(); } } - if (tile.isMalletable()) { - if ((mHandItem.getDamage(mHandStack) == 24) || (mHandItem.getDamage(mHandStack) == 154)){ + if (tile.isMalletable() || player.capabilities.isCreativeMode) { + if (ItemUtils.isToolMallet(mHandStack)){ mDidTool = tile.onMalletRMB(); } } - if (tile.isWrenchable()) { - if ((mHandItem.getDamage(mHandStack) == 26) || (mHandItem.getDamage(mHandStack) == 164)){ + if (tile.isWrenchable() || player.capabilities.isCreativeMode) { + if (ItemUtils.isToolWrench(mHandStack)){ mDidTool = tile.onWrenchRMB(); } } @@ -129,17 +133,17 @@ public abstract class BlockGenericRedstone extends BlockContainer { final TileEntityRedstoneHandler tile = (TileEntityRedstoneHandler) aWorld.getTileEntity(aX, aY, aZ); if (tile != null) { if (tile.isScrewdriverable()) { - if ((mHandItem.getDamage(mHandStack) == 22) || (mHandItem.getDamage(mHandStack) == 150)){ + if (ItemUtils.isToolScrewdriver(mHandStack)){ mDidTool = tile.onScrewdriverLMB(); } } if (tile.isMalletable()) { - if ((mHandItem.getDamage(mHandStack) == 24) || (mHandItem.getDamage(mHandStack) == 154)){ + if (ItemUtils.isToolMallet(mHandStack)){ mDidTool = tile.onMalletLMB(); } } if (tile.isWrenchable()) { - if ((mHandItem.getDamage(mHandStack) == 26) || (mHandItem.getDamage(mHandStack) == 164)){ + if (ItemUtils.isToolWrench(mHandStack)){ mDidTool = tile.onWrenchLMB(); } } @@ -148,7 +152,7 @@ public abstract class BlockGenericRedstone extends BlockContainer { } catch (Throwable t) {} - if (!mDidTool) { + if (!mDidTool && !aPlayer.capabilities.isCreativeMode) { super.onBlockClicked(aWorld, aX, aY, aZ, aPlayer); } else { diff --git a/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstoneDetector.java b/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstoneDetector.java index 7728b29a7c..43247110f1 100644 --- a/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstoneDetector.java +++ b/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstoneDetector.java @@ -32,6 +32,16 @@ public class BlockGenericRedstoneDetector extends BlockGenericRedstone { public class TileEntityRedstoneDetector extends TileEntityRedstoneHandler { public TileEntityRedstoneDetector() { super(0); + } + + @Override + protected Class getTileEntityClass() { + return this.getClass(); + } + + @Override + protected String getTileEntityNameForRegistration() { + return "TileEntityRedstoneDetector"; } } diff --git a/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstoneTest.java b/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstoneTest.java new file mode 100644 index 0000000000..f2a5c3f36a --- /dev/null +++ b/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstoneTest.java @@ -0,0 +1,205 @@ +package gtPlusPlus.core.block.general.redstone; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Random; + +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.tileentities.general.redstone.TileEntityRedstoneHandler; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; + +public class BlockGenericRedstoneTest extends BlockGenericRedstone { + + public BlockGenericRedstoneTest() { + super("test", "Redstone Test"); + setTickRandomly(true); + } + + @Override + public TileEntity createNewTileEntity(World world, int p_149915_2_) { + return new TileEntityRedstoneTest(); + } + + public class TileEntityRedstoneTest extends TileEntityRedstoneHandler { + public TileEntityRedstoneTest() { + super(2); + } + + @Override + public boolean isScrewdriverable() { + return true; + } + + @Override + public boolean onScrewdriverLMB() { + // TODO Auto-generated method stub + return super.onScrewdriverLMB(); + } + + @Override + public boolean onScrewdriverRMB() { + if (this.mLightValue + 1 <= 1) { + this.mLightValue += 1; + } + else { + this.mLightValue = 0; + } + Logger.INFO("Screwdriver | "+this.getLightBrightness()); + this.markForUpdate(); + return super.onScrewdriverRMB(); + } + + @Override + public boolean isMalletable() { + return true; + } + + @Override + public boolean onMalletLMB() { + // TODO Auto-generated method stub + return super.onMalletLMB(); + } + + @Override + public boolean onMalletRMB() { + this.mLightMode = Utils.invertBoolean(mLightMode); + return super.onMalletRMB(); + } + + @Override + public boolean isWrenchable() { + return true; + } + + @Override + public boolean onWrenchLMB() { + // TODO Auto-generated method stub + return super.onWrenchLMB(); + } + + @Override + public boolean onWrenchRMB() { + // TODO Auto-generated method stub + return super.onWrenchRMB(); + } + + @Override + protected Class getTileEntityClass() { + return this.getClass(); + } + + @Override + protected String getTileEntityNameForRegistration() { + // TODO Auto-generated method stub + return "TileEntityRedstoneTest"; + } + + @Override + public int isProvidingWeakPower(IBlockAccess world, int x, int y, int z, int side) { + // TODO Auto-generated method stub + return super.isProvidingWeakPower(world, x, y, z, side); + } + + @Override + public int isProvidingStrongPower(IBlockAccess world, int x, int y, int z, int side) { + // TODO Auto-generated method stub + return super.isProvidingStrongPower(world, x, y, z, side); + } + } + + @Override + public void getSubBlocks(Item p_149666_1_, CreativeTabs p_149666_2_, List aList) { + aList.add(ItemUtils.getSimpleStack(this)); + } + + + @Override + public void updateTick(World aWorld, int aX, int aY, int aZ, Random aRand) { + super.updateTick(aWorld, aX, aY, aZ, aRand); + } + + @Override + public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_) { + // TODO Auto-generated method stub + return ItemUtils.getSimpleStack(this).getItem(); + } + + @Override + public Item getItem(World p_149694_1_, int p_149694_2_, int p_149694_3_, int p_149694_4_) { + // TODO Auto-generated method stub + return ItemUtils.getSimpleStack(this).getItem(); + } + + @Override + protected ItemStack createStackedBlock(int p_149644_1_) { + return ItemUtils.simpleMetaStack(this, p_149644_1_, 1); + } + + public void generateTextureArray(final IIconRegister iicon) { + HashMap> aTextures = new HashMap>(); + + + //New Block for Each Meta + int aMeta = 0; + { + HashMap aTempMap = new HashMap(); + aTempMap.put(ForgeDirection.UP, iicon.registerIcon(CORE.MODID + ":" + "redstone/redstone_meter/" + "top")); + aTempMap.put(ForgeDirection.DOWN, iicon.registerIcon(CORE.MODID + ":" + "redstone/redstone_meter/" + "top")); + aTempMap.put(ForgeDirection.NORTH, iicon.registerIcon(CORE.MODID + ":" + "redstone/redstone_meter/" + "top")); + aTempMap.put(ForgeDirection.SOUTH, iicon.registerIcon(CORE.MODID + ":" + "redstone/redstone_meter/" + "top")); + aTempMap.put(ForgeDirection.EAST, iicon.registerIcon(CORE.MODID + ":" + "redstone/redstone_meter/" + "top")); + aTempMap.put(ForgeDirection.WEST, iicon.registerIcon(CORE.MODID + ":" + "redstone/redstone_meter/" + "top")); + aTextures.put(aMeta++, aTempMap); + } + + } + + @Override + public IIcon getIcon(int side, int meta) { + HashMap aTemp = getTextureArray().get(meta); + if (aTemp != null) { + IIcon aSide = aTemp.get(ForgeDirection.getOrientation(side)); + if (aSide != null) { + return aSide; + } + else { + //Smart calculate missing sides + if (side <= 1) { + for (int ss = 0; ss < 2; ss++) { + aSide = aTemp.get(ForgeDirection.getOrientation(side)); + if (aSide != null) { + return aSide; + } + } + } + for (int ss = 2; ss < 6; ss++) { + aSide = aTemp.get(ForgeDirection.getOrientation(side)); + if (aSide != null) { + return aSide; + } + } + } + } + return blockIcon; + } + + @Override + public ArrayList getDrops(World world, int x, int y, int z, int metadata, int fortune) { + ArrayList aDrops = new ArrayList(); + aDrops.add(ItemUtils.getSimpleStack(this)); + return aDrops; + } + +} diff --git a/src/Java/gtPlusPlus/core/tileentities/ModTileEntities.java b/src/Java/gtPlusPlus/core/tileentities/ModTileEntities.java index 5a0d2cc256..c3670ef959 100644 --- a/src/Java/gtPlusPlus/core/tileentities/ModTileEntities.java +++ b/src/Java/gtPlusPlus/core/tileentities/ModTileEntities.java @@ -32,7 +32,6 @@ public class ModTileEntities { GameRegistry.registerTileEntity(TileEntityDecayablesChest.class, "TileDecayablesChest"); GameRegistry.registerTileEntity(TileEntitySuperJukebox.class, "TileEntitySuperJukebox"); GameRegistry.registerTileEntity(TileEntitySuperLight.class, "TileEntitySuperLight"); - GameRegistry.registerTileEntity(TileEntityRedstoneHandler.class, "TileEntityRedstoneHandler"); //Mod TEs diff --git a/src/Java/gtPlusPlus/core/tileentities/general/redstone/TileEntityRedstoneHandler.java b/src/Java/gtPlusPlus/core/tileentities/general/redstone/TileEntityRedstoneHandler.java index 163c4453b6..152790951a 100644 --- a/src/Java/gtPlusPlus/core/tileentities/general/redstone/TileEntityRedstoneHandler.java +++ b/src/Java/gtPlusPlus/core/tileentities/general/redstone/TileEntityRedstoneHandler.java @@ -1,6 +1,8 @@ package gtPlusPlus.core.tileentities.general.redstone; +import cpw.mods.fml.common.registry.GameRegistry; import gtPlusPlus.api.interfaces.IToolable; +import gtPlusPlus.api.objects.Logger; import gtPlusPlus.api.objects.minecraft.BlockPos; import gtPlusPlus.core.util.Utils; import net.minecraft.block.Block; @@ -11,7 +13,7 @@ import net.minecraft.util.IIcon; import net.minecraft.world.EnumSkyBlock; import net.minecraft.world.IBlockAccess; -public class TileEntityRedstoneHandler extends TileEntity implements IToolable { +public abstract class TileEntityRedstoneHandler extends TileEntity implements IToolable { private final int mTileType; private BlockPos mTilePos; @@ -19,7 +21,7 @@ public class TileEntityRedstoneHandler extends TileEntity implements IToolable { private Long mStartTime; public boolean mLightMode = false; - public int mLightValue = 0; + public float mLightValue = 0; /** * Sets the Redstone Handler Type. @@ -27,8 +29,17 @@ public class TileEntityRedstoneHandler extends TileEntity implements IToolable { */ public TileEntityRedstoneHandler(int aTileType) { mTileType = aTileType; + registerTileEntity(); } + private void registerTileEntity() { + GameRegistry.registerTileEntity(getTileEntityClass(), getTileEntityNameForRegistration()); + } + + protected abstract Class getTileEntityClass(); + + protected abstract String getTileEntityNameForRegistration(); + public Block getBlock() { return mTilePos != null ? mTilePos.getBlockAtPos() : Blocks.redstone_block; } @@ -37,7 +48,7 @@ public class TileEntityRedstoneHandler extends TileEntity implements IToolable { return mLightMode; } - public final int getLightBrightness() { + public final float getLightBrightness() { if (!isLight()) { return 0; } @@ -50,7 +61,7 @@ public class TileEntityRedstoneHandler extends TileEntity implements IToolable { public void readFromNBT(NBTTagCompound aNBT) { mStartTime = aNBT.getLong("mStartTime"); mInvName = aNBT.getString("mInvName"); - mLightValue = aNBT.getInteger("mLightValue"); + mLightValue = aNBT.getFloat("mLightValue"); mLightMode = aNBT.getBoolean("mLightMode"); super.readFromNBT(aNBT); } @@ -60,8 +71,8 @@ public class TileEntityRedstoneHandler extends TileEntity implements IToolable { aNBT.setInteger("mTileType", mTileType); aNBT.setLong("mStartTime", mStartTime); aNBT.setString("mInvName", mInvName); - aNBT.setInteger("mLightValue", mLightValue); - aNBT.setBoolean("mLightMode", mLightMode); + aNBT.setFloat("mLightValue", getLightBrightness()); + aNBT.setBoolean("mLightMode", isLight()); super.writeToNBT(aNBT); } @@ -94,18 +105,23 @@ public class TileEntityRedstoneHandler extends TileEntity implements IToolable { if (!init()) { return; } - if (mRequiresUpdate) { + if (mRequiresUpdate || mLastUpdate == null) { mRequiresUpdate = false; mHasUpdatedRecently = true; mLastUpdate = System.currentTimeMillis(); - if (mTilePos.world.getBlockLightValue(xCoord, yCoord, zCoord) != mLightValue) { - mTilePos.world.setLightValue(EnumSkyBlock.Block, xCoord, yCoord, zCoord, mLightValue); - } + if (mTilePos.world.getBlockLightValue(xCoord, yCoord, zCoord) != getLightBrightness()) { + mTilePos.getBlockAtPos().setLightLevel(getLightBrightness()); + mTilePos.world.setLightValue(EnumSkyBlock.Block, xCoord, yCoord, zCoord, (int) (getLightBrightness()/0.625f)); + mTilePos.world.updateLightByType(EnumSkyBlock.Block, xCoord, yCoord, zCoord); + Logger.INFO("Updating Light"); + } + mTilePos.world.scheduleBlockUpdate(xCoord, yCoord, zCoord, mTilePos.getBlockAtPos(), 1); markDirty(); } if (Utils.getMillisSince(mLastUpdate, System.currentTimeMillis()) >= 5000) { if (mHasUpdatedRecently) { mHasUpdatedRecently = false; + this.markForUpdate(); } } diff --git a/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java index d32ff4e160..e266ee02d4 100644 --- a/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java +++ b/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java @@ -13,6 +13,7 @@ import gregtech.api.enums.OrePrefixes; import gregtech.api.util.GT_ModHandler; import gregtech.api.util.GT_OreDictUnificator; import gregtech.api.util.GT_Utility; +import gregtech.common.items.GT_MetaGenerated_Tool_01; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.api.objects.data.Pair; import gtPlusPlus.api.objects.minecraft.BlockPos; @@ -1113,5 +1114,65 @@ public class ItemUtils { } return aDisplay; } + + public static boolean isItemGregtechTool(ItemStack aStack) { + if (aStack == null) { + return false; + } + final Item mItem = aStack.getItem(); + if (mItem instanceof GT_MetaGenerated_Tool_01) { + return true; + } + return false; + } + + public static boolean isToolWrench(ItemStack aWrench) { + if (isItemGregtechTool(aWrench) && (aWrench.getItemDamage() == 16 || aWrench.getItemDamage() == 120 || aWrench.getItemDamage() == 122 || aWrench.getItemDamage() == 124)) { + return true; + } + return false; + } + + public static boolean isToolMallet(ItemStack aMallet) { + if (isItemGregtechTool(aMallet) && (aMallet.getItemDamage() == 14)) { + return true; + } + return false; + } + + public static boolean isToolScrewdriver(ItemStack aScrewdriver) { + if (isItemGregtechTool(aScrewdriver) && (aScrewdriver.getItemDamage() == 22 || aScrewdriver.getItemDamage() == 150)) { + return true; + } + return false; + } + + public static boolean isToolCrowbar(ItemStack aCrowbar) { + if (isItemGregtechTool(aCrowbar) && (aCrowbar.getItemDamage() == 20)) { + return true; + } + return false; + } + + public static boolean isToolWirecutters(ItemStack aWirecutters) { + if (isItemGregtechTool(aWirecutters) && (aWirecutters.getItemDamage() == 26)) { + return true; + } + return false; + } + + public static boolean isToolHammer(ItemStack aHammer) { + if (isItemGregtechTool(aHammer) && (aHammer.getItemDamage() == 12)) { + return true; + } + return false; + } + + public static boolean isToolSolderingIron(ItemStack aSoldering) { + if (isItemGregtechTool(aSoldering) && (aSoldering.getItemDamage() == 160)) { + return true; + } + return false; + } } -- cgit From af61708010aef717ecc3537fa115547acb9aa9c7 Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Tue, 2 Apr 2019 18:20:28 +1000 Subject: $ More fixes. --- .../general/redstone/BlockGenericRedstone.java | 8 +++-- .../general/redstone/BlockGenericRedstoneTest.java | 17 ++++++----- .../redstone/TileEntityRedstoneHandler.java | 16 +++++++--- .../core/util/minecraft/EntityUtils.java | 35 +++++++++++++++++++++- .../gtPlusPlus/core/util/minecraft/ItemUtils.java | 10 ++++--- .../common/items/MetaGeneratedGregtechTools.java | 14 --------- 6 files changed, 67 insertions(+), 33 deletions(-) (limited to 'src/Java/gtPlusPlus/core/util') diff --git a/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstone.java b/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstone.java index a021a39ac8..65d89c0577 100644 --- a/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstone.java +++ b/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstone.java @@ -92,17 +92,19 @@ public abstract class BlockGenericRedstone extends BlockContainer { final TileEntityRedstoneHandler tile = (TileEntityRedstoneHandler) world.getTileEntity(x, y, z); if (tile != null) { - if (tile.isScrewdriverable() || player.capabilities.isCreativeMode) { + if (tile.isScrewdriverable()) { if (ItemUtils.isToolScrewdriver(mHandStack)){ mDidTool = tile.onScrewdriverRMB(); + PlayerUtils.messagePlayer(player, "Adjusted Light level by 0.0625f. "+tile.getLightBrightness()); } } - if (tile.isMalletable() || player.capabilities.isCreativeMode) { + if (tile.isMalletable()) { if (ItemUtils.isToolMallet(mHandStack)){ mDidTool = tile.onMalletRMB(); + PlayerUtils.messagePlayer(player, "Light Mode active: "+mDidTool); } } - if (tile.isWrenchable() || player.capabilities.isCreativeMode) { + if (tile.isWrenchable()) { if (ItemUtils.isToolWrench(mHandStack)){ mDidTool = tile.onWrenchRMB(); } diff --git a/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstoneTest.java b/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstoneTest.java index f2a5c3f36a..ad59a83d0c 100644 --- a/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstoneTest.java +++ b/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstoneTest.java @@ -10,6 +10,7 @@ import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.tileentities.general.redstone.TileEntityRedstoneHandler; import gtPlusPlus.core.util.Utils; import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.core.world.explosions.ExplosionHandler; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.Item; @@ -50,15 +51,14 @@ public class BlockGenericRedstoneTest extends BlockGenericRedstone { @Override public boolean onScrewdriverRMB() { - if (this.mLightValue + 1 <= 1) { - this.mLightValue += 1; + if (this.mLightValue + 0.0625f <= 1) { + this.mLightValue += 0.0625f; } else { this.mLightValue = 0; } - Logger.INFO("Screwdriver | "+this.getLightBrightness()); this.markForUpdate(); - return super.onScrewdriverRMB(); + return true; } @Override @@ -75,7 +75,8 @@ public class BlockGenericRedstoneTest extends BlockGenericRedstone { @Override public boolean onMalletRMB() { this.mLightMode = Utils.invertBoolean(mLightMode); - return super.onMalletRMB(); + this.markForUpdate(); + return mLightMode; } @Override @@ -91,8 +92,10 @@ public class BlockGenericRedstoneTest extends BlockGenericRedstone { @Override public boolean onWrenchRMB() { - // TODO Auto-generated method stub - return super.onWrenchRMB(); + Logger.INFO("Found Wrench"); + ExplosionHandler explode = new ExplosionHandler(); + explode.createExplosion(this.worldObj, null, this.xCoord, this.yCoord, this.zCoord, 1f, false, true); + return true; } @Override diff --git a/src/Java/gtPlusPlus/core/tileentities/general/redstone/TileEntityRedstoneHandler.java b/src/Java/gtPlusPlus/core/tileentities/general/redstone/TileEntityRedstoneHandler.java index 152790951a..43f2c15251 100644 --- a/src/Java/gtPlusPlus/core/tileentities/general/redstone/TileEntityRedstoneHandler.java +++ b/src/Java/gtPlusPlus/core/tileentities/general/redstone/TileEntityRedstoneHandler.java @@ -1,10 +1,16 @@ package gtPlusPlus.core.tileentities.general.redstone; +import java.lang.reflect.Field; +import java.util.HashMap; +import java.util.Map; + import cpw.mods.fml.common.registry.GameRegistry; import gtPlusPlus.api.interfaces.IToolable; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.api.objects.minecraft.BlockPos; import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.minecraft.EntityUtils; +import gtPlusPlus.core.util.reflect.ReflectionUtils; import net.minecraft.block.Block; import net.minecraft.init.Blocks; import net.minecraft.nbt.NBTTagCompound; @@ -33,7 +39,9 @@ public abstract class TileEntityRedstoneHandler extends TileEntity implements IT } private void registerTileEntity() { - GameRegistry.registerTileEntity(getTileEntityClass(), getTileEntityNameForRegistration()); + if (!EntityUtils.isTileEntityRegistered(getTileEntityClass(), getTileEntityNameForRegistration())) { + GameRegistry.registerTileEntity(getTileEntityClass(), getTileEntityNameForRegistration()); + } } protected abstract Class getTileEntityClass(); @@ -109,9 +117,9 @@ public abstract class TileEntityRedstoneHandler extends TileEntity implements IT mRequiresUpdate = false; mHasUpdatedRecently = true; mLastUpdate = System.currentTimeMillis(); - if (mTilePos.world.getBlockLightValue(xCoord, yCoord, zCoord) != getLightBrightness()) { - mTilePos.getBlockAtPos().setLightLevel(getLightBrightness()); - mTilePos.world.setLightValue(EnumSkyBlock.Block, xCoord, yCoord, zCoord, (int) (getLightBrightness()/0.625f)); + if (mTilePos.world.getBlockLightValue(xCoord, yCoord, zCoord) != getLightBrightness()/0.0625f) { + mTilePos.getBlockAtPos().setLightLevel(getLightBrightness()/0.0625f); + mTilePos.world.setLightValue(EnumSkyBlock.Block, xCoord, yCoord, zCoord, (int) (getLightBrightness()/0.0625f)); mTilePos.world.updateLightByType(EnumSkyBlock.Block, xCoord, yCoord, zCoord); Logger.INFO("Updating Light"); } diff --git a/src/Java/gtPlusPlus/core/util/minecraft/EntityUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/EntityUtils.java index 839cb164cb..844bb0bcaf 100644 --- a/src/Java/gtPlusPlus/core/util/minecraft/EntityUtils.java +++ b/src/Java/gtPlusPlus/core/util/minecraft/EntityUtils.java @@ -1,10 +1,13 @@ package gtPlusPlus.core.util.minecraft; +import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; import cpw.mods.fml.common.registry.EntityRegistry; - +import cpw.mods.fml.common.registry.GameRegistry; import net.minecraft.block.Block; import net.minecraft.entity.*; import net.minecraft.entity.player.EntityPlayer; @@ -16,6 +19,7 @@ import net.minecraft.world.biome.BiomeGenBase; import gregtech.api.util.GT_Utility; import gtPlusPlus.api.objects.minecraft.BlockPos; +import gtPlusPlus.core.util.reflect.ReflectionUtils; import ic2.core.IC2Potion; import ic2.core.item.armor.ItemArmorHazmat; @@ -125,5 +129,34 @@ public class EntityUtils { public static void doDamage(Entity entity, DamageSource dmg, int i) { entity.attackEntityFrom(dmg, i); } + + public static boolean isTileEntityRegistered(Class aTileClass, String aTileName) { + Field aRegistry = ReflectionUtils.getField(ReflectionUtils.getClass("net.minecraft.tileentity.TileEntity"), "nameToClassMap"); + Field aRegistry2 = ReflectionUtils.getField(ReflectionUtils.getClass("net.minecraft.tileentity.TileEntity"), "classToNameMap"); + try { + Object o = aRegistry.get(null); + if (o != null) { + Map nameToClassMap = (Map) o; + if (!nameToClassMap.containsKey(aTileName)) { + o = aRegistry2.get(null); + if (o != null) { + Map classToNameMap = (Map) o; + if (!classToNameMap.containsKey(aTileClass)) { + return false; + } + else { + return true; + } + } + } + else { + return true; + } + } + } catch (IllegalArgumentException | IllegalAccessException e) { + e.printStackTrace(); + } + return false; + } } diff --git a/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java index e266ee02d4..9617d12b66 100644 --- a/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java +++ b/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java @@ -30,6 +30,8 @@ import gtPlusPlus.core.lib.LoadedMods; import gtPlusPlus.core.material.Material; import gtPlusPlus.core.util.Utils; import gtPlusPlus.core.util.reflect.ReflectionUtils; +import gtPlusPlus.xmod.gregtech.api.items.Gregtech_MetaTool; +import gtPlusPlus.xmod.gregtech.common.items.MetaGeneratedGregtechTools; import gtPlusPlus.xmod.gregtech.loaders.RecipeGen_DustGeneration; import net.minecraft.block.Block; import net.minecraft.init.Items; @@ -1120,14 +1122,14 @@ public class ItemUtils { return false; } final Item mItem = aStack.getItem(); - if (mItem instanceof GT_MetaGenerated_Tool_01) { + if (mItem instanceof GT_MetaGenerated_Tool_01 || mItem instanceof MetaGeneratedGregtechTools || mItem instanceof Gregtech_MetaTool) { return true; - } + } return false; } public static boolean isToolWrench(ItemStack aWrench) { - if (isItemGregtechTool(aWrench) && (aWrench.getItemDamage() == 16 || aWrench.getItemDamage() == 120 || aWrench.getItemDamage() == 122 || aWrench.getItemDamage() == 124)) { + if (isItemGregtechTool(aWrench) && (aWrench.getItemDamage() == 16 || aWrench.getItemDamage() == 120 || aWrench.getItemDamage() == 122 || aWrench.getItemDamage() == 124 || aWrench.getItemDamage() == 7734)) { return true; } return false; @@ -1162,7 +1164,7 @@ public class ItemUtils { } public static boolean isToolHammer(ItemStack aHammer) { - if (isItemGregtechTool(aHammer) && (aHammer.getItemDamage() == 12)) { + if (isItemGregtechTool(aHammer) && (aHammer.getItemDamage() == 12 || aHammer.getItemDamage() == 7734)) { return true; } return false; diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/items/MetaGeneratedGregtechTools.java b/src/Java/gtPlusPlus/xmod/gregtech/common/items/MetaGeneratedGregtechTools.java index d228fdc04a..f6bbbfcabe 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/common/items/MetaGeneratedGregtechTools.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/items/MetaGeneratedGregtechTools.java @@ -1,25 +1,11 @@ package gtPlusPlus.xmod.gregtech.common.items; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.concurrent.ConcurrentHashMap; - import gregtech.api.GregTech_API; -import gregtech.api.enums.GT_Values; import gregtech.api.enums.TC_Aspects; import gregtech.api.enums.ToolDictNames; -import gregtech.api.interfaces.IItemBehaviour; -import gregtech.api.items.GT_MetaBase_Item; import gregtech.api.items.GT_MetaGenerated_Tool; -import gregtech.api.util.GT_Log; -import gtPlusPlus.api.objects.Logger; -import gtPlusPlus.core.util.reflect.ReflectionUtils; import gtPlusPlus.xmod.gregtech.api.enums.GregtechToolDictNames; import gtPlusPlus.xmod.gregtech.common.tools.TOOL_Gregtech_Choocher; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.world.World; -import net.minecraftforge.fluids.FluidStack; public class MetaGeneratedGregtechTools extends GT_MetaGenerated_Tool { -- cgit From 60b9e2b720abca8908a1ac2a7f5767af08bccaf9 Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Mon, 8 Apr 2019 14:12:52 +1000 Subject: % Allowed Skookum Choocher as a valid Wrench and Hard Hammer. $ Fixed infinite loop between TE and Block functions. --- .../core/block/general/redstone/BlockGenericRedstone.java | 4 ++-- .../general/redstone/TileEntityRedstoneHandler.java | 11 +++-------- src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java | 4 +++- 3 files changed, 8 insertions(+), 11 deletions(-) (limited to 'src/Java/gtPlusPlus/core/util') diff --git a/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstone.java b/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstone.java index 65d89c0577..b84c96be99 100644 --- a/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstone.java +++ b/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstone.java @@ -86,7 +86,7 @@ public abstract class BlockGenericRedstone extends BlockContainer { try { final ItemStack mHandStack = PlayerUtils.getItemStackInPlayersHand(world, player.getDisplayName()); final Item mHandItem = mHandStack.getItem(); - if (mHandItem instanceof GT_MetaGenerated_Tool_01) { + if (ItemUtils.isItemGregtechTool(mHandStack)) { Logger.INFO("Found Tool in players hand!"); @@ -250,7 +250,7 @@ public abstract class BlockGenericRedstone extends BlockContainer { if (aThis != null) { return aThis.shouldCheckWeakPower(world, x, y, z, side); } - return false; + return isNormalCube(); } @Override diff --git a/src/Java/gtPlusPlus/core/tileentities/general/redstone/TileEntityRedstoneHandler.java b/src/Java/gtPlusPlus/core/tileentities/general/redstone/TileEntityRedstoneHandler.java index 43f2c15251..fa2597eae9 100644 --- a/src/Java/gtPlusPlus/core/tileentities/general/redstone/TileEntityRedstoneHandler.java +++ b/src/Java/gtPlusPlus/core/tileentities/general/redstone/TileEntityRedstoneHandler.java @@ -1,16 +1,11 @@ package gtPlusPlus.core.tileentities.general.redstone; -import java.lang.reflect.Field; -import java.util.HashMap; -import java.util.Map; - import cpw.mods.fml.common.registry.GameRegistry; import gtPlusPlus.api.interfaces.IToolable; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.api.objects.minecraft.BlockPos; import gtPlusPlus.core.util.Utils; import gtPlusPlus.core.util.minecraft.EntityUtils; -import gtPlusPlus.core.util.reflect.ReflectionUtils; import net.minecraft.block.Block; import net.minecraft.init.Blocks; import net.minecraft.nbt.NBTTagCompound; @@ -233,7 +228,7 @@ public abstract class TileEntityRedstoneHandler extends TileEntity implements IT if (mTilePos == null) { return false; } - return getBlock().canConnectRedstone(world, xCoord, yCoord, zCoord, side); + return canAcceptRedstoneSignal() || canSupplyRedstoneSignal(); } /** @@ -249,7 +244,7 @@ public abstract class TileEntityRedstoneHandler extends TileEntity implements IT if (mTilePos == null) { return false; } - return getBlock().shouldCheckWeakPower(world, xCoord, yCoord, zCoord, side); + return getBlock().isNormalCube(); } /** @@ -268,7 +263,7 @@ public abstract class TileEntityRedstoneHandler extends TileEntity implements IT if (mTilePos == null) { return false; } - return getBlock().getWeakChanges(world, xCoord, yCoord, zCoord); + return false; } diff --git a/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java index 9617d12b66..ae799baa2b 100644 --- a/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java +++ b/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java @@ -1122,7 +1122,9 @@ public class ItemUtils { return false; } final Item mItem = aStack.getItem(); - if (mItem instanceof GT_MetaGenerated_Tool_01 || mItem instanceof MetaGeneratedGregtechTools || mItem instanceof Gregtech_MetaTool) { + final Item aSkookum = ItemUtils.getItemFromFQRN("miscutils:gt.plusplus.metatool.01"); + final Class aSkookClass = aSkookum.getClass(); + if (aSkookClass.isInstance(mItem) || mItem instanceof GT_MetaGenerated_Tool_01 || mItem instanceof MetaGeneratedGregtechTools || mItem instanceof Gregtech_MetaTool || mItem == aSkookum) { return true; } return false; -- cgit From f2a08747b22b51c6f051ca035abf38a6121ef320 Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Mon, 8 Apr 2019 14:30:42 +1000 Subject: + Added Hazmat utils. --- src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java (limited to 'src/Java/gtPlusPlus/core/util') diff --git a/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java new file mode 100644 index 0000000000..2f160c3cf6 --- /dev/null +++ b/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java @@ -0,0 +1,5 @@ +package gtPlusPlus.core.util.minecraft; + +public class HazmatUtils { + +} -- cgit From c0bea0f7df83c34cab115ec8f050f7e4ac8f2404 Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Mon, 8 Apr 2019 14:43:42 +1000 Subject: + Added ways to provide custom Hazmat armour. --- .../core/util/minecraft/HazmatUtils.java | 58 ++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'src/Java/gtPlusPlus/core/util') diff --git a/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java index 2f160c3cf6..f05b1ef393 100644 --- a/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java +++ b/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java @@ -1,5 +1,63 @@ package gtPlusPlus.core.util.minecraft; +import static gregtech.api.GregTech_API.sBioHazmatList; +import static gregtech.api.GregTech_API.sElectroHazmatList; +import static gregtech.api.GregTech_API.sFrostHazmatList; +import static gregtech.api.GregTech_API.sGasHazmatList; +import static gregtech.api.GregTech_API.sHeatHazmatList; +import static gregtech.api.GregTech_API.sRadioHazmatList; + +import gregtech.api.objects.GT_HashSet; +import gtPlusPlus.api.objects.data.AutoMap; +import net.minecraft.item.ItemStack; + public class HazmatUtils { + /** + * Registers the {@link ItemStack} to all types of protection. + * Provides full hazmat protection. Frost, Fire, Bio, Gas, Radioaton & Electricity. + * @param aStack - The Armour to provide protection. + * @return - Did we register this ItemStack properly? + */ + public boolean addProtection(ItemStack aStack) { + AutoMap aAdded = new AutoMap(); + aAdded.put(addProtection_Frost(aStack)); + aAdded.put(addProtection_Fire(aStack)); + aAdded.put(addProtection_Biohazard(aStack)); + aAdded.put(addProtection_Gas(aStack)); + aAdded.put(addProtection_Radiation(aStack)); + aAdded.put(addProtection_Electricty(aStack)); + for (boolean b : aAdded) { + if (!b) { + return false; + } + } + return true; + } + + public static boolean addProtection_Frost(ItemStack aStack) { + return addProtection_Generic(sFrostHazmatList, aStack); + } + public static boolean addProtection_Fire(ItemStack aStack) { + return addProtection_Generic(sHeatHazmatList, aStack); + } + public static boolean addProtection_Biohazard(ItemStack aStack) { + return addProtection_Generic(sBioHazmatList, aStack); + } + public static boolean addProtection_Gas(ItemStack aStack) { + return addProtection_Generic(sGasHazmatList, aStack); + } + public static boolean addProtection_Radiation(ItemStack aStack) { + return addProtection_Generic(sRadioHazmatList, aStack); + } + public static boolean addProtection_Electricty(ItemStack aStack) { + return addProtection_Generic(sElectroHazmatList, aStack); + } + + private static boolean addProtection_Generic(GT_HashSet aSet, ItemStack aStack) { + int aMapSize = aSet.size(); + aSet.add(aStack); + return aMapSize < aSet.size(); + } + } -- cgit From b6368490a3d910bcff1837b15f44bd78411d37bd Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Mon, 8 Apr 2019 16:04:31 +1000 Subject: + Added Custom tooltips to Items with Hazmat bonuses granted by GT++. + Made AutoMap implement List. % More work on HazmatUtils.java. $ Fixed a bug with my GeneralTooltipEventHandler. --- src/Java/gtPlusPlus/api/objects/data/AutoMap.java | 79 ++++++++- .../handler/events/GeneralTooltipEventHandler.java | 14 +- .../core/util/minecraft/HazmatUtils.java | 190 ++++++++++++++++++++- 3 files changed, 269 insertions(+), 14 deletions(-) (limited to 'src/Java/gtPlusPlus/core/util') diff --git a/src/Java/gtPlusPlus/api/objects/data/AutoMap.java b/src/Java/gtPlusPlus/api/objects/data/AutoMap.java index 4663229514..fe2caa466d 100644 --- a/src/Java/gtPlusPlus/api/objects/data/AutoMap.java +++ b/src/Java/gtPlusPlus/api/objects/data/AutoMap.java @@ -3,7 +3,7 @@ package gtPlusPlus.api.objects.data; import java.io.Serializable; import java.util.*; -public class AutoMap implements Iterable, Cloneable, Serializable, Collection, Queue { +public class AutoMap implements Iterable, Cloneable, Serializable, Collection, Queue, List { /** * The Internal Map @@ -22,6 +22,10 @@ public class AutoMap implements Iterable, Cloneable, Serializable, Collect this(new LinkedHashMap()); } + public Map getMap(){ + return mInternalMap; + } + public AutoMap(Map defaultMapType) { mInternalMap = defaultMapType; mInternalNameMap = new LinkedHashMap(); @@ -211,5 +215,78 @@ public class AutoMap implements Iterable, Cloneable, Serializable, Collect public V peek() { return element(); } + + @Override + public boolean addAll(int index, Collection c) { + for (V y : c) { + add(y); + } + return true; + } + + @Override + public V set(int index, V element) { + return mInternalMap.put(index, element); + } + + @Override + public void add(int index, V element) { + add(element); + } + + @Override + public V remove(int index) { + V h = mInternalMap.get(index); + set(index, null); + return h; + } + + @Override + public int indexOf(Object o) { + int aCount = 0; + for (V of : mInternalMap.values()) { + if (of != o) { + aCount++; + continue; + } + else { + return aCount; + } + } + return -1; + } + + @Override + public int lastIndexOf(Object o) { + //TODO + return indexOf(o); + } + + @Override + public ListIterator listIterator() { + // TODO Auto-generated method stub + return null; + } + + @Override + public ListIterator listIterator(int index) { + // TODO Auto-generated method stub + return null; + } + + @Override + public List subList(int fromIndex, int toIndex) { + AutoMap aNewSubList = new AutoMap(); + for (int slot=fromIndex; slot<=toIndex; slot++) { + V obj = mInternalMap.get(slot); + if (obj == null) { + continue; + } + else { + aNewSubList.put(obj); + } + } + return aNewSubList; + } } diff --git a/src/Java/gtPlusPlus/core/handler/events/GeneralTooltipEventHandler.java b/src/Java/gtPlusPlus/core/handler/events/GeneralTooltipEventHandler.java index ef91647c1a..5b49b495ce 100644 --- a/src/Java/gtPlusPlus/core/handler/events/GeneralTooltipEventHandler.java +++ b/src/Java/gtPlusPlus/core/handler/events/GeneralTooltipEventHandler.java @@ -1,22 +1,16 @@ package gtPlusPlus.core.handler.events; import cpw.mods.fml.common.eventhandler.SubscribeEvent; - -import net.minecraft.block.Block; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.util.EnumChatFormatting; - import gregtech.api.enums.ItemList; -import gregtech.api.util.GT_Utility; import gtPlusPlus.GTplusplus; import gtPlusPlus.GTplusplus.INIT_PHASE; -import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.block.ModBlocks; -import gtPlusPlus.core.handler.events.BlockEventHandler; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.util.minecraft.ItemUtils; import gtPlusPlus.core.util.sys.KeyboardUtils; +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.event.entity.player.ItemTooltipEvent; public class GeneralTooltipEventHandler { @@ -29,7 +23,7 @@ public class GeneralTooltipEventHandler { public void onItemTooltip(ItemTooltipEvent event){ - if (GTplusplus.CURRENT_LOAD_PHASE != INIT_PHASE.STARTED && GTplusplus.CURRENT_LOAD_PHASE != INIT_PHASE.SERVER_START) { + if (GTplusplus.CURRENT_LOAD_PHASE != INIT_PHASE.STARTED || GTplusplus.CURRENT_LOAD_PHASE != INIT_PHASE.SERVER_START) { return; } if (event.itemStack == null) { diff --git a/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java index f05b1ef393..638e5dec10 100644 --- a/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java +++ b/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java @@ -7,50 +7,186 @@ import static gregtech.api.GregTech_API.sGasHazmatList; import static gregtech.api.GregTech_API.sHeatHazmatList; import static gregtech.api.GregTech_API.sRadioHazmatList; +import java.util.Collections; +import java.util.HashMap; + +import cpw.mods.fml.common.eventhandler.SubscribeEvent; import gregtech.api.objects.GT_HashSet; +import gregtech.api.objects.GT_ItemStack; +import gregtech.api.util.GT_ModHandler; +import gtPlusPlus.GTplusplus; +import gtPlusPlus.GTplusplus.INIT_PHASE; import gtPlusPlus.api.objects.data.AutoMap; +import gtPlusPlus.core.util.Utils; +import ic2.core.Ic2Items; +import ic2.core.item.armor.ItemArmorHazmat; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.item.ItemStack; +import net.minecraftforge.event.entity.player.ItemTooltipEvent; public class HazmatUtils { + + + public static final GT_HashSet sHazmatList = new GT_HashSet(); + + private static final HashMap> mToolTips = new HashMap>(); + + + private static boolean mInit = false; + private static HazmatUtils mInstance; + + public static void init() { + if (mInit){ + return; + } + + mInstance = new HazmatUtils(); + + sHazmatList.add(GT_ModHandler.getIC2Item("hazmatHelmet", 1L, 32767)); + sHazmatList.add(GT_ModHandler.getIC2Item("hazmatChestplate", 1L, 32767)); + sHazmatList.add(GT_ModHandler.getIC2Item("hazmatLeggings", 1L, 32767)); + sHazmatList.add(GT_ModHandler.getIC2Item("hazmatBoots", 1L, 32767)); + //Make Nano a hazmat suit + addProtection(Ic2Items.nanoHelmet); + addProtection(Ic2Items.nanoBodyarmor); + addProtection(Ic2Items.nanoLeggings); + addProtection(Ic2Items.nanoBoots); + + //Make Quantum a hazmat suit + addProtection(Ic2Items.quantumHelmet); + addProtection(Ic2Items.quantumBodyarmor); + addProtection(Ic2Items.quantumLeggings); + addProtection(Ic2Items.quantumBoots); + + Utils.registerEvent(mInstance); + + } + + private final static String mToolTipText = "Provides protection from:"; + + @SubscribeEvent + public void onItemTooltip(ItemTooltipEvent event){ + if (GTplusplus.CURRENT_LOAD_PHASE != INIT_PHASE.STARTED || GTplusplus.CURRENT_LOAD_PHASE != INIT_PHASE.SERVER_START) { + return; + } + if (event.itemStack == null || isVanillaHazmatPiece(event.itemStack)) { + return; + } + else { + ItemStack aStack = event.itemStack; + String[] aTooltips = getTooltips(aStack); + if (aTooltips == null || aTooltips.length == 0) { + return; + } + else { + if (providesProtection(aStack)) { + event.toolTip.add("Provides full hazmat protection."); + } + else { + event.toolTip.add(mToolTipText); + for (String r : aTooltips) { + event.toolTip.add(" - "+r); + } + } + } + } + } + + + /** + * Static function to replace {@link #ic2.core.item.armor.ItemArmorHazmat.hasCompleteHazmat(EntityLivingBase)}. + * Because IC2 doesn't let us register things ourself, anything registered via GT/GT++ will return true. + * @param living - Entity Wearing Armour + * @return - Does {@link EntityLivingBase} have a full hazmat suit on? + */ + public static boolean hasCompleteHazmat(EntityLivingBase living) { + //Entity is Null, cannot have Hazmat. + if (living == null || living.isDead) { + return false; + } + else { + + //Map All Player Armour slots + AutoMap aEquipment = new AutoMap(); + for (int i = 1; i < 5; ++i) { + ItemStack stack = living.getEquipmentInSlot(i); + + //Item is Null, cannot have full suit + if (stack == null) { + return false; + } + else { + aEquipment.put(stack); + } + } + + //Compare Equipment to all items mapped for full hazmat. + for (ItemStack aSlotStack : aEquipment) { + if (!isHazmatPiece(aSlotStack)) { + return false; + } + } + + //We are in some kind of full hazmat, huzzah! + return true; + } + } + + + + public static boolean isVanillaHazmatPiece(ItemStack aArmour) { + return aArmour != null ? aArmour.getItem() instanceof ItemArmorHazmat : false; + } + + public static boolean isHazmatPiece(ItemStack aStack) { + return isVanillaHazmatPiece(aStack) || providesProtection(aStack); + } + /** * Registers the {@link ItemStack} to all types of protection. * Provides full hazmat protection. Frost, Fire, Bio, Gas, Radioaton & Electricity. * @param aStack - The Armour to provide protection. * @return - Did we register this ItemStack properly? */ - public boolean addProtection(ItemStack aStack) { + public static boolean addProtection(ItemStack aStack) { AutoMap aAdded = new AutoMap(); aAdded.put(addProtection_Frost(aStack)); aAdded.put(addProtection_Fire(aStack)); aAdded.put(addProtection_Biohazard(aStack)); aAdded.put(addProtection_Gas(aStack)); aAdded.put(addProtection_Radiation(aStack)); - aAdded.put(addProtection_Electricty(aStack)); + aAdded.put(addProtection_Electricty(aStack)); for (boolean b : aAdded) { if (!b) { return false; } } + sHazmatList.add(aStack); return true; } - public static boolean addProtection_Frost(ItemStack aStack) { + registerTooltip(aStack, "Frost"); return addProtection_Generic(sFrostHazmatList, aStack); } public static boolean addProtection_Fire(ItemStack aStack) { + registerTooltip(aStack, "Heat"); return addProtection_Generic(sHeatHazmatList, aStack); } public static boolean addProtection_Biohazard(ItemStack aStack) { + registerTooltip(aStack, "Biohazards"); return addProtection_Generic(sBioHazmatList, aStack); } public static boolean addProtection_Gas(ItemStack aStack) { + registerTooltip(aStack, "Gas"); return addProtection_Generic(sGasHazmatList, aStack); } public static boolean addProtection_Radiation(ItemStack aStack) { + registerTooltip(aStack, "Radiation"); return addProtection_Generic(sRadioHazmatList, aStack); } public static boolean addProtection_Electricty(ItemStack aStack) { + registerTooltip(aStack, "Electricity"); return addProtection_Generic(sElectroHazmatList, aStack); } @@ -60,4 +196,52 @@ public class HazmatUtils { return aMapSize < aSet.size(); } + public static boolean providesProtection(ItemStack aStack) { + return providesProtetion_Generic(sHazmatList, aStack); + } + public static boolean providesProtetion_Frost(ItemStack aStack) { + return providesProtetion_Generic(sFrostHazmatList, aStack); + } + public static boolean providesProtetion_Fire(ItemStack aStack) { + return providesProtetion_Generic(sHeatHazmatList, aStack); + } + public static boolean providesProtetion_Biohazard(ItemStack aStack) { + return providesProtetion_Generic(sBioHazmatList, aStack); + } + public static boolean providesProtetion_Gas(ItemStack aStack) { + return providesProtetion_Generic(sGasHazmatList, aStack); + } + public static boolean providesProtetion_Radiation(ItemStack aStack) { + return providesProtetion_Generic(sRadioHazmatList, aStack); + } + public static boolean providesProtetion_Electricity(ItemStack aStack) { + return providesProtetion_Generic(sElectroHazmatList, aStack); + } + + private static boolean providesProtetion_Generic(GT_HashSet aSet, ItemStack aStack) { + if (isVanillaHazmatPiece(aStack)) { + return true; + } + return aSet.getMap().containsKey(aStack); + } + + private static String[] getTooltips(ItemStack aStack) { + AutoMap aTempTooltipData = mToolTips.get(aStack); + if (aTempTooltipData == null) { + return new String[] {}; + } + else { + Collections.sort(aTempTooltipData); + return aTempTooltipData.toArray(); + } + } + + private static void registerTooltip(ItemStack aStack, String aTooltip) { + AutoMap aTempTooltipData = mToolTips.get(aStack); + if (aTempTooltipData == null) { + aTempTooltipData = new AutoMap(); + } + aTempTooltipData.add(aTooltip); + } + } -- cgit From 08e93930faa225c4bcd91115160e91671aaa4884 Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Mon, 8 Apr 2019 16:41:11 +1000 Subject: $ Finished work on HazmatUtils.java. < Reverted the changes to GeneralTooltipEventHandler.java. --- src/Java/gtPlusPlus/GTplusplus.java | 2 + .../general/redstone/BlockGenericRedstoneTest.java | 9 +-- .../handler/events/GeneralTooltipEventHandler.java | 2 +- .../core/util/minecraft/HazmatUtils.java | 81 ++++++++++++++++------ .../xmod/ic2/item/reactor/IC2_FuelRod_Base.java | 52 ++++++++++++++ 5 files changed, 115 insertions(+), 31 deletions(-) create mode 100644 src/Java/gtPlusPlus/xmod/ic2/item/reactor/IC2_FuelRod_Base.java (limited to 'src/Java/gtPlusPlus/core/util') diff --git a/src/Java/gtPlusPlus/GTplusplus.java b/src/Java/gtPlusPlus/GTplusplus.java index e10369abe3..429ead6266 100644 --- a/src/Java/gtPlusPlus/GTplusplus.java +++ b/src/Java/gtPlusPlus/GTplusplus.java @@ -46,6 +46,7 @@ import gtPlusPlus.core.material.nuclear.FLUORIDES; import gtPlusPlus.core.util.Utils; import gtPlusPlus.core.util.data.LocaleUtils; import gtPlusPlus.core.util.minecraft.FluidUtils; +import gtPlusPlus.core.util.minecraft.HazmatUtils; import gtPlusPlus.core.util.minecraft.ItemUtils; import gtPlusPlus.core.util.minecraft.RecipeUtils; import gtPlusPlus.core.util.reflect.ReflectionUtils; @@ -186,6 +187,7 @@ public class GTplusplus implements ActionListener { INIT_PHASE.INIT.setPhaseActive(true); mChunkLoading.init(event); proxy.init(event); + HazmatUtils.init(); proxy.registerNetworkStuff(); instanceGtProxy.init(); Core_Manager.init(); diff --git a/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstoneTest.java b/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstoneTest.java index ad59a83d0c..0f1f983cd0 100644 --- a/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstoneTest.java +++ b/src/Java/gtPlusPlus/core/block/general/redstone/BlockGenericRedstoneTest.java @@ -45,7 +45,6 @@ public class BlockGenericRedstoneTest extends BlockGenericRedstone { @Override public boolean onScrewdriverLMB() { - // TODO Auto-generated method stub return super.onScrewdriverLMB(); } @@ -68,7 +67,6 @@ public class BlockGenericRedstoneTest extends BlockGenericRedstone { @Override public boolean onMalletLMB() { - // TODO Auto-generated method stub return super.onMalletLMB(); } @@ -86,7 +84,6 @@ public class BlockGenericRedstoneTest extends BlockGenericRedstone { @Override public boolean onWrenchLMB() { - // TODO Auto-generated method stub return super.onWrenchLMB(); } @@ -105,23 +102,21 @@ public class BlockGenericRedstoneTest extends BlockGenericRedstone { @Override protected String getTileEntityNameForRegistration() { - // TODO Auto-generated method stub return "TileEntityRedstoneTest"; } @Override public int isProvidingWeakPower(IBlockAccess world, int x, int y, int z, int side) { - // TODO Auto-generated method stub return super.isProvidingWeakPower(world, x, y, z, side); } @Override public int isProvidingStrongPower(IBlockAccess world, int x, int y, int z, int side) { - // TODO Auto-generated method stub return super.isProvidingStrongPower(world, x, y, z, side); } } + @SuppressWarnings("unchecked") @Override public void getSubBlocks(Item p_149666_1_, CreativeTabs p_149666_2_, List aList) { aList.add(ItemUtils.getSimpleStack(this)); @@ -135,13 +130,11 @@ public class BlockGenericRedstoneTest extends BlockGenericRedstone { @Override public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_) { - // TODO Auto-generated method stub return ItemUtils.getSimpleStack(this).getItem(); } @Override public Item getItem(World p_149694_1_, int p_149694_2_, int p_149694_3_, int p_149694_4_) { - // TODO Auto-generated method stub return ItemUtils.getSimpleStack(this).getItem(); } diff --git a/src/Java/gtPlusPlus/core/handler/events/GeneralTooltipEventHandler.java b/src/Java/gtPlusPlus/core/handler/events/GeneralTooltipEventHandler.java index 5b49b495ce..fda7760607 100644 --- a/src/Java/gtPlusPlus/core/handler/events/GeneralTooltipEventHandler.java +++ b/src/Java/gtPlusPlus/core/handler/events/GeneralTooltipEventHandler.java @@ -23,7 +23,7 @@ public class GeneralTooltipEventHandler { public void onItemTooltip(ItemTooltipEvent event){ - if (GTplusplus.CURRENT_LOAD_PHASE != INIT_PHASE.STARTED || GTplusplus.CURRENT_LOAD_PHASE != INIT_PHASE.SERVER_START) { + if (GTplusplus.CURRENT_LOAD_PHASE != INIT_PHASE.STARTED && GTplusplus.CURRENT_LOAD_PHASE != INIT_PHASE.SERVER_START) { return; } if (event.itemStack == null) { diff --git a/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java index 638e5dec10..ed5b2bcdf6 100644 --- a/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java +++ b/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java @@ -16,12 +16,14 @@ import gregtech.api.objects.GT_ItemStack; import gregtech.api.util.GT_ModHandler; import gtPlusPlus.GTplusplus; import gtPlusPlus.GTplusplus.INIT_PHASE; +import gtPlusPlus.api.objects.Logger; import gtPlusPlus.api.objects.data.AutoMap; import gtPlusPlus.core.util.Utils; import ic2.core.Ic2Items; import ic2.core.item.armor.ItemArmorHazmat; import net.minecraft.entity.EntityLivingBase; import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.event.entity.player.ItemTooltipEvent; public class HazmatUtils { @@ -29,7 +31,7 @@ public class HazmatUtils { public static final GT_HashSet sHazmatList = new GT_HashSet(); - private static final HashMap> mToolTips = new HashMap>(); + private static final HashMap> mToolTips = new HashMap>(); private static boolean mInit = false; @@ -67,20 +69,27 @@ public class HazmatUtils { @SubscribeEvent public void onItemTooltip(ItemTooltipEvent event){ - if (GTplusplus.CURRENT_LOAD_PHASE != INIT_PHASE.STARTED || GTplusplus.CURRENT_LOAD_PHASE != INIT_PHASE.SERVER_START) { + Logger.INFO("Ticking Hazmat handler"); + if (GTplusplus.CURRENT_LOAD_PHASE != INIT_PHASE.STARTED && GTplusplus.CURRENT_LOAD_PHASE != INIT_PHASE.SERVER_START) { + Logger.INFO("Bad Phase : "+GTplusplus.CURRENT_LOAD_PHASE); return; } if (event.itemStack == null || isVanillaHazmatPiece(event.itemStack)) { + Logger.INFO("Invalid Itemstack or vanilla hazmat"); return; } else { - ItemStack aStack = event.itemStack; + Logger.INFO("Finding Tooltip Data"); + ItemStack aStackTemp = event.itemStack; + GT_ItemStack aStack = new GT_ItemStack(aStackTemp); String[] aTooltips = getTooltips(aStack); if (aTooltips == null || aTooltips.length == 0) { + Logger.INFO("No Info!"); return; } - else { - if (providesProtection(aStack)) { + else { + Logger.INFO("Found Tooltips!"); + if (providesProtection(aStackTemp)) { event.toolTip.add("Provides full hazmat protection."); } else { @@ -134,11 +143,20 @@ public class HazmatUtils { } - + /** + * Is this item vanilla IC2 hazmat? + * @param aArmour - The Armour to provide protection. + * @return + */ public static boolean isVanillaHazmatPiece(ItemStack aArmour) { return aArmour != null ? aArmour.getItem() instanceof ItemArmorHazmat : false; } + /** + * Is this item a registered piece of full hazmat? (Provides all 6 protections) + * @param aStack - The Armour to provide protection. + * @return + */ public static boolean isHazmatPiece(ItemStack aStack) { return isVanillaHazmatPiece(aStack) || providesProtection(aStack); } @@ -149,7 +167,8 @@ public class HazmatUtils { * @param aStack - The Armour to provide protection. * @return - Did we register this ItemStack properly? */ - public static boolean addProtection(ItemStack aStack) { + public static boolean addProtection(ItemStack aVanStack) { + GT_ItemStack aStack = getGtStackFromVanilla(aVanStack); AutoMap aAdded = new AutoMap(); aAdded.put(addProtection_Frost(aStack)); aAdded.put(addProtection_Fire(aStack)); @@ -165,37 +184,43 @@ public class HazmatUtils { sHazmatList.add(aStack); return true; } - public static boolean addProtection_Frost(ItemStack aStack) { - registerTooltip(aStack, "Frost"); + public static boolean addProtection_Frost(GT_ItemStack aStack) { + registerTooltip(aStack, EnumChatFormatting.AQUA+"Frost"); return addProtection_Generic(sFrostHazmatList, aStack); } - public static boolean addProtection_Fire(ItemStack aStack) { - registerTooltip(aStack, "Heat"); + public static boolean addProtection_Fire(GT_ItemStack aStack) { + registerTooltip(aStack, EnumChatFormatting.DARK_RED+"Heat"); return addProtection_Generic(sHeatHazmatList, aStack); } - public static boolean addProtection_Biohazard(ItemStack aStack) { - registerTooltip(aStack, "Biohazards"); + public static boolean addProtection_Biohazard(GT_ItemStack aStack) { + registerTooltip(aStack, EnumChatFormatting.GREEN+"Biohazards"); return addProtection_Generic(sBioHazmatList, aStack); } - public static boolean addProtection_Gas(ItemStack aStack) { - registerTooltip(aStack, "Gas"); + public static boolean addProtection_Gas(GT_ItemStack aStack) { + registerTooltip(aStack, EnumChatFormatting.WHITE+"Gas"); return addProtection_Generic(sGasHazmatList, aStack); } - public static boolean addProtection_Radiation(ItemStack aStack) { - registerTooltip(aStack, "Radiation"); + public static boolean addProtection_Radiation(GT_ItemStack aStack) { + registerTooltip(aStack, EnumChatFormatting.DARK_GREEN+"Radiation"); return addProtection_Generic(sRadioHazmatList, aStack); } - public static boolean addProtection_Electricty(ItemStack aStack) { - registerTooltip(aStack, "Electricity"); + public static boolean addProtection_Electricty(GT_ItemStack aStack) { + registerTooltip(aStack, EnumChatFormatting.YELLOW+"Electricity"); return addProtection_Generic(sElectroHazmatList, aStack); } - private static boolean addProtection_Generic(GT_HashSet aSet, ItemStack aStack) { + private static boolean addProtection_Generic(GT_HashSet aSet, GT_ItemStack aStack) { int aMapSize = aSet.size(); aSet.add(aStack); return aMapSize < aSet.size(); } + /** + * Does this item provide hazmat protection? (Protection against Frost, Heat, Bio, Gas, Rads, Elec) + * An item may return false even if it protects against all six damage types. This is because it's not actually registered as hazmat correct. + * @param aStack - The item to check for protection + * @return + */ public static boolean providesProtection(ItemStack aStack) { return providesProtetion_Generic(sHazmatList, aStack); } @@ -225,18 +250,22 @@ public class HazmatUtils { return aSet.getMap().containsKey(aStack); } - private static String[] getTooltips(ItemStack aStack) { + + private static String[] getTooltips(GT_ItemStack aStack) { AutoMap aTempTooltipData = mToolTips.get(aStack); if (aTempTooltipData == null) { + Logger.INFO("Item was not mapped for TTs"); return new String[] {}; } else { + Logger.INFO("Item was mapped for TTs"); Collections.sort(aTempTooltipData); + Logger.INFO("Sorted TTs"); return aTempTooltipData.toArray(); } } - private static void registerTooltip(ItemStack aStack, String aTooltip) { + private static void registerTooltip(GT_ItemStack aStack, String aTooltip) { AutoMap aTempTooltipData = mToolTips.get(aStack); if (aTempTooltipData == null) { aTempTooltipData = new AutoMap(); @@ -244,4 +273,12 @@ public class HazmatUtils { aTempTooltipData.add(aTooltip); } + public static ItemStack getStackFromGtStack(GT_ItemStack aGtStack) { + return ItemUtils.simpleMetaStack(aGtStack.mItem, aGtStack.mMetaData, aGtStack.mStackSize); + } + + public static GT_ItemStack getGtStackFromVanilla(ItemStack aStack) { + return new GT_ItemStack(aStack); + } + } diff --git a/src/Java/gtPlusPlus/xmod/ic2/item/reactor/IC2_FuelRod_Base.java b/src/Java/gtPlusPlus/xmod/ic2/item/reactor/IC2_FuelRod_Base.java new file mode 100644 index 0000000000..01151024c4 --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/ic2/item/reactor/IC2_FuelRod_Base.java @@ -0,0 +1,52 @@ +package gtPlusPlus.xmod.ic2.item.reactor; + +import ic2.api.reactor.IReactor; +import ic2.api.reactor.IReactorComponent; +import net.minecraft.item.ItemStack; + +public class IC2_FuelRod_Base implements IReactorComponent { + + @Override + public void processChamber(IReactor var1, ItemStack var2, int var3, int var4, boolean var5) { + // TODO Auto-generated method stub + + } + + @Override + public boolean acceptUraniumPulse(IReactor var1, ItemStack var2, ItemStack var3, int var4, int var5, int var6, + int var7, boolean var8) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean canStoreHeat(IReactor var1, ItemStack var2, int var3, int var4) { + // TODO Auto-generated method stub + return false; + } + + @Override + public int getMaxHeat(IReactor var1, ItemStack var2, int var3, int var4) { + // TODO Auto-generated method stub + return 0; + } + + @Override + public int getCurrentHeat(IReactor var1, ItemStack var2, int var3, int var4) { + // TODO Auto-generated method stub + return 0; + } + + @Override + public int alterHeat(IReactor var1, ItemStack var2, int var3, int var4, int var5) { + // TODO Auto-generated method stub + return 0; + } + + @Override + public float influenceExplosion(IReactor var1, ItemStack var2) { + // TODO Auto-generated method stub + return 0; + } + +} -- cgit From 75d417bfadc00fe14cfa3322a89dfc4b929919d4 Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Tue, 9 Apr 2019 14:28:22 +1000 Subject: + Added some new OSRS materials. % Logging tweaks to HazmatUtils.java. --- src/Java/gtPlusPlus/core/item/ModItems.java | 8 +++++- src/Java/gtPlusPlus/core/material/ELEMENT.java | 8 ++++++ .../core/util/minecraft/HazmatUtils.java | 30 ++++++++++++++-------- 3 files changed, 35 insertions(+), 11 deletions(-) (limited to 'src/Java/gtPlusPlus/core/util') diff --git a/src/Java/gtPlusPlus/core/item/ModItems.java b/src/Java/gtPlusPlus/core/item/ModItems.java index e8f0e31458..aa450ccd4b 100644 --- a/src/Java/gtPlusPlus/core/item/ModItems.java +++ b/src/Java/gtPlusPlus/core/item/ModItems.java @@ -522,7 +522,13 @@ public final class ModItems { MaterialGenerator.generate(ELEMENT.STANDALONE.CELESTIAL_TUNGSTEN); MaterialGenerator.generate(ELEMENT.STANDALONE.HYPOGEN); MaterialGenerator.generate(ELEMENT.STANDALONE.CHRONOMATIC_GLASS); - + + //Custom Materials that are from Runescape + MaterialGenerator.generate(ELEMENT.STANDALONE.BLACK_METAL); + MaterialGenerator.generate(ELEMENT.STANDALONE.WHITE_METAL); + MaterialGenerator.generate(ELEMENT.STANDALONE.GRANITE); + MaterialGenerator.generate(ELEMENT.STANDALONE.RUNITE); + MaterialGenerator.generate(ELEMENT.STANDALONE.DRAGON_METAL); //Carbides - Tungsten Carbide exists in .09 so don't generate it. - Should still come before alloys though if (!CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK){ diff --git a/src/Java/gtPlusPlus/core/material/ELEMENT.java b/src/Java/gtPlusPlus/core/material/ELEMENT.java index 62e1163a39..9a4947027d 100644 --- a/src/Java/gtPlusPlus/core/material/ELEMENT.java +++ b/src/Java/gtPlusPlus/core/material/ELEMENT.java @@ -214,6 +214,14 @@ public final class ELEMENT { public static final Material ADVANCED_NITINOL = new Material("Advanced Nitinol", MaterialState.SOLID, TextureSets.ENRICHED.get(), ALLOY.NITINOL_60.getRGB(), 8400, 14377, 40, 51, true, "⚷⚙⚷ Ni4Ti6", 0);//Not a GT Inherited Material public static final Material HYPOGEN = new Material("Hypogen", MaterialState.SOLID, TextureSets.NUCLEAR.get(), new short[]{220, 120, 75}, 12255, 19377, 240, 251, true, "Hy⚶", 0);//Not a GT Inherited Material + + //Runescape materials + public static final Material BLACK_METAL = new Material("Black", MaterialState.SOLID, TextureSet.SET_FINE, new short[] {5, 5, 5}, 2350, 4650, 24, 17, false, "҈", 0);//Not a GT Inherited Material + public static final Material WHITE_METAL = new Material("White", MaterialState.SOLID, TextureSet.SET_FINE, new short[] {250, 250, 250}, 4560, 7580, 35, 41, false, "҉", 0);//Not a GT Inherited Material + public static final Material GRANITE = new Material("Ancient Granite", MaterialState.SOLID, TextureSet.SET_SAND, new short[] {127, 127, 127}, 500, 2000, 16, 12, false, "«»", 0);//Not a GT Inherited Material + public static final Material RUNITE = new Material("Runite", MaterialState.SOLID, TextureSet.SET_METALLIC, new short[] {20, 40, 220}, 6750, 11550, 73, 87, true, "§", 0);//Not a GT Inherited Material + public static final Material DRAGON_METAL = new Material("Dragon", MaterialState.SOLID, TextureSet.SET_SHINY, new short[] {220, 40, 20}, 12560, 19850, 96, 105, true, "۞", 0);//Not a GT Inherited Material + } diff --git a/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java index ed5b2bcdf6..e6ffe1e89d 100644 --- a/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java +++ b/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java @@ -55,13 +55,18 @@ public class HazmatUtils { addProtection(Ic2Items.nanoLeggings); addProtection(Ic2Items.nanoBoots); + Logger.INFO("[Hazmat] Registered Nano as hazmat gear."); + //Make Quantum a hazmat suit addProtection(Ic2Items.quantumHelmet); addProtection(Ic2Items.quantumBodyarmor); addProtection(Ic2Items.quantumLeggings); - addProtection(Ic2Items.quantumBoots); + addProtection(Ic2Items.quantumBoots); + Logger.INFO("[Hazmat] Registered Quantum as hazmat gear."); - Utils.registerEvent(mInstance); + Utils.registerEvent(mInstance); + Logger.INFO("[Hazmat] Registered Tooltip handler for hazmat gear."); + mInit = true; } @@ -71,24 +76,24 @@ public class HazmatUtils { public void onItemTooltip(ItemTooltipEvent event){ Logger.INFO("Ticking Hazmat handler"); if (GTplusplus.CURRENT_LOAD_PHASE != INIT_PHASE.STARTED && GTplusplus.CURRENT_LOAD_PHASE != INIT_PHASE.SERVER_START) { - Logger.INFO("Bad Phase : "+GTplusplus.CURRENT_LOAD_PHASE); + Logger.INFO("[Hazmat] Bad Phase : "+GTplusplus.CURRENT_LOAD_PHASE); return; } if (event.itemStack == null || isVanillaHazmatPiece(event.itemStack)) { - Logger.INFO("Invalid Itemstack or vanilla hazmat"); + Logger.INFO("[Hazmat] Invalid Itemstack or vanilla hazmat"); return; } else { - Logger.INFO("Finding Tooltip Data"); + Logger.INFO("[Hazmat] Finding Tooltip Data"); ItemStack aStackTemp = event.itemStack; GT_ItemStack aStack = new GT_ItemStack(aStackTemp); String[] aTooltips = getTooltips(aStack); if (aTooltips == null || aTooltips.length == 0) { - Logger.INFO("No Info!"); + Logger.INFO("[Hazmat] No Info!"); return; } else { - Logger.INFO("Found Tooltips!"); + Logger.INFO("[Hazmat] Found Tooltips!"); if (providesProtection(aStackTemp)) { event.toolTip.add("Provides full hazmat protection."); } @@ -168,6 +173,7 @@ public class HazmatUtils { * @return - Did we register this ItemStack properly? */ public static boolean addProtection(ItemStack aVanStack) { + Logger.INFO("[Hazmat] Registering "+aVanStack.getDisplayName() +" for full Hazmat protection."); GT_ItemStack aStack = getGtStackFromVanilla(aVanStack); AutoMap aAdded = new AutoMap(); aAdded.put(addProtection_Frost(aStack)); @@ -181,6 +187,7 @@ public class HazmatUtils { return false; } } + Logger.INFO("[Hazmat] Protection added for all 6 damage types, registering to master Hazmat list."); sHazmatList.add(aStack); return true; } @@ -254,23 +261,26 @@ public class HazmatUtils { private static String[] getTooltips(GT_ItemStack aStack) { AutoMap aTempTooltipData = mToolTips.get(aStack); if (aTempTooltipData == null) { - Logger.INFO("Item was not mapped for TTs"); + Logger.INFO("[Hazmat] Item was not mapped for TTs"); return new String[] {}; } else { - Logger.INFO("Item was mapped for TTs"); + Logger.INFO("[Hazmat] Item was mapped for TTs"); Collections.sort(aTempTooltipData); - Logger.INFO("Sorted TTs"); + Logger.INFO("[Hazmat] Sorted TTs"); return aTempTooltipData.toArray(); } } private static void registerTooltip(GT_ItemStack aStack, String aTooltip) { + Logger.INFO("[Hazmat] Mapping "+aTooltip+" for "+getStackFromGtStack(aStack).getDisplayName()); AutoMap aTempTooltipData = mToolTips.get(aStack); if (aTempTooltipData == null) { + Logger.INFO("No data mapped yet, creating."); aTempTooltipData = new AutoMap(); } aTempTooltipData.add(aTooltip); + mToolTips.put(aStack, aTempTooltipData); } public static ItemStack getStackFromGtStack(GT_ItemStack aGtStack) { -- cgit From d087513a06066296455b1cdc00164398c0260da3 Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Thu, 11 Apr 2019 00:31:16 +1000 Subject: + Added some base classes for future content. + Made Teflon a refined version of PTFE. $ Fixed bad usage of PRASEODYMIUM. $ Fixed bug regrading null chemical symbols on Materials. $ Finally fixed Nano/Quantum handling for Hazmat. $ Fixed Worldgen in Everglades being too dense. --- .../core/item/bauble/MonsterKillerBaseBauble.java | 5 + .../core/item/chemistry/GenericChem.java | 28 +- .../item/wearable/armour/hazmat/ArmourHazmat.java | 117 ++++++++ src/Java/gtPlusPlus/core/material/ALLOY.java | 2 +- src/Java/gtPlusPlus/core/material/Material.java | 7 +- src/Java/gtPlusPlus/core/material/NONMATERIAL.java | 6 +- .../core/util/minecraft/HazmatUtils.java | 268 +++++++++++------- .../everglades/gen/gt/WorldGen_Ores.java | 309 ++++----------------- src/resources/assets/gregtech/lang/en_US.lang | 6 +- 9 files changed, 375 insertions(+), 373 deletions(-) create mode 100644 src/Java/gtPlusPlus/core/item/bauble/MonsterKillerBaseBauble.java create mode 100644 src/Java/gtPlusPlus/core/item/wearable/armour/hazmat/ArmourHazmat.java (limited to 'src/Java/gtPlusPlus/core/util') diff --git a/src/Java/gtPlusPlus/core/item/bauble/MonsterKillerBaseBauble.java b/src/Java/gtPlusPlus/core/item/bauble/MonsterKillerBaseBauble.java new file mode 100644 index 0000000000..213a3f5b7c --- /dev/null +++ b/src/Java/gtPlusPlus/core/item/bauble/MonsterKillerBaseBauble.java @@ -0,0 +1,5 @@ +package gtPlusPlus.core.item.bauble; + +public class MonsterKillerBaseBauble { + +} diff --git a/src/Java/gtPlusPlus/core/item/chemistry/GenericChem.java b/src/Java/gtPlusPlus/core/item/chemistry/GenericChem.java index 02afada849..6360429415 100644 --- a/src/Java/gtPlusPlus/core/item/chemistry/GenericChem.java +++ b/src/Java/gtPlusPlus/core/item/chemistry/GenericChem.java @@ -2,8 +2,11 @@ package gtPlusPlus.core.item.chemistry; import gregtech.api.enums.TextureSet; import gtPlusPlus.api.objects.minecraft.ItemPackage; +import gtPlusPlus.core.material.ELEMENT; import gtPlusPlus.core.material.Material; import gtPlusPlus.core.material.MaterialGenerator; +import gtPlusPlus.core.material.MaterialStack; +import gtPlusPlus.core.material.NONMATERIAL; import gtPlusPlus.core.material.state.MaterialState; import gtPlusPlus.core.util.Utils; import gtPlusPlus.core.util.minecraft.FluidUtils; @@ -18,9 +21,28 @@ public class GenericChem extends ItemPackage { * Materials */ - public static final Material BAKELITE = new Material("Bakelite", MaterialState.SOLID, TextureSet.SET_DULL, new short[]{90, 140, 140}, 120, 240, 23, 24, true, "", 0);//Not a GT Inherited Material - public static final Material NYLON = new Material("Nylon", MaterialState.SOLID, TextureSet.SET_SHINY, new short[]{45, 45, 45}, 300, 600, 44, 48, true, "", 0);//Not a GT Inherited Material - public static final Material TEFLON = new Material("Teflon", MaterialState.SOLID, TextureSet.SET_SHINY, new short[]{75, 45, 75}, 300, 600, 44, 48, true, "", 0);//Not a GT Inherited Material + public static final Material BAKELITE = new Material("Bakelite", MaterialState.SOLID, TextureSet.SET_DULL, new short[]{90, 140, 140}, 120, 240, 23, 24, true, null, 0);//Not a GT Inherited Material + public static final Material NYLON = new Material("Nylon", MaterialState.SOLID, TextureSet.SET_SHINY, new short[]{45, 45, 45}, 300, 600, 44, 48, true, null, 0);//Not a GT Inherited Material + + //Refined PTFE + public static final Material TEFLON = new Material( + "Teflon", + MaterialState.SOLID, + TextureSet.SET_SHINY, + new short[] { 75, 45, 75 }, + 330, 640, + -1, -1, + false, + null, + 0, + new MaterialStack[] { + new MaterialStack(NONMATERIAL.PTFE, 88), + new MaterialStack(NONMATERIAL.PLASTIC, 6), + new MaterialStack(ELEMENT.getInstance().CHLORINE, 3), + new MaterialStack(ELEMENT.getInstance().SODIUM, 3) + });// Not a GT + // Inherited + // Material //public static final Material HYPOGEN = new Material("Hypogen", MaterialState.SOLID, TextureSets.NUCLEAR.get(), new short[]{220, 120, 75}, 12255, 19377, 240, 251, true, "Hy⚶", 0);//Not a GT Inherited Material //public static final Material HYPOGEN = new Material("Hypogen", MaterialState.SOLID, TextureSets.NUCLEAR.get(), new short[]{220, 120, 75}, 12255, 19377, 240, 251, true, "Hy⚶", 0);//Not a GT Inherited Material diff --git a/src/Java/gtPlusPlus/core/item/wearable/armour/hazmat/ArmourHazmat.java b/src/Java/gtPlusPlus/core/item/wearable/armour/hazmat/ArmourHazmat.java new file mode 100644 index 0000000000..9fd7bf7020 --- /dev/null +++ b/src/Java/gtPlusPlus/core/item/wearable/armour/hazmat/ArmourHazmat.java @@ -0,0 +1,117 @@ +package gtPlusPlus.core.item.wearable.armour.hazmat; + +import java.util.List; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gtPlusPlus.core.item.wearable.armour.ArmourLoader; +import gtPlusPlus.core.item.wearable.armour.base.BaseArmourHelm; +import gtPlusPlus.core.lib.CORE; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.ItemStack; +import net.minecraft.util.DamageSource; +import net.minecraft.util.IIcon; +import net.minecraft.world.World; + +public class ArmourHazmat extends BaseArmourHelm { + + public IIcon iconHelm; + + public ArmourHazmat() { + super(ArmourLoader.TinFoilArmour, 0); + } + + @SideOnly(Side.CLIENT) + public void registerIcons(IIconRegister ir) { + this.iconHelm = ir.registerIcon(CORE.MODID + ":itemHatTinFoil"); + } + + @Override + public int getRenderIndex() { + return 0; + } + + @SideOnly(Side.CLIENT) + public IIcon getIconFromDamage(int par1) { + return this.iconHelm; + } + + public String getArmorTexture(ItemStack stack, Entity entity, int slot, String type) { + return CORE.MODID + ":textures/models/TinFoil.png"; + } + + public EnumRarity getRarity(ItemStack itemstack) { + return EnumRarity.rare; + } + + public boolean getIsRepairable(ItemStack par1ItemStack, ItemStack par2ItemStack) { + return false; + } + + @Override + public int getArmorDisplay(EntityPlayer player, ItemStack armor, int slot) { + return super.getArmorDisplay(player, armor, slot); + } + + @Override + public void damageArmor(EntityLivingBase entity, ItemStack stack, DamageSource source, int damage, int slot) { + + } + + @SuppressWarnings({ "unchecked" }) + @Override + public void addInformation(ItemStack p_77624_1_, EntityPlayer p_77624_2_, List aList, boolean p_77624_4_) { + aList.add("DoomSquirter's protection against cosmic radiation!"); + aList.add("General paranoia makes the wearer unable to collect xp"); + aList.add("Movement speed is also reduced, to keep you safe"); + aList.add("This hat may also have other strange powers"); + } + + @Override + public ArmorProperties getProperties(EntityLivingBase player, ItemStack armor, DamageSource source, double damage, + int slot) { + return new ArmorProperties(0, 0, 0); + } + + @Override + public boolean isDamageable() { + return false; + } + + @Override + public boolean itemInteractionForEntity(ItemStack p_111207_1_, EntityPlayer p_111207_2_, + EntityLivingBase p_111207_3_) { + return super.itemInteractionForEntity(p_111207_1_, p_111207_2_, p_111207_3_); + } + + @Override + public void onUpdate(ItemStack aStack, World aWorld, Entity aEntity, int p_77663_4_, boolean p_77663_5_) { + super.onUpdate(aStack, aWorld, aEntity, p_77663_4_, p_77663_5_); + } + + @Override + public boolean onEntityItemUpdate(EntityItem entityItem) { + return super.onEntityItemUpdate(entityItem); + } + + @Override + public void onArmorTick(World world, EntityPlayer player, ItemStack itemStack) { + if (itemStack != null && player != null && world != null && !world.isRemote) { + if (player instanceof EntityPlayer) { + + } + } + super.onArmorTick(world, player, itemStack); + } + + @Override + public boolean showDurabilityBar(ItemStack stack) { + return false; + } + +} diff --git a/src/Java/gtPlusPlus/core/material/ALLOY.java b/src/Java/gtPlusPlus/core/material/ALLOY.java index f18cd4ec73..8bcbb2a051 100644 --- a/src/Java/gtPlusPlus/core/material/ALLOY.java +++ b/src/Java/gtPlusPlus/core/material/ALLOY.java @@ -864,7 +864,7 @@ public final class ALLOY { //Material Stacks with Percentage of required elements. new MaterialStack[]{ new MaterialStack(ELEMENT.getInstance().TITANIUM, 55), - new MaterialStack(ELEMENT.getInstance().PRASEODYMIUM, 12), + new MaterialStack(ELEMENT.getInstance().LANTHANUM, 12), new MaterialStack(ELEMENT.getInstance().TUNGSTEN, 8), new MaterialStack(ELEMENT.getInstance().COBALT, 6), new MaterialStack(ELEMENT.getInstance().MANGANESE, 4), diff --git a/src/Java/gtPlusPlus/core/material/Material.java b/src/Java/gtPlusPlus/core/material/Material.java index 58a7f68afe..8fb3c5fc3b 100644 --- a/src/Java/gtPlusPlus/core/material/Material.java +++ b/src/Java/gtPlusPlus/core/material/Material.java @@ -141,7 +141,7 @@ public class Material { this (materialName, defaultState, set, durability, rgba, meltingPoint, boilingPoint, protons, neutrons, blastFurnace, chemicalSymbol, radiationLevel, true, true, inputs); } - public Material(final String materialName, final MaterialState defaultState, final TextureSet set, final long durability, short[] rgba, final int meltingPoint, final int boilingPoint, final long protons, final long neutrons, final boolean blastFurnace, final String chemicalSymbol, final int radiationLevel, boolean generateCells, boolean generateFluid, final MaterialStack... inputs){ + public Material(final String materialName, final MaterialState defaultState, final TextureSet set, final long durability, short[] rgba, final int meltingPoint, final int boilingPoint, final long protons, final long neutrons, final boolean blastFurnace, String chemicalSymbol, final int radiationLevel, boolean generateCells, boolean generateFluid, final MaterialStack... inputs){ if (mMaterialMap.add(this)) { @@ -442,6 +442,11 @@ public class Material { //Makes a Fancy Chemical Tooltip + + if (chemicalSymbol == null) { + chemicalSymbol = ""; + } + this.vChemicalSymbol = chemicalSymbol; if (this.vMaterialInput != null){ this.vChemicalFormula = this.getToolTip(chemicalSymbol, OrePrefixes.dust.mMaterialAmount / M, true); diff --git a/src/Java/gtPlusPlus/core/material/NONMATERIAL.java b/src/Java/gtPlusPlus/core/material/NONMATERIAL.java index 4da34ae16c..7ab72d50bc 100644 --- a/src/Java/gtPlusPlus/core/material/NONMATERIAL.java +++ b/src/Java/gtPlusPlus/core/material/NONMATERIAL.java @@ -27,7 +27,11 @@ public class NONMATERIAL { //Wrought Iron public static final Material WROUGHT_IRON = MaterialUtils.generateMaterialFromGtENUM(Materials.WroughtIron); - + //PTFE + public static final Material PTFE = MaterialUtils.generateMaterialFromGtENUM(MaterialUtils.getMaterial("Polytetrafluoroethylene", "Plastic")); + + //Plastic + public static final Material PLASTIC = MaterialUtils.generateMaterialFromGtENUM(MaterialUtils.getMaterial("Plastic", "Rubber")); static { diff --git a/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java index e6ffe1e89d..c37b1271d7 100644 --- a/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java +++ b/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java @@ -21,159 +21,184 @@ import gtPlusPlus.api.objects.data.AutoMap; import gtPlusPlus.core.util.Utils; import ic2.core.Ic2Items; import ic2.core.item.armor.ItemArmorHazmat; +import ic2.core.item.armor.ItemArmorNanoSuit; +import ic2.core.item.armor.ItemArmorQuantumSuit; import net.minecraft.entity.EntityLivingBase; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.event.entity.player.ItemTooltipEvent; public class HazmatUtils { - - public static final GT_HashSet sHazmatList = new GT_HashSet(); - - private static final HashMap> mToolTips = new HashMap>(); - - + public static final GT_HashSet sHazmatList = new GT_HashSet(); + + private static final HashMap> mToolTips = new HashMap>(); + private static boolean mInit = false; private static HazmatUtils mInstance; - + public static void init() { - if (mInit){ + if (mInit) { return; } - + mInstance = new HazmatUtils(); - + sHazmatList.add(GT_ModHandler.getIC2Item("hazmatHelmet", 1L, 32767)); sHazmatList.add(GT_ModHandler.getIC2Item("hazmatChestplate", 1L, 32767)); sHazmatList.add(GT_ModHandler.getIC2Item("hazmatLeggings", 1L, 32767)); sHazmatList.add(GT_ModHandler.getIC2Item("hazmatBoots", 1L, 32767)); - //Make Nano a hazmat suit - addProtection(Ic2Items.nanoHelmet); - addProtection(Ic2Items.nanoBodyarmor); - addProtection(Ic2Items.nanoLeggings); - addProtection(Ic2Items.nanoBoots); - + // Make Nano a hazmat suit + addProtection(ItemUtils.getItemStackFromFQRN("IC2:itemArmorNanoHelmet:27", 1)); + addProtection(ItemUtils.getItemStackFromFQRN("IC2:itemArmorNanoChestplate:27", 1)); + addProtection(ItemUtils.getItemStackFromFQRN("IC2:itemArmorNanoLegs:27", 1)); + addProtection(ItemUtils.getItemStackFromFQRN("IC2:itemArmorNanoBoots:27", 1)); + Logger.INFO("[Hazmat] Registered Nano as hazmat gear."); - - //Make Quantum a hazmat suit - addProtection(Ic2Items.quantumHelmet); - addProtection(Ic2Items.quantumBodyarmor); - addProtection(Ic2Items.quantumLeggings); - addProtection(Ic2Items.quantumBoots); - Logger.INFO("[Hazmat] Registered Quantum as hazmat gear."); - - Utils.registerEvent(mInstance); + + // Make Quantum a hazmat suit + addProtection(ItemUtils.getItemStackFromFQRN("IC2:itemArmorQuantumHelmet:27", 1)); + addProtection(ItemUtils.getItemStackFromFQRN("IC2:itemArmorQuantumChestplate:27", 1)); + addProtection(ItemUtils.getItemStackFromFQRN("IC2:itemArmorQuantumLegs:27", 1)); + addProtection(ItemUtils.getItemStackFromFQRN("IC2:itemArmorQuantumBoots:27", 1)); + Logger.INFO("[Hazmat] Registered Quantum as hazmat gear."); + + Utils.registerEvent(mInstance); Logger.INFO("[Hazmat] Registered Tooltip handler for hazmat gear."); mInit = true; - + } - + private final static String mToolTipText = "Provides protection from:"; - + @SubscribeEvent - public void onItemTooltip(ItemTooltipEvent event){ - Logger.INFO("Ticking Hazmat handler"); - if (GTplusplus.CURRENT_LOAD_PHASE != INIT_PHASE.STARTED && GTplusplus.CURRENT_LOAD_PHASE != INIT_PHASE.SERVER_START) { - Logger.INFO("[Hazmat] Bad Phase : "+GTplusplus.CURRENT_LOAD_PHASE); + public void onItemTooltip(ItemTooltipEvent event) { + //Logger.INFO("Ticking Hazmat handler"); + if (GTplusplus.CURRENT_LOAD_PHASE != INIT_PHASE.STARTED + && GTplusplus.CURRENT_LOAD_PHASE != INIT_PHASE.SERVER_START) { + //Logger.INFO("[Hazmat] Bad Phase : " + GTplusplus.CURRENT_LOAD_PHASE); return; } if (event.itemStack == null || isVanillaHazmatPiece(event.itemStack)) { Logger.INFO("[Hazmat] Invalid Itemstack or vanilla hazmat"); return; - } - else { - Logger.INFO("[Hazmat] Finding Tooltip Data"); + } else { ItemStack aStackTemp = event.itemStack; GT_ItemStack aStack = new GT_ItemStack(aStackTemp); - String[] aTooltips = getTooltips(aStack); - if (aTooltips == null || aTooltips.length == 0) { - Logger.INFO("[Hazmat] No Info!"); - return; + if (isNanoArmourPiece(aStackTemp) || isQuantumArmourPiece(aStackTemp)) { + event.toolTip.add("Provides full hazmat protection."); } - else { - Logger.INFO("[Hazmat] Found Tooltips!"); - if (providesProtection(aStackTemp)) { - event.toolTip.add("Provides full hazmat protection."); - } - else { - event.toolTip.add(mToolTipText); - for (String r : aTooltips) { - event.toolTip.add(" - "+r); - } - } - } - } + else { + Logger.INFO("[Hazmat] Finding Tooltip Data"); + String[] aTooltips = getTooltips(aStack); + if (aTooltips == null || aTooltips.length == 0) { + Logger.INFO("[Hazmat] No Info!"); + return; + } else { + Logger.INFO("[Hazmat] Found Tooltips!"); + if (providesProtection(aStackTemp)) { + event.toolTip.add("Provides full hazmat protection."); + } else { + event.toolTip.add(mToolTipText); + for (String r : aTooltips) { + event.toolTip.add(" - " + r); + } + } + } + } + } } - - + /** - * Static function to replace {@link #ic2.core.item.armor.ItemArmorHazmat.hasCompleteHazmat(EntityLivingBase)}. - * Because IC2 doesn't let us register things ourself, anything registered via GT/GT++ will return true. + * Static function to replace + * {@link #ic2.core.item.armor.ItemArmorHazmat.hasCompleteHazmat(EntityLivingBase)}. + * Because IC2 doesn't let us register things ourself, anything registered via + * GT/GT++ will return true. + * * @param living - Entity Wearing Armour * @return - Does {@link EntityLivingBase} have a full hazmat suit on? */ - public static boolean hasCompleteHazmat(EntityLivingBase living) { - //Entity is Null, cannot have Hazmat. + public static boolean hasCompleteHazmat(EntityLivingBase living) { + // Entity is Null, cannot have Hazmat. if (living == null || living.isDead) { return false; - } - else { - - //Map All Player Armour slots + } else { + + // Map All Player Armour slots AutoMap aEquipment = new AutoMap(); for (int i = 1; i < 5; ++i) { ItemStack stack = living.getEquipmentInSlot(i); - - //Item is Null, cannot have full suit + + // Item is Null, cannot have full suit if (stack == null) { return false; - } - else { + } else { aEquipment.put(stack); } } - - //Compare Equipment to all items mapped for full hazmat. + + // Compare Equipment to all items mapped for full hazmat. for (ItemStack aSlotStack : aEquipment) { if (!isHazmatPiece(aSlotStack)) { return false; } } - - //We are in some kind of full hazmat, huzzah! - return true; - } + + // We are in some kind of full hazmat, huzzah! + return true; + } } - - + /** * Is this item vanilla IC2 hazmat? + * * @param aArmour - The Armour to provide protection. * @return */ public static boolean isVanillaHazmatPiece(ItemStack aArmour) { - return aArmour != null ? aArmour.getItem() instanceof ItemArmorHazmat : false; - } + return aArmour != null ? aArmour.getItem() instanceof ItemArmorHazmat : false; + } + + /** + * Is this item vanilla IC2 Nanosuit? + * + * @param aArmour - The Armour to provide protection. + * @return + */ + public static boolean isNanoArmourPiece(ItemStack aArmour) { + return aArmour != null ? aArmour.getItem() instanceof ItemArmorNanoSuit : false; + } + /** + * Is this item vanilla IC2 Quantum? + * + * @param aArmour - The Armour to provide protection. + * @return + */ + public static boolean isQuantumArmourPiece(ItemStack aArmour) { + return aArmour != null ? aArmour.getItem() instanceof ItemArmorQuantumSuit : false; + } + /** * Is this item a registered piece of full hazmat? (Provides all 6 protections) + * * @param aStack - The Armour to provide protection. * @return */ public static boolean isHazmatPiece(ItemStack aStack) { return isVanillaHazmatPiece(aStack) || providesProtection(aStack); } - + /** - * Registers the {@link ItemStack} to all types of protection. - * Provides full hazmat protection. Frost, Fire, Bio, Gas, Radioaton & Electricity. + * Registers the {@link ItemStack} to all types of protection. Provides full + * hazmat protection. Frost, Fire, Bio, Gas, Radioaton & Electricity. + * * @param aStack - The Armour to provide protection. * @return - Did we register this ItemStack properly? */ - public static boolean addProtection(ItemStack aVanStack) { - Logger.INFO("[Hazmat] Registering "+aVanStack.getDisplayName() +" for full Hazmat protection."); + public static boolean addProtection(ItemStack aVanStack) { + Logger.INFO("[Hazmat] Registering " + aVanStack.getDisplayName() + " for full Hazmat protection."); GT_ItemStack aStack = getGtStackFromVanilla(aVanStack); AutoMap aAdded = new AutoMap(); aAdded.put(addProtection_Frost(aStack)); @@ -181,7 +206,7 @@ public class HazmatUtils { aAdded.put(addProtection_Biohazard(aStack)); aAdded.put(addProtection_Gas(aStack)); aAdded.put(addProtection_Radiation(aStack)); - aAdded.put(addProtection_Electricty(aStack)); + aAdded.put(addProtection_Electricty(aStack)); for (boolean b : aAdded) { if (!b) { return false; @@ -189,63 +214,78 @@ public class HazmatUtils { } Logger.INFO("[Hazmat] Protection added for all 6 damage types, registering to master Hazmat list."); sHazmatList.add(aStack); - return true; + return true; } + public static boolean addProtection_Frost(GT_ItemStack aStack) { - registerTooltip(aStack, EnumChatFormatting.AQUA+"Frost"); + registerTooltip(aStack, EnumChatFormatting.AQUA + "Frost"); return addProtection_Generic(sFrostHazmatList, aStack); } + public static boolean addProtection_Fire(GT_ItemStack aStack) { - registerTooltip(aStack, EnumChatFormatting.DARK_RED+"Heat"); + registerTooltip(aStack, EnumChatFormatting.DARK_RED + "Heat"); return addProtection_Generic(sHeatHazmatList, aStack); } + public static boolean addProtection_Biohazard(GT_ItemStack aStack) { - registerTooltip(aStack, EnumChatFormatting.GREEN+"Biohazards"); + registerTooltip(aStack, EnumChatFormatting.GREEN + "Biohazards"); return addProtection_Generic(sBioHazmatList, aStack); } + public static boolean addProtection_Gas(GT_ItemStack aStack) { - registerTooltip(aStack, EnumChatFormatting.WHITE+"Gas"); + registerTooltip(aStack, EnumChatFormatting.WHITE + "Gas"); return addProtection_Generic(sGasHazmatList, aStack); } + public static boolean addProtection_Radiation(GT_ItemStack aStack) { - registerTooltip(aStack, EnumChatFormatting.DARK_GREEN+"Radiation"); + registerTooltip(aStack, EnumChatFormatting.DARK_GREEN + "Radiation"); return addProtection_Generic(sRadioHazmatList, aStack); } + public static boolean addProtection_Electricty(GT_ItemStack aStack) { - registerTooltip(aStack, EnumChatFormatting.YELLOW+"Electricity"); + registerTooltip(aStack, EnumChatFormatting.YELLOW + "Electricity"); return addProtection_Generic(sElectroHazmatList, aStack); } - + private static boolean addProtection_Generic(GT_HashSet aSet, GT_ItemStack aStack) { int aMapSize = aSet.size(); aSet.add(aStack); return aMapSize < aSet.size(); } - + /** - * Does this item provide hazmat protection? (Protection against Frost, Heat, Bio, Gas, Rads, Elec) - * An item may return false even if it protects against all six damage types. This is because it's not actually registered as hazmat correct. + * Does this item provide hazmat protection? (Protection against Frost, Heat, + * Bio, Gas, Rads, Elec) An item may return false even if it protects against + * all six damage types. This is because it's not actually registered as hazmat + * correct. + * * @param aStack - The item to check for protection * @return */ public static boolean providesProtection(ItemStack aStack) { return providesProtetion_Generic(sHazmatList, aStack); } + public static boolean providesProtetion_Frost(ItemStack aStack) { return providesProtetion_Generic(sFrostHazmatList, aStack); } + public static boolean providesProtetion_Fire(ItemStack aStack) { return providesProtetion_Generic(sHeatHazmatList, aStack); } + public static boolean providesProtetion_Biohazard(ItemStack aStack) { return providesProtetion_Generic(sBioHazmatList, aStack); } + public static boolean providesProtetion_Gas(ItemStack aStack) { return providesProtetion_Generic(sGasHazmatList, aStack); } + public static boolean providesProtetion_Radiation(ItemStack aStack) { return providesProtetion_Generic(sRadioHazmatList, aStack); } + public static boolean providesProtetion_Electricity(ItemStack aStack) { return providesProtetion_Generic(sElectroHazmatList, aStack); } @@ -256,39 +296,55 @@ public class HazmatUtils { } return aSet.getMap().containsKey(aStack); } - - - private static String[] getTooltips(GT_ItemStack aStack) { - AutoMap aTempTooltipData = mToolTips.get(aStack); + + private static String[] getTooltips(GT_ItemStack aStack) { + String aKey = convertGtItemstackToStringData(aStack); + AutoMap aTempTooltipData = mToolTips.get(aKey); if (aTempTooltipData == null) { - Logger.INFO("[Hazmat] Item was not mapped for TTs"); + Logger.INFO("[Hazmat] Item was not mapped for TTs - "+aKey); return new String[] {}; - } - else { + } else { Logger.INFO("[Hazmat] Item was mapped for TTs"); Collections.sort(aTempTooltipData); Logger.INFO("[Hazmat] Sorted TTs"); return aTempTooltipData.toArray(); } } - + private static void registerTooltip(GT_ItemStack aStack, String aTooltip) { - Logger.INFO("[Hazmat] Mapping "+aTooltip+" for "+getStackFromGtStack(aStack).getDisplayName()); - AutoMap aTempTooltipData = mToolTips.get(aStack); + String aKey = convertGtItemstackToStringData(aStack); + Logger.INFO("[Hazmat] Mapping " + aTooltip + " for " + aKey); + AutoMap aTempTooltipData = mToolTips.get(aKey); if (aTempTooltipData == null) { Logger.INFO("No data mapped yet, creating."); aTempTooltipData = new AutoMap(); } aTempTooltipData.add(aTooltip); - mToolTips.put(aStack, aTempTooltipData); + mToolTips.put(convertGtItemstackToStringData(aStack), aTempTooltipData); } - + public static ItemStack getStackFromGtStack(GT_ItemStack aGtStack) { return ItemUtils.simpleMetaStack(aGtStack.mItem, aGtStack.mMetaData, aGtStack.mStackSize); } - + public static GT_ItemStack getGtStackFromVanilla(ItemStack aStack) { return new GT_ItemStack(aStack); } + + private static String convertGtItemstackToStringData(GT_ItemStack aStack) { + if (aStack == null) { + return "NULL"; + } else { + return aStack.mItem.getUnlocalizedName() + "." + aStack.mMetaData + "." + aStack.mStackSize; + } + } + private static String convertGtItemstackToStringDataIgnoreDamage(GT_ItemStack aStack) { + if (aStack == null) { + return "NULL"; + } else { + return aStack.mItem.getUnlocalizedName() + "." + aStack.mStackSize; + } + } + } diff --git a/src/Java/gtPlusPlus/everglades/gen/gt/WorldGen_Ores.java b/src/Java/gtPlusPlus/everglades/gen/gt/WorldGen_Ores.java index 978deb1d25..0715f86e01 100644 --- a/src/Java/gtPlusPlus/everglades/gen/gt/WorldGen_Ores.java +++ b/src/Java/gtPlusPlus/everglades/gen/gt/WorldGen_Ores.java @@ -2,288 +2,77 @@ package gtPlusPlus.everglades.gen.gt; import java.util.Hashtable; -import net.minecraft.block.Block; - -import gregtech.api.enums.Materials; - -import gtPlusPlus.api.objects.data.Pair; import gtPlusPlus.core.material.ELEMENT; -import gtPlusPlus.core.material.Material; import gtPlusPlus.core.material.ORES; import gtPlusPlus.core.material.nuclear.FLUORIDES; -import gtPlusPlus.core.util.minecraft.MaterialUtils; -import gtPlusPlus.everglades.object.BoxedQuad; public class WorldGen_Ores { - - /** - * Set Ore Types on by one. - */ - public static volatile Pair Geikielite; // MgTiO3 - public static volatile Pair Zimbabweite; // (Na,K)2PbAs4(Nb,Ta,Ti)4O18 - public static volatile Pair Titanite; // CaTiSiO5 - public static volatile Pair Zirconolite; // CaZrTi2O7 - public static volatile Pair Crocoite; // PbCrO4 - public static volatile Pair Nichromite; // (Ni,Co,Fe)(Cr,Fe,Al)2O4 - public static volatile Pair Yttriaite; // Y2O3 - public static volatile Pair Samarskite_Y; // (YFe3+Fe2+U,Th,Ca)2(Nb,Ta)2O8 - public static volatile Pair Samarskite_Yb; // (YbFe3+)2(Nb,Ta)2O8 - public static volatile Pair Zircon; // ZrSiO4 - public static volatile Pair Gadolinite_Ce; // (Ce2,La,Nd,Y)2FeBe2Si1O14 - public static volatile Pair Gadolinite_Y; // (Ce,La,Nd,Y2)2FeBe2Si4O9 - public static volatile Pair Lepersonnite; // Ca(Gd,Dy)2(UO2)24(SiO4)4(CO3)8(OH)24·48H2O - public static volatile Pair Xenotime; // YPO4 - public static volatile Pair Yttrialite; // Y2Th2Si2O7 - public static volatile Pair Yttrocerite; // CaF5YCe - public static volatile Pair Polycrase; // YCaCeUThTi2Nb2Ta2O6 - public static volatile Pair Zircophyllite; // (K,Na)3(Mn,Fe)7(Zr,Ti,Nb)2Si8O24(OH,F)7 - public static volatile Pair Zirkelite; // (Ca,Th,Ce)Zr(Ti,Nb)2O7 - public static volatile Pair Lanthanite_La; // (La)2(CO3)3·8(H2O). - public static volatile Pair Lanthanite_Ce; // (Ce)2(CO3)3·8(H2O). - public static volatile Pair Lanthanite_Nd; // (Nd)2(CO3)3·8(H2O). - public static volatile Pair Hibonite; // ((Ca,Ce)(Al,Ti,Mg)12O19) - public static volatile Pair Cerite; // (Ce,La,Ca)9(Mg,Fe+3)(SiO4)6(SiO3OH)(OH)3 - public static volatile Pair Agardite_Y; // (YCa)Cu5(As2O4)3(OH)6·3H2O - public static volatile Pair Agardite_Cd; // (CdCa)Cu7(AsO2)4(O2H)5·3H2O - public static volatile Pair Agardite_La; // (LaCa)Cu5(AsO6)2(OH)4·3H2O - public static volatile Pair Agardite_Nd; // (NdCa)Cu6(As3O3)2(O2H)6·3H2O - public static volatile Pair Fluorcaphite; // (Ca,Sr,Ce,Na)5(PO4)3F - public static volatile Pair Florencite; // SmAl3(PO4)2(OH)6 - public static volatile Pair Cryolite; // Na3AlF6 - //public static volatile Pair Pyroxene; // - - - - - public static WorldGen_GT_Ore_Layer BaseVein = new WorldGen_GT_Ore_Layer( - "veinA", - 20, 40, - 1, - 8, - 128, - ELEMENT.getInstance().IRON, - ELEMENT.getInstance().IRON, - ELEMENT.getInstance().IRON, + public static WorldGen_GT_Ore_Layer BaseVein = new WorldGen_GT_Ore_Layer("veinA", 20, 40, 1, 1, 128, + ELEMENT.getInstance().IRON, ELEMENT.getInstance().IRON, ELEMENT.getInstance().IRON, ELEMENT.getInstance().IRON); - - - + /** * Custom ore Veins */ - - public static WorldGen_GT_Ore_Layer Vein1 = new WorldGen_GT_Ore_Layer( - "vein1", - 0, 60, - 30, - 16, - 16, - ORES.AGARDITE_CD, - ORES.AGARDITE_LA, - ORES.DEMICHELEITE_BR, - ORES.IRARSITE); - - public static WorldGen_GT_Ore_Layer Vein2 = new WorldGen_GT_Ore_Layer( - "vein2", - 0, 60, - 30, - 16, - 16, - ORES.AGARDITE_ND, - ORES.AGARDITE_Y, - ORES.KASHINITE, - ORES.CERITE); - public static WorldGen_GT_Ore_Layer Vein3 = new WorldGen_GT_Ore_Layer( - "vein3", - 0, 60, - 30, - 16, - 32, - ORES.CERITE, - ORES.NICHROMITE, - ORES.XENOTIME, - ORES.HIBONITE); + public static WorldGen_GT_Ore_Layer Vein1 = new WorldGen_GT_Ore_Layer("vein1", 0, 60, 30, 2, 16, ORES.AGARDITE_CD, + ORES.AGARDITE_LA, ORES.DEMICHELEITE_BR, ORES.IRARSITE); + + public static WorldGen_GT_Ore_Layer Vein2 = new WorldGen_GT_Ore_Layer("vein2", 0, 60, 30, 2, 16, ORES.AGARDITE_ND, + ORES.AGARDITE_Y, ORES.KASHINITE, ORES.CERITE); - public static WorldGen_GT_Ore_Layer Vein4 = new WorldGen_GT_Ore_Layer( - "vein4", - 0, 60, - 40, - 16, - 32, - ORES.GEIKIELITE, - ORES.CRYOLITE, - ORES.GADOLINITE_CE, - ORES.AGARDITE_ND); - - - - public static WorldGen_GT_Ore_Layer Vein5 = new WorldGen_GT_Ore_Layer( - "vein5", - 30, 128, - 20, - 8, - 48, - ORES.HIBONITE, - ORES.YTTRIALITE, - ORES.ZIRCONILITE, - ORES.CERITE); - public static WorldGen_GT_Ore_Layer Vein6 = new WorldGen_GT_Ore_Layer( - "vein6", - 0, 40, - 20, - 8, - 48, - ORES.XENOTIME, - ORES.ZIRKELITE, - ORES.CROCROITE, - ORES.IRARSITE); - public static WorldGen_GT_Ore_Layer Vein7 = new WorldGen_GT_Ore_Layer( - "vein7", - 40, 128, - 20, - 8, - 48, - ORES.HONEAITE, - ORES.MIESSIITE, - ORES.SAMARSKITE_Y, - ORES.SAMARSKITE_YB); - public static WorldGen_GT_Ore_Layer Vein8 = new WorldGen_GT_Ore_Layer( - "vein8", - 0, 40, - 20, - 8, - 48, - ORES.TITANITE, - ORES.ZIMBABWEITE, - ORES.ZIRCON, - ORES.FLORENCITE); - - - + public static WorldGen_GT_Ore_Layer Vein3 = new WorldGen_GT_Ore_Layer("vein3", 0, 60, 30, 3, 32, ORES.CERITE, + ORES.NICHROMITE, ORES.XENOTIME, ORES.HIBONITE); + + public static WorldGen_GT_Ore_Layer Vein4 = new WorldGen_GT_Ore_Layer("vein4", 0, 60, 40, 3, 32, ORES.GEIKIELITE, + ORES.CRYOLITE, ORES.GADOLINITE_CE, ORES.AGARDITE_ND); + + public static WorldGen_GT_Ore_Layer Vein5 = new WorldGen_GT_Ore_Layer("vein5", 30, 128, 20, 2, 48, ORES.HIBONITE, + ORES.YTTRIALITE, ORES.ZIRCONILITE, ORES.CERITE); + public static WorldGen_GT_Ore_Layer Vein6 = new WorldGen_GT_Ore_Layer("vein6", 0, 40, 20, 2, 48, ORES.XENOTIME, + ORES.ZIRKELITE, ORES.CROCROITE, ORES.IRARSITE); + public static WorldGen_GT_Ore_Layer Vein7 = new WorldGen_GT_Ore_Layer("vein7", 40, 128, 20, 2, 48, ORES.HONEAITE, + ORES.MIESSIITE, ORES.SAMARSKITE_Y, ORES.SAMARSKITE_YB); + public static WorldGen_GT_Ore_Layer Vein8 = new WorldGen_GT_Ore_Layer("vein8", 0, 40, 20, 2, 48, ORES.TITANITE, + ORES.ZIMBABWEITE, ORES.ZIRCON, ORES.FLORENCITE); + + public static WorldGen_GT_Ore_Layer Vein9 = new WorldGen_GT_Ore_Layer("vein9", 10, 30, 20, 1, 48, + ORES.LANTHANITE_CE, FLUORIDES.FLUORITE, ORES.LAFOSSAITE, ORES.FLORENCITE); + public static WorldGen_GT_Ore_Layer Vein10 = new WorldGen_GT_Ore_Layer("vein10", 20, 50, 20, 2, 32, ORES.GEIKIELITE, + ORES.YTTROCERITE, ORES.LANTHANITE_LA, ORES.RADIOBARITE); + public static WorldGen_GT_Ore_Layer Vein11 = new WorldGen_GT_Ore_Layer("vein11", 30, 70, 20, 1, 48, + FLUORIDES.FLUORITE, ORES.KASHINITE, ORES.ZIRCON, ORES.CRYOLITE); + public static WorldGen_GT_Ore_Layer Vein12 = new WorldGen_GT_Ore_Layer("vein12", 40, 80, 20, 3, 32, ORES.CERITE, + ORES.ALBURNITE, ORES.MIESSIITE, ORES.HIBONITE); - public static WorldGen_GT_Ore_Layer Vein9 = new WorldGen_GT_Ore_Layer( - "vein9", - 10, 30, - 20, - 4, - 48, - ORES.LANTHANITE_CE, - FLUORIDES.FLUORITE, - ORES.LAFOSSAITE, - ORES.FLORENCITE); - public static WorldGen_GT_Ore_Layer Vein10 = new WorldGen_GT_Ore_Layer( - "vein10", - 20, 50, - 20, - 8, - 32, - ORES.GEIKIELITE, - ORES.YTTROCERITE, - ORES.LANTHANITE_LA, - ORES.RADIOBARITE); - public static WorldGen_GT_Ore_Layer Vein11 = new WorldGen_GT_Ore_Layer( - "vein11", - 30, 70, - 20, - 5, - 48, - FLUORIDES.FLUORITE, - ORES.KASHINITE, - ORES.ZIRCON, - ORES.CRYOLITE); - public static WorldGen_GT_Ore_Layer Vein12 = new WorldGen_GT_Ore_Layer( - "vein12", - 40, 80, - 20, - 8, - 32, - ORES.CERITE, - ORES.ALBURNITE, - ORES.MIESSIITE, - ORES.HIBONITE); - /** * Best Rarest Veins 2017 */ - - public static WorldGen_GT_Ore_Layer Vein13 = new WorldGen_GT_Ore_Layer( - "vein13", - 5, 15, - 5, - 5, - 16, - ORES.CRYOLITE, - ORES.RADIOBARITE, - ORES.HONEAITE, - ORES.FLORENCITE); - public static WorldGen_GT_Ore_Layer Vein14 = new WorldGen_GT_Ore_Layer( - "vein14", - 10, 20, - 8, - 3, - 16, - ORES.DEMICHELEITE_BR, - ORES.PERROUDITE, - ORES.IRARSITE, - ORES.RADIOBARITE); + public static WorldGen_GT_Ore_Layer Vein13 = new WorldGen_GT_Ore_Layer("vein13", 5, 15, 5, 1, 16, ORES.CRYOLITE, + ORES.RADIOBARITE, ORES.HONEAITE, ORES.FLORENCITE); + + public static WorldGen_GT_Ore_Layer Vein14 = new WorldGen_GT_Ore_Layer("vein14", 10, 20, 8, 2, 16, + ORES.DEMICHELEITE_BR, ORES.PERROUDITE, ORES.IRARSITE, ORES.RADIOBARITE); - public static WorldGen_GT_Ore_Layer Vein15 = new WorldGen_GT_Ore_Layer( - "vein15", - 5, 25, - 5, - 6, - 24, - ORES.FLUORCAPHITE, - ORES.LAFOSSAITE, - ORES.GADOLINITE_CE, - ORES.GADOLINITE_Y); + public static WorldGen_GT_Ore_Layer Vein15 = new WorldGen_GT_Ore_Layer("vein15", 5, 25, 5, 3, 24, ORES.FLUORCAPHITE, + ORES.LAFOSSAITE, ORES.GADOLINITE_CE, ORES.GADOLINITE_Y); + + public static WorldGen_GT_Ore_Layer Vein16 = new WorldGen_GT_Ore_Layer("vein16", 0, 25, 4, 2, 32, ORES.YTTROCERITE, + ORES.LEPERSONNITE, ORES.LAUTARITE, FLUORIDES.FLUORITE); + + public static WorldGen_GT_Ore_Layer Vein17 = new WorldGen_GT_Ore_Layer("vein17", 10, 35, 4, 1, 32, ORES.FLORENCITE, + ORES.LAUTARITE, ORES.SAMARSKITE_YB, ORES.POLYCRASE); + public static WorldGen_GT_Ore_Layer Vein18 = new WorldGen_GT_Ore_Layer("vein18", 15, 40, 4, 1, 48, + ORES.GADOLINITE_CE, ORES.GADOLINITE_Y, ORES.AGARDITE_LA, ORES.AGARDITE_CD); - public static WorldGen_GT_Ore_Layer Vein16 = new WorldGen_GT_Ore_Layer( - "vein16", - 0, 25, - 4, - 6, - 32, - ORES.YTTROCERITE, - ORES.LEPERSONNITE, - ORES.LAUTARITE, - FLUORIDES.FLUORITE); - - public static WorldGen_GT_Ore_Layer Vein17 = new WorldGen_GT_Ore_Layer( - "vein17", - 10, 35, - 4, - 5, - 32, - ORES.FLORENCITE, - ORES.LAUTARITE, - ORES.SAMARSKITE_YB, - ORES.POLYCRASE); - public static WorldGen_GT_Ore_Layer Vein18 = new WorldGen_GT_Ore_Layer( - "vein18", - 15, 40, - 4, - 4, - 48, - ORES.GADOLINITE_CE, - ORES.GADOLINITE_Y, - ORES.AGARDITE_LA, - ORES.AGARDITE_CD); - - - - public static Hashtable validOreveins = new Hashtable( 1024); - - public static volatile BoxedQuad OreVein1 = new BoxedQuad(null, null, null, null); - static long ID = 0; - public static void generateValidOreVeins(){ + + public static void generateValidOreVeins() { validOreveins.put(ID++, BaseVein); validOreveins.put(ID++, Vein1); validOreveins.put(ID++, Vein2); @@ -304,5 +93,5 @@ public class WorldGen_Ores { validOreveins.put(ID++, Vein17); validOreveins.put(ID++, Vein18); } - + } diff --git a/src/resources/assets/gregtech/lang/en_US.lang b/src/resources/assets/gregtech/lang/en_US.lang index ffbb3d8a7a..a9bfa8993d 100644 --- a/src/resources/assets/gregtech/lang/en_US.lang +++ b/src/resources/assets/gregtech/lang/en_US.lang @@ -46,7 +46,11 @@ GTPP.nanohealer.tooltip.4=WILL NOT PREVENT DEATH GTPP.nanohealer.tooltip.5=Shift+RMB to toggle notifications GTPP.nanohealer.hidden=Hiding Info? - +//10/4/19 +//Tooltips for the Mob Killing Baubles +GTPP.monsterkiller.tooltip.1=Worn as an Amulet within Baubles +GTPP.monsterkiller.tooltip.2=Drains +GTPP.monsterkiller.tooltip.3=to kill -- cgit From 3b7cff8412af5afbf99bfd40fee1193a6cd8c400 Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Thu, 11 Apr 2019 02:59:02 +1000 Subject: + Added some new Monster Killer Baubles. Kill nearby mobs for power, power cost scales with HP total, left and other EntityLiving stats. + Added new constructors for AutoMaps. + Added a Wrapper (AABB) for AxisAlignedBB. $ Fixed Hot Titanium Ingot recipe. --- src/Java/gtPlusPlus/api/objects/data/AutoMap.java | 40 +++++++++++ .../gtPlusPlus/api/objects/minecraft/AABB.java | 65 ++++++++++++++++++ .../core/common/compat/COMPAT_Baubles.java | 12 ++++ src/Java/gtPlusPlus/core/item/ModItems.java | 12 +++- .../core/item/bauble/MonsterKillerBaseBauble.java | 78 +++++++++++++++++----- .../core/util/minecraft/EntityUtils.java | 48 ++++++++++--- 6 files changed, 227 insertions(+), 28 deletions(-) create mode 100644 src/Java/gtPlusPlus/api/objects/minecraft/AABB.java (limited to 'src/Java/gtPlusPlus/core/util') diff --git a/src/Java/gtPlusPlus/api/objects/data/AutoMap.java b/src/Java/gtPlusPlus/api/objects/data/AutoMap.java index fe2caa466d..3583a04a74 100644 --- a/src/Java/gtPlusPlus/api/objects/data/AutoMap.java +++ b/src/Java/gtPlusPlus/api/objects/data/AutoMap.java @@ -31,6 +31,46 @@ public class AutoMap implements Iterable, Cloneable, Serializable, Collect mInternalNameMap = new LinkedHashMap(); } + /** + * Generates an AutoMap from the List. + * @param aList - Data to be inserted into the AutoMap. + */ + public AutoMap(List aList) { + mInternalMap = new LinkedHashMap(); + mInternalNameMap = new LinkedHashMap(); + if (aList != null && aList.size() > 0) { + for (V obj : aList) { + add(obj); + } + } + } + /** + * Generates an AutoMap from a Set. + * @param aList - Data to be inserted into the AutoMap. + */ + public AutoMap(Set aList) { + mInternalMap = new LinkedHashMap(); + mInternalNameMap = new LinkedHashMap(); + if (aList != null && aList.size() > 0) { + for (V obj : aList) { + add(obj); + } + } + } + /** + * Generates an AutoMap from a Collection. + * @param aList - Data to be inserted into the AutoMap. + */ + public AutoMap(Collection aList) { + mInternalMap = new LinkedHashMap(); + mInternalNameMap = new LinkedHashMap(); + if (aList != null && aList.size() > 0) { + for (V obj : aList) { + add(obj); + } + } + } + @Override public Iterator iterator() { return values().iterator(); diff --git a/src/Java/gtPlusPlus/api/objects/minecraft/AABB.java b/src/Java/gtPlusPlus/api/objects/minecraft/AABB.java new file mode 100644 index 0000000000..722ac00b64 --- /dev/null +++ b/src/Java/gtPlusPlus/api/objects/minecraft/AABB.java @@ -0,0 +1,65 @@ +package gtPlusPlus.api.objects.minecraft; + +import gtPlusPlus.core.util.minecraft.EntityUtils; +import net.minecraft.entity.Entity; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.world.World; + +/** + * Generates an AABB around an entity. + * @author Alkalus + * + */ +public class AABB { + + private final AxisAlignedBB mAabb; + private final World mWorld; + + /** + * Creates a AxisAlignedBB based around an Entity. + * @param aEntity - The Entity to work with. + * @param x - Maximum X from origin. + * @param y - Maximum Y from origin. + * @param z - Maximum Z from origin. + */ + public AABB(Entity aEntity, int x, int y, int z) { + if (aEntity == null) { + mAabb = null; + mWorld = null; + } + else { + mWorld = aEntity.worldObj; + BlockPos aEntityLocation = EntityUtils.findBlockPosUnderEntity(aEntity); + int xMin, xMax, yMin, yMax, zMin, zMax; + xMin = aEntityLocation.xPos; + yMin = aEntityLocation.yPos; + zMin = aEntityLocation.zPos; + xMax = aEntityLocation.xPos + x; + yMax = aEntityLocation.yPos + y; + zMax = aEntityLocation.zPos + z; + mAabb = AxisAlignedBB.getBoundingBox(xMin, yMin, zMin, xMax, yMax, zMax); + } + + } + + /** + * Used to get the AxisAlignedBB from this class. + * @return + */ + public AxisAlignedBB get() { + return mAabb; + } + + /** + * Used to determine if this object is valid or not. + * @return + */ + public boolean valid() { + return mAabb != null && mWorld != null; + } + + public World world() { + return mWorld; + } + +} diff --git a/src/Java/gtPlusPlus/core/common/compat/COMPAT_Baubles.java b/src/Java/gtPlusPlus/core/common/compat/COMPAT_Baubles.java index f57c09b62d..d779e60975 100644 --- a/src/Java/gtPlusPlus/core/common/compat/COMPAT_Baubles.java +++ b/src/Java/gtPlusPlus/core/common/compat/COMPAT_Baubles.java @@ -3,10 +3,16 @@ package gtPlusPlus.core.common.compat; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.item.ModItems; import gtPlusPlus.core.item.bauble.BatteryPackBaseBauble; +import gtPlusPlus.core.item.bauble.MonsterKillerBaseBauble; import gtPlusPlus.core.item.general.ItemCloakingDevice; import gtPlusPlus.core.item.general.ItemHealingDevice; import gtPlusPlus.core.item.general.ItemSlowBuildingRing; import gtPlusPlus.core.lib.LoadedMods; +import net.minecraft.entity.monster.EntityCreeper; +import net.minecraft.entity.monster.EntityEnderman; +import net.minecraft.entity.monster.EntitySkeleton; +import net.minecraft.entity.monster.EntitySpider; +import net.minecraft.entity.monster.EntityZombie; public class COMPAT_Baubles { @@ -34,6 +40,12 @@ public class COMPAT_Baubles { catch (Throwable t) { t.printStackTrace(); } + + ModItems.itemAmuletMonsterKiller_Zombie = new MonsterKillerBaseBauble(new Class[] {EntityZombie.class}, "Zombie", 6); + ModItems.itemAmuletMonsterKiller_Skeleton = new MonsterKillerBaseBauble(new Class[] {EntitySkeleton.class}, "Skeleton", 6); + ModItems.itemAmuletMonsterKiller_Spider = new MonsterKillerBaseBauble(new Class[] {EntitySpider.class}, "Spider", 6); + ModItems.itemAmuletMonsterKiller_Creeper = new MonsterKillerBaseBauble(new Class[] {EntityCreeper.class}, "Creeper", 6); + ModItems.itemAmuletMonsterKiller_Enderman = new MonsterKillerBaseBauble(new Class[] {EntityEnderman.class}, "Enderman", 6); if (LoadedMods.PlayerAPI){ ModItems.itemSlowBuildingRing = new ItemSlowBuildingRing(); diff --git a/src/Java/gtPlusPlus/core/item/ModItems.java b/src/Java/gtPlusPlus/core/item/ModItems.java index e3c01b7ea5..68aacd6943 100644 --- a/src/Java/gtPlusPlus/core/item/ModItems.java +++ b/src/Java/gtPlusPlus/core/item/ModItems.java @@ -32,6 +32,7 @@ import gtPlusPlus.core.item.base.plates.BaseItemPlateDouble; import gtPlusPlus.core.item.bauble.BatteryPackBaseBauble; import gtPlusPlus.core.item.bauble.HealthBoostBauble; import gtPlusPlus.core.item.bauble.ModularBauble; +import gtPlusPlus.core.item.bauble.MonsterKillerBaseBauble; import gtPlusPlus.core.item.chemistry.AgriculturalChem; import gtPlusPlus.core.item.chemistry.CoalTar; import gtPlusPlus.core.item.chemistry.GenericChem; @@ -345,6 +346,15 @@ public final class ModItems { public static CoreItem itemDetCable; public static ItemThrowableBomb itemBomb; + public static MonsterKillerBaseBauble itemAmuletMonsterKiller_Zombie; + public static MonsterKillerBaseBauble itemAmuletMonsterKiller_Skeleton; + public static MonsterKillerBaseBauble itemAmuletMonsterKiller_Spider; + public static MonsterKillerBaseBauble itemAmuletMonsterKiller_Creeper; + public static MonsterKillerBaseBauble itemAmuletMonsterKiller_Enderman; + + public static MonsterKillerBaseBauble itemAmuletMonsterKiller_Nether; + public static MonsterKillerBaseBauble itemAmuletMonsterKiller_Infernal; + static { Logger.INFO("Items!"); //Default item used when recipes fail, handy for debugging. Let's make sure they exist when this class is called upon. @@ -829,7 +839,7 @@ public final class ModItems { else { itemHotTitaniumIngot = ItemUtils.getItemStackOfAmountFromOreDictNoBroken("ingotHotTitanium", 1); } - GT_Values.RA.addBlastRecipe(ELEMENT.getInstance().TITANIUM.getIngot(1), null, itemHotTitaniumIngot, null, 10 * 20, 512, Materials.Titanium.mBlastFurnaceTemp); + GT_Values.RA.addBlastRecipe(ELEMENT.getInstance().TITANIUM.getIngot(1), CI.getNumberedCircuit(16), itemHotTitaniumIngot, null, 10 * 20, 500, Materials.Titanium.mBlastFurnaceTemp); //Special Sillyness if (true) { diff --git a/src/Java/gtPlusPlus/core/item/bauble/MonsterKillerBaseBauble.java b/src/Java/gtPlusPlus/core/item/bauble/MonsterKillerBaseBauble.java index 024f6aa907..2cffb8737f 100644 --- a/src/Java/gtPlusPlus/core/item/bauble/MonsterKillerBaseBauble.java +++ b/src/Java/gtPlusPlus/core/item/bauble/MonsterKillerBaseBauble.java @@ -3,14 +3,18 @@ package gtPlusPlus.core.item.bauble; import java.util.List; import baubles.api.BaubleType; -import cpw.mods.fml.common.Optional; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import gregtech.api.enums.GT_Values; +import gtPlusPlus.api.objects.data.AutoMap; +import gtPlusPlus.api.objects.minecraft.AABB; import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.EntityUtils; import ic2.api.item.ElectricItem; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; @@ -20,14 +24,13 @@ import net.minecraft.util.StatCollector; import net.minecraft.world.World; public class MonsterKillerBaseBauble extends ElectricBaseBauble { - - private final int mTier; + private final Class[] mTargets; - public MonsterKillerBaseBauble(Class[] aMonsterBaseClassArray, String aMonsterTypeName, int aPowerTier) { - super(BaubleType.AMULET, aPowerTier, GT_Values.V[aPowerTier] * 20 * 300, "GTPP.MonsterKiller."+aMonsterTypeName+".name"); - mTier = aPowerTier; - mTargets = aMonsterBaseClassArray; + public MonsterKillerBaseBauble(Class[] aMonsterBaseClassArray, String aMonsterTypeName, int aPowerTier) { + super(BaubleType.AMULET, aPowerTier, GT_Values.V[aPowerTier] * 20 * 300, + "GTPP.MonsterKiller." + aMonsterTypeName + ".name"); + mTargets = aMonsterBaseClassArray; } @SideOnly(Side.CLIENT) @@ -56,7 +59,7 @@ public class MonsterKillerBaseBauble extends ElectricBaseBauble { @Override public boolean canProvideEnergy(final ItemStack itemStack) { - double aItemCharge = ElectricItem.manager.getCharge(itemStack); + double aItemCharge = ElectricItem.manager.getCharge(itemStack); return aItemCharge > 0; } @@ -78,17 +81,18 @@ public class MonsterKillerBaseBauble extends ElectricBaseBauble { String aString2 = StatCollector.translateToLocal("GTPP.monsterkiller.tooltip.2"); String aString3 = StatCollector.translateToLocal("GTPP.monsterkiller.tooltip.3"); String aString4 = StatCollector.translateToLocal("GTPP.monsterkiller.tooltip.4"); - String aEU = StatCollector.translateToLocal("GTPP.info.eu"); - String aEUT = aEU+"/t"; + String aEU = StatCollector.translateToLocal("GTPP.info.eu"); + String aEUT = aEU + "/t"; list.add(EnumChatFormatting.GREEN + aString1 + EnumChatFormatting.GRAY); - list.add(EnumChatFormatting.GREEN + aString2+" " + (int) getTransferLimit(stack) + aEUT + aString3 + EnumChatFormatting.GRAY); + list.add(EnumChatFormatting.GREEN + aString2 + " " + (int) getTransferLimit(stack) + aEUT + aString3 + + EnumChatFormatting.GRAY); list.add(""); - list.add(""+EnumChatFormatting.GREEN + aString4 + " " + EnumChatFormatting.GRAY); + list.add("" + EnumChatFormatting.GREEN + aString4 + " " + EnumChatFormatting.GRAY); for (Class cz : mTargets) { - list.add("- "+EnumChatFormatting.DARK_GREEN + cz.getSimpleName() + EnumChatFormatting.GRAY); + list.add("- " + EnumChatFormatting.DARK_GREEN + cz.getSimpleName() + EnumChatFormatting.GRAY); } - + super.addInformation(stack, aPlayer, list, bool); } @@ -113,17 +117,57 @@ public class MonsterKillerBaseBauble extends ElectricBaseBauble { } @Override // TODO - public void onWornTick(final ItemStack aBaubleStack, final EntityLivingBase aPlayer) { + public void onWornTick(final ItemStack aBaubleStack, final EntityLivingBase aPlayerEntity) { + if (aPlayerEntity == null) { + return; + } + EntityPlayer aPlayer = (EntityPlayer) aPlayerEntity; if (!aPlayer.worldObj.isRemote) { if (this.getCharge(aBaubleStack) >= getTransferLimit(aBaubleStack)) { - + AABB aPlayerBox = new AABB(aPlayerEntity, 5, 5, 5); + if (this.mTargets != null && this.mTargets.length > 0) { + for (Class clazz : mTargets) { + AutoMap aEnts = EntityUtils.getEntitiesWithinBoundingBox(clazz, aPlayerBox); + if (aEnts.isEmpty()) { + continue; + } else { + EntityLiving aClosest = null; + double aEntityDistance = Short.MIN_VALUE; + for (Object ent : aEnts) { + if (!EntityLiving.class.isInstance(ent)) { + continue; + } else { + double aCurEntDis = EntityUtils.getDistance(aPlayerEntity, (Entity) ent); + if (aEntityDistance == Short.MIN_VALUE || aCurEntDis < aEntityDistance) { + aEntityDistance = aCurEntDis; + aClosest = (EntityLiving) ent; + } + } + } + if (aClosest != null) { + float aEntHealth = aClosest.getHealth(); + float aEntMaxHealth = aClosest.getMaxHealth(); + double aEntHealthPerc = MathUtils.findPercentage(aEntHealth, aEntMaxHealth); + long aEuUsage = (long) (aEntHealthPerc * 50 * aEntMaxHealth); + if (this.discharge(aBaubleStack, aEuUsage, mTier, true, false, false) > 0) { + aClosest.setDead(); + break; + } + } else { + continue; + } + } + } + } + } else { + return; } } } @Override public String getTextureNameForBauble() { - return CORE.MODID+":"+""; + return CORE.MODID + ":" + "baubles/itemAmulet"; } } diff --git a/src/Java/gtPlusPlus/core/util/minecraft/EntityUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/EntityUtils.java index 844bb0bcaf..8c5a9f6581 100644 --- a/src/Java/gtPlusPlus/core/util/minecraft/EntityUtils.java +++ b/src/Java/gtPlusPlus/core/util/minecraft/EntityUtils.java @@ -3,26 +3,28 @@ package gtPlusPlus.core.util.minecraft; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.HashMap; +import java.util.List; import java.util.Map; import cpw.mods.fml.common.registry.EntityRegistry; -import cpw.mods.fml.common.registry.GameRegistry; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.api.objects.data.AutoMap; +import gtPlusPlus.api.objects.minecraft.AABB; +import gtPlusPlus.api.objects.minecraft.BlockPos; +import gtPlusPlus.core.util.reflect.ReflectionUtils; +import ic2.core.IC2Potion; +import ic2.core.item.armor.ItemArmorHazmat; import net.minecraft.block.Block; -import net.minecraft.entity.*; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.EnumCreatureType; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.DamageSource; import net.minecraft.util.MathHelper; import net.minecraft.world.World; import net.minecraft.world.biome.BiomeGenBase; -import gregtech.api.util.GT_Utility; - -import gtPlusPlus.api.objects.minecraft.BlockPos; -import gtPlusPlus.core.util.reflect.ReflectionUtils; -import ic2.core.IC2Potion; -import ic2.core.item.armor.ItemArmorHazmat; - public class EntityUtils { public static void setEntityOnFire(final Entity entity, final int length){ @@ -158,5 +160,31 @@ public class EntityUtils { } return false; } + + public static double getDistance(Entity p1, Entity p2) { + return Math.sqrt( Math.pow(p1.posX - p2.posX, 2) + Math.pow(p1.posY - p2.posY, 2) + Math.pow(p1.posZ - p2.posZ, 2)); + } + + public static AutoMap getEntitiesWithinBoundingBoxExcluding(Entity aExclusion, AABB aBoundingBox){ + + if (aExclusion == null) { + return new AutoMap(); + } + else { + List aEntities = aBoundingBox.world().getEntitiesWithinAABBExcludingEntity(aExclusion, aBoundingBox.get()); + return new AutoMap(aEntities); + } + } + + public static AutoMap getEntitiesWithinBoundingBox(Class aEntityType, AABB aBoundingBox){ + + if (aEntityType == null) { + return new AutoMap(); + } + else { + List aEntities = aBoundingBox.world().getEntitiesWithinAABB(aEntityType, aBoundingBox.get()); + return new AutoMap(aEntities); + } + } } -- cgit From be88e9009e66ef27d9bccd27cce7fd13ae3b06cd Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Thu, 11 Apr 2019 04:14:27 +1000 Subject: + Added the ASM segment for IC2 Hazmat. - Disabled most Hazmat logging. % Mild adjustment to formatting for mob types in MK Baubles tooltips. --- .../core/item/bauble/MonsterKillerBaseBauble.java | 6 +- .../core/util/minecraft/HazmatUtils.java | 19 ++- .../transformers/ClassTransformer_IC2_Hazmat.java | 132 +++++++++++++++++++++ .../Preloader_Transformer_Handler.java | 6 + 4 files changed, 151 insertions(+), 12 deletions(-) create mode 100644 src/Java/gtPlusPlus/preloader/asm/transformers/ClassTransformer_IC2_Hazmat.java (limited to 'src/Java/gtPlusPlus/core/util') diff --git a/src/Java/gtPlusPlus/core/item/bauble/MonsterKillerBaseBauble.java b/src/Java/gtPlusPlus/core/item/bauble/MonsterKillerBaseBauble.java index 2cffb8737f..aa89ff1627 100644 --- a/src/Java/gtPlusPlus/core/item/bauble/MonsterKillerBaseBauble.java +++ b/src/Java/gtPlusPlus/core/item/bauble/MonsterKillerBaseBauble.java @@ -11,6 +11,7 @@ import gtPlusPlus.api.objects.minecraft.AABB; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.util.math.MathUtils; import gtPlusPlus.core.util.minecraft.EntityUtils; +import gtPlusPlus.core.util.minecraft.PlayerUtils; import ic2.api.item.ElectricItem; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; @@ -85,12 +86,12 @@ public class MonsterKillerBaseBauble extends ElectricBaseBauble { String aEUT = aEU + "/t"; list.add(EnumChatFormatting.GREEN + aString1 + EnumChatFormatting.GRAY); - list.add(EnumChatFormatting.GREEN + aString2 + " " + (int) getTransferLimit(stack) + aEUT + aString3 + list.add(EnumChatFormatting.GREEN + aString2 + " " + (int) getTransferLimit(stack) + aEUT + " " + aString3 + EnumChatFormatting.GRAY); list.add(""); list.add("" + EnumChatFormatting.GREEN + aString4 + " " + EnumChatFormatting.GRAY); for (Class cz : mTargets) { - list.add("- " + EnumChatFormatting.DARK_GREEN + cz.getSimpleName() + EnumChatFormatting.GRAY); + list.add("- " + EnumChatFormatting.DARK_GREEN + cz.getSimpleName().replace("Entity", "") + EnumChatFormatting.GRAY); } super.addInformation(stack, aPlayer, list, bool); @@ -151,6 +152,7 @@ public class MonsterKillerBaseBauble extends ElectricBaseBauble { long aEuUsage = (long) (aEntHealthPerc * 50 * aEntMaxHealth); if (this.discharge(aBaubleStack, aEuUsage, mTier, true, false, false) > 0) { aClosest.setDead(); + PlayerUtils.messagePlayer(aPlayer, "Removed 1x "+aClosest.getCommandSenderName()); break; } } else { diff --git a/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java index c37b1271d7..c529f60ba1 100644 --- a/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java +++ b/src/Java/gtPlusPlus/core/util/minecraft/HazmatUtils.java @@ -19,7 +19,6 @@ import gtPlusPlus.GTplusplus.INIT_PHASE; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.api.objects.data.AutoMap; import gtPlusPlus.core.util.Utils; -import ic2.core.Ic2Items; import ic2.core.item.armor.ItemArmorHazmat; import ic2.core.item.armor.ItemArmorNanoSuit; import ic2.core.item.armor.ItemArmorQuantumSuit; @@ -81,24 +80,24 @@ public class HazmatUtils { return; } if (event.itemStack == null || isVanillaHazmatPiece(event.itemStack)) { - Logger.INFO("[Hazmat] Invalid Itemstack or vanilla hazmat"); + //Logger.INFO("[Hazmat] Invalid Itemstack or vanilla hazmat"); return; } else { ItemStack aStackTemp = event.itemStack; GT_ItemStack aStack = new GT_ItemStack(aStackTemp); if (isNanoArmourPiece(aStackTemp) || isQuantumArmourPiece(aStackTemp)) { - event.toolTip.add("Provides full hazmat protection."); + event.toolTip.add(EnumChatFormatting.DARK_PURPLE+"Provides full hazmat protection."); } else { - Logger.INFO("[Hazmat] Finding Tooltip Data"); + //Logger.INFO("[Hazmat] Finding Tooltip Data"); String[] aTooltips = getTooltips(aStack); if (aTooltips == null || aTooltips.length == 0) { - Logger.INFO("[Hazmat] No Info!"); + //Logger.INFO("[Hazmat] No Info!"); return; } else { - Logger.INFO("[Hazmat] Found Tooltips!"); + //Logger.INFO("[Hazmat] Found Tooltips!"); if (providesProtection(aStackTemp)) { - event.toolTip.add("Provides full hazmat protection."); + event.toolTip.add(EnumChatFormatting.LIGHT_PURPLE+"Provides full hazmat protection."); } else { event.toolTip.add(mToolTipText); for (String r : aTooltips) { @@ -301,12 +300,12 @@ public class HazmatUtils { String aKey = convertGtItemstackToStringData(aStack); AutoMap aTempTooltipData = mToolTips.get(aKey); if (aTempTooltipData == null) { - Logger.INFO("[Hazmat] Item was not mapped for TTs - "+aKey); + //Logger.INFO("[Hazmat] Item was not mapped for TTs - "+aKey); return new String[] {}; } else { - Logger.INFO("[Hazmat] Item was mapped for TTs"); + //Logger.INFO("[Hazmat] Item was mapped for TTs"); Collections.sort(aTempTooltipData); - Logger.INFO("[Hazmat] Sorted TTs"); + //Logger.INFO("[Hazmat] Sorted TTs"); return aTempTooltipData.toArray(); } } diff --git a/src/Java/gtPlusPlus/preloader/asm/transformers/ClassTransformer_IC2_Hazmat.java b/src/Java/gtPlusPlus/preloader/asm/transformers/ClassTransformer_IC2_Hazmat.java new file mode 100644 index 0000000000..4bb7ef7d46 --- /dev/null +++ b/src/Java/gtPlusPlus/preloader/asm/transformers/ClassTransformer_IC2_Hazmat.java @@ -0,0 +1,132 @@ +package gtPlusPlus.preloader.asm.transformers; + +import static org.objectweb.asm.Opcodes.*; + +import org.apache.logging.log4j.Level; +import org.objectweb.asm.ClassReader; +import org.objectweb.asm.ClassVisitor; +import org.objectweb.asm.ClassWriter; +import org.objectweb.asm.Label; +import org.objectweb.asm.MethodVisitor; + +import cpw.mods.fml.relauncher.FMLRelaunchLog; +import gtPlusPlus.core.util.minecraft.HazmatUtils; +import net.minecraft.entity.EntityLivingBase; + +public class ClassTransformer_IC2_Hazmat { + + private final boolean isValid; + private final ClassReader reader; + private final ClassWriter writer; + private final String className; + + public boolean hasCompleteHazmat(EntityLivingBase living) { + return HazmatUtils.hasCompleteHazmat(living); + } + + public ClassTransformer_IC2_Hazmat(byte[] basicClass, String aClassName) { + className = aClassName; + ClassReader aTempReader = null; + ClassWriter aTempWriter = null; + + FMLRelaunchLog.log("[GT++ ASM] IC2 Hazmat Patch", Level.INFO, "Attempting to patch in mode " + className + "."); + + aTempReader = new ClassReader(basicClass); + aTempWriter = new ClassWriter(aTempReader, ClassWriter.COMPUTE_FRAMES); + aTempReader.accept(new localClassVisitor(aTempWriter, className), 0); + + if (aTempReader != null && aTempWriter != null) { + isValid = true; + } else { + isValid = false; + } + + FMLRelaunchLog.log("[GT++ ASM] IC2 Hazmat Patch", Level.INFO, "Valid patch? " + isValid + "."); + reader = aTempReader; + writer = aTempWriter; + + if (reader != null && writer != null) { + FMLRelaunchLog.log("[GT++ ASM] IC2 Hazmat Patch", Level.INFO, "Attempting Method Injection."); + injectMethod("hasCompleteHazmat"); + } + + } + + public boolean isValidTransformer() { + return isValid; + } + + public ClassReader getReader() { + return reader; + } + + public ClassWriter getWriter() { + return writer; + } + + public boolean injectMethod(String aMethodName) { + MethodVisitor mv; + boolean didInject = false; + ClassWriter cw = getWriter(); + + boolean isObf; + try { + isObf = Class.forName("net.minecraft.entity.EntityLivingBase") == null; + } catch (ClassNotFoundException e) { + isObf = true; + } + String aEntityLivingBase = "net/minecraft/entity/EntityLivingBase"; + if (isObf) { + aEntityLivingBase = "sv"; + } + + + FMLRelaunchLog.log("[GT++ ASM] IC2 Hazmat Patch", Level.INFO, "Injecting " + aMethodName + "."); + if (aMethodName.equals("hasCompleteHazmat")) { + mv = cw.visitMethod(ACC_PUBLIC, "hasCompleteHazmat", "(L"+aEntityLivingBase+";)Z", null, null); + mv.visitCode(); + Label l0 = new Label(); + mv.visitLabel(l0); + mv.visitLineNumber(23, l0); + mv.visitVarInsn(ALOAD, 1); + mv.visitMethodInsn(INVOKESTATIC, "gtPlusPlus/core/util/minecraft/HazmatUtils", "hasCompleteHazmat", "(L"+aEntityLivingBase+";)Z", false); + mv.visitInsn(IRETURN); + Label l1 = new Label(); + mv.visitLabel(l1); + mv.visitLocalVariable("this", "Lic2/core/item/armor/ItemArmorHazmat;", null, l0, l1, 0); + mv.visitLocalVariable("living", "L"+aEntityLivingBase+";", null, l0, l1, 1); + mv.visitMaxs(1, 2); + mv.visitEnd(); + } + FMLRelaunchLog.log("[GT++ ASM] IC2 Hazmat Patch", Level.INFO, "Method injection complete."); + return didInject; + } + + public final class localClassVisitor extends ClassVisitor { + + String aClassName; + + public localClassVisitor(ClassVisitor cv, String aName) { + super(ASM5, cv); + aClassName = aName; + } + + @Override + public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { + MethodVisitor methodVisitor; + + if (name.equals("hasCompleteHazmat")) { + methodVisitor = null; + } else { + methodVisitor = super.visitMethod(access, name, desc, signature, exceptions); + } + + if (methodVisitor == null) { + FMLRelaunchLog.log("[GT++ ASM] IC2 Hazmat Patch", Level.INFO, + "Found method " + name + ", removing."); + } + return methodVisitor; + } + } + +} diff --git a/src/Java/gtPlusPlus/preloader/asm/transformers/Preloader_Transformer_Handler.java b/src/Java/gtPlusPlus/preloader/asm/transformers/Preloader_Transformer_Handler.java index 81302a59d4..3f5897d590 100644 --- a/src/Java/gtPlusPlus/preloader/asm/transformers/Preloader_Transformer_Handler.java +++ b/src/Java/gtPlusPlus/preloader/asm/transformers/Preloader_Transformer_Handler.java @@ -201,6 +201,12 @@ public class Preloader_Transformer_Handler implements IClassTransformer { return new ClassTransformer_IC2_GetHarvestTool(basicClass, obfuscated, transformedName).getWriter().toByteArray(); } } + //Fix IC2 Hazmat + + if (transformedName.equals("ic2.core.item.armor.ItemArmorHazmat")) { + FMLRelaunchLog.log("[GT++ ASM] IC2 Hazmat Patch", Level.INFO, "Transforming %s", transformedName); + return new ClassTransformer_IC2_Hazmat(basicClass, transformedName).getWriter().toByteArray(); + } //Fix Thaumcraft Shit //Patching ItemWispEssence to allow invalid item handling -- cgit From 95747970ad7d142a2a981119bdfafca5ab5b27d2 Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Wed, 17 Apr 2019 10:35:07 +1000 Subject: + Added rmb information to Energy Buffers to show current Amperage. % Migrated getFieldFromGregtechProxy() from Meta_GT_Proxy.java to StaticFields59.java. $ Fixed hardness/resistance on a few blocks. $ Fixed bad handling of Item Entities by Fluid Collectors. --- .../core/block/machine/CircuitProgrammer.java | 2 + .../gtPlusPlus/core/block/machine/FishTrap.java | 1 + .../core/block/machine/Machine_PooCollector.java | 2 + .../machines/TileEntityBaseFluidCollector.java | 12 +++--- .../machines/TileEntityPooCollector.java | 15 +++++--- .../gtPlusPlus/core/util/reflect/ProxyFinder.java | 2 +- .../GT_MetaTileEntity_Hatch_Muffler_Adv.java | 3 +- .../GregtechMetaPipeEntityFluid.java | 4 +- .../xmod/gregtech/common/Meta_GT_Proxy.java | 45 ++++------------------ .../xmod/gregtech/common/StaticFields59.java | 38 ++++++++++++++++-- .../storage/GregtechMetaEnergyBuffer.java | 3 +- 11 files changed, 69 insertions(+), 58 deletions(-) (limited to 'src/Java/gtPlusPlus/core/util') diff --git a/src/Java/gtPlusPlus/core/block/machine/CircuitProgrammer.java b/src/Java/gtPlusPlus/core/block/machine/CircuitProgrammer.java index 1600d9944f..6ae1a52aba 100644 --- a/src/Java/gtPlusPlus/core/block/machine/CircuitProgrammer.java +++ b/src/Java/gtPlusPlus/core/block/machine/CircuitProgrammer.java @@ -51,6 +51,8 @@ public class CircuitProgrammer extends BlockContainer implements ITileTooltip @SuppressWarnings("deprecation") public CircuitProgrammer(){ super(Material.iron); + this.setHardness(5f); + this.setResistance(1f); this.setBlockName("blockCircuitProgrammer"); this.setCreativeTab(AddToCreativeTab.tabMachines); GameRegistry.registerBlock(this, ItemBlockBasicTile.class, "blockCircuitProgrammer"); diff --git a/src/Java/gtPlusPlus/core/block/machine/FishTrap.java b/src/Java/gtPlusPlus/core/block/machine/FishTrap.java index b5e78f23ef..037ec61ced 100644 --- a/src/Java/gtPlusPlus/core/block/machine/FishTrap.java +++ b/src/Java/gtPlusPlus/core/block/machine/FishTrap.java @@ -51,6 +51,7 @@ public class FishTrap extends BlockContainer implements ITileTooltip super(Material.iron); this.setBlockName("blockFishTrap"); this.setHardness(5f); + this.setResistance(1f); this.setCreativeTab(AddToCreativeTab.tabMachines); GameRegistry.registerBlock(this, ItemBlockBasicTile.class, "blockFishTrap"); LanguageRegistry.addName(this, "Fish Catcher"); diff --git a/src/Java/gtPlusPlus/core/block/machine/Machine_PooCollector.java b/src/Java/gtPlusPlus/core/block/machine/Machine_PooCollector.java index 23fdfe9733..945cf7b581 100644 --- a/src/Java/gtPlusPlus/core/block/machine/Machine_PooCollector.java +++ b/src/Java/gtPlusPlus/core/block/machine/Machine_PooCollector.java @@ -38,6 +38,8 @@ public class Machine_PooCollector extends BlockContainer { public Machine_PooCollector() { super(Material.iron); + this.setHardness(5f); + this.setResistance(1f); this.setBlockName("blockPooCollector"); this.setCreativeTab(AddToCreativeTab.tabMachines); GameRegistry.registerBlock(this, ItemBlockMeta.class,"blockPooCollector"); diff --git a/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityBaseFluidCollector.java b/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityBaseFluidCollector.java index 78b8f74799..cdae4cf829 100644 --- a/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityBaseFluidCollector.java +++ b/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityBaseFluidCollector.java @@ -2,7 +2,6 @@ package gtPlusPlus.core.tileentities.machines; import java.util.List; -import gtPlusPlus.api.objects.Logger; import gtPlusPlus.api.objects.data.AutoMap; import gtPlusPlus.api.objects.minecraft.BTF_FluidTank; import gtPlusPlus.api.objects.minecraft.BlockPos; @@ -11,7 +10,6 @@ import gtPlusPlus.core.util.math.MathUtils; import gtPlusPlus.core.util.minecraft.FluidUtils; import gtPlusPlus.core.util.minecraft.ItemUtils; import net.minecraft.entity.item.EntityItem; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.NetworkManager; @@ -208,9 +206,11 @@ public abstract class TileEntityBaseFluidCollector extends TileEntityBase implem this.tank.fill(FluidUtils.getFluidStack(fluidToProvide(), aFluidAmount), true); } else { - ItemStack aDirtStack = ItemUtils.getSimpleStack(itemToSpawnInWorldIfTankIsFull()); - if (aDirtStack != null) - if (!this.mInventory.addItemStack(aDirtStack)) { + ItemStack aDirtStack = ItemUtils.getSimpleStack(itemToSpawnInWorldIfTankIsFull(), 1); + if (!ItemUtils.checkForInvalidItems(aDirtStack)) { + return; + } + if (!this.mInventory.addItemStack(aDirtStack)) { EntityItem entity = new EntityItem(worldObj, xCoord, yCoord+1.5, zCoord, aDirtStack); worldObj.spawnEntityInWorld(entity); } @@ -230,7 +230,7 @@ public abstract class TileEntityBaseFluidCollector extends TileEntityBase implem public abstract Fluid fluidToProvide(); - public abstract Item itemToSpawnInWorldIfTankIsFull(); + public abstract ItemStack itemToSpawnInWorldIfTankIsFull(); diff --git a/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityPooCollector.java b/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityPooCollector.java index f6570c6cc6..25348a31f8 100644 --- a/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityPooCollector.java +++ b/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityPooCollector.java @@ -12,7 +12,6 @@ import net.minecraft.entity.passive.EntityHorse; import net.minecraft.entity.passive.EntityMooshroom; import net.minecraft.entity.passive.EntitySheep; import net.minecraft.entity.passive.IAnimals; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.Fluid; @@ -53,7 +52,11 @@ public class TileEntityPooCollector extends TileEntityBaseFluidCollector { } else { return false; + } + if (!ItemUtils.checkForInvalidItems(aPoop)) { + return false; } + //Add poop to world //Logger.INFO("Adding animal waste for "+aPooMaker.getCommandSenderName()); @@ -123,17 +126,17 @@ public class TileEntityPooCollector extends TileEntityBaseFluidCollector { } @Override - public Item itemToSpawnInWorldIfTankIsFull() { + public ItemStack itemToSpawnInWorldIfTankIsFull() { int a = MathUtils.randInt(0, 100); - Item aItem = null; + ItemStack aItem = null; if (a <= 30) { - aItem = AgriculturalChem.dustDirt; + aItem = ItemUtils.getSimpleStack(AgriculturalChem.dustDirt); } else if (a <= 40) { - aItem = ItemUtils.getItemStackOfAmountFromOreDict("dustSmallManureByproducts", 1).getItem(); + aItem = ItemUtils.getItemStackOfAmountFromOreDict("dustSmallManureByproducts", 1); } else if (a <= 55) { - aItem = ItemUtils.getItemStackOfAmountFromOreDict("dustTinyManureByproducts", 1).getItem(); + aItem = ItemUtils.getItemStackOfAmountFromOreDict("dustTinyManureByproducts", 1); } return aItem; } diff --git a/src/Java/gtPlusPlus/core/util/reflect/ProxyFinder.java b/src/Java/gtPlusPlus/core/util/reflect/ProxyFinder.java index d22fafb37b..aaa9b2fae7 100644 --- a/src/Java/gtPlusPlus/core/util/reflect/ProxyFinder.java +++ b/src/Java/gtPlusPlus/core/util/reflect/ProxyFinder.java @@ -20,7 +20,7 @@ public class ProxyFinder { } } catch (final NoClassDefFoundError err) { - //its server side + //its client side return null; } break; diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Muffler_Adv.java b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Muffler_Adv.java index 5ce74588fa..8c0c47bea2 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Muffler_Adv.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Muffler_Adv.java @@ -6,7 +6,6 @@ import gregtech.api.objects.GT_RenderedTexture; import gregtech.api.util.GT_Config; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.util.minecraft.gregtech.PollutionUtils; -import gtPlusPlus.xmod.gregtech.common.Meta_GT_Proxy; import gtPlusPlus.xmod.gregtech.common.StaticFields59; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; import net.minecraft.entity.player.EntityPlayer; @@ -24,7 +23,7 @@ public class GT_MetaTileEntity_Hatch_Muffler_Adv extends GT_MetaTileEntity_Hatch super.onConfigLoad(aConfig); if (CORE.MAIN_GREGTECH_5U_EXPERIMENTAL_FORK || CORE.GTNH) { try { - Integer a1 = (int) Meta_GT_Proxy.getFieldFromGregtechProxy(false, "mPollutionSmogLimit"); + Integer a1 = (int) StaticFields59.getFieldFromGregtechProxy(false, "mPollutionSmogLimit"); if (a1 != null && a1 > 0) { mPollutionSmogLimit = a1; } diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GregtechMetaPipeEntityFluid.java b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GregtechMetaPipeEntityFluid.java index f6056af87a..929dee22e4 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GregtechMetaPipeEntityFluid.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GregtechMetaPipeEntityFluid.java @@ -15,7 +15,7 @@ import gregtech.api.objects.GT_RenderedTexture; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.xmod.gregtech.api.enums.GregtechOrePrefixes.GT_Materials; -import gtPlusPlus.xmod.gregtech.common.Meta_GT_Proxy; +import gtPlusPlus.xmod.gregtech.common.StaticFields59; public class GregtechMetaPipeEntityFluid extends GT_MetaPipeEntity_Fluid { @@ -23,7 +23,7 @@ public class GregtechMetaPipeEntityFluid extends GT_MetaPipeEntity_Fluid { public static final boolean mGt6Pipe; static { - Boolean aGt6 = (Boolean) Meta_GT_Proxy.getFieldFromGregtechProxy(false, "gt6Pipe"); + Boolean aGt6 = (Boolean) StaticFields59.getFieldFromGregtechProxy(false, "gt6Pipe"); if (aGt6 != null) { mGt6Pipe = aGt6; } diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/Meta_GT_Proxy.java b/src/Java/gtPlusPlus/xmod/gregtech/common/Meta_GT_Proxy.java index 6b4bab9e26..7505c2a808 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/common/Meta_GT_Proxy.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/Meta_GT_Proxy.java @@ -5,7 +5,6 @@ import static gtPlusPlus.xmod.gregtech.common.covers.GTPP_Cover_Overflow.mOverfl import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; -import java.util.Collection; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; @@ -16,7 +15,6 @@ import java.util.TimerTask; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import gregtech.GT_Mod; import gregtech.api.GregTech_API; import gregtech.api.enums.GT_Values; import gregtech.api.enums.Materials; @@ -24,11 +22,8 @@ import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.BaseMetaTileEntity; import gregtech.api.util.GT_LanguageManager; import gregtech.api.util.GT_Log; -import gregtech.api.util.GT_Recipe; -import gregtech.api.util.GT_Recipe.GT_Recipe_Map; import gregtech.api.util.GT_Utility; import gregtech.api.util.Recipe_GT; -import gregtech.api.util.Recipe_GT.Gregtech_Recipe_Map; import gregtech.common.GT_Proxy; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.api.objects.data.AutoMap; @@ -39,11 +34,8 @@ import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.material.ELEMENT; import gtPlusPlus.core.util.minecraft.FluidUtils; import gtPlusPlus.core.util.minecraft.MaterialUtils; -import gtPlusPlus.core.util.reflect.ProxyFinder; -import gtPlusPlus.core.util.reflect.ReflectionUtils; import gtPlusPlus.xmod.gregtech.api.metatileentity.BaseCustomTileEntity; import gtPlusPlus.xmod.gregtech.api.metatileentity.custom.power.BaseCustomPower_MTE; -import gtPlusPlus.xmod.gregtech.loaders.misc.AssLineAchievements; import net.minecraft.block.Block; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.player.EntityPlayer; @@ -98,6 +90,9 @@ public class Meta_GT_Proxy { GT_Log.out.println("GT++ Mod: Fatal Error ocurred while initializing TileEntities, crashing Minecraft."); throw new RuntimeException(""); } + + //Gotta set it here so that we don't try call gregtech too early. + StaticFields59.mGT6StylePipes = (boolean) StaticFields59.getFieldFromGregtechProxy(true, "gt6Pipe"); GT_Log.out.println("GT++ Mod: Registering the BaseMetaTileEntity."); GameRegistry.registerTileEntity(tBaseMetaTileEntity.getClass(), "BaseMetaTileEntity_GTPP"); @@ -375,37 +370,13 @@ public class Meta_GT_Proxy { } - private static GT_Proxy[] mProxies = new GT_Proxy[2]; + static GT_Proxy[] mProxies = new GT_Proxy[2]; + /** + * @deprecated Use {@link StaticFields59#getFieldFromGregtechProxy(boolean,String)} instead + */ public static Object getFieldFromGregtechProxy(boolean client, String fieldName) { - Object proxyGT; - - if (mProxies[0] != null && client) { - proxyGT = mProxies[0]; - } else if (mProxies[1] != null && !client) { - proxyGT = mProxies[1]; - } else { - try { - proxyGT = (client ? ProxyFinder.getClientProxy(GT_Mod.instance) - : ProxyFinder.getServerProxy(GT_Mod.instance)); - } catch (final ReflectiveOperationException e1) { - proxyGT = null; - Logger.INFO("Failed to obtain instance of GT " + (client ? "Client" : "Server") + " proxy."); - } - if (mProxies[0] == null && client) { - mProxies[0] = (GT_Proxy) proxyGT; - } else if (mProxies[1] == null && !client) { - mProxies[1] = (GT_Proxy) proxyGT; - } - } - - if (proxyGT != null && proxyGT instanceof GT_Proxy) { - try { - return ReflectionUtils.getField(proxyGT.getClass(), fieldName).get(proxyGT); - } catch (IllegalArgumentException | IllegalAccessException e) { - } - } - return null; + return StaticFields59.getFieldFromGregtechProxy(client, fieldName); } public void setCustomGregtechTooltip(String aNbtTagName, FormattedTooltipString aData) { diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/StaticFields59.java b/src/Java/gtPlusPlus/xmod/gregtech/common/StaticFields59.java index 2287d7964c..2a3fd5e77c 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/common/StaticFields59.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/StaticFields59.java @@ -9,6 +9,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import gregtech.GT_Mod; import gregtech.api.GregTech_API; import gregtech.api.enums.Materials; import gregtech.api.enums.OrePrefixes; @@ -18,8 +19,10 @@ import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Muffl import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_TieredMachineBlock; import gregtech.api.util.GT_ModHandler; import gregtech.api.util.GT_Recipe.GT_Recipe_Map; +import gregtech.common.GT_Proxy; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.reflect.ProxyFinder; import gtPlusPlus.core.util.reflect.ReflectionUtils; import net.minecraft.block.Block; import net.minecraft.item.ItemStack; @@ -27,7 +30,7 @@ import net.minecraft.item.ItemStack; public class StaticFields59 { - public static final boolean mGT6StylePipes; + public static boolean mGT6StylePipes; public static final Field mGtBlockCasings5; public static final Field mPreventableComponents; @@ -49,8 +52,6 @@ public class StaticFields59 { static { Logger.INFO("[SH] Creating Static Helper for various fields which require reflective access."); - mGT6StylePipes = (boolean) Meta_GT_Proxy.getFieldFromGregtechProxy(false, "gt6Pipe"); - mGtBlockCasings5 = getField(GregTech_API.class, "sBlockCasings5"); Logger.INFO("[SH] Got Field: sBlockCasings5"); mPreventableComponents = getField(OrePrefixes.class, "mPreventableComponents"); @@ -182,5 +183,36 @@ public class StaticFields59 { return null; } + public static Object getFieldFromGregtechProxy(boolean client, String fieldName) { + Object proxyGT; + + if (Meta_GT_Proxy.mProxies[0] != null && client) { + proxyGT = Meta_GT_Proxy.mProxies[0]; + } else if (Meta_GT_Proxy.mProxies[1] != null && !client) { + proxyGT = Meta_GT_Proxy.mProxies[1]; + } else { + try { + proxyGT = (client ? ProxyFinder.getClientProxy(GT_Mod.instance) + : ProxyFinder.getServerProxy(GT_Mod.instance)); + } catch (final ReflectiveOperationException e1) { + proxyGT = null; + Logger.INFO("Failed to obtain instance of GT " + (client ? "Client" : "Server") + " proxy."); + } + if (Meta_GT_Proxy.mProxies[0] == null && client) { + Meta_GT_Proxy.mProxies[0] = (GT_Proxy) proxyGT; + } else if (Meta_GT_Proxy.mProxies[1] == null && !client) { + Meta_GT_Proxy.mProxies[1] = (GT_Proxy) proxyGT; + } + } + + if (proxyGT != null && proxyGT instanceof GT_Proxy) { + try { + return ReflectionUtils.getField(proxyGT.getClass(), fieldName).get(proxyGT); + } catch (IllegalArgumentException | IllegalAccessException e) { + } + } + return null; + } + } diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/GregtechMetaEnergyBuffer.java b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/GregtechMetaEnergyBuffer.java index 9674871477..86d02eae9a 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/GregtechMetaEnergyBuffer.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/GregtechMetaEnergyBuffer.java @@ -38,7 +38,7 @@ public class GregtechMetaEnergyBuffer extends GregtechMetaTileEntity { @Override public String[] getDescription() { - return new String[] {this.mDescription, "Defaults 4A In/Out", "Change output Amperage with a screwdriver", "Now Portable!", CORE.GT_Tooltip}; + return new String[] {this.mDescription, "Defaults 4A In/Out", "Change output Amperage with a screwdriver", "Now Portable!"}; } @Override @@ -253,6 +253,7 @@ public class GregtechMetaEnergyBuffer extends GregtechMetaTileEntity { final double c = ((double) tempStorage / this.maxEUStore()) * 100; final double roundOff = Math.round(c * 100.00) / 100.00; PlayerUtils.messagePlayer(playerIn, "Energy: " + GT_Utility.formatNumbers(tempStorage) + " EU at "+V[this.mTier]+"v ("+roundOff+"%)"); + PlayerUtils.messagePlayer(playerIn, "Amperage: " + GT_Utility.formatNumbers(maxAmperesIn())+"A"); } //Utils.LOG_WARNING("Begin Show Energy"); -- cgit