Jump to content

[1.19.4] How to load ramdom loot to a custome chessblock using the existhing tools ???


perromercenary00

Recommended Posts

i find the code piece but no idea on how to use it 

 

 

i made this custome block is basically a dead rotten body whit a tile entity for now im user hooppertile entity 

i get how to set some items to the bodies 

Spoiler

				
			// ########## ########## ########## ##########
		public void tick(BlockState blkstate, ServerLevel slevel, BlockPos pos, RandomSource randomsource) {
		Level warudo = (Level) slevel;
		//System.out.println("tick( " + ( (warudo.isClientSide)? "Local World" : "Server World" ) + " )");
		
		
		Postate postate = new Postate(warudo, pos);
		postate.update_WATERLOGGED();
		boolean remove = false;
		
		int age = postate.get_AGE_5();
		
		if( age < 1 ) {
		remove = Block_Helper.get_luck();
		if (!remove) {
		age = ((int) ((Math.random() * 40) / 10)) + 1;
		postate.set_AGE_5(age);
		}
		
		
		if (remove) {
		postate.removeBlock();
		} else {
		postate.setBlock(10);
		
		BlockEntity blockentity = warudo.getBlockEntity(pos);
		if (blockentity instanceof HopperBlockEntity) {
		//System.out.println("tick( Loading hooper )");
		
		HopperBlockEntity be = (HopperBlockEntity) blockentity;
		be.setItem(0, ramdomItem() );
		be.setItem(1, ramdomItem() );
		}
		}
		}
		}
		
		
		
		public static ItemStack ramdomItem(){
		
		Map<Item, Integer> lista = new HashMap<Item, Integer>();
		lista.put(Items.AIR, 1);
		lista.put(Items.WHEAT_SEEDS, 15);
		lista.put(Items.DIAMOND_AXE, 1);
		lista.put(Items.DIAMOND_SWORD, 1);
		lista.put(Items.DIAMOND_PICKAXE, 1);
		lista.put(Items.IRON_AXE, 1);
		lista.put(Items.IRON_SWORD, 1);
		lista.put(Items.IRON_PICKAXE, 1);
		lista.put(Items.STICK, 16);
		
		ItemStack is = new ItemStack(Items.DIAMOND_SWORD, 1);
		
		
		//is.dama
		
		
		Item list[] = lista.keySet().toArray(new Item[0]);
		
		Item objeto = list[ ((int)( Math.random() * list.length )) ];
		int cant = lista.get(objeto);
		cant = (cant < 2)? 1 : ((int)( Math.random() * cant ) + 1 );
		
		return new ItemStack(objeto, cant);
		}				
			

 

but it has no sense to write a whole loot system to load this things when alredy minecraft has this in the tileEntity code 

### this is the one i have troubles whit ###

 

	public void setLootTable(ResourceLocation p_59627_, long p_59628_) {
this.lootTable = p_59627_;
this.lootTableSeed = p_59628_;
}
	

setloottable i supouse i have to pass the loot file as resource location 

minecraft/loot_tables/chests/village/village_plains_house.json

 

ResourceLocation rl = new ResourceLocation(this.modname, "structures/" + structureName + ".nbt");
Optional<Resource> rs = this.resourceManager.getResource(rl);

eee pues i dont have idea on how to declare tha file as a resource location 

i have to say more about the seed i see is a long value but any value is valid or tehre is some rules for it to work ?? 

 

#########################################

anyway i need a working example of 

 

HopperBlockEntity be = (HopperBlockEntity) blockentity;

be.setLootTable(ResourceLocation , );

 

 

thanks for your time 

 

 

 

 

 

 

 

 

 

 

 

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.