From 907482b1d3df8b4769c9e6a3b9c6f3ad669c1e6f Mon Sep 17 00:00:00 2001 From: Zarathul Date: Sun, 15 May 2016 00:50:11 +0200 Subject: [PATCH] - Changed java requirements to Java 8. - Now uses the generic "Simple Mods" tab. - Moved fluid container manipulation methods from ValveBlock to Utils. - FluidFillingEvent should now always report the correct amount when fluid is added to the tank. - ValveBlock model now renders the same way in the GUI as in third person. - Added detection and handling of stackable IFluidContainerItems that don't respect their own stack size (Fixed #10). --- build.gradle | 7 +- .../simplefluidtanks/SimpleFluidTanks.java | 3 + .../simplefluidtanks/blocks/ValveBlock.java | 166 +----------- .../simplefluidtanks/common/Utils.java | 252 ++++++++++++++++-- .../items/CreativeTabLogoItem.java | 25 ++ .../registration/Registry.java | 44 +-- .../tileentities/ValveBlockEntity.java | 2 +- .../models/item/creativeTabLogo.json | 18 ++ .../models/item/valveBlock.json | 9 +- .../textures/items/creativeTabLogo.png | Bin 0 -> 4254 bytes 10 files changed, 322 insertions(+), 204 deletions(-) create mode 100644 src/main/java/net/zarathul/simplefluidtanks/items/CreativeTabLogoItem.java create mode 100644 src/main/resources/assets/simplefluidtanks/models/item/creativeTabLogo.json create mode 100644 src/main/resources/assets/simplefluidtanks/textures/items/creativeTabLogo.png diff --git a/build.gradle b/build.gradle index 0d8bd4c..9f3dba7 100644 --- a/build.gradle +++ b/build.gradle @@ -17,10 +17,13 @@ buildscript apply plugin: 'net.minecraftforge.gradle.forge' -version = "1.8.9-1.3.0.5" +version = "1.8.9-1.3.0.6" group= "net.zarathul.simplefluidtanks" // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = "simplefluidtanks" +sourceCompatibility = 1.8 +targetCompatibility = 1.8 + jar { exclude 'mcp/**' @@ -28,7 +31,7 @@ jar minecraft { - version = "1.8.9-11.15.1.1751" + version = "1.8.9-11.15.1.1890-1.8.9" runDir = "run" mappings = "stable_20" diff --git a/src/main/java/net/zarathul/simplefluidtanks/SimpleFluidTanks.java b/src/main/java/net/zarathul/simplefluidtanks/SimpleFluidTanks.java index 17506ed..a691706 100644 --- a/src/main/java/net/zarathul/simplefluidtanks/SimpleFluidTanks.java +++ b/src/main/java/net/zarathul/simplefluidtanks/SimpleFluidTanks.java @@ -12,6 +12,7 @@ import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.zarathul.simplefluidtanks.blocks.TankBlock; import net.zarathul.simplefluidtanks.blocks.ValveBlock; +import net.zarathul.simplefluidtanks.items.CreativeTabLogoItem; import net.zarathul.simplefluidtanks.items.WrenchItem; @Mod(modid = SimpleFluidTanks.MOD_ID, name = "SimpleFluidTanks", version = SimpleFluidTanks.VERSION, guiFactory = "net.zarathul.simplefluidtanks.configuration.ConfigGuiFactory") @@ -29,6 +30,7 @@ public class SimpleFluidTanks // items public static WrenchItem wrenchItem; + public static CreativeTabLogoItem creativeTabLogoItem; // creative tabs public static CreativeTabs creativeTab; @@ -43,6 +45,7 @@ public class SimpleFluidTanks // constants public static final String MOD_ID = "simplefluidtanks"; public static final String MOD_READABLE_NAME = "Simple Fluid Tanks"; + public static final String MOD_TAB_NAME = "Simple Mods"; public static final String VERSION = "@VERSION@"; @EventHandler diff --git a/src/main/java/net/zarathul/simplefluidtanks/blocks/ValveBlock.java b/src/main/java/net/zarathul/simplefluidtanks/blocks/ValveBlock.java index 6919280..1865b9f 100644 --- a/src/main/java/net/zarathul/simplefluidtanks/blocks/ValveBlock.java +++ b/src/main/java/net/zarathul/simplefluidtanks/blocks/ValveBlock.java @@ -6,18 +6,14 @@ import net.minecraft.block.state.BlockState; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.BlockPos; import net.minecraft.util.EnumFacing; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; -import net.minecraftforge.common.util.FakePlayer; import net.minecraftforge.fluids.FluidContainerRegistry; -import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.IFluidContainerItem; import net.zarathul.simplefluidtanks.SimpleFluidTanks; import net.zarathul.simplefluidtanks.common.Utils; @@ -165,7 +161,8 @@ public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, En // react to fluid containers if (equippedItemStack.getItem() instanceof IFluidContainerItem || FluidContainerRegistry.isContainer(equippedItemStack)) { - handleContainerClick(world, pos, player, equippedItemStack); + ValveBlockEntity valveEntity = Utils.getTileEntityAt(world, ValveBlockEntity.class, pos); + Utils.fillDrainFluidContainer(player, equippedItemStack, valveEntity); return true; } @@ -207,7 +204,7 @@ public int getComparatorInputOverride(World world, BlockPos pos) @Override protected void handleToolWrenchClick(World world, BlockPos pos, EntityPlayer player, ItemStack equippedItemStack) { - // on sneak use: disband the multiblock | on use: rebuild the multiblock + // On sneak use: disband the multiblock | On use: rebuild the multiblock ValveBlockEntity valveEntity = Utils.getTileEntityAt(world, ValveBlockEntity.class, pos); @@ -219,7 +216,6 @@ protected void handleToolWrenchClick(World world, BlockPos pos, EntityPlayer pla } world.setBlockToAir(pos); - // last two parameters are metadata and fortune dropBlockAsItem(world, pos, this.getDefaultState(), 0); } else if (valveEntity != null) @@ -228,160 +224,4 @@ else if (valveEntity != null) valveEntity.formMultiblock(); } } - - /** - * Handles fluid containers used on the {@link ValveBlock}. - * - * @param world - * The world. - * @param pos - * The {@link ValveBlock}s coordinates. - * @param player - * The player using the item. - * @param equippedItemStack - * The item(stack) used on the {@link ValveBlock}. - */ - private void handleContainerClick(World world, BlockPos pos, EntityPlayer player, ItemStack equippedItemStack) - { - ValveBlockEntity valveEntity = Utils.getTileEntityAt(world, ValveBlockEntity.class, pos); - - if (valveEntity != null) - { - if (FluidContainerRegistry.isEmptyContainer(equippedItemStack) || - Utils.isEmptyComplexContainer(equippedItemStack) || - (equippedItemStack.getItem() instanceof IFluidContainerItem && player.isSneaking())) - { - fillContainerFromTank(world, pos, player, equippedItemStack, valveEntity); - } - else - { - drainContainerIntoTank(world, pos, player, equippedItemStack, valveEntity); - } - } - } - - /** - * Fills an empty container with the liquid contained in the multiblock tank. - * - * @param world - * The world. - * @param pos - * The {@link ValveBlock}s coordinates. - * @param player - * The player holding the container. - * @param equippedItemStack - * The container {@link ItemStack}. - * @param valveEntity - * The affected {@link ValveBlock}s {@link TileEntity} ({@link ValveBlockEntity}). - */ - private void fillContainerFromTank(World world, BlockPos pos, EntityPlayer player, ItemStack equippedItemStack, ValveBlockEntity valveEntity) - { - if (valveEntity.getFluid() == null) return; - - if (equippedItemStack.getItem() instanceof IFluidContainerItem) - { - // handle IFluidContainerItem items - - IFluidContainerItem containerItem = (IFluidContainerItem) equippedItemStack.getItem(); - int fillFluidAmount = containerItem.fill(equippedItemStack, valveEntity.getFluid(), true); - valveEntity.drain(null, fillFluidAmount, true); - } - else - { - // handle drain/fill by exchange items - - ItemStack filledContainer = Utils.fillFluidContainer(valveEntity.getFluid(), equippedItemStack); - - if (filledContainer != null) - { - int containerCapacity = Utils.getFluidContainerCapacity(valveEntity.getFluid(), equippedItemStack); - - if (containerCapacity > 0) - { - FluidStack drainedFluid = valveEntity.drain(null, containerCapacity, true); - if (drainedFluid != null && drainedFluid.amount == containerCapacity) - { - if (--equippedItemStack.stackSize <= 0) - { - player.inventory.setInventorySlotContents(player.inventory.currentItem, null); - } - - // add filled container to player inventory or drop it to the ground if the inventory is full or we're dealing with a fake player - - if (player instanceof FakePlayer || !player.inventory.addItemStackToInventory(filledContainer)) - { - world.spawnEntityInWorld(new EntityItem(world, player.posX + 0.5D, player.posY + 1.5D, player.posZ + 0.5D, filledContainer)); - } - else if (player instanceof EntityPlayerMP) - { - ((EntityPlayerMP) player).sendContainerToPlayer(player.inventoryContainer); - } - } - } - } - } - } - - /** - * Drains the contents of a container into the multiblock tank. - * - * @param world - * The world. - * @param pos - * The {@link ValveBlock}s coordinates. - * @param player - * The player holding the container. - * @param equippedItemStack - * The container {@link ItemStack}. - * @param valveEntity - * The affected {@link ValveBlock}s {@link TileEntity} ({@link ValveBlockEntity}). - */ - private void drainContainerIntoTank(World world, BlockPos pos, EntityPlayer player, ItemStack equippedItemStack, ValveBlockEntity valveEntity) - { - if (valveEntity.isFull()) return; - - if (equippedItemStack.getItem() instanceof IFluidContainerItem) - { - // handle IFluidContainerItem items - - IFluidContainerItem containerItem = (IFluidContainerItem) equippedItemStack.getItem(); - FluidStack containerFluid = containerItem.getFluid(equippedItemStack); - FluidStack tankFluid = valveEntity.getFluid(); - - if (tankFluid == null || tankFluid.isFluidEqual(containerFluid)) - { - int drainAmount = Math.min(valveEntity.getRemainingCapacity(), containerFluid.amount); - // drain the fluid from the container first because the amount per drain could be limited - FluidStack drainFluid = containerItem.drain(equippedItemStack, drainAmount, true); - valveEntity.fill(null, drainFluid, true); - } - } - else - { - // handle drain/fill by exchange items - - FluidStack containerFluid = Utils.getFluidForFilledItem(equippedItemStack); - - if (valveEntity.fill(null, containerFluid, true) > 0 && !player.capabilities.isCreativeMode) // don't consume the container contents in creative mode - { - ItemStack emptyContainer = FluidContainerRegistry.drainFluidContainer(equippedItemStack); - - if (--equippedItemStack.stackSize <= 0) - { - player.inventory.setInventorySlotContents(player.inventory.currentItem, null); - } - - // add emptied container to player inventory or drop it to the ground if the inventory is full or we're dealing with a fake player - - if (player instanceof FakePlayer || !player.inventory.addItemStackToInventory(emptyContainer)) - { - world.spawnEntityInWorld(new EntityItem(world, player.posX + 0.5D, player.posY + 1.5D, player.posZ + 0.5D, emptyContainer)); - } - else if (player instanceof EntityPlayerMP) - { - ((EntityPlayerMP) player).sendContainerToPlayer(player.inventoryContainer); - } - } - } - } } diff --git a/src/main/java/net/zarathul/simplefluidtanks/common/Utils.java b/src/main/java/net/zarathul/simplefluidtanks/common/Utils.java index 9fe37b3..dc87eab 100644 --- a/src/main/java/net/zarathul/simplefluidtanks/common/Utils.java +++ b/src/main/java/net/zarathul/simplefluidtanks/common/Utils.java @@ -6,12 +6,16 @@ import com.google.common.base.Strings; import com.google.common.collect.Iterables; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.BlockPos; import net.minecraft.util.StatCollector; import net.minecraft.world.IBlockAccess; +import net.minecraftforge.common.util.FakePlayer; import net.minecraftforge.fluids.FluidContainerRegistry; import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData; import net.minecraftforge.fluids.FluidStack; @@ -31,7 +35,7 @@ public final class Utils public static final ItemStack FILLED_BOTTLE = new ItemStack(Items.potionitem); /** - * Chances that other mods register fluid containers while the game is already running are low. So we cache the container data. + * Chances that other mods register fluid containers while the game is already running are low. So cache the container data. */ private static FluidContainerData[] cachedFluidContainerData = null; @@ -141,6 +145,228 @@ public static final ArrayList multiLineTranslateToLocal(String key, Obje return lines; } + + /** + * Calculates the fluid level for the specified fill percentage. + * + * @param percentage + * The fill percentage. + * @return + * A value between 0 and {@code TankModelFactory.FLUID_LEVELS}. + */ + public static int getFluidLevel(int fillPercentage) + { + int level = (int)Math.round((fillPercentage / 100.0d) * TankModelFactory.FLUID_LEVELS); + + // Make sure that even for small amounts the fluid is rendered at the first level. + return (fillPercentage > 0) ? Math.max(1, level) : 0; + } + + public static final void fillDrainFluidContainer(EntityPlayer player, ItemStack containerStack, ValveBlockEntity valveEntity) + { + if (player == null || containerStack == null || containerStack.stackSize < 1 || valveEntity == null) return; + + if (FluidContainerRegistry.isEmptyContainer(containerStack) || + isEmptyComplexContainer(containerStack) || + (containerStack.getItem() instanceof IFluidContainerItem && player.isSneaking())) + { + fillContainerFromTank(player, containerStack, valveEntity); + } + else + { + drainContainerIntoTank(player, containerStack, valveEntity); + } + } + + /** + * Fills an empty container with the liquid contained in the multiblock tank. + * + * @param world + * The world. + * @param pos + * The {@link ValveBlock}s coordinates. + * @param player + * The player holding the container. + * @param containerStack + * The container {@link ItemStack}. + * @param valveEntity + * The affected {@link ValveBlock}s {@link TileEntity} ({@link ValveBlockEntity}). + */ + private static final void fillContainerFromTank(EntityPlayer player, ItemStack containerStack, ValveBlockEntity valveEntity) + { + if (valveEntity.getFluid() == null) return; + + boolean doItemExchange = false; + ItemStack filledContainer; + + if (containerStack.getItem() instanceof IFluidContainerItem) + { + // Handle IFluidContainerItem items + + doItemExchange = containerNeedsUnstacking(containerStack); + IFluidContainerItem containerItem = (IFluidContainerItem) containerStack.getItem(); + filledContainer = containerStack; + + if (doItemExchange) + { + filledContainer = containerStack.copy(); + filledContainer.stackSize = 1; + } + + int fillFluidAmount = containerItem.fill(filledContainer, valveEntity.getFluid(), true); + valveEntity.drain(null, fillFluidAmount, true); + } + else + { + // Handle filling by exchange items + + filledContainer = Utils.fillFluidContainer(valveEntity.getFluid(), containerStack); + + if (filledContainer != null) + { + int containerCapacity = Utils.getFluidContainerCapacity(valveEntity.getFluid(), containerStack); + + if (containerCapacity > 0) + { + FluidStack drainedFluid = valveEntity.drain(null, containerCapacity, true); + doItemExchange = (drainedFluid != null && drainedFluid.amount == containerCapacity); + } + } + } + + // Give filled container to the player + + if (doItemExchange) + { + exchangeItems(player, containerStack, filledContainer); + } + } + + /** + * Drains the contents of a container into the multiblock tank. + * + * @param world + * The world. + * @param pos + * The {@link ValveBlock}s coordinates. + * @param player + * The player holding the container. + * @param containerStack + * The container {@link ItemStack}. + * @param valveEntity + * The affected {@link ValveBlock}s {@link TileEntity} ({@link ValveBlockEntity}). + */ + private static final void drainContainerIntoTank(EntityPlayer player, ItemStack containerStack, ValveBlockEntity valveEntity) + { + if (valveEntity.isFull()) return; + + boolean doItemExchange = false; + ItemStack emptyContainer = null; + + if (containerStack.getItem() instanceof IFluidContainerItem) + { + // Handle IFluidContainerItem items + + doItemExchange = containerNeedsUnstacking(containerStack); + IFluidContainerItem containerItem = (IFluidContainerItem) containerStack.getItem(); + emptyContainer = containerStack; + + if (doItemExchange) + { + emptyContainer = containerStack.copy(); + emptyContainer.stackSize = 1; + } + + FluidStack containerFluid = containerItem.getFluid(emptyContainer); + FluidStack tankFluid = valveEntity.getFluid(); + + if (tankFluid == null || tankFluid.isFluidEqual(containerFluid)) + { + int drainAmount = Math.min(valveEntity.getRemainingCapacity(), containerFluid.amount); + // Drain the fluid from the container first because the amount per drain could be limited + FluidStack drainedFluid = containerItem.drain(emptyContainer, drainAmount, true); + valveEntity.fill(null, drainedFluid, true); + } + } + else + { + // Handle empty by exchange items + + FluidStack containerFluid = Utils.getFluidForFilledItem(containerStack); + + // Don't consume the container contents in creative mode + if (valveEntity.fill(null, containerFluid, true) > 0 && !player.capabilities.isCreativeMode) + { + emptyContainer = FluidContainerRegistry.drainFluidContainer(containerStack); + doItemExchange = (emptyContainer != null); + } + } + + // Give the emptied container to the player + + if (doItemExchange) + { + exchangeItems(player, containerStack, emptyContainer); + } + } + + /** + * Exchanges one of the items in the original stack with a new item. + * + * @param player + * The player in whose inventory the items should be exchanged. + * @param originalStack + * The original stack of items. + * @param newStack + * The new item stack. + */ + private static final void exchangeItems(EntityPlayer player, ItemStack originalStack, ItemStack newStack) + { + if (player == null || originalStack == null || newStack == null) return; + + if (--originalStack.stackSize <= 0) + { + player.inventory.setInventorySlotContents(player.inventory.currentItem, null); + } + + // Add new ItemStack to player inventory or drop it to the ground if the inventory is full or we're dealing with a fake player + + if (player instanceof FakePlayer || !player.inventory.addItemStackToInventory(newStack)) + { + player.worldObj.spawnEntityInWorld(new EntityItem(player.worldObj, player.posX + 0.5D, player.posY + 1.5D, player.posZ + 0.5D, newStack)); + } + else + { + if (player instanceof EntityPlayerMP) + { + ((EntityPlayerMP)player).sendContainerToPlayer(player.inventoryContainer); + } + + float pitch = ((player.worldObj.rand.nextFloat() - player.worldObj.rand.nextFloat()) * 0.7F + 1.0F) * 2.0F; + player.worldObj.playSoundEffect(player.posX, player.posY, player.posZ, "random.pop", 0.2F, pitch); + } + } + + /** + * Tries to ascertain if a IFluidContainerItem has to be unstacked before manipulating the contents. + * + * @param containerStack + * A stack of the container item that should be checked. + * @return + * true if the container item returns the same capacity for different + * stack sizes, otherwise false. + */ + private static final boolean containerNeedsUnstacking(ItemStack containerStack) + { + if (containerStack == null || containerStack.stackSize < 2) return false; + + ItemStack sizeOneContainerStack = containerStack.copy(); + sizeOneContainerStack.stackSize = 1; + + IFluidContainerItem container = (IFluidContainerItem)containerStack.getItem(); + + return container.getCapacity(containerStack) == container.getCapacity(sizeOneContainerStack); + } /** * Checks if an item is a container that implements {@code IFluidContainerItem} and is empty. @@ -150,7 +376,7 @@ public static final ArrayList multiLineTranslateToLocal(String key, Obje * @return * {@code true} if the container is empty and implements {@code IFluidContainerItem}, otherwise {@code false}. */ - public static final boolean isEmptyComplexContainer(ItemStack item) + private static final boolean isEmptyComplexContainer(ItemStack item) { if (item == null) return false; @@ -175,7 +401,7 @@ public static final boolean isEmptyComplexContainer(ItemStack item) * @return * The containers capacity or 0 if the container could not be found. */ - public static final int getFluidContainerCapacity(FluidStack fluid, ItemStack container) + private static final int getFluidContainerCapacity(FluidStack fluid, ItemStack container) { if (fluid == null || container == null) return 0; @@ -195,7 +421,7 @@ public static final int getFluidContainerCapacity(FluidStack fluid, ItemStack co * @return * Filled container if successful, otherwise null. */ - public static ItemStack fillFluidContainer(FluidStack fluid, ItemStack container) + private static ItemStack fillFluidContainer(FluidStack fluid, ItemStack container) { if (container == null || fluid == null) return null; @@ -228,7 +454,7 @@ public static ItemStack fillFluidContainer(FluidStack fluid, ItemStack container * @return * FluidStack representing stored fluid. */ - public static FluidStack getFluidForFilledItem(ItemStack filledContainer) + private static FluidStack getFluidForFilledItem(ItemStack filledContainer) { if (filledContainer == null) return null; @@ -242,20 +468,4 @@ public static FluidStack getFluidForFilledItem(ItemStack filledContainer) return fluid; } - - /** - * Calculates the fluid level for the specified fill percentage. - * - * @param percentage - * The fill percentage. - * @return - * A value between 0 and {@code TankModelFactory.FLUID_LEVELS}. - */ - public static int getFluidLevel(int fillPercentage) - { - int level = (int)Math.round((fillPercentage / 100.0d) * TankModelFactory.FLUID_LEVELS); - - // Make sure that even for small amounts the fluid is rendered at the first level. - return (fillPercentage > 0) ? Math.max(1, level) : 0; - } } diff --git a/src/main/java/net/zarathul/simplefluidtanks/items/CreativeTabLogoItem.java b/src/main/java/net/zarathul/simplefluidtanks/items/CreativeTabLogoItem.java new file mode 100644 index 0000000..3100548 --- /dev/null +++ b/src/main/java/net/zarathul/simplefluidtanks/items/CreativeTabLogoItem.java @@ -0,0 +1,25 @@ +package net.zarathul.simplefluidtanks.items; + +import net.minecraft.item.Item; +import net.zarathul.simplefluidtanks.registration.Registry; + + +/** + * Serves no purpose other than providing the icon for the creative tab. + */ +public class CreativeTabLogoItem extends Item +{ + public CreativeTabLogoItem() + { + super(); + + setUnlocalizedName(Registry.CREATIVE_TAB_LOGO_ITEM_NAME); + setCreativeTab(null); + } + + @Override + public boolean isFull3D() + { + return false; + } +} \ No newline at end of file diff --git a/src/main/java/net/zarathul/simplefluidtanks/registration/Registry.java b/src/main/java/net/zarathul/simplefluidtanks/registration/Registry.java index 2075bd8..6c5254a 100644 --- a/src/main/java/net/zarathul/simplefluidtanks/registration/Registry.java +++ b/src/main/java/net/zarathul/simplefluidtanks/registration/Registry.java @@ -1,5 +1,6 @@ package net.zarathul.simplefluidtanks.registration; +import java.util.Arrays; import net.minecraft.client.resources.model.ModelResourceLocation; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.Item; @@ -16,6 +17,7 @@ import net.zarathul.simplefluidtanks.blocks.ValveBlock; import net.zarathul.simplefluidtanks.configuration.Config; import net.zarathul.simplefluidtanks.configuration.Recipe; +import net.zarathul.simplefluidtanks.items.CreativeTabLogoItem; import net.zarathul.simplefluidtanks.items.TankItem; import net.zarathul.simplefluidtanks.items.ValveItem; import net.zarathul.simplefluidtanks.items.WrenchItem; @@ -34,6 +36,7 @@ public final class Registry public static final String VALVE_ITEM_NAME = "valveItem"; public static final String WRENCH_ITEM_NAME = "wrench"; + public static final String CREATIVE_TAB_LOGO_ITEM_NAME = "creativeTabLogo"; private static final String TANKBLOCK_ENTITY_NAME = "tankBlockEntity"; private static final String TANKBLOCK_ENTITY_KEY = SimpleFluidTanks.MOD_ID + ":" + TANKBLOCK_ENTITY_NAME; @@ -44,6 +47,7 @@ public final class Registry private static final String TANKITEM_MODEL_RESLOC = SimpleFluidTanks.MOD_ID + ":" + TANK_BLOCK_NAME; private static final String VALVEITEM_MODEL_RESLOC = SimpleFluidTanks.MOD_ID + ":" + VALVE_BLOCK_NAME; private static final String WRENCHITEM_MODEL_RESLOC = SimpleFluidTanks.MOD_ID + ":" + WRENCH_ITEM_NAME; + private static final String CREATIVETABITEM_MODEL_RESLOC = SimpleFluidTanks.MOD_ID + ":" + CREATIVE_TAB_LOGO_ITEM_NAME; /** * Creates and registers all blocks added by the mod. @@ -70,6 +74,9 @@ public static void registerItems() { SimpleFluidTanks.wrenchItem = new WrenchItem(); GameRegistry.registerItem(SimpleFluidTanks.wrenchItem, WRENCH_ITEM_NAME); + + SimpleFluidTanks.creativeTabLogoItem = new CreativeTabLogoItem(); + GameRegistry.registerItem(SimpleFluidTanks.creativeTabLogoItem, CREATIVE_TAB_LOGO_ITEM_NAME); } /** @@ -83,6 +90,7 @@ public static void registerItemModels() ModelLoader.setCustomModelResourceLocation(tankItem, 0, new ModelResourceLocation(TANKITEM_MODEL_RESLOC, "inventory")); ModelLoader.setCustomModelResourceLocation(valveItem, 0, new ModelResourceLocation(VALVEITEM_MODEL_RESLOC, "inventory")); ModelLoader.setCustomModelResourceLocation(SimpleFluidTanks.wrenchItem, 0, new ModelResourceLocation(WRENCHITEM_MODEL_RESLOC, "inventory")); + ModelLoader.setCustomModelResourceLocation(SimpleFluidTanks.creativeTabLogoItem, 0, new ModelResourceLocation(CREATIVETABITEM_MODEL_RESLOC, "inventory")); } /** @@ -177,24 +185,30 @@ private static final boolean registerRecipe(ItemStack result, Recipe recipe) } /** - * Adds a tab in creative mode for the mod. + * Adds a creative mode tab. */ @SideOnly(Side.CLIENT) public static final void addCreativeTab() { - SimpleFluidTanks.creativeTab = new CreativeTabs(SimpleFluidTanks.MOD_READABLE_NAME) - { - @Override - public String getTranslatedTabLabel() - { - return this.getTabLabel(); - } - - @Override - public Item getTabIconItem() - { - return Item.getItemFromBlock(SimpleFluidTanks.tankBlock); - } - }; + // Check if a a "Simple Mods" tab already exists, otherwise make one. + SimpleFluidTanks.creativeTab = Arrays.stream(CreativeTabs.creativeTabArray) + .filter(tab -> tab.getTabLabel().equals(SimpleFluidTanks.MOD_TAB_NAME)) + .findFirst() + .orElse( + new CreativeTabs(SimpleFluidTanks.MOD_TAB_NAME) + { + @Override + public String getTranslatedTabLabel() + { + return this.getTabLabel(); + } + + @Override + public Item getTabIconItem() + { + return SimpleFluidTanks.creativeTabLogoItem; + } + } + ); } } diff --git a/src/main/java/net/zarathul/simplefluidtanks/tileentities/ValveBlockEntity.java b/src/main/java/net/zarathul/simplefluidtanks/tileentities/ValveBlockEntity.java index 4358304..50ad534 100644 --- a/src/main/java/net/zarathul/simplefluidtanks/tileentities/ValveBlockEntity.java +++ b/src/main/java/net/zarathul/simplefluidtanks/tileentities/ValveBlockEntity.java @@ -170,7 +170,7 @@ public int fill(EnumFacing from, FluidStack fillFluid, boolean doFill) worldObj.markChunkDirty(pos, this); worldObj.markBlockForUpdate(pos); worldObj.updateComparatorOutputLevel(pos, SimpleFluidTanks.valveBlock); - FluidEvent.fireEvent(new FluidEvent.FluidFillingEvent(fillFluid, worldObj, pos, internalTank, fillFluid.amount)); + FluidEvent.fireEvent(new FluidEvent.FluidFillingEvent(fillFluid, worldObj, pos, internalTank, fillAmount)); } return fillAmount; diff --git a/src/main/resources/assets/simplefluidtanks/models/item/creativeTabLogo.json b/src/main/resources/assets/simplefluidtanks/models/item/creativeTabLogo.json new file mode 100644 index 0000000..ea3f327 --- /dev/null +++ b/src/main/resources/assets/simplefluidtanks/models/item/creativeTabLogo.json @@ -0,0 +1,18 @@ +{ + "parent": "builtin/generated", + "textures": { + "layer0": "simplefluidtanks:items/creativeTabLogo" + }, + "display": { + "thirdperson": { + "rotation": [ -90, 0, 0 ], + "translation": [ 0, 1, -3 ], + "scale": [ 0.55, 0.55, 0.55 ] + }, + "firstperson": { + "rotation": [ 0, -135, 25 ], + "translation": [ 0, 4, 2 ], + "scale": [ 1.7, 1.7, 1.7 ] + } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/simplefluidtanks/models/item/valveBlock.json b/src/main/resources/assets/simplefluidtanks/models/item/valveBlock.json index 3b42e92..21105d2 100644 --- a/src/main/resources/assets/simplefluidtanks/models/item/valveBlock.json +++ b/src/main/resources/assets/simplefluidtanks/models/item/valveBlock.json @@ -13,6 +13,11 @@ "rotation": [ 10, -45, 170 ], "translation": [ 0, 1.5, -2.75 ], "scale": [ 0.375, 0.375, 0.375 ] - } - } + }, + "gui": { + "rotation": [ 0, 180, 0 ], + "translation": [ 0.00, 0.00, 0.00 ], + "scale": [ 1.00, 1.00, 1.00 ] + } + } } diff --git a/src/main/resources/assets/simplefluidtanks/textures/items/creativeTabLogo.png b/src/main/resources/assets/simplefluidtanks/textures/items/creativeTabLogo.png new file mode 100644 index 0000000000000000000000000000000000000000..2b31f911a65a517af47a663e290bdb1933cc8853 GIT binary patch literal 4254 zcmcImOHWfl6h1Aqh0K<=W))=_nk9m&h5<;tw*Eb(y)j` zn~pV}L|?&{6U6Vu_V!71!L!Xr8_`4N8Xk3^%RPVW^hJ@pO>92tzEgt5(50r9!=b)F zeo=YZ-R3SF8Qa~|SbwT5*H;ni9p&~+rT#`qNdlXanp(^Btc>mJoWM1i^(Il13Vgju zRHg&IUL;C00sr453f2N{Baw}{tN2_sB4L0}T^<}vGC3ZN%7MH**%k;$uFofPiG+Mx zSdeGa)AC?^Jjs?5oFO$@qqN2%nVg2WwjeF z=6r?(DN_*`#!FzRKPXRG7kC&+>;S2QC|2pnN@}ODX0jcLM66_F0uBTCHwX}H1mkxg zR)wTwBKk3=FiBZtyu#}lfgk|8wrsKPTo)le$*qV4g(O%7$8FWG1U6pa-0x>1q!QjY zYdwWY#%rMP>9H{(s}S-+qfStt?~tTiH-*@KyvqhR5==AJbru$3AASSSVyn-GK_B)Ya=2K?jwJt&oImHCib0(txNX^==#M-2OG&rX^2cCmOtrH0v zvAmj5APEAIly0;$g-_8*OmONo0ghjTM3oZ>ddnx*uW~_O1$*7J=loES>@Q`@gSFVf zxo#5R{0m5w*-5al((4~Ml%HXSm!D#@agDlZuZo9KoWQy6_@UXSU9|g{LyXqrhkAU732YAGc#MPl8t+RT9+r6ZM z*X01tvbYM|I>_UPf6e&t*VNSB0uKyt^;$@%J*D2Kr)iN131wTE=F#b!r9(p5)TDo^ vhh@+9?K!4NDiTUpXWFmJ*olN%tIrhhO7`B~4==|%xUcDOYvcVxXFC4?kHS!+ literal 0 HcmV?d00001