Skip to content

Commit

Permalink
fix lamp drops and recipes
Browse files Browse the repository at this point in the history
  • Loading branch information
cubebotfan committed Nov 6, 2024
1 parent 978967d commit e60416f
Showing 1 changed file with 168 additions and 4 deletions.
172 changes: 168 additions & 4 deletions kubejs/server_scripts/yttr_block_fix.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//Block Drop Fixes
onEvent("block.loot_tables", (event) => {
[
["yttr:yttrium_block"],
Expand Down Expand Up @@ -75,15 +76,178 @@ onEvent("block.loot_tables", (event) => {
["yttr:black_project_table"],
["yttr:neodymium_slab"],
["yttr:neodymium_block"],
["yttr:lamp"],
["yttr:fixture"],
["yttr:cage_lamp"],
["yttr:panel"],
["yttr:aware_hopper"],
["yttr:levitation_chamber"],
["yttr:magtank"],
["yttr:dsu"],
].forEach((loot) => {
event.addSimpleBlock(loot[0], loot[0]);
});
//Lamp Blocks
const lampColors = [ //don't include colorless
"white",
"orange",
"magenta",
"light_blue",
"yellow",
"lime",
"pink",
"gray",
"light_gray",
"cyan",
"purple",
"blue",
"brown",
"green",
"red",
"black",
"teal"
];
[
"yttr:lamp",
"yttr:fixture",
"yttr:cage_lamp",
"yttr:panel"
].forEach((lamp) => {
event.addJson(lamp, {
type: "minecraft:block",
pools: [
{
rolls: 1,
bonus_rolls: 0,
entries: [
{
type: "minecraft:item",
name: lamp,
functions: [
{
function: "minecraft:set_nbt",
tag: "{Inverted: false, LampColor: \"colorless\"}"
},
{
function: "minecraft:set_nbt",
tag: "{Inverted: true}",
conditions: [
{
block: lamp,
condition: "minecraft:block_state_property",
properties: {
inverted: true
}
}
]
}
].concat(lampColors.map(color=>{
return {
function: "minecraft:set_nbt",
tag: `{LampColor: \"${color}\"}`,
conditions: [
{
block: lamp,
condition: "minecraft:block_state_property",
properties: {
color: color
}
}
]
}
}))
}
],
conditions: [
{
condition: "minecraft:survives_explosion"
}
]
}
]
})
})
});

//Lamp Recipe Fixes
onEvent("recipes", (event) => {

const lampTypes = [
"lamp",
"fixture",
"cage_lamp",
"panel"
];
const lampColors = [ //don't include colorless
["white", "$minecraft:white_dye"],
["orange", "minecraft:orange_dye"],
["magenta", "minecraft:white_dye"],
["light_blue", "minecraft:light_blue_dye"],
["yellow", "minecraft:yellow_dye"],
["lime", "minecraft:lime_dye"],
["pink", "minecraft:pink_dye"],
["gray", "minecraft:gray_dye"],
["light_gray", "minecraft:light_gray_dye"],
["cyan", "minecraft:cyan_dye"],
["purple", "minecraft:purple_dye"],
["blue", "minecraft:blue_dye"],
["brown", "minecraft:brown_dye"],
["green", "minecraft:green_dye"],
["red", "minecraft:red_dye"],
["black", "minecraft:black_dye"],
["teal", "yttr:yttrium_dust"]
];


//Lamp recipe fixes
lampTypes.forEach(lamp=>{
//this recipe is shaped for some reason
event.remove({id:`yttr:crafting/lamp/${lamp}_invert`});
//this recipe doesn't even work
event.remove({id:`yttr:crafting/lamp/${lamp}_dye`});

//recreate lamp inversion recipe as a shapeless one. Also make it not consume the redstone torch
event.shapeless(
Item.of(`yttr:${lamp}`).withNBT('{Inverted:true, LampColor:\"colorless\"}'),
[
`yttr:${lamp}`,
'minecraft:redstone_torch'
]
)
.modifyResult((grid, result)=>{
let item = grid.find(Ingredient.of(`yttr:${lamp}`).ignoreNBT());

let nbt = {};
nbt.Inverted = !item.nbt.Inverted;
if (item.nbt.LampColor) {
nbt.LampColor = item.nbt.LampColor;
}
return result.withNBT(nbt);
})
.keepIngredient("minecraft:redstone_torch")
.id(`createastral:crafting/yttr/lamp/${lamp}_invert`)

//Create lamp dyeing recipes that actually work
event.shapeless(
Item.of(`yttr:${lamp}`).withNBT('{Inverted:false, LampColor:\"white\"}'),
[
`yttr:${lamp}`,
'#yttr:lamp_dyes'
]
)
.modifyResult((grid, result)=>{
let item = grid.find(Ingredient.of(`yttr:${lamp}`).ignoreNBT());
let dye = grid.find(`#yttr:lamp_dyes`);

let nbt = {};

nbt.Inverted = !!item.nbt.Inverted;

for (let i=0;i<lampColors.length;++i) {
if (dye.getId()===lampColors[i][1]) {
nbt.LampColor = lampColors[i][0];
break;
}
}

return result.withNBT(nbt);
})
.id(`createastral:crafting/yttr/lamp/${lamp}_dye`)
})
})

0 comments on commit e60416f

Please sign in to comment.