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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I'm working in the forge mdk for 1.20.2 and using Terrablender (version 3.2.0.11) to create a custom biome. The biome itself works and generates just fine, but I need to create a custom tag for it in order to have a very specific structures generate in that biome and ONLY that biome. That's when the problem comes in: I've created a ModBiomeTagGenerator class that extends BiomeTagGenerator from the vanilla code, and the same way the vanilla BiomeTagGenerator assigns tags to biomes, I'm trying to assign my custom tag to my custom biome so I can use it in a has_structure json. However, when I do this and try to runData, an error pops up: "Couldn't define tag decayingplanetmod:is_abandoned_city as it is missing following references: decayingplanetmod:abandoned_city." After experimenting, I found that I can add my tag "is_abandoned_city" to other vanilla biomes, but I can't add vanilla tags or ANY tags to my custom biome, abandoned_city, so it's definitely a problem with the custom biome itself, despite the fact that the biome generates in-game just fine. I've included the code that defines my biome, my biome tags, and assigns my tag to my biome. I've scoured online for similar problems and found very few-- the ones I did find had no concrete solutions, just "it suddenly started working" or "I updated to another version and it works now," which is very vague, as they don't specify what they're updating or how. Nothing seems to work so far. Faulty code: https://paste.ee/p/79my3 Any input is appreciated.
    • ASIABET adalah pilihan terbaik bagi Anda yang mencari slot gacor hari ini dengan server Rusia dan jackpot menggiurkan. Berikut adalah beberapa alasan mengapa Anda harus memilih ASIABET: Slot Gacor Hari Ini Kami menyajikan koleksi slot gacor terbaik yang diperbarui setiap hari. Dengan fitur-fitur unggulan dan peluang kemenangan yang tinggi, Anda akan merasakan pengalaman bermain yang tak terlupakan setiap kali Anda memutar gulungan. Server Rusia yang Handal Kami menggunakan server Rusia yang handal dan stabil untuk memastikan kelancaran dan keadilan dalam setiap putaran permainan. Anda dapat bermain dengan nyaman tanpa khawatir tentang gangguan atau lag. Jackpot Menggiurkan Nikmati kesempatan untuk memenangkan jackpot menggiurkan yang dapat mengubah hidup Anda secara instan. Dengan hadiah-hadiah besar yang ditawarkan, setiap putaran permainan bisa menjadi peluang untuk meraih keberuntungan besar.
    • Sonic77 adalah pilihan tepat bagi Anda yang menginginkan pengalaman bermain slot yang unggul dengan akun pro Swiss terbaik. Berikut adalah beberapa alasan mengapa Anda harus memilih Sonic77: Slot Gacor Terbaik Kami menyajikan koleksi slot gacor terbaik dari provider terkemuka. Dengan fitur-fitur unggulan dan peluang kemenangan yang tinggi, Anda akan merasakan pengalaman bermain yang tak terlupakan. Akun Pro Swiss Berkualitas Kami menawarkan akun pro Swiss yang berkualitas dan terpercaya. Dengan akun ini, Anda dapat menikmati berbagai keuntungan eksklusif dan fasilitas premium yang tidak tersedia untuk akun reguler.
    • SV388 SITUS RESMI SABUNG AYAM 2024   Temukan situs resmi untuk sabung ayam terpercaya di tahun 2024 dengan SV388! Dengan layanan terbaik dan pengalaman bertaruh yang tak tertandingi, SV388 adalah tempat terbaik untuk pecinta sabung ayam. Daftar sekarang untuk mengakses arena sabung ayam yang menarik dan nikmati kesempatan besar untuk meraih kemenangan. Jelajahi sensasi taruhan yang tak terlupakan di tahun ini dengan SV388! [[jumpuri:❱❱❱❱❱ DAFTAR DI SINI ❰❰❰❰❰ > https://w303.pink/orochimaru]] [[jumpuri:❱❱❱❱❱ DAFTAR DI SINI ❰❰❰❰❰ > https://w303.pink/orochimaru]]   JURAGANSLOT88 SITUS JUDI SLOT ONLINE TERPERCAYA 2024 Jelajahi pengalaman judi slot online terpercaya di tahun 2024 dengan JuraganSlot88! Sebagai salah satu situs terkemuka, JuraganSlot88 menawarkan berbagai pilihan permainan slot yang menarik dengan layanan terbaik dan keamanan yang terjamin. Daftar sekarang untuk mengakses sensasi taruhan yang tak terlupakan dan raih kesempatan besar untuk meraih kemenangan di tahun ini dengan JuraganSlot88 [[jumpuri:❱❱❱❱❱ DAFTAR DI SINI ❰❰❰❰❰ > https://w303.pink/orochimaru]] [[jumpuri:❱❱❱❱❱ DAFTAR DI SINI ❰❰❰❰❰ > https://w303.pink/orochimaru]]
  • Topics

×
×
  • Create New...

Important Information

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