#Stripping log drop bark and rebarking

58 messages · Page 1 of 1 (latest)

desert beacon
#

worked on a script so stripping log in world give you farmer's delight bark item and right clicking the stripped log with said bark place it back on
PS: I'm not a programmer and did this for fun so it may not be the most clean way of doing it but I'm still proud of what I got and I even used helper function successfully to make it easily expendable to support the mod you want

frank escarpBOT
#

Paste version of message.txt from @desert beacon

solid marten
#

I think you forgor to include to helper function in the script? or I am blind

#

nvm you put it inside the event

lofty oak
#

Would be cool if you popped the item in the direction the player is standing so that the items don't fly everywhere

desert beacon
#

@lofty oak that would be nice but with my limited knowledge I don't know how to, I'll search around if I find something

clear kernel
#

For loops, please

desert beacon
#

I found a solution! it doesn't pop the item in the player direction but with popItemFromFace I can pop the item from the face the event was trigger

frank escarpBOT
#

Paste version of message.txt from @desert beacon

full pond
# desert beacon I found a solution! it doesn't pop the item in the player direction but with pop...

I don't want to be rude, but I saw a way to shrink your code a bit. This may or may not be what DINO meant when asking for "For loops, please", but it should significantly reduce your file size at minimal increase to loading time.

const barked_logs = [
        //minecraft
        "minecraft:oak_log",
        "minecraft:oak_wood",
        "minecraft:spruce_log",
        "minecraft:spruce_wood",
        "minecraft:birch_log",
        "minecraft:birch_wood",
        "minecraft:jungle_log",
        "minecraft:jungle_wood",
        "minecraft:acacia_log",
        "minecraft:acacia_wood",
        "minecraft:dark_oak_log",
        "minecraft:dark_oak_wood",
        "minecraft:mangrove_log",
        "minecraft:mangrove_wood",
        "minecraft:cherry_log",
        "minecraft:cherry_wood",
        "minecraft:crimson_stem",
        "minecraft:crimson_hyphae",
        "minecraft:warped_stem",
        "minecraft:warped_hyphae",
        //cobblemon
        "cobblemon:apricorn_log",
        "cobblemon:apricorn_wood",
        "cobblemon:saccharine_log",
        "cobblemon:saccharine_wood"
    ];

ServerEvents.tags("item", (event) => {
    barked_logs.forEach((log) => {
        event.add("c:barked_logs", log);
    });
    //farmersdelight
    event.add("c:bark", "farmersdelight:tree_bark");
});
//Stripping give bark
BlockEvents.rightClicked((event) => {
    if (
        event.player.getMainHandItem().hasTag("minecraft:axes") &&
        Item.of(event.block.id).hasTag("c:barked_logs")
    ) {
        event.block.popItemFromFace("farmersdelight:tree_bark", event.facing);
    }
});
//Bark puts bark back on
BlockEvents.rightClicked((event) => {
    const barkking = (stripped, barked) => {
        if (
            event.player.getMainHandItem().id == "farmersdelight:tree_bark" &&
            event.block.id == stripped
        ) {
            event.player.getMainHandItem().shrink(1);
            event.server.runCommandSilent(
                `playsound minecraft:item.axe.strip block @a ${event.block.x} ${event.block.y} ${event.block.z}`
            );
            event.block.set(barked);
        }
    };

    barked_logs.forEach((log) => {
        const stripped_log = log.replace(':',":stripped_")
        barkking(stripped_log,log)
    })
});
desert beacon
#

@full pond i'm a full on noob so no I don't find it rude and welcome any upgrade and to be frank I don't even understand what ''for loops'' mean 😅 . has for your code I understand the const and tag event but not sure I understand the last part completely would it work with the _wood variant too?

full pond
# desert beacon <@211699493190631424> i'm a full on noob so no I don't find it rude and welcome ...

so barked_logs.forEach(log => { is a "for loop" that starts by taking each element of the barked_logs list, for example "minecraft:cherry_wood", assigns it to the variable "log", and then runs the inside code for each element.
stripped_log = log.replace(':',":stripped_") then takes log, which in the case of the example is "minecraft:cherry_wood" , and fits "stripped_" in the middle, so stripped_log now equals "minecraft:stripped_cherry_wood".
Then barkking(stripped_log,log) does what you had it do before, aka barkking('minecraft:stripped_cherry_wood', 'minecraft:cherry_wood'). It just happens to repeat it for each variable, so this already does both _log and _wood variants.

desert beacon
#

ok I see! thank for the explanation and helping me learn

#

so now only the const barked_Logs need to be updated when you wnat to add stuff

full pond
#

Exactly!

#

As long as the mod adding logs using "stripped_" and not something weird like "modname:mylogs_stripped", in which case you'll want to manually add the log to the tag and manually call barkked("modname:mylogs_stripped", "modname:mylog"), outside of the for loop.

#

Like how you had it before.

desert beacon
#

yeah figured has much has it's very dependent on nomenclature order

full pond
#

Thankfully most mod authors follow minecraft nomenclature.

desert beacon
#

@full pond i'm currently trying your iteration of the code and the re-barking doesn't work

frank escarpBOT
#

Paste version of log.txt from @desert beacon

full pond
# desert beacon <@211699493190631424> i'm currently trying your iteration of the code and the r...

I see.

Well, the BlockEvents.rightClicked() event has multiple overrides, so if you pass a block first, then the event, it can work that way too.

Try this:

const barked_logs = [
    //minecraft
    "minecraft:oak_log",
    "minecraft:oak_wood",
    "minecraft:spruce_log",
    "minecraft:spruce_wood",
    "minecraft:birch_log",
    "minecraft:birch_wood",
    "minecraft:jungle_log",
    "minecraft:jungle_wood",
    "minecraft:acacia_log",
    "minecraft:acacia_wood",
    "minecraft:dark_oak_log",
    "minecraft:dark_oak_wood",
    "minecraft:mangrove_log",
    "minecraft:mangrove_wood",
    "minecraft:cherry_log",
    "minecraft:cherry_wood",
    "minecraft:crimson_stem",
    "minecraft:crimson_hyphae",
    "minecraft:warped_stem",
    "minecraft:warped_hyphae",
    //cobblemon
    "cobblemon:apricorn_log",
    "cobblemon:apricorn_wood",
    "cobblemon:saccharine_log",
    "cobblemon:saccharine_wood"
];

ServerEvents.tags("item", (event) => {
    barked_logs.forEach((log) => {
        event.add("c:barked_logs", log);
    });
    //farmersdelight
    event.add("c:bark", "farmersdelight:tree_bark");
});
//Stripping give bark
BlockEvents.rightClicked((event) => {
    if (
        event.player.getMainHandItem().hasTag("minecraft:axes") &&
        Item.of(event.block.id).hasTag("c:barked_logs")
    ) {
        event.block.popItemFromFace("farmersdelight:tree_bark", event.facing);
    }
});
//Bark puts bark back on
barked_logs.forEach((barked) => {
    const stripped = barked.replace(":", ":stripped_");

    BlockEvents.rightClicked(stripped, (event) => {
        if (
            event.player.getMainHandItem().id == "farmersdelight:tree_bark" 
        ) {
            event.player.getMainHandItem().shrink(1);
            event.server.runCommandSilent(
                `playsound minecraft:item.axe.strip block @a ${event.block.x} ${event.block.y} ${event.block.z}`
            );
            event.block.set(barked);
        }
    });
});
desert beacon
full pond
#

Sorry, I missed one instance of that. Try now.

#

Edited to fix

desert beacon
full pond
#

edited to fix x2 combo, forgot const again. I keep trying to treat JS like PY

desert beacon
#

and it work! thank for the help

full pond
#

The lack of 'let' or 'const' is probably why the first 'fix' I gave failed.

lofty osprey
#

It works on 1.20.1 as well

THANK YOU SO MUCH

tropic anvil
# full pond I see. Well, the BlockEvents.rightClicked() event has multiple overrides, so if...

IDK if I can get in troble for necro-ing an #1048591172165189632, sorry if this isn't allowed, but I did a minor adjustment to allow for other barks to be used on a per-log basis and it broke... kinda

Important code (other OBJs in barked_logs omitted):

const barked_logs = [
  { log: `minecraft:oak_log`, stripped: `minecraft:stripped_oak_log`, bark: `farmersdelight:tree_bark` }
];

//Stripping give bark
BlockEvents.rightClicked( ( event ) => {
  barked_logs.forEach( ( OBJ_barked_logs ) => {
    if (
      event.player.getMainHandItem().hasTag("minecraft:axes") &&
      Item.of(event.block.id).hasTag("c:barked_logs")
    ) {
      event.block.popItemFromFace( OBJ_barked_logs.bark, event.facing );
    }
  })
});```

This makes it produce 20 bark when stripped, but it otherwise works 😭 MC ver 1.21.1, so this should work
I can still put bark on the logs too, it just produces too many
#

I've tried to change event.block.popItemFromFace( ***OBJ_barked_logs.bark***, event.facing ); => event.block.popItemFromFace( ***Item.of(OBJ_barked_logs.bark, 1)***, event.facing ); and it breaks completely

full pond
tropic anvil
#

You know what, you're exactly right. I have 20 logs listed

#

TY! Do you have an idea to fix it?

full pond
#

In your if condition inside the loop, compare event.block to OBJ_barked_logs.log

#

In addition to the tool used

tropic anvil
#
    if (
      event.player.getMainHandItem().hasTag("minecraft:axes") &&
      Item.of(event.block.id).hasTag("c:barked_logs") &&
      (event.block.id == OBJ_barked_logs.log)
    )```
#

I forgot the .log

full pond
#

And then you don't need the hasTag() check because it's a block in your list already.

tropic anvil
#

True

#

That worked! TY

frank escarpBOT
#

Paste version of bark_stripping.js from @tropic anvil

full pond
#

For future reference, if the last comment on a pozt is less than two months old, it's not a necro, however it is considered polite if you're modifying a script and need support to make a support ticket and link the example thread. Then once your modification is complete and working, then its best to put that in the example thread, and link your solved support thread.

If your question is only about a small change, for example adding objects to an existing list, then best practice is asking in the example thread.

Not saying you did anything wrong this time, just a better way to do this in the future.

tropic anvil
#

Okay! ty

#

I usually don't edit example scripts so I don't need to ask for help often

full pond
#

No worries, we call them examples for a reason. They can be used as-is or tailored for a given situation or user. Changes are expected, not exceptions to a rule.

lofty osprey
#

now i dont have to

tropic anvil
#

This

if ( config.console.stripping.tag || config.console.stripping.all ) { console.info(`TAG \"c:bark\": ADDED \"farmersdelight:tree_bark\"`); }

It's in the tag section

#

I use a constant in a high priority file to configure what I want logged for bugfixing :p

lofty osprey
#

For anyone using ars delight, heres the logs

const barked_logs = [
  { log: `ars_nouveau:green_archwood_log`, stripped: `ars_nouveau:stripped_green_archwood_log`, bark: `arsdelight:flourishing_bark`},
  { log: `ars_nouveau:green_archwood_wood`, stripped: `ars_nouveau:stripped_green_archwood_wood`, bark: `arsdelight:flourishing_bark`},
  { log: `ars_nouveau:purple_archwood_log`, stripped: `ars_nouveau:stripped_purple_archwood_log`, bark: `arsdelight:vexing_bark`},
  { log: `ars_nouveau:purple_archwood_wood`, stripped: `ars_nouveau:stripped_purple_archwood_wood`, bark: `arsdelight:vexing_bark`},
  { log: `ars_nouveau:blue_archwood_log`, stripped: `ars_nouveau:stripped_blue_archwood_log`, bark: `arsdelight:cascading_bark`},
  { log: `ars_nouveau:blue_archwood_wood`, stripped: `ars_nouveau:stripped_blue_archwood_wood`, bark: `arsdelight:cascading_bark`},
  { log: `ars_nouveau:red_archwood_log`, stripped: `ars_nouveau:stripped_red_archwood_log`, bark: `arsdelight:blazing_bark`},
  { log: `ars_nouveau:red_archwood_wood`, stripped: `ars_nouveau:stripped_red_archwood_wood`, bark: `arsdelight:blazing_bark`}
];
tawdry flume
#
// requires: lycheejs
// requires: farmersdelight

ServerEvents.recipes((event) => {
  const post = PostBuilder.create();
  const contextual = ContextualBuilder.create();

  Ingredient.of("#minecraft:logs").itemIds.forEach((/**@type {string}*/ log) => {
    let [namespace, path] = log.split(":");
    if (path.startsWith("stripped_")) return;
    event.recipes.lychee.block_interacting(
      [SizedIngredientWrapper.of("farmersdelight:tree_bark")],
      BlockPredicateWrapper.block(`${namespace}:stripped_${path}`),
      post.consumeAndPlace(log)
    );
  });
});