Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hi, I maked a custom bucket. The texture is the everytime the same.

 

ItemBucket:

Spoiler

public class ClayBucket extends UniversalBucket implements IHasModel{
	
		private final ItemStack empty = new ItemStack(this);

		public ClayBucket(final String str_001) {
			this(str_001, Fluid.BUCKET_VOLUME);
			setRegistryName(str_001);
			setUnlocalizedName(str_001);
			ItemList.modItems.add(this);
		}

		public ClayBucket(final String name, final int capacity) {
			super(capacity, ItemStack.EMPTY, true);
		}

		@Override
		public void getSubItems(@Nullable final CreativeTabs tab, final NonNullList<ItemStack> subItems) {
			if (!this.isInCreativeTab(tab)) return;

			subItems.add(empty);

			for (final Fluid fluid : FluidRegistry.getRegisteredFluids().values()) {
				final FluidStack fs = new FluidStack(fluid, getCapacity());
				final ItemStack stack = new ItemStack(this);
				final IFluidHandlerItem fluidHandler = stack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null);
				if (fluidHandler != null && fluidHandler.fill(fs, true) == fs.amount) {
					final ItemStack filled = fluidHandler.getContainer();
					subItems.add(filled);
				}
			}
		}

		@SuppressWarnings("deprecation")
		@Override
		public String getItemStackDisplayName(final ItemStack stack) {
			final FluidStack fluidStack = getFluid(stack);
			final String unlocalisedName = this.getUnlocalizedNameInefficiently(stack);

			if (fluidStack == null) {
				return I18n.translateToLocal(unlocalisedName + ".name").trim();
			}

			final String fluidUnlocalisedName = unlocalisedName + ".filled." + fluidStack.getFluid().getName() + ".name";
			if (I18n.canTranslate(fluidUnlocalisedName)) {
				return I18n.translateToLocal(fluidUnlocalisedName);
			}

			return I18n.translateToLocalFormatted(unlocalisedName + ".filled.name", fluidStack.getLocalizedName());
		}

		@Override
		public ActionResult<ItemStack> onItemRightClick(final World world, final EntityPlayer player, final EnumHand hand) {
			final ItemStack heldItem = player.getHeldItem(hand);
			final FluidStack fluidStack = getFluid(heldItem);

			if (fluidStack != null) return super.onItemRightClick(world, player, hand);

			final RayTraceResult target = this.rayTrace(world, player, true);

			if (target == null || target.typeOfHit != RayTraceResult.Type.BLOCK) {
				return new ActionResult<>(EnumActionResult.PASS, heldItem);
			}

			final BlockPos pos = target.getBlockPos();

			final ItemStack singleBucket = heldItem.copy();
			singleBucket.setCount(1);

			final FluidActionResult filledResult = FluidUtil.tryPickUpFluid(singleBucket, player, world, pos, target.sideHit);
			if (filledResult.isSuccess()) {
				final ItemStack filledBucket = filledResult.result;

				if (player.capabilities.isCreativeMode)
					return new ActionResult<>(EnumActionResult.SUCCESS, heldItem);

				heldItem.shrink(1);
				if (heldItem.isEmpty())
					return new ActionResult<>(EnumActionResult.SUCCESS, filledBucket);

				ItemHandlerHelper.giveItemToPlayer(player, filledBucket);

				return new ActionResult<>(EnumActionResult.SUCCESS, heldItem);
			}

			return new ActionResult<>(EnumActionResult.PASS, heldItem);
		}


		@Override
		public ItemStack getEmpty() {
			return empty;
		}

		@Nullable
		@Override
		public FluidStack getFluid(final ItemStack container) {
			return FluidUtil.getFluidContained(container);
		}

		@Override
		public ICapabilityProvider initCapabilities(final ItemStack stack, final NBTTagCompound nbt) {
			return new HUniversalBucket(stack, getCapacity());
		}

		@Override public void registerModels() {
			Dreams.proxy.registerItemRenderer(this, 0, "inventory");
		}

 

HUniversalBucket:

Spoiler

public class HUniversalBucket extends FluidHandlerItemStackSimple {

	public HUniversalBucket(final ItemStack container, final int capacity) {
		super(container, capacity);
	}

	@Override
	public boolean canFillFluidType(final FluidStack fluid) {
		return fluid.getFluid() == FluidRegistry.WATER ||
				fluid.getFluid() == FluidRegistry.LAVA ||
				fluid.getFluid().getName().equals("milk") ||
				FluidRegistry.getBucketFluids().contains(fluid.getFluid());
	}

}

 

Model:

Spoiler


{
   "parent": "item/generated",
   "textures": {
       "layer0": "nex:items/clay_bucket"
   }
}

 

What is the problem?

 

THREAD SOLVED. Solution:

buckets not need a model but they need a blockstate:

{
  "forge_marker": 1,
  "defaults": {
    "model": "forge:item-layer",
    "textures": {
      "layer0": "nex:items/clay_bucket_base",
      "layer2": "nex:items/clay_bucket_cover"
    },
    "transform": "forge:default-item"
  },
  "variants": {
    "inventory": {
      "model": "forge:forgebucket",
      "textures": {
        "base": "nex:items/clay_bucket_base",
        "fluid": "forge:items/bucket_fluid",
        "cover": "nex:items/clay_bucket_cover"
      },
      "custom": {
        "fluid": "water",
        "flipGas": true
      }
    },
    "milk": [{
      "textures": {
        "layer1": "forge:items/bucket_fluid"
      }
    }]
  }
}

 

Edited by nov4e

Post your code as a GitHub repository please, you don’t need IHasModel, it’s a useless class that makes you write repetitive code. Why are all your variables named so horribly?

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

  • Author
8 minutes ago, Cadiboo said:

Post your code as a GitHub repository please, you don’t need IHasModel, it’s a useless class that makes you write repetitive code. Why are all your variables named so horribly?

I can't post it. But buckets need a special model?

 

12 minutes ago, nov4e said:

final ItemStack container, final int capacity

horribly??

28 minutes ago, nov4e said:

str_001

Sorry, I saw that and jumped to conclusions, still that’s a bad variable name. 

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

  • Author
Just now, Cadiboo said:

Sorry, I saw that and jumped to conclusions, still that’s a bad variable name. 

Yeah I'm going to change all my strings

  • Author

so what is the problem?

Buckets need a special model?

Edited by nov4e

  • Author
On 11/5/2018 at 9:56 PM, nov4e said:

 

I changed my code. Now I'm trying to use metadata but the model registry try to find the model with a random name example: 

com.nov4e.nex.obj.items.tools.claybucket@3c55c035

 

public void registerItemRenderer(Item str_001, int str_002, String str_003) {
		for (int i = 0; i < ItemList.NAMES.length + 1; i++) {
            String model = "nex" + ":" + ItemList.clayBucket;
            if (i != 0) {
            	model += "_" + ItemList.NAMES[i - 1];
            }

            ModelResourceLocation loc = new ModelResourceLocation(model);
            ModelLoader.setCustomModelResourceLocation(ItemList.clayBucket, i, loc);
        }
	}

ItemList.NAMES =  public static final String[] NAMES = {"water", "lava"};

1 hour ago, nov4e said:

example: 

com.nov4e.nex.obj.items.tools.claybucket@3c55c035

1 hour ago, nov4e said:

String model = "nex" + ":" + ItemList.clayBucket;

 

Object#toString will return a fully qualified class name appended by @ and the object's hashcode in hex. Item doesn't override that method so you get this.

 

In any case don't use metadata for buckets, use capabilities to store the fluid. As for the model - forge uses a custom model for it's buckets - ModelDynBucket. It is needed because any mod can add any fluid it wants and the forge bucket must be able to contain it and display the propper fluid textures. You can utilize forge's bucket model in json - the parent model becomes forge:forgebucket, and the textures it expects are:

base: The bucket's empty texture

fluid: The dummy fluid texture. I think this is basically the mask for the fluid's actual texture to apply to, and anything outside of the mask is discarded. You can use the dummy fluid texture provided by forge - forge:items/bucket_fluid if your bucket is of the same shape as vanilla's, otherwise you need to create it yourself.

cover: The bucket's texture that has fluid in it, but the fluid's pixels are transparent.

 

If you are using forge's blockstates you can also pass some custom data:

fluid: the name of the fluid to put in the bucket when baking. If this is not specified water is used as a default fluid.

flipGas: whether or not to flip your texture upside-down when the fluid is a gas.

applyTint: whether to tint the fluid's textures based on the fluid's colour.

Actually you can read the javadoc yourself - ModelDynBucket#process.

 

If you need an example of using the dynamic bucket model with custom buckets - here is one. Note that the example uses forge's blockstates to define the bucket's model, not a model json.

 

And yeah, these parameter names make no sense.

1 hour ago, nov4e said:

Item str_001, int str_002, String str_003

I can kinda see naming strings as str_something, although that is actually what's called a Hungarian notation(kinda, but close enough for me to classify this as one) and has absolutely no place in modern programming whatsoever(and I think you are the first person I've ever seen to apply it to java code, congratulations), but why is Item also named like that? Or an int? This makes zero sense.

  • Author
On 11/5/2018 at 9:43 PM, nov4e said:

Hi, I maked a custom bucket. The texture is the everytime the same.

 

ItemBucket:

  Reveal hidden contents


public class ClayBucket extends UniversalBucket implements IHasModel{
	
		private final ItemStack empty = new ItemStack(this);

		public ClayBucket(final String str_001) {
			this(str_001, Fluid.BUCKET_VOLUME);
			setRegistryName(str_001);
			setUnlocalizedName(str_001);
			ItemList.modItems.add(this);
		}

		public ClayBucket(final String name, final int capacity) {
			super(capacity, ItemStack.EMPTY, true);
		}

		@Override
		public void getSubItems(@Nullable final CreativeTabs tab, final NonNullList<ItemStack> subItems) {
			if (!this.isInCreativeTab(tab)) return;

			subItems.add(empty);

			for (final Fluid fluid : FluidRegistry.getRegisteredFluids().values()) {
				final FluidStack fs = new FluidStack(fluid, getCapacity());
				final ItemStack stack = new ItemStack(this);
				final IFluidHandlerItem fluidHandler = stack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null);
				if (fluidHandler != null && fluidHandler.fill(fs, true) == fs.amount) {
					final ItemStack filled = fluidHandler.getContainer();
					subItems.add(filled);
				}
			}
		}

		@SuppressWarnings("deprecation")
		@Override
		public String getItemStackDisplayName(final ItemStack stack) {
			final FluidStack fluidStack = getFluid(stack);
			final String unlocalisedName = this.getUnlocalizedNameInefficiently(stack);

			if (fluidStack == null) {
				return I18n.translateToLocal(unlocalisedName + ".name").trim();
			}

			final String fluidUnlocalisedName = unlocalisedName + ".filled." + fluidStack.getFluid().getName() + ".name";
			if (I18n.canTranslate(fluidUnlocalisedName)) {
				return I18n.translateToLocal(fluidUnlocalisedName);
			}

			return I18n.translateToLocalFormatted(unlocalisedName + ".filled.name", fluidStack.getLocalizedName());
		}

		@Override
		public ActionResult<ItemStack> onItemRightClick(final World world, final EntityPlayer player, final EnumHand hand) {
			final ItemStack heldItem = player.getHeldItem(hand);
			final FluidStack fluidStack = getFluid(heldItem);

			if (fluidStack != null) return super.onItemRightClick(world, player, hand);

			final RayTraceResult target = this.rayTrace(world, player, true);

			if (target == null || target.typeOfHit != RayTraceResult.Type.BLOCK) {
				return new ActionResult<>(EnumActionResult.PASS, heldItem);
			}

			final BlockPos pos = target.getBlockPos();

			final ItemStack singleBucket = heldItem.copy();
			singleBucket.setCount(1);

			final FluidActionResult filledResult = FluidUtil.tryPickUpFluid(singleBucket, player, world, pos, target.sideHit);
			if (filledResult.isSuccess()) {
				final ItemStack filledBucket = filledResult.result;

				if (player.capabilities.isCreativeMode)
					return new ActionResult<>(EnumActionResult.SUCCESS, heldItem);

				heldItem.shrink(1);
				if (heldItem.isEmpty())
					return new ActionResult<>(EnumActionResult.SUCCESS, filledBucket);

				ItemHandlerHelper.giveItemToPlayer(player, filledBucket);

				return new ActionResult<>(EnumActionResult.SUCCESS, heldItem);
			}

			return new ActionResult<>(EnumActionResult.PASS, heldItem);
		}


		@Override
		public ItemStack getEmpty() {
			return empty;
		}

		@Nullable
		@Override
		public FluidStack getFluid(final ItemStack container) {
			return FluidUtil.getFluidContained(container);
		}

		@Override
		public ICapabilityProvider initCapabilities(final ItemStack stack, final NBTTagCompound nbt) {
			return new HUniversalBucket(stack, getCapacity());
		}

		@Override public void registerModels() {
			Dreams.proxy.registerItemRenderer(this, 0, "inventory");
		}

 

HUniversalBucket:

  Reveal hidden contents


public class HUniversalBucket extends FluidHandlerItemStackSimple {

	public HUniversalBucket(final ItemStack container, final int capacity) {
		super(container, capacity);
	}

	@Override
	public boolean canFillFluidType(final FluidStack fluid) {
		return fluid.getFluid() == FluidRegistry.WATER ||
				fluid.getFluid() == FluidRegistry.LAVA ||
				fluid.getFluid().getName().equals("milk") ||
				FluidRegistry.getBucketFluids().contains(fluid.getFluid());
	}

}

 

Model:

  Reveal hidden contents



{
   "parent": "item/generated",
   "textures": {
       "layer0": "nex:items/clay_bucket"
   }
}

 

What is the problem?

@V0idWa1k3r that code was correct? 

The model file is going to be:

Spoiler

{
   "parent": "forge:items/bucket_fluid",
   "textures": {
       "layer0": "nex:items/clay_bucket"
   }
}

 

or

Spoiler

{
   "parent": "forge:items/bucket_fluid",
   "textures": {
       "layer0": "nex:items/clay_bucket_base"
       "layer1": "nex:items/clay_bucket_fluid"
   }
}

 

Thanks for you reply :D

Edited by nov4e

Post your working code for people in the future please

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

  • Author
12 hours ago, Cadiboo said:

Post your working code for people in the future please

ok ;)

 

*doesn’t do it*

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.