Jump to content

A few things first.....


WaffleKing26

Recommended Posts

Hello, I am fairly new to modding I am following someone's tutorial series but I am now ahead of where he is. I am trying to create a custom bucket I have the items all set up i just do not know how to make them function as a normal bucket. I want to be able to only pick up water with it and nothing else. I will and another bucket soon that will be the same but can pick up lava although I can just copy/paste and change the code to lava. I have done a few attempts but to no avail any ideas? Also, i am wanting to have sticks have a 50% chance of dropping from trees, unable to break logs with hand, and wood/stone tools disabled. 2nd to the last thing is only having something spawn only near a waterbed on the surface like sugar cane as a singular block, not in a cluster. The last thing is that I have a crafting table set up I just don't know how to make it a crafting table because at the moment it is just a block. If you can solve any of these things please respond. Thanks!

Link to comment
Share on other sites

10 hours ago, jabelar said:

I looked through the code and that picks up any fluid and changes the type, I am using a custom model for my item and I want the bucket to only pick up water, also I have 2 items so I just need to check to see if the water is the block clicked with the empty bucket and then remove it then switch the item, my code is not working, I am doing the picking up fluids first. I will post the java file I have for the item once I get the chance. The code you sent picks up any fluid and changes the texture but that wouldn't work because I want to use my custom model.

Link to comment
Share on other sites

package com.posidon.startertech.items;

import net.minecraft.world.World;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumActionResult;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Item;
import net.minecraft.init.Blocks;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.block.state.IBlockState;

import com.posidon.startertech.init.ModItems;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;

public class WoodBucketEmpty extends ItemBase {
		public WoodBucketEmpty(String name) {
			super(name);
			setMaxDamage(1);
			maxStackSize = 16;
		}

		@Override
		public float getDestroySpeed(ItemStack par1ItemStack, IBlockState par2Block) {
			return 0.5F;
		}

		@Override
		public EnumActionResult onItemUseFirst(EntityPlayer entity, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ,
				EnumHand hand) {
			float var4 = 1.0F;
			int i = pos.getX();
			int j = pos.getY();
			int k = pos.getZ();

			if (world.getBlockState(new BlockPos(i, j, k)).getBlock() == Blocks.WATER) {
 				world.setBlockToAir(new BlockPos(i, j, k));
                 
 				if (entity instanceof EntityPlayer) {
                   ((EntityPlayer) entity).inventory.addItemStackToInventory(new ItemStack(ModItems.WOOD_BUCKET_FULL_ITEM, 1));
                   ((EntityPlayer) entity).inventory.clearMatchingItems(ModItems.WOOD_BUCKET_ITEM, -1, 1, null);
 				}
			}	
		return EnumActionResult.PASS;
		}
}

 

that's the code in my items java file, here is where I put them into an array to be registered: 

package com.posidon.startertech.init;

import java.util.ArrayList;
import java.util.List;

import com.posidon.startertech.items.ItemBase;
import com.posidon.startertech.items.WoodBucketEmpty;

import net.minecraft.item.Item;

public class ModItems {
	public static final List<Item> ITEMS = new ArrayList<Item>();
	
	public static final Item SULFUR = new ItemBase("sulfur");
	public static final Item CINNABAR = new ItemBase("cinnabar");
	public static final Item SULFUR_CRYSTAL = new ItemBase("sulfur_crystal");
	public static final Item WOOD_BUCKET_ITEM = new WoodBucketEmpty("wood_bucket_item");
	public static final Item WOOD_BUCKET_FULL_ITEM = new ItemBase("wood_bucket_full_item");
}

Here is where I take the Item list and register it

package com.posidon.startertech.items;

import com.posidon.startertech.Main;
import com.posidon.startertech.init.ModItems;
import com.posidon.startertech.util.IHasModel;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;

public class ItemBase extends Item implements IHasModel {
	
	public ItemBase(String name) {
		setUnlocalizedName(name);
		setRegistryName(name);
		setCreativeTab(CreativeTabs.MATERIALS);
		
		ModItems.ITEMS.add(this);
	}
	
	@Override
	public void registerModels() {
		Main.proxy.registerItemRenderer(this, 0, "inventory");
	}
}

 

If you need any other information tell me.

Link to comment
Share on other sites

5 hours ago, WaffleKing26 said:

I meant the picking up water in the bucket

You need two states. One if the bucket is full and one if not. I'd suggest using PropertyBool to create a BlockProperty. Then you override the methods that are provided by the Item class your Item is 

extended from. I don't know the exact name, but I think it is onItemUse(Use the one were a blockstate is given that is Right-Clicked on). Then perform checks. Like, if the bucket is full, empty it. If not, check if the player clicked water and in that case, fill the bucket. That is all there is to it.

Link to comment
Share on other sites

18 minutes ago, ArmamentHaki said:

You need two states. One if the bucket is full and one if not. I'd suggest using PropertyBool to create a BlockProperty. Then you override the methods that are provided by the Item class your Item is 

extended from. I don't know the exact name, but I think it is onItemUse(Use the one were a blockstate is given that is Right-Clicked on). Then perform checks. Like, if the bucket is full, empty it. If not, check if the player clicked water and in that case, fill the bucket. That is all there is to it.

i have 2 custom buckets and in the empty one it has the code i talked about above. im doing empty before i code the full one so i know it works first

 

Link to comment
Share on other sites

22 minutes ago, WaffleKing26 said:

i have 2 custom buckets and in the empty one it has the code i talked about above. im doing empty before i code the full one so i know it works first

 

My fault, I forget we were talking about an item. In that case, I have some points:

  • if(entity instanceof EntityPlayer) will always be true
  • use onItemUse(), not onItemUseFirst
    	/**
    	 * Called when a Block is right-clicked with this Item
         */
        public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, 	  float hitZ)
        {
            return EnumActionResult.PASS;
        }

     

  • The casts are unnessecary

  • Try using
     

    	entity.inventory.deleteStack(entity.inventory.getCurrentItem());
    	entity.inventory.add(entity.inventory.currentItem, new ItemStack(Items.WATER_BUCKET));
    	

     

  • You need to change the bucket back, otherwise, this will only work in one direction

Edited by ArmamentHaki
Link to comment
Share on other sites

I'm starting to think that it was just the way I called the java file wrong cause i changed all the things you said to didnt work so i changed the water to stone and still didnt work. here is the code where i create the item: 

package com.posidon.startertech.init;

import java.util.ArrayList;
import java.util.List;

import com.posidon.startertech.items.ItemBase;
import com.posidon.startertech.items.WoodBucketEmpty;

import net.minecraft.item.Item;

public class ModItems {
	public static final List<Item> ITEMS = new ArrayList<Item>();
	
	public static final Item SULFUR = new ItemBase("sulfur");
	public static final Item CINNABAR = new ItemBase("cinnabar");
	public static final Item SULFUR_CRYSTAL = new ItemBase("sulfur_crystal");
	public static final Item WOOD_BUCKET_ITEM = new WoodBucketEmpty("wood_bucket_item");
	public static final Item WOOD_BUCKET_FULL_ITEM = new ItemBase("wood_bucket_full_item");
}
Link to comment
Share on other sites

here is item java file and where I register the item. 

 

package com.posidon.startertech.items;

import net.minecraft.world.World;
import net.minecraftforge.fluids.Fluid;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumActionResult;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Item;
import net.minecraft.init.Blocks;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.block.state.IBlockState;

import com.posidon.startertech.init.ModItems;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;

public class WoodBucketEmpty extends ItemBase {
		public WoodBucketEmpty(String name) {
			super(name);
			setMaxDamage(1);
			maxStackSize = 16;
		}

		@Override
		public float getDestroySpeed(ItemStack par1ItemStack, IBlockState par2Block) {
			return 0.5F;
		}

		@Override
		public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ){
			BlockPos hitLocation = new BlockPos(hitX, hitY, hitZ);
			if (worldIn.getBlockState(new BlockPos(hitLocation)).getBlock() == Blocks.WATER) {
 				worldIn.setBlockToAir(new BlockPos(hitLocation));
 				
 				player.inventory.deleteStack(player.inventory.getCurrentItem());
 				player.inventory.add(player.inventory.currentItem, new ItemStack(ModItems.WOOD_BUCKET_FULL_ITEM));
			}	
	        return EnumActionResult.PASS;
	    }
}
package com.posidon.startertech.util.handlers;

import com.posidon.startertech.init.ModBlocks;
import com.posidon.startertech.init.ModItems;
import com.posidon.startertech.util.IHasModel;

import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

@EventBusSubscriber
public class RegistryHandler {
	@SubscribeEvent
	public static void onItemRegister(RegistryEvent.Register<Item> event) {
		event.getRegistry().registerAll(ModItems.ITEMS.toArray(new Item[0]));
	}
	
	@SubscribeEvent
	public static void onBlockRegister(RegistryEvent.Register<Block> event) {
		event.getRegistry().registerAll(ModBlocks.BLOCKS.toArray(new Block[0]));
	}
	
	@SubscribeEvent
	public static void onModelRegister(ModelRegistryEvent event) {
		for (Item item : ModItems.ITEMS) {
			if (item instanceof IHasModel) {
				((IHasModel)item).registerModels();
			}
		}
		
		for (Block block : ModBlocks.BLOCKS) {
			if (block instanceof IHasModel) {
				((IHasModel)block).registerModels();
			}
		}
	}
}
package com.posidon.startertech.items;

import com.posidon.startertech.Main;
import com.posidon.startertech.init.ModItems;
import com.posidon.startertech.util.IHasModel;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;

public class ItemBase extends Item implements IHasModel {
	public ItemBase(String name) {
		setUnlocalizedName(name);
		setRegistryName(name);
		setCreativeTab(CreativeTabs.MATERIALS);
		
		ModItems.ITEMS.add(this);
	}
	
	@Override
	public void registerModels() {
		Main.proxy.registerItemRenderer(this, 0, "inventory");
	}
}

 

Link to comment
Share on other sites

  • 1 month later...
  • 2 weeks later...

after the line:

if (worldIn.getBlockState(new BlockPos(hitLocation)).getBlock() == Blocks.WATER)

try adding a trace call (output a string into a console). keep the trace call there until you get the condition right.

use the trace call to see the values of method parameters.

Spoiler

 

i should just leave it at that, but here:

1) try using use the "pos" thingy. it's nice.

2) instead of comparing block instances, i'd check material and the value of level property.

 

 

Link to comment
Share on other sites

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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