#Preventing vine/bamboo growth

67 messages · Page 1 of 1 (latest)

granite tideBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

river fossil
#

no

crude fiber
#

this will work for bamboo..... but as chief said, nothing for vines

BlockEvents.rightClicked('minecraft:bamboo', event => {
    const { block, item, hand, player } = event
    if (hand != 'main_hand') return;
    if (item.id == 'minecraft:shears') {
        if (block.up.id != 'minecraft:bamboo') {
            let properties = block.getProperties()
            properties.put('stage', '1')
            block.set(block.id, properties)
            if (player) { player.swing() }
        }
    }
})
#

bamboo naturally has stage=0, and checks for the top piece to be 0 for growing, once it hits max height it changes to stage=1. This does that early, as long as you are right clicking on the upper most piece of bamboo

chrome thicket
#

With vines, you could maybe make a fake vine block which you replace the real vine with on right click with shears?

river fossil
#

you can create an exact copy, but you cannot change mutch (ie random tick behaviour)

chrome thicket
#

Minecraft's asset system allows you to make it a child of existing assets, so you can point to the vine's existing model, texture

river fossil
#

nope

#

easiest way would be to go through an ide to where the block is defined

chrome thicket
#

Or check the Minecraft wiki

crimson radishBOT
#

[Quote ➤](#1082700619569188874 message) This requires many files, but I will list all of them, along with their contents.
Ask me if you have any questions, or if you need something explained!

:warn_lex:The file contents in this example are compressed to not make the post very long.:warn_lex:

/kubejs/startup_scripts/dark_glass.js

const $TintedGlassBlock = Java.loadClass('net.minecraft.world.level.block.TintedGlassBlock')
const $Blocks = Java.loadClass('net.minecraft.world.level.block.Blocks')
const $Properties = Java.loadClass('net.minecraft.world.level.block.state.BlockBehaviour$Properties')
const $BlockItem = Java.loadClass('net.minecraft.world.item.BlockItem')
const $IProperties = Java.loadClass('net.minecraft.world.item.Item$Properties')

let darkGlass
StartupEvents.registry('block', e => { darkGlass = e.custom('dark_glass', new $TintedGlassBlock($Properties.copy($Blocks.TINTED_GLASS))) }) // Block
StartupEvents.registry('item', e => { e.custom('dark_glass', new $BlockItem(darkGlass.get(), new $IProperties())) })  // BlockItem (delete this line if you just want a block without item)

/kubejs/assets/kubejs/blockstates/dark_glass.json

{ "variants": { "": { "model": "kubejs:block/dark_glass" } } }

/kubejs/assets/kubejs/models/block/dark_glass.json

{
  "parent": "block/cube_all",
  "textures": { "all": "kubejs:block/dark_glass" },
  "render_type": "translucent"
}

/kubejs/assets/kubejs/models/item/dark_glass.json

{ "parent": "kubejs:block/dark_glass" }

/kubejs/assets/kubejs/textures/block/dark_glass.png
This is where you add the texture

river fossil
#

you swap out the TintedGlassBlock for the VineBlock class path

#

and the models can be swapped out too

chrome thicket
#

That shouldn't help solving this issue though since it will still have the same random growth behaviour

river fossil
#

p3lim asked 🤷

#

actually

#

you can disable random ticking through block modification

crude fiber
#

it'd be something like

BlockEvents.modification(event => {
  event.modify('blockid', block => {
    block.setIsRandomlyTicking(false)
  })
})
river fossil
#

ah,yeah colour makes sense. that needs separate reg
as for the properties, how are you setting/placing it?

crude fiber
#

you can get the properties of the original vine before replacing it like I did in the bamboo function

river fossil
#

forge or fabric?

crude fiber
#

you should basically have another block right click event on vanilla vines

river fossil
crude fiber
#

could you add a mapping to BlockColors you think?

river fossil
#
const $BiomeColors = Java.loadClass('net.minecraft.client.renderer.BiomeColors')
const $FoliageColors = Java.loadClass('net.minecraft.world.level.FoliageColor')

let blockColor = (state, tintGetter, pos, tintIndex) => tintGetter != null && pos != null ? $BiomeColors.getAverageFoliageColor(tintGetter, pos) : $FoliageColor.getDefaultColor()

Client.getBlockColors().register(blockColor, vinetip.get())
#

the key thing is firing this after block reg, and only on the client side so put the loadClass things inside the event

#

i think theres a client init event this would work well in

#

??kjswiki

crimson radishBOT
river fossil
#

oh and also moving the variable you store the block in to a higher scope

crude fiber
#

you'd have to global it?

river fossil
#

should be able to run a client event in startup, i think

#
const $Blocks = Java.loadClass('net.minecraft.world.level.block.Blocks')
const $Properties = Java.loadClass('net.minecraft.world.level.block.state.BlockBehaviour$Properties')
const $VineBlock = Java.loadClass('net.minecraft.world.level.block.VineBlock')

let vinetip;
StartupEvents.registry('block', event => {
    vinetip = event.custom('vine_tip', new $VineBlock($Properties.copy($Blocks.VINE)))
})

BlockEvents.modification(event => {
    event.modify('kubejs:vine_tip', block => {
        block.setIsRandomlyTicking(false)
    })
})

ClientEvents.init(event => {
  const $BiomeColors = Java.loadClass('net.minecraft.client.renderer.BiomeColors')
  const $FoliageColors = Java.loadClass('net.minecraft.world.level.FoliageColor')

  let blockColor = (state, tintGetter, pos, tintIndex) => tintGetter != null && pos != null ? $BiomeColors.getAverageFoliageColor(tintGetter, pos) : $FoliageColor.getDefaultColor()

  Client.getBlockColors().register(blockColor, vinetip.get())
})
crude fiber
#

yeah, didn't think about that

river fossil
#

hrm

#

need a later event

crude fiber
#

what about the forge event? or can you not listen to that one with ForgeEvents.onEvent ?

river fossil
#

thats a mod bus event, so ForgeEvents doesnt work

crude fiber
#

don't use it enough to know what is and isn't available, learn something new every day

river fossil
#

may be able to grab the event bus and subscribe to it, but its very generic heavy so rhino will probably have issues

crude fiber
#

I think assets should be after init

#

ClientEvents.highPriorityAssets

#

no.... wait.... that wouldn't make sense

river fossil
#

thats fired when one of the assets is called for

crude fiber
#

startup postinit ?

river fossil
#

could work with a server check

crude fiber
#

didn't error on me, and gave me an instance of BlockColors

#

oh yeah, I could see where that would be an issue on headless startup

river fossil
#

if (Java.loadClass('net.minecraftforge.fml.loading.FMLEnvironment').dist == "DEDICATED_SERVER") return

crude fiber
#

Client has isLocalServer() and isMultiplayerServer() that should work yeah?

river fossil
#

ClientWrapper?

#

or Minecraft itself

crude fiber
#

minecraft itself, which client wraps.... multiplayer is private, but local should work

river fossil
#

Minecraft doesnt exist on servers

crude fiber
#

sigh

river fossil
#

actuallt

#

a null check on Client

crude fiber
#

platform wrapper has a client check

#
StartupEvents.postInit(event => {
  if (!Platform.isClientEnvironment()) { return }
  const $BiomeColors = Java.loadClass('net.minecraft.client.renderer.BiomeColors')
  const $FoliageColors = Java.loadClass('net.minecraft.world.level.FoliageColor')

  let blockColor = (state, tintGetter, pos, tintIndex) => tintGetter != null && pos != null ? $BiomeColors.getAverageFoliageColor(tintGetter, pos) : $FoliageColors.getDefaultColor()

  Client.getBlockColors().register(blockColor, vinetip.get())
})
river fossil
#

oh nice

crude fiber
#

don't forget your loot table to make it drop a regular vine with shears

crude fiber
#

I'd just check for the block below to not be a vine

#

similar to what I did for block above in bamboo

#

because if you did that and the vine was on the ground it would destroy the block below

#

errr nevermind, I see what you did there

chrome thicket
#

Does the f3 screen not list them when you look at it?