KubeJS (Old)

KubeJS (Old)

3M Downloads

Want to add docs, can't edit wiki or post in discord

dymavion opened this issue ยท 1 comments

commented

Minecraft Version

1.19.2

KubeJS Version

1902.6.0-build.142

Rhino Version

n/a

Architectury Version

6.5.85-forge

Forge/Fabric Version

Forge 43.2.11

Describe your issue

I worked out some scripts that aren't currently documented in the wiki (ItemEvents in startup scripts and entityLootTables in server scripts) and I'd like to document them, but can't see how to edit in the wiki (I created an account, to no avail), and I don't seem to have access to post in Discord (I was going to ask how there). Thus, I'm here instead, sorry.

For the curious... both scripts tested and working with the github bug report params listed on this entry

In startup scripts, to edit item properties:


ItemEvents.modification(event => {
	
	/*
	let exploreItem = function(item) {		
		console.info('exploring item: ' + item);
		for (var key in item) {
			try{ console.info(`${key}: ${item[key]}`)} catch(e) {}
		}		
	}
	
	let listDiggableProperties = function(item) {
		console.info(item);
		try{console.info('digSpeed: ' + item.digSpeed)} catch(e) { console.info(e) }
		try{console.info('speed: ' + item.speed)} catch(e) { console.info(e) }
		try{console.info('maxDamage: ' + item.maxDamage)} catch(e) { console.info(e) }
		try{console.info('attackDamage: ' + item.attackDamage)} catch(e) { console.info(e) }
	}
	*/
	
	//event.modify('minecraft:iron_sword', item => { exploreItem(item); });




	// can't seem to set .damage property directly or .setDamage(10)... leaving it for now
	// (vanilla damages, 3, 4, 5, 3, 6, 7)
	event.modify('minecraft:wooden_sword', item => { item.maxDamage = 15 });
	event.modify('minecraft:stone_sword', item => { item.maxDamage = 75 });
	event.modify('minecraft:iron_sword', item => { item.maxDamage = 180 });
	event.modify('minecraft:golden_sword', item => { item.maxDamage = 32 });
	event.modify('minecraft:diamond_sword', item => { item.maxDamage = 2000 });
	event.modify('minecraft:netherite_sword', item => { item.maxDamage = 3000 });


	let setDiggables = function(item, speed, maxDamage) {
		item.digSpeed = speed;
		item.speed = speed;
		item.maxDamage = maxDamage
	}
	
	event.modify('minecraft:wooden_pickaxe', item => { setDiggables(item, 1, 15)});
	event.modify('minecraft:wooden_shovel', item => { setDiggables(item, 1, 15)});
	event.modify('minecraft:wooden_hoe', item => { setDiggables(item, 1, 15)});
	event.modify('minecraft:wooden_axe', item => { setDiggables(item, 1, 15)});
	
	event.modify('minecraft:stone_pickaxe', item => { setDiggables(item, 1, 75)});
	event.modify('minecraft:stone_shovel', item => { setDiggables(item, 1, 75)});
	event.modify('minecraft:stone_hoe', item => { setDiggables(item, 1, 75)});
	event.modify('minecraft:stone_axe', item => { setDiggables(item, 1, 75)});
	
	event.modify('minecraft:iron_pickaxe', item => { setDiggables(item, 5, 180)});
	event.modify('minecraft:iron_shovel', item => { setDiggables(item, 5, 180)});
	event.modify('minecraft:iron_hoe', item => { setDiggables(item, 5, 180)});
	event.modify('minecraft:iron_axe', item => { setDiggables(item, 5, 180)});
		
	// golden_* remains unchanged
		
	event.modify('minecraft:diamond_pickaxe', item => { setDiggables(item, 10, 2000)});
	event.modify('minecraft:diamond_shovel', item => { setDiggables(item, 10, 2000)});
	event.modify('minecraft:diamond_hoe', item => { setDiggables(item, 10, 2000)});
	event.modify('minecraft:diamond_axe', item => { setDiggables(item, 10, 2000)});
	
	event.modify('minecraft:netherite_pickaxe', item => { setDiggables(item, 12, 3000)});
	event.modify('minecraft:netherite_shovel', item => { setDiggables(item, 12, 3000)});
	event.modify('minecraft:netherite_hoe', item => { setDiggables(item, 12, 3000)});
	event.modify('minecraft:netherite_axe', item => { setDiggables(item, 12, 3000)});
	
});

In server scripts, to edit entity loot tables:


ServerEvents.entityLootTables(event => {
	
	// have sheep drop leather on 75% random chance
	event.modifyEntity('minecraft:sheep', table => {
		table.addPool(pool => {
			pool.addItem('minecraft:leather').randomChance(0.75)
		})
	})
})

Crash report/logs

No response

commented

You need to be given wiki edit perms by Lat, the usual way to ask for that is through the discord. Not sure why you can't post in there.

I have made a new wiki page for item modification here: https://wiki.latvian.dev/books/kubejs/page/item-modification
It is also documented on the legacy wiki, which is still mostly correct except for the event handler.
https://wiki.latvian.dev/books/kubejs-legacy/page/item-modification

For loot tables that is also documented on the legacy wiki, where the only thing wrong is the event handler: https://wiki.latvian.dev/books/kubejs-legacy/page/loot-table-modification