mirror of
https://github.com/GTNewHorizons/Binnie.git
synced 2026-11-18 11:29:23 +00:00
Improve Fluid Containers
This commit is contained in:
1 parent
f35f247cb4
commit
ce5232841a
9 files changed
+76
-30
No files matched your search
@@ -2,8 +2,6 @@ package binnie.core.liquid;
|
||||
|
||||
import binnie.core.BinnieCore;
|
||||
import binnie.core.Mods;
|
||||
import binnie.genetics.item.GeneticsItems;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||
@@ -43,7 +41,19 @@ public enum FluidContainerType {
|
||||
public boolean isActive() {
|
||||
return this.getEmpty() != null;
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
public ItemFluidContainer getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
public ItemStack get(int amount){
|
||||
if(item == null){
|
||||
throw new IllegalArgumentException("Null container item: " + this);
|
||||
}
|
||||
return new ItemStack(item, amount);
|
||||
}
|
||||
|
||||
public ItemStack getEmpty() {
|
||||
switch (this) {
|
||||
case CAN: {
|
||||
@@ -52,15 +62,12 @@ public enum FluidContainerType {
|
||||
case CAPSULE: {
|
||||
return Mods.Forestry.stack("capsule");
|
||||
}
|
||||
case GLASS: {
|
||||
return new ItemStack(Items.GLASS_BOTTLE, 1, 0);
|
||||
}
|
||||
case CYLINDER:
|
||||
case GLASS:
|
||||
return new ItemStack(item);
|
||||
case REFARACTORY: {
|
||||
return Mods.Forestry.stack("refractory");
|
||||
}
|
||||
case CYLINDER: {
|
||||
return GeneticsItems.Cylinder.get(1);
|
||||
}
|
||||
default: {
|
||||
throw new IllegalArgumentException("Unknown container: " + this);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.capability.templates.FluidHandlerItemStackSimple;
|
||||
|
||||
public class FluidHandlerItemBinnie extends FluidHandlerItemStackSimple.Consumable {
|
||||
public class FluidHandlerItemBinnie extends FluidHandlerItemStackSimple {
|
||||
private final FluidContainerType containerType;
|
||||
|
||||
public FluidHandlerItemBinnie(ItemStack container, FluidContainerType containerType) {
|
||||
@@ -40,4 +40,17 @@ public class FluidHandlerItemBinnie extends FluidHandlerItemStackSimple.Consumab
|
||||
public boolean canDrainFluidType(FluidStack fluid) {
|
||||
return contentsAllowed(fluid);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setContainerToEmpty()
|
||||
{
|
||||
super.setContainerToEmpty();
|
||||
container.setItemDamage(0); // show the empty container model
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setFluid(FluidStack fluid) {
|
||||
super.setFluid(fluid);
|
||||
container.setItemDamage(1); // show the filled container model
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
||||
@@ -36,7 +37,7 @@ import java.util.List;
|
||||
public class ItemFluidContainer extends ItemFood implements IItemModelRegister {
|
||||
private final FluidContainerType container;
|
||||
|
||||
public ItemFluidContainer(final FluidContainerType container) {
|
||||
public ItemFluidContainer(FluidContainerType container) {
|
||||
super(0, false);
|
||||
this.container = container;
|
||||
container.item = this;
|
||||
@@ -54,13 +55,14 @@ public class ItemFluidContainer extends ItemFood implements IItemModelRegister {
|
||||
}
|
||||
FluidStack fluid = getContained(itemstack);
|
||||
if (fluid == null) {
|
||||
return "Missing Fluid";
|
||||
return "Empty " + container.getDisplayName();
|
||||
}
|
||||
return fluid.getFluid().getLocalizedName(fluid) + " " + this.container.getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSubItems(final Item par1, final CreativeTabs par2CreativeTabs, final List itemList) {
|
||||
public void getSubItems(final Item item, final CreativeTabs tab, final List subItems) {
|
||||
super.getSubItems(item, tab, subItems);
|
||||
for (final IFluidType liquid : Binnie.LIQUID.fluids.values()) {
|
||||
if (!liquid.canPlaceIn(this.container)) {
|
||||
continue;
|
||||
@@ -68,7 +70,7 @@ public class ItemFluidContainer extends ItemFood implements IItemModelRegister {
|
||||
if (!liquid.showInCreative(this.container)) {
|
||||
continue;
|
||||
}
|
||||
itemList.add(getContainer(liquid));
|
||||
subItems.add(getContainer(liquid));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,13 +86,9 @@ public class ItemFluidContainer extends ItemFood implements IItemModelRegister {
|
||||
public ItemStack getContainer(final IFluidType liquid) {
|
||||
ItemStack itemStack = new ItemStack(this);
|
||||
IFluidHandler fluidHandler = new FluidHandlerItemBinnie(itemStack, container);
|
||||
try{
|
||||
if (fluidHandler.fill(new FluidStack(FluidRegistry.getFluid(liquid.getIdentifier()), Fluid.BUCKET_VOLUME), true) == Fluid.BUCKET_VOLUME) {
|
||||
return itemStack;
|
||||
}
|
||||
}catch(Exception e){
|
||||
getClass();
|
||||
}
|
||||
return container.getEmpty();
|
||||
}
|
||||
|
||||
@@ -117,11 +115,6 @@ public class ItemFluidContainer extends ItemFood implements IItemModelRegister {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxItemUseDuration(final ItemStack stack) {
|
||||
return 32;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumAction getItemUseAction(final ItemStack stack) {
|
||||
if(isDrinkable(stack)){
|
||||
@@ -131,12 +124,22 @@ public class ItemFluidContainer extends ItemFood implements IItemModelRegister {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World worldIn, EntityPlayer player, EnumHand hand) {
|
||||
if (player.canEat(false) && this.isDrinkable(stack)) {
|
||||
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand) {
|
||||
if (this.isDrinkable(stack) && player.canEat(false)) {
|
||||
player.setActiveHand(hand);
|
||||
return new ActionResult(EnumActionResult.SUCCESS, stack);
|
||||
}else{
|
||||
return super.onItemRightClick(stack, world, player, hand);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxItemUseDuration(ItemStack stack) {
|
||||
if(isDrinkable(stack)){
|
||||
return 32;
|
||||
}else{
|
||||
return 0;
|
||||
}
|
||||
return new ActionResult(EnumActionResult.PASS, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -160,7 +163,7 @@ public class ItemFluidContainer extends ItemFood implements IItemModelRegister {
|
||||
public void registerModel(Item item, IModelManager manager) {
|
||||
FluidContainerMeshDefinition meshDefinition = new FluidContainerMeshDefinition();
|
||||
manager.registerItemModel(item, meshDefinition);
|
||||
ModelBakery.registerItemVariants(item, meshDefinition.location);
|
||||
ModelBakery.registerItemVariants(item, meshDefinition.location, meshDefinition.empty);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -172,13 +175,19 @@ public class ItemFluidContainer extends ItemFood implements IItemModelRegister {
|
||||
private class FluidContainerMeshDefinition implements ItemMeshDefinition{
|
||||
|
||||
final ModelResourceLocation location;
|
||||
final ModelResourceLocation empty;
|
||||
|
||||
public FluidContainerMeshDefinition() {
|
||||
this.location = new ModelResourceLocation(getRegistryName(), "inventory");
|
||||
ResourceLocation location = getRegistryName();
|
||||
this.location = new ModelResourceLocation(location, "inventory");
|
||||
this.empty = new ModelResourceLocation(new ResourceLocation(location.getResourceDomain(), location.getResourcePath() + "_empty"), "inventory");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelResourceLocation getModelLocation(ItemStack stack) {
|
||||
if(stack.getItemDamage() == 0){
|
||||
return empty;
|
||||
}
|
||||
return location;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,12 +3,17 @@ package binnie.core.liquid;
|
||||
import binnie.core.ManagerBase;
|
||||
import forestry.api.core.EnumContainerType;
|
||||
import forestry.core.render.TextureManager;
|
||||
import forestry.core.utils.OreDictUtil;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.client.event.TextureStitchEvent;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import net.minecraftforge.oredict.ShapedOreRecipe;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -63,6 +68,11 @@ public class ManagerLiquid extends ManagerBase {
|
||||
}
|
||||
}
|
||||
}
|
||||
GameRegistry.addShapelessRecipe(FluidContainerType.GLASS.get(1), Items.GLASS_BOTTLE);
|
||||
GameRegistry.addShapelessRecipe(new ItemStack(Items.GLASS_BOTTLE), FluidContainerType.GLASS.get(1));
|
||||
GameRegistry.addRecipe(new ShapedOreRecipe(FluidContainerType.GLASS.get(3),
|
||||
" b ", "g g", " g ",
|
||||
'g', OreDictUtil.BLOCK_GLASS, 'b', OreDictUtil.SLAB_WOOD));
|
||||
}
|
||||
|
||||
public IFluidType getFluidType(final String liquid) {
|
||||
|
||||
@@ -17,7 +17,6 @@ public enum GeneticsItems implements IItemMiscProvider {
|
||||
EmptySequencer("Blank Sequence", "sequencerEmpty"),
|
||||
EmptySerum("Empty Serum Vial", "serumEmpty"),
|
||||
EmptyGenome("Empty Serum Array", "genomeEmpty"),
|
||||
Cylinder("Glass Cylinder", "cylinderEmpty"),
|
||||
IntegratedCircuit("Integrated Circuit Board", "integratedCircuit"),
|
||||
IntegratedCPU("Integrated CPU", "integratedCPU"),
|
||||
IntegratedCasing("Integrated Casing", "casingCircuit");
|
||||
|
||||
@@ -6,6 +6,7 @@ import binnie.core.BinnieCore;
|
||||
import binnie.core.IInitializable;
|
||||
import binnie.core.Mods;
|
||||
import binnie.core.item.ItemMisc;
|
||||
import binnie.core.liquid.FluidContainerType;
|
||||
import binnie.core.resource.BinnieSprite;
|
||||
import binnie.extrabees.ExtraBees;
|
||||
import binnie.extratrees.ExtraTrees;
|
||||
@@ -103,7 +104,7 @@ public class ModuleItem implements IInitializable {
|
||||
GameRegistry.addRecipe(new ShapedOreRecipe(GeneticsItems.EmptyGenome.get(itemGenetics, 1),
|
||||
"sss", "sss", "sss",
|
||||
's', GeneticsItems.EmptySerum.get(itemGenetics, 1)));
|
||||
GameRegistry.addRecipe(new ShapedOreRecipe(GeneticsItems.Cylinder.get(itemGenetics, 8),
|
||||
GameRegistry.addRecipe(new ShapedOreRecipe(FluidContainerType.CYLINDER.get(8),
|
||||
" g ", "g g", " ",
|
||||
'g', Blocks.GLASS_PANE));
|
||||
GameRegistry.addRecipe(new ShapedOreRecipe(GeneticsItems.IntegratedCircuit.get(itemGenetics, 1),
|
||||
|
||||
Reference in new issue
Block a user