diff options
Diffstat (limited to 'src/main/java/gregtech/common')
5 files changed, 252 insertions, 25 deletions
diff --git a/src/main/java/gregtech/common/blocks/GT_Block_Ores_Abstract.java b/src/main/java/gregtech/common/blocks/GT_Block_Ores_Abstract.java index 48cd41187d..d862e5a555 100644 --- a/src/main/java/gregtech/common/blocks/GT_Block_Ores_Abstract.java +++ b/src/main/java/gregtech/common/blocks/GT_Block_Ores_Abstract.java @@ -12,6 +12,7 @@ import gregtech.api.items.GT_Generic_Block; import gregtech.api.util.GT_LanguageManager; import gregtech.api.util.GT_ModHandler; import gregtech.api.util.GT_OreDictUnificator; +import gregtech.api.util.GT_Utility; import gregtech.common.render.GT_Renderer_Block; import net.minecraft.block.Block; import net.minecraft.block.ITileEntityProvider; @@ -20,6 +21,7 @@ import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; import net.minecraft.entity.boss.EntityDragon; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -135,6 +137,22 @@ public abstract class GT_Block_Ores_Abstract extends GT_Generic_Block implements } @Override + public boolean onBlockActivated(World aWorld, int aX, int aY, int aZ, EntityPlayer aPlayer, int aSide, float par1, float par2, float par3) { + if (!aPlayer.isSneaking() || !aPlayer.capabilities.isCreativeMode) { + return false; + } + + TileEntity tTileEntity = aWorld.getTileEntity(aX, aY, aZ); + if (!(tTileEntity instanceof GT_TileEntity_Ores)) { + return false; + } + + boolean tNatural = (((GT_TileEntity_Ores) tTileEntity).mNatural = !((GT_TileEntity_Ores) tTileEntity).mNatural); + GT_Utility.sendChatToPlayer(aPlayer, "Ore \"mNatural\" flag set to: " + tNatural); + return true; + } + + @Override public boolean onBlockEventReceived(World p_149696_1_, int p_149696_2_, int p_149696_3_, int p_149696_4_, int p_149696_5_, int p_149696_6_) { super.onBlockEventReceived(p_149696_1_, p_149696_2_, p_149696_3_, p_149696_4_, p_149696_5_, p_149696_6_); TileEntity tileentity = p_149696_1_.getTileEntity(p_149696_2_, p_149696_3_, p_149696_4_); diff --git a/src/main/java/gregtech/common/items/GT_MetaGenerated_Item_98.java b/src/main/java/gregtech/common/items/GT_MetaGenerated_Item_98.java new file mode 100644 index 0000000000..b7b73b86b4 --- /dev/null +++ b/src/main/java/gregtech/common/items/GT_MetaGenerated_Item_98.java @@ -0,0 +1,189 @@ +package gregtech.common.items; + +import com.google.common.collect.ImmutableMap; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gregtech.api.enums.ItemList; +import gregtech.api.enums.Materials; +import gregtech.api.enums.OrePrefixes; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.items.GT_MetaGenerated_Item; +import gregtech.api.util.GT_LanguageManager; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidContainerRegistry; +import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.fluids.FluidStack; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** This class holds cells for non-GT fluids. */ +public class GT_MetaGenerated_Item_98 extends GT_MetaGenerated_Item { + public static GT_MetaGenerated_Item_98 INSTANCE; + + /** + * Map of internal fluid name to cell type to register for that fluid. + * + * <p>The fluid at index {@code i} (in entry set iteration order) will be assigned ID {@code i}. + * + * <p>When adding a fluid, don't forget to make sure that GregTech loads after the mod that adds + * that fluid! + * + * <p>In order to avoid breaking existing worlds, the entries in this list must not be + * re-ordered or removed! The only safe modification that can be made to this list is adding new + * entries to the end. To remove an entry, pass {@code null} in for the fluid name. + */ + private static final ImmutableMap<String, CellType> FLUIDS = + ImmutableMap.<String, CellType>builder() + .put("steam", CellType.REGULAR) + .put("bacterialsludge", CellType.REGULAR) + .put("mutagen", CellType.REGULAR) + .put("ender", CellType.REGULAR) + .put("endergoo", CellType.REGULAR) + .build(); + + /** + * We support adding two different types of cells. + * + * <p>Regular cells have capacity 1000 and use the regular cell icon. Molten cells have capacity + * 144 and use the molten cell icon. + */ + private enum CellType { + REGULAR(1_000, OrePrefixes.cell), + MOLTEN(144, OrePrefixes.cellMolten); + // We could also add plasma cells (cellPlasma) here if we need to. + // Plasma cells look like molten cells, but have 1000 capacity. + + private final int capacity; + private final OrePrefixes prefix; + + CellType(int capacity, OrePrefixes prefix) { + this.capacity = capacity; + this.prefix = prefix; + } + } + + /** Struct class holding data that we need to properly handle a registered fluid cell item. */ + private static class RegisteredFluidData { + private final Fluid fluid; + private final short[] rgba; + private final IIconContainer iconContainer; + + private RegisteredFluidData(Fluid fluid, short[] rgba, IIconContainer iconContainer) { + this.fluid = fluid; + this.rgba = rgba; + this.iconContainer = iconContainer; + } + } + + /** + * Map of ID to registered fluid data. + * + * <p>Only contains IDs that were successfully registered. + */ + private final Map<Integer, RegisteredFluidData> registeredFluidDataMap; + + public GT_MetaGenerated_Item_98() { + // For some reason, fluid cells will be rendered only if the metadata ID is less than the + // offset. So we will specify maximum offset here. + // See: GT_MetaGenerated_Item_Renderer.java + super("metaitem.98", (short) 32766, (short) FLUIDS.size()); + + INSTANCE = this; + registeredFluidDataMap = new HashMap<>(); + + int i = -1; + for (Map.Entry<String, CellType> entry : FLUIDS.entrySet()) { + i++; // Increment first so that we don't accidentally skip doing so with continue + String fluidName = entry.getKey(); + CellType cellType = entry.getValue(); + if (fluidName == null) { + continue; + } + + Fluid fluid = FluidRegistry.getFluid(fluidName); + if (fluid == null) { + // Fluid is not guaranteed to exist. + // These fluids are non-GT fluids, so the mod may not be present. + continue; + } + + ItemStack itemStack = new ItemStack(this, 1, i); + FluidStack fluidStack = new FluidStack(fluid, cellType.capacity); + + FluidContainerRegistry.registerFluidContainer( + new FluidContainerRegistry.FluidContainerData( + fluidStack, itemStack, ItemList.Cell_Empty.get(1L))); + + GT_LanguageManager.addStringLocalization( + getUnlocalizedName(itemStack) + ".name", + cellType.prefix.mLocalizedMaterialPre + fluid.getLocalizedName(fluidStack) + cellType.prefix.mLocalizedMaterialPost); + + int color = fluid.getColor(); + short[] rgba = new short[4]; + rgba[0] = (short) ((color & 0x00FF0000) >> 16); + rgba[1] = (short) ((color & 0x0000FF00) >> 8); + rgba[2] = (short) (color & 0x000000FF); + rgba[3] = (short) ((color & 0xFF000000) >> 24); + + // We'll just steal the icons from Water. They are all the same anyway (except _NULL is broken for cells). + IIconContainer iconContainer = Materials.Water.mIconSet.mTextures[cellType.prefix.mTextureIndex]; + registeredFluidDataMap.put(i, new RegisteredFluidData(fluid, rgba, iconContainer)); + } + + // We're not going to use these BitSets, so clear them to save memory. + mEnabledItems.clear(); + mVisibleItems.clear(); + } + + @Override + public short[] getRGBa(ItemStack aStack) { + RegisteredFluidData fluidData = registeredFluidDataMap.get(aStack.getItemDamage()); + if (fluidData == null) { + return Materials._NULL.mRGBa; + } + + return fluidData.rgba; + } + + @Override + public ItemStack getContainerItem(ItemStack aStack) { + return ItemList.Cell_Empty.get(1L); + } + + @Override + @SideOnly(Side.CLIENT) + public void getSubItems(Item var1, CreativeTabs aCreativeTab, List aList) { + registeredFluidDataMap.keySet().stream() + .map(i -> new ItemStack(this, 1, i)) + .forEach(aList::add); + } + + @Override + public final IIcon getIconFromDamage(int aMetaData) { + IIconContainer iconContainer = getIconContainer(aMetaData); + if (iconContainer != null) { + return iconContainer.getIcon(); + } + return null; + } + + @Override + public IIconContainer getIconContainer(int aMetaData) { + RegisteredFluidData fluidData = registeredFluidDataMap.get(aMetaData); + if (fluidData == null) { + return null; + } + return fluidData.iconContainer; + } + + @Override + public int getItemStackLimit(ItemStack aStack) { + return 64; + } +} diff --git a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Miner.java b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Miner.java index 4d7a6c4af5..6d4b160a86 100644 --- a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Miner.java +++ b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Miner.java @@ -176,18 +176,21 @@ public class GT_MetaTileEntity_Miner extends GT_MetaTileEntity_BasicMachine { moveOneDown(aBaseMetaTileEntity); } else { ChunkPosition oreBlockPos; - Block block; + int x = 0, y = 0, z = 0; + Block oreBlock; + int oreBlockMetadata = 0; do { oreBlockPos = oreBlockPositions.remove(0); - block = aBaseMetaTileEntity.getBlockOffset(oreBlockPos.chunkPosX, oreBlockPos.chunkPosY, oreBlockPos.chunkPosZ); + oreBlock = aBaseMetaTileEntity.getBlockOffset(oreBlockPos.chunkPosX, oreBlockPos.chunkPosY, oreBlockPos.chunkPosZ); + x = aBaseMetaTileEntity.getXCoord() + oreBlockPos.chunkPosX; + y = aBaseMetaTileEntity.getYCoord() + oreBlockPos.chunkPosY; + z = aBaseMetaTileEntity.getZCoord() + oreBlockPos.chunkPosZ; + oreBlockMetadata = getBaseMetaTileEntity().getWorld().getBlockMetadata(x, y, z); } // someone else might have removed the block - while (block == Blocks.air && !oreBlockPositions.isEmpty()); + while (!GT_Utility.isOre(oreBlock, oreBlockMetadata) && !oreBlockPositions.isEmpty()); - if (block != Blocks.air) { - mineBlock(aBaseMetaTileEntity, block, - aBaseMetaTileEntity.getXCoord() + oreBlockPos.chunkPosX, - aBaseMetaTileEntity.getYCoord() + oreBlockPos.chunkPosY, - aBaseMetaTileEntity.getZCoord() + oreBlockPos.chunkPosZ); + if (GT_Utility.isOre(oreBlock, oreBlockMetadata)) { + mineBlock(aBaseMetaTileEntity, oreBlock, x, y, z); } } } @@ -265,7 +268,15 @@ public class GT_MetaTileEntity_Miner extends GT_MetaTileEntity_BasicMachine { mOutputItems[0] = drops.get(0); if (drops.size() > 1) mOutputItems[1] = drops.get(1); - aBaseMetaTileEntity.getWorld().setBlockToAir(x, y, z); + + short metaData = 0; + TileEntity tTileEntity = getBaseMetaTileEntity().getTileEntity(x, y, z); + if (tTileEntity instanceof GT_TileEntity_Ores) { + metaData = ((GT_TileEntity_Ores) tTileEntity).mMetaData; + } + + ItemStack cobble = GT_Utility.getCobbleForOre(block, metaData); + aBaseMetaTileEntity.getWorld().setBlock(x, y, z, Block.getBlockFromItem(cobble.getItem()), cobble.getItemDamage(), 3); if (debugBlockMiner) GT_Log.out.println("MINER: Mining GT ore block at " + x + " " + y + " " + z); } diff --git a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_PotionBrewer.java b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_PotionBrewer.java index 60056ec39d..79b363fac3 100644 --- a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_PotionBrewer.java +++ b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_PotionBrewer.java @@ -144,16 +144,15 @@ public class GT_MetaTileEntity_PotionBrewer extends GT_MetaTileEntity_BasicMachi } private int setOutput(String aFluidName) { + if (getFillableStack().amount < 750) { + return 0; + } + this.mOutputFluid = FluidRegistry.getFluidStack(aFluidName, 750); if (this.mOutputFluid == null) { this.mOutputFluid = FluidRegistry.getFluidStack("potion.mundane", getFillableStack().amount); - getInputAt(0).stackSize -= 1; - getFillableStack().amount = 0; - return 2; - } - if (getFillableStack().amount < 750) { - return 0; } + getInputAt(0).stackSize -= 1; getFillableStack().amount -= 750; return 2; @@ -171,6 +170,6 @@ public class GT_MetaTileEntity_PotionBrewer extends GT_MetaTileEntity_BasicMachi @Override public int getCapacity() { - return 750; + return 6000; } } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OreDrillingPlantBase.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OreDrillingPlantBase.java index b168e44c41..50f28a83b4 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OreDrillingPlantBase.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OreDrillingPlantBase.java @@ -17,7 +17,6 @@ import gregtech.common.blocks.GT_TileEntity_Ores; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; @@ -32,8 +31,6 @@ import java.util.Collection; import java.util.Collections; import java.util.HashSet; -import org.lwjgl.input.Keyboard; - import static gregtech.api.enums.GT_Values.VN; public abstract class GT_MetaTileEntity_OreDrillingPlantBase extends GT_MetaTileEntity_DrillerBase { @@ -109,21 +106,34 @@ public abstract class GT_MetaTileEntity_OreDrillingPlantBase extends GT_MetaTile } private boolean processOreList(){ ChunkPosition oreBlockPos = null; + int x = 0, y = 0, z = 0; Block oreBlock = null; + int oreBlockMetadata = 0; - while ((oreBlock == null || oreBlock == Blocks.air) && !oreBlockPositions.isEmpty()) { + while ((oreBlock == null || !GT_Utility.isOre(oreBlock, oreBlockMetadata)) && !oreBlockPositions.isEmpty()) { oreBlockPos = oreBlockPositions.remove(0); - if (GT_Utility.eraseBlockByFakePlayer(getFakePlayer(getBaseMetaTileEntity()), oreBlockPos.chunkPosX, oreBlockPos.chunkPosY, oreBlockPos.chunkPosZ, true)) - oreBlock = getBaseMetaTileEntity().getBlock(oreBlockPos.chunkPosX, oreBlockPos.chunkPosY, oreBlockPos.chunkPosZ); + x = oreBlockPos.chunkPosX; + y = oreBlockPos.chunkPosY; + z = oreBlockPos.chunkPosZ; + if (GT_Utility.eraseBlockByFakePlayer(getFakePlayer(getBaseMetaTileEntity()), x, y, z, true)) + oreBlock = getBaseMetaTileEntity().getBlock(x, y, z); + oreBlockMetadata = getBaseMetaTileEntity().getWorld().getBlockMetadata(x, y, z); } if (!tryConsumeDrillingFluid()) { oreBlockPositions.add(0, oreBlockPos); return false; } - if (oreBlock != null && oreBlock != Blocks.air) { - Collection<ItemStack> oreBlockDrops = getBlockDrops(oreBlock, oreBlockPos.chunkPosX, oreBlockPos.chunkPosY, oreBlockPos.chunkPosZ); - getBaseMetaTileEntity().getWorld().setBlockToAir(oreBlockPos.chunkPosX, oreBlockPos.chunkPosY, oreBlockPos.chunkPosZ); + if (oreBlock != null && GT_Utility.isOre(oreBlock, oreBlockMetadata)) { + short metaData = 0; + TileEntity tTileEntity = getBaseMetaTileEntity().getTileEntity(x, y, z); + if (tTileEntity instanceof GT_TileEntity_Ores) { + metaData = ((GT_TileEntity_Ores) tTileEntity).mMetaData; + } + + Collection<ItemStack> oreBlockDrops = getBlockDrops(oreBlock, x, y, z); + ItemStack cobble = GT_Utility.getCobbleForOre(oreBlock, metaData); + getBaseMetaTileEntity().getWorld().setBlock(x, y, z, Block.getBlockFromItem(cobble.getItem()), cobble.getItemDamage(), 3); mOutputItems = getOutputByDrops(oreBlockDrops); } return true; |