From e38c800f215040158c47a34eeb7a6ecc84a74500 Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Tue, 17 May 2016 21:12:33 +0100 Subject: [PATCH] Added Universal Cell --- src/main/java/techreborn/init/ModItems.java | 18 ++-- .../java/techreborn/init/RecipeCompact.java | 9 +- .../techreborn/init/SubItemRetriever.java | 10 +- .../java/techreborn/items/DynamicCell.java | 94 ++++++++++++++++++ src/main/java/techreborn/items/EmptyCell.java | 25 +++++ src/main/java/techreborn/items/ItemCells.java | 1 + .../java/techreborn/proxies/ClientProxy.java | 18 ++++ .../java/techreborn/utils/RecipeUtils.java | 4 +- .../techreborn/blockstates/dyncell.json | 18 ++++ .../assets/techreborn/models/item/cell.json | 6 ++ .../techreborn/textures/items/cell_base.png | Bin 0 -> 486 bytes .../techreborn/textures/items/cell_cover.png | Bin 0 -> 14678 bytes .../techreborn/textures/items/cell_fluid.png | Bin 0 -> 15416 bytes 13 files changed, 179 insertions(+), 24 deletions(-) create mode 100644 src/main/java/techreborn/items/DynamicCell.java create mode 100644 src/main/java/techreborn/items/EmptyCell.java create mode 100644 src/main/resources/assets/techreborn/blockstates/dyncell.json create mode 100644 src/main/resources/assets/techreborn/models/item/cell.json create mode 100644 src/main/resources/assets/techreborn/textures/items/cell_base.png create mode 100644 src/main/resources/assets/techreborn/textures/items/cell_cover.png create mode 100644 src/main/resources/assets/techreborn/textures/items/cell_fluid.png diff --git a/src/main/java/techreborn/init/ModItems.java b/src/main/java/techreborn/init/ModItems.java index c9b84f1a2..bc8e03e3a 100644 --- a/src/main/java/techreborn/init/ModItems.java +++ b/src/main/java/techreborn/init/ModItems.java @@ -28,18 +28,11 @@ import techreborn.api.Reference; public class ModItems { - // This are deprected to stop people using them in the recipes. - @Deprecated public static Item gems; - @Deprecated public static Item ingots; - @Deprecated public static Item nuggets; - @Deprecated public static Item dusts; - @Deprecated public static Item smallDusts; - @Deprecated public static Item parts; @Deprecated public static Item cells; @@ -52,8 +45,6 @@ public class ModItems public static Item manual; public static Item uuMatter; public static Item plate; - public static Item crushedOre; - public static Item purifiedCrushedOre; public static Item cloakingDevice; public static Item reBattery; @@ -124,6 +115,9 @@ public class ModItems public static Item missingRecipe; public static Item debug; + public static Item emptyCell; + public static DynamicCell dynamicCell; + public static void init() throws InstantiationException, IllegalAccessException { gems = new ItemGems(); @@ -312,6 +306,12 @@ public class ModItems debug = new ItemDebugTool(); GameRegistry.registerItem(debug, "debug"); + emptyCell = new EmptyCell(); + GameRegistry.registerItem(emptyCell, "emptyCell"); + + dynamicCell = new DynamicCell(); + GameRegistry.registerItem(dynamicCell, "dynamicCell"); + MinecraftForge.EVENT_BUS.register(BucketHandler.INSTANCE); Core.logHelper.info("TechReborns Items Loaded"); diff --git a/src/main/java/techreborn/init/RecipeCompact.java b/src/main/java/techreborn/init/RecipeCompact.java index bf40656cb..3684da3e5 100644 --- a/src/main/java/techreborn/init/RecipeCompact.java +++ b/src/main/java/techreborn/init/RecipeCompact.java @@ -3,6 +3,7 @@ package techreborn.init; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidRegistry; import techreborn.api.recipe.IRecipeCompact; import techreborn.blocks.BlockMachineFrame; import techreborn.items.*; @@ -36,8 +37,8 @@ public class RecipeCompact implements IRecipeCompact recipes.put("iridiumOre", ItemIngots.getIngotByName("iridium")); recipes.put("plateiron", ItemPlates.getPlateByName("iron")); recipes.put("iridiumPlate", ItemPlates.getPlateByName("iridium")); - recipes.put("cell", ItemCells.getCellByName("empty")); - recipes.put("airCell", ItemCells.getCellByName("empty")); + recipes.put("cell", new ItemStack(ModItems.emptyCell)); + recipes.put("airCell", new ItemStack(ModItems.emptyCell)); recipes.put("electronicCircuit", ItemParts.getPartByName("electronicCircuit")); recipes.put("advancedCircuit", ItemParts.getPartByName("advancedCircuit")); recipes.put("rubberWood", new ItemStack(ModBlocks.rubberLog)); @@ -52,8 +53,8 @@ public class RecipeCompact implements IRecipeCompact recipes.put("diamondDrill", new ItemStack(ModItems.diamondDrill)); recipes.put("miningDrill", new ItemStack(ModItems.ironDrill)); recipes.put("solarPanel", new ItemStack(ModBlocks.solarPanel)); - recipes.put("waterCell", ItemCells.getCellByName("water")); - recipes.put("lavaCell", ItemCells.getCellByName("lava")); + recipes.put("waterCell", DynamicCell.getCellWithFluid(FluidRegistry.WATER)); + recipes.put("lavaCell", DynamicCell.getCellWithFluid(FluidRegistry.LAVA)); recipes.put("pump", new ItemStack(ModBlocks.pump)); // recipes.put("teleporter", new ItemStack(ModItems.missingRecipe)); recipes.put("advancedAlloy", ItemIngots.getIngotByName("advancedAlloy")); diff --git a/src/main/java/techreborn/init/SubItemRetriever.java b/src/main/java/techreborn/init/SubItemRetriever.java index 89ace0718..d97f18779 100644 --- a/src/main/java/techreborn/init/SubItemRetriever.java +++ b/src/main/java/techreborn/init/SubItemRetriever.java @@ -4,15 +4,7 @@ import net.minecraft.item.ItemStack; import techreborn.api.ISubItemRetriever; import techreborn.blocks.BlockOre; import techreborn.blocks.BlockStorage; -import techreborn.items.ItemCells; -import techreborn.items.ItemDusts; -import techreborn.items.ItemDustsSmall; -import techreborn.items.ItemGems; -import techreborn.items.ItemIngots; -import techreborn.items.ItemNuggets; -import techreborn.items.ItemParts; -import techreborn.items.ItemPlates; -import techreborn.items.ItemUpgrades; +import techreborn.items.*; /** * Created by Mark on 03/04/2016. diff --git a/src/main/java/techreborn/items/DynamicCell.java b/src/main/java/techreborn/items/DynamicCell.java new file mode 100644 index 000000000..308fcbc59 --- /dev/null +++ b/src/main/java/techreborn/items/DynamicCell.java @@ -0,0 +1,94 @@ +package techreborn.items; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.ActionResult; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumHand; +import net.minecraft.world.World; +import net.minecraftforge.event.entity.player.FillBucketEvent; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.UniversalBucket; +import techreborn.client.TechRebornCreativeTab; +import techreborn.init.ModItems; + +/** + * Created by modmuss50 on 17/05/2016. + */ +public class DynamicCell extends UniversalBucket{ + + public DynamicCell() { + super(1000, new ItemStack(ModItems.emptyCell), false); + setCreativeTab(TechRebornCreativeTab.instance); + setUnlocalizedName("techreborn.cellFilled"); + } + + @Override + public ActionResult onItemRightClick(ItemStack itemstack, World world, EntityPlayer player, EnumHand hand) { + return ActionResult.newResult(EnumActionResult.FAIL, itemstack); + } + + @Override + public void onFillBucket(FillBucketEvent event) { + return; + } + + @Override + public String getItemStackDisplayName(ItemStack stack) + { + FluidStack fluidStack = getFluid(stack); + if (fluidStack == null) + { + if(getEmpty() != null) + { + return getEmpty().getDisplayName(); + } + return super.getItemStackDisplayName(stack); + } + + return fluidStack.getLocalizedName() + " Cell"; + } + + @Override + public int fill(ItemStack container, FluidStack resource, boolean doFill) + { + // has to be exactly 1, must be handled from the caller + if (container.stackSize != 1) + { + return 0; + } + + // can only fill exact capacity + if (resource == null || resource.amount != getCapacity()) + { + return 0; + } + // fill the container + if (doFill) + { + NBTTagCompound tag = container.getTagCompound(); + if (tag == null) + { + tag = new NBTTagCompound(); + } + resource.writeToNBT(tag); + container.setTagCompound(tag); + } + return getCapacity(); + } + + public static ItemStack getCellWithFluid(Fluid fluid, int stackSize){ + ItemStack stack = new ItemStack(ModItems.dynamicCell, stackSize); + ModItems.dynamicCell.fill(stack, new FluidStack(fluid, ModItems.dynamicCell.getCapacity()), true); + return stack; + } + + public static ItemStack getCellWithFluid(Fluid fluid){ + ItemStack stack = new ItemStack(ModItems.dynamicCell); + ModItems.dynamicCell.fill(stack, new FluidStack(fluid, ModItems.dynamicCell.getCapacity()), true); + return stack; + } + +} diff --git a/src/main/java/techreborn/items/EmptyCell.java b/src/main/java/techreborn/items/EmptyCell.java new file mode 100644 index 000000000..1c320c6bc --- /dev/null +++ b/src/main/java/techreborn/items/EmptyCell.java @@ -0,0 +1,25 @@ +package techreborn.items; + +import techreborn.client.TechRebornCreativeTab; +import techreborn.lib.ModInfo; + +/** + * Created by modmuss50 on 17/05/2016. + */ +public class EmptyCell extends ItemTextureBase { + + public EmptyCell() + { + setUnlocalizedName("techreborn.cell"); + setCreativeTab(TechRebornCreativeTab.instance); + } + @Override + public String getTextureName(int damage) { + return ModInfo.MOD_ID + ":items/cell_base"; + } + + @Override + public int getMaxMeta() { + return 0; + } +} diff --git a/src/main/java/techreborn/items/ItemCells.java b/src/main/java/techreborn/items/ItemCells.java index db0233b57..4be0f0ce2 100644 --- a/src/main/java/techreborn/items/ItemCells.java +++ b/src/main/java/techreborn/items/ItemCells.java @@ -14,6 +14,7 @@ import techreborn.client.TechRebornCreativeTab; import techreborn.init.ModItems; import techreborn.lib.ModInfo; +@Deprecated public class ItemCells extends ItemTextureBase implements IFluidContainerItem { diff --git a/src/main/java/techreborn/proxies/ClientProxy.java b/src/main/java/techreborn/proxies/ClientProxy.java index 9c1168385..e72e08e4a 100644 --- a/src/main/java/techreborn/proxies/ClientProxy.java +++ b/src/main/java/techreborn/proxies/ClientProxy.java @@ -3,15 +3,20 @@ package techreborn.proxies; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.client.renderer.ItemMeshDefinition; +import net.minecraft.client.renderer.block.model.ModelBakery; import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.client.renderer.block.statemap.StateMap; import net.minecraft.client.renderer.block.statemap.StateMapperBase; import net.minecraft.client.renderer.entity.Render; import net.minecraft.client.renderer.entity.RenderManager; +import net.minecraft.client.resources.IResourceManager; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; import net.minecraft.util.Util; +import net.minecraftforge.client.model.ICustomModelLoader; +import net.minecraftforge.client.model.IModel; +import net.minecraftforge.client.model.ModelDynBucket; import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.client.registry.ClientRegistry; @@ -34,6 +39,7 @@ import techreborn.client.keybindings.KeyBindings; import techreborn.client.render.entitys.RenderNukePrimed; import techreborn.entitys.EntityNukePrimed; import techreborn.init.ModBlocks; +import techreborn.init.ModItems; import techreborn.init.ModSounds; import techreborn.lib.ModInfo; import techreborn.manual.loader.ManualLoader; @@ -46,6 +52,8 @@ public class ClientProxy extends CommonProxy public static MultiblockRenderEvent multiblockRenderEvent; + public static final ModelResourceLocation MODEL_DYNAMIC_CELL = new ModelResourceLocation(new ResourceLocation("techreborn", "dyncell"), "inventory"); + @Override public void preInit(FMLPreInitializationEvent event) { @@ -69,6 +77,16 @@ public class ClientProxy extends CommonProxy registerItemModel(Item.getItemFromBlock(base)); } } + + ModelLoader.setCustomMeshDefinition(ModItems.dynamicCell, new ItemMeshDefinition() + { + @Override + public ModelResourceLocation getModelLocation(ItemStack stack) + { + return MODEL_DYNAMIC_CELL; + } + }); + ModelBakery.registerItemVariants(ModItems.dynamicCell, MODEL_DYNAMIC_CELL); } @Override diff --git a/src/main/java/techreborn/utils/RecipeUtils.java b/src/main/java/techreborn/utils/RecipeUtils.java index 7116e2f71..3db8c49be 100644 --- a/src/main/java/techreborn/utils/RecipeUtils.java +++ b/src/main/java/techreborn/utils/RecipeUtils.java @@ -1,7 +1,7 @@ package techreborn.utils; import net.minecraft.item.ItemStack; -import techreborn.items.ItemCells; +import techreborn.init.ModItems; public class RecipeUtils { @@ -12,7 +12,7 @@ public class RecipeUtils // cell.stackSize = stackSize; // return cell; // } else { - return ItemCells.getCellByName("empty", stackSize); + return new ItemStack(ModItems.emptyCell); // } } } diff --git a/src/main/resources/assets/techreborn/blockstates/dyncell.json b/src/main/resources/assets/techreborn/blockstates/dyncell.json new file mode 100644 index 000000000..530221d06 --- /dev/null +++ b/src/main/resources/assets/techreborn/blockstates/dyncell.json @@ -0,0 +1,18 @@ +{ + "forge_marker": 1, + "variants": { + "inventory": { + "model": "forge:forgebucket", + "textures": { + "base": "techreborn:items/cell_base", + "fluid": "techreborn:items/cell_fluid", + "cover": "techreborn:items/cell_cover" + }, + "transform": "forge:default-item", + "custom": { + "fluid": "water", + "flipGas": true + } + } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/techreborn/models/item/cell.json b/src/main/resources/assets/techreborn/models/item/cell.json new file mode 100644 index 000000000..4a8c26d79 --- /dev/null +++ b/src/main/resources/assets/techreborn/models/item/cell.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "forge:items/bucket_base" + } +} diff --git a/src/main/resources/assets/techreborn/textures/items/cell_base.png b/src/main/resources/assets/techreborn/textures/items/cell_base.png new file mode 100644 index 0000000000000000000000000000000000000000..538b65c5194e93558a72506cf9e9e65934e5cd25 GIT binary patch literal 486 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Ea{HEjtmSN`?>!lvI6;x#X;^) z4C~IxyaaL-l0AZa85pWm85kOx85n;42hu?CQUeBtR|yOZRx=nF#PcV`A9Vw&WlQpQ zcVYMsf(!O8p9~b?EbxddW?1=Hnx}fBfj6dt$t;02$i>6(mxukg(go-5eiZl+@T@#AoAp3-y!&UvW2cYp zp8w(A_0rhFbBq&$4$a8-<5>7@p}yua*?ZsTezwtnTh++-MW9MA)*C9V-ADTyViR>?)FK#IZ0z|dINz*yJFD8$IX z%EZLVz)ah~(8|ET;CD+0iiX_$l+3hBs0JflBeM_#ODjV&D-#QdhSo^)GN1-2kPX54 sX(i=}MX3w{iJ5sNdVa1U3T4K6rh0}3249L60#z}1y85}Sb4q9e0L3e(OaK4? literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/techreborn/textures/items/cell_cover.png b/src/main/resources/assets/techreborn/textures/items/cell_cover.png new file mode 100644 index 0000000000000000000000000000000000000000..739f2d573b28b3535aa9ada7284ab30ff2b3d974 GIT binary patch literal 14678 zcmeI3U2GIp6vuC)C{{5wK4?k|lSPQAyYsQ#ZFe%e2;D-fZd=P5ia}vIbGMzaJ2TEq z*=?UhA_)%~gGLlcFl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