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.

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

Featured Replies

Posted

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 

 

 

 

 

 

 

 

 

 

 

 

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.