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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hallo all! I'm working on a custom mod pack for a few friends an I. However, whenever I launch it, it crashes and returns this error code. It appears to be crashing while trying to render some sprites from different mods, but I can't find a way to fix this.      The game crashed whilst stitching Error:      net.minecraft.client.renderer.texture.StitcherException:      Unable to fit: minecolonies:entity/citizen/nether/noblemale3_b - size: 128x64 -      Maybe try a lower resolution resourcepack? Here's the pastebin of the crash report: https://pastebin.com/17hgAPFS
    • when i join it looks normal until i look a mob or i have some thing in my hand and my screen starts turning different colors when i look around. i can see my inventory and the menu but not mobs or blocks in my hand I've tried to turn off the anti virus  uninstall and reinstalling the best driver  going back from version 20 to 8 and putting a ton of ram into minecraft. if i could get any help. thank you
    • Hi fellow minecrafter,   We've got exciting news from the Pacific Laboratory for Artificial Intelligence (PLAI) at UBC! We're merging the worlds of Minecraft and AI research, and you're invited to join through our platform, plaicraft.ai, to aid our data collection process. It's not just playing games; it's contributing to cutting-edge AI research.   BetterStructures and more!!: We want to make the server as fun as possible for everyone so we recently added a bunch of structural plugins that adds over a hundred of new structures and sites for you to explore and challenge. We are also working on PVP, bedwars and skyblock content, which will make the server even more fun!   Here’s how you can get involved! -Register on plaicraft.ai with your email(you can fake one, as long as you can receive email from it it's fine). -Complete a consent form. -Play Minecraft and contribute to science! (all you need is a Chrome browser and a steady internet, you'll be playing on VM)   Why You Should Participate? -Support AI Research: Your gameplay directly contributes to important AI advancements.  -Free Minecraft Access: Enjoy the game without any cost. -We have shaders and a bunch of cool mods loaded on our instances  -Great Community: Our server currently has a fantastic community, with many awesome players you can meet.   Elephant in the room: Now I want to address some obvious concerns, I sure did a good job making us sound like a scam by the above content. I know that the "free Minecraft" thing has always been taboo in the Minecraft community. So how can I prove to you that this is not a scam? - The easiest way and most official way is that we are approved by the University of British Columbia ethics board, our BREB number is H23-02389. You can verify this case number yourself. - The harder way is that I'll explain the technical details of this project and why we choose to provide free Minecraft. So the goal of this project is very similar to the paper MineDojo or MineRL, we want to collect a multi-modal dataset that consists of video, audio, keyboard and mouse movement. Minecraft has been a very important simulation environment for the ML community and there are tons of papers related to it. Now we obviously don't have enough money like those big tech companies who can just pay people to play, so we have to turn to the Minecraft community. To record all the data mentioned, there needs to be a lot of setup and coding, and it's definitely impossible for us to ask people to run these recording programs on their personal computers. So we carefully configured the AWS EC2 instance to run Minecraft alongside the programs. And that's where and why we also provide you with free Minecraft licenses, of course, we are not giving the account to you, just allowing you to be able to play Minecraft on these instances. You might ask, "Why can't I log in with my account on the instances?", that's because first login with your personal Minecraft account is another privacy risk; second not all our target audiences have an account; and lastly we restricted a lot on what you can do on the instance, basically all you can do is play Minecraft and that's all the data we want, allowing you to log in will make things complicated to control.   For more information on the project and the team, visit Dr. Frank Wood’s website or follow @frankdonaldwood on Twitter. You can also learn more about PLAI lab research on our website (just search ubc plai). Join us in transforming your gaming experience into a meaningful contribution to AI research. Let’s push the boundaries of what gaming can achieve together! Happy plaiing!   Best,  The PLAI Team
    • The mod has improved a lot from yesterday just 1 last issue  Here's the crash report- https://pastebin.com/k2A1BAKn   Please help, Thanks.
    • Take Your Gaming Experience to the Next Level with These Essential Tools   If you're a Minecraft enthusiast, you've likely experienced the need to customize your world and server to make it more exciting and challenging. Fortunately, there's a perfect solution for you: https://menzatyx.xyz, the website that offers a wide selection of free and pre-configured Minecraft plugins. At https://menzatyx.xyz, you'll find a diverse range of plugins that will allow you to take your gaming experience to the next level. From server management tools to mods that add new functionalities, each of these plugins has been carefully selected and configured, so you can enjoy a more personalized and thrilling Minecraft experience. One of the primary benefits of using these pre-configured plugins is the ease of implementation. You no longer have to spend hours configuring and adjusting each individual plugin. Simply download the package that best suits your needs, and you're good to go! You'll be able to enjoy all the features and improvements without investing too much time and effort. From plugins that enhance the security of your server to mods that add new game modes, the variety offered by https://menzatyx.xyz is impressive. Moreover, as these are free plugins, you can access these tools without spending a single penny. It's the perfect opportunity to take your Minecraft experience to the next level without affecting your wallet! Whether you're a casual player or an experienced server administrator, at https://menzatyx.xyz you'll find the Minecraft plugins you need to personalize and enhance your game. Visit the website now and discover how you can transform your Minecraft world into something unique and thrilling!
  • Topics

×
×
  • Create New...

Important Information

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