From d50d2412e188436ceab99fe377e9f441f129111b Mon Sep 17 00:00:00 2001 From: Calclavia Date: Mon, 29 Dec 2014 11:52:22 +0800 Subject: [PATCH] Added mixture and molten buckets --- .../assets/resonantinduction/lang/en_US.lang | 1 + .../core/resource/ResourceFactory.scala | 9 +- .../resource/content/ItemMixtureBucket.scala | 11 ++ .../resource/content/ItemMoltenBucket.scala | 11 ++ .../core/resource/content/TBucket.scala | 118 ++++++++++++++++++ 5 files changed, 146 insertions(+), 4 deletions(-) create mode 100644 src/main/scala/resonantinduction/core/resource/content/ItemMixtureBucket.scala create mode 100644 src/main/scala/resonantinduction/core/resource/content/ItemMoltenBucket.scala create mode 100644 src/main/scala/resonantinduction/core/resource/content/TBucket.scala diff --git a/src/main/resources/assets/resonantinduction/lang/en_US.lang b/src/main/resources/assets/resonantinduction/lang/en_US.lang index ca53a5aaf..40f06995a 100644 --- a/src/main/resources/assets/resonantinduction/lang/en_US.lang +++ b/src/main/resources/assets/resonantinduction/lang/en_US.lang @@ -232,6 +232,7 @@ tooltip.ingot=Ingot tooltip.rubble=Rubble tooltip.dust=Dust tooltip.refinedDust=Refined Dust +tooltip.bucket=Bucket tooltip.pipe.rate=Flow Rate: %v tooltip.pipe.pressure=Max Pressure: %v diff --git a/src/main/scala/resonantinduction/core/resource/ResourceFactory.scala b/src/main/scala/resonantinduction/core/resource/ResourceFactory.scala index e0f6b20fb..ca4dae7f8 100644 --- a/src/main/scala/resonantinduction/core/resource/ResourceFactory.scala +++ b/src/main/scala/resonantinduction/core/resource/ResourceFactory.scala @@ -20,7 +20,6 @@ import net.minecraftforge.fluids.{FluidContainerRegistry, FluidRegistry, FluidSt import net.minecraftforge.oredict.OreDictionary import resonant.api.recipe.MachineRecipes import resonant.lib.factory.resources.RecipeType -import resonant.lib.prefab.item.ItemFluidBucket import resonant.lib.utility.LanguageUtility import resonant.lib.wrapper.StringWrapper._ import resonantinduction.core.resource.content._ @@ -72,7 +71,7 @@ object ResourceFactory if (LanguageUtility.getLocal(localizedName) != null && LanguageUtility.getLocal(localizedName) != "") localizedName = LanguageUtility.getLocal(localizedName) - localizedName.replace(LanguageUtility.getLocal("misc.resonantinduction.ingot"), "").replaceAll("^ ", "").replaceAll(" $", "") + localizedName.replace("misc.resonantinduction.ingot".getLocal, "").replaceAll("^ ", "").replaceAll(" $", "") } //Generate molten fluid @@ -84,7 +83,8 @@ object ResourceFactory moltenFluidMap += (materialName -> blockFluidMaterial) //Generate molten bucket - val moltenBucket = new ItemFluidBucket + val moltenBucket = CoreContent.manager.newItem("bucketMolten" + materialName.capitalizeFirst, new ItemMoltenBucket(materialName)) + LanguageRegistry.instance.addStringLocalization(moltenBucket.getUnlocalizedName + ".name", "tooltip.molten".getLocal + " " + localizedName + " " + "tooltip.bucket".getLocal) FluidContainerRegistry.registerFluidContainer(fluidMolten, new ItemStack(moltenBucket)) moltenBucketMap += materialName -> moltenBucket @@ -97,7 +97,8 @@ object ResourceFactory mixtureFluidMap += materialName -> blockFluidMixture //Generate mixture bucket - val mixtureBucket = new ItemFluidBucket + val mixtureBucket = CoreContent.manager.newItem("bucketMixture" + materialName.capitalizeFirst, new ItemMixtureBucket(materialName)) + LanguageRegistry.instance.addStringLocalization(mixtureBucket.getUnlocalizedName + ".name", "tooltip.mixture".getLocal + " " + localizedName + " " + "tooltip.bucket".getLocal) FluidContainerRegistry.registerFluidContainer(fluidMixture, new ItemStack(mixtureBucket)) mixtureBucketMap += materialName -> mixtureBucket diff --git a/src/main/scala/resonantinduction/core/resource/content/ItemMixtureBucket.scala b/src/main/scala/resonantinduction/core/resource/content/ItemMixtureBucket.scala new file mode 100644 index 000000000..e913e994c --- /dev/null +++ b/src/main/scala/resonantinduction/core/resource/content/ItemMixtureBucket.scala @@ -0,0 +1,11 @@ +package resonantinduction.core.resource.content + +import resonantinduction.core.Reference + +/** + * @author Calclavia + */ +class ItemMixtureBucket(material: String) extends ItemResource(material) with TBucket +{ + setTextureName(Reference.prefix + "bucketMixture") +} diff --git a/src/main/scala/resonantinduction/core/resource/content/ItemMoltenBucket.scala b/src/main/scala/resonantinduction/core/resource/content/ItemMoltenBucket.scala new file mode 100644 index 000000000..276099e69 --- /dev/null +++ b/src/main/scala/resonantinduction/core/resource/content/ItemMoltenBucket.scala @@ -0,0 +1,11 @@ +package resonantinduction.core.resource.content + +import resonantinduction.core.Reference + +/** + * @author Calclavia + */ +class ItemMoltenBucket(material: String) extends ItemResource(material) with TBucket +{ + setTextureName(Reference.prefix + "bucketMolten") +} diff --git a/src/main/scala/resonantinduction/core/resource/content/TBucket.scala b/src/main/scala/resonantinduction/core/resource/content/TBucket.scala new file mode 100644 index 000000000..f10892f1a --- /dev/null +++ b/src/main/scala/resonantinduction/core/resource/content/TBucket.scala @@ -0,0 +1,118 @@ +package resonantinduction.core.resource.content + +import net.minecraft.item.ItemStack +import net.minecraft.nbt.NBTTagCompound +import net.minecraftforge.fluids.{FluidContainerRegistry, FluidStack, IFluidContainerItem} + +/** + * A trait implemented by buckets + * @author Calclavia + */ +trait TBucket extends IFluidContainerItem +{ + protected var capacity = FluidContainerRegistry.BUCKET_VOLUME + + def getFluid(container: ItemStack): FluidStack = + { + if (container.stackTagCompound == null || !container.stackTagCompound.hasKey("Fluid")) + { + return null + } + return FluidStack.loadFluidStackFromNBT(container.stackTagCompound.getCompoundTag("Fluid")) + } + + def getCapacity(container: ItemStack): Int = + { + return capacity + } + + override def fill(container: ItemStack, resource: FluidStack, doFill: Boolean): Int = + { + if (resource == null) + { + return 0 + } + if (!doFill) + { + if (container.stackTagCompound == null || !container.stackTagCompound.hasKey("Fluid")) + { + return Math.min(capacity, resource.amount) + } + val stack: FluidStack = FluidStack.loadFluidStackFromNBT(container.stackTagCompound.getCompoundTag("Fluid")) + if (stack == null) + { + return Math.min(capacity, resource.amount) + } + if (!stack.isFluidEqual(resource)) + { + return 0 + } + return Math.min(capacity - stack.amount, resource.amount) + } + if (container.stackTagCompound == null) + { + container.stackTagCompound = new NBTTagCompound + } + if (!container.stackTagCompound.hasKey("Fluid")) + { + val fluidTag: NBTTagCompound = resource.writeToNBT(new NBTTagCompound) + if (capacity < resource.amount) + { + fluidTag.setInteger("Amount", capacity) + container.stackTagCompound.setTag("Fluid", fluidTag) + return capacity + } + container.stackTagCompound.setTag("Fluid", fluidTag) + return resource.amount + } + val fluidTag: NBTTagCompound = container.stackTagCompound.getCompoundTag("Fluid") + val stack: FluidStack = FluidStack.loadFluidStackFromNBT(fluidTag) + if (!stack.isFluidEqual(resource)) + { + return 0 + } + var filled: Int = capacity - stack.amount + if (resource.amount < filled) + { + stack.amount += resource.amount + filled = resource.amount + } + else + { + stack.amount = capacity + } + container.stackTagCompound.setTag("Fluid", stack.writeToNBT(fluidTag)) + return filled + } + + override def drain(container: ItemStack, maxDrain: Int, doDrain: Boolean): FluidStack = + { + if (container.stackTagCompound == null || !container.stackTagCompound.hasKey("Fluid")) + { + return null + } + val stack: FluidStack = FluidStack.loadFluidStackFromNBT(container.stackTagCompound.getCompoundTag("Fluid")) + if (stack == null) + { + return null + } + val currentAmount: Int = stack.amount + stack.amount = Math.min(stack.amount, maxDrain) + if (doDrain) + { + if (currentAmount == stack.amount) + { + container.stackTagCompound.removeTag("Fluid") + if (container.stackTagCompound.hasNoTags) + { + container.stackTagCompound = null + } + return stack + } + val fluidTag: NBTTagCompound = container.stackTagCompound.getCompoundTag("Fluid") + fluidTag.setInteger("Amount", currentAmount - stack.amount) + container.stackTagCompound.setTag("Fluid", fluidTag) + } + return stack + } +}