#Preventing vine/bamboo growth
67 messages · Page 1 of 1 (latest)
no
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
With vines, you could maybe make a fake vine block which you replace the real vine with on right click with shears?
you can create an exact copy, but you cannot change mutch (ie random tick behaviour)
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
Or check the Minecraft wiki
[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
you swap out the TintedGlassBlock for the VineBlock class path
and the models can be swapped out too
That shouldn't help solving this issue though since it will still have the same random growth behaviour
it'd be something like
BlockEvents.modification(event => {
event.modify('blockid', block => {
block.setIsRandomlyTicking(false)
})
})
ah,yeah colour makes sense. that needs separate reg
as for the properties, how are you setting/placing it?
you can get the properties of the original vine before replacing it like I did in the bamboo function
forge or fabric?
you should basically have another block right click event on vanilla vines
^^
could you add a mapping to BlockColors you think?
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
This is a list of all the events. Choose your version.
oh and also moving the variable you store the block in to a higher scope
you'd have to global it?
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())
})
yeah, didn't think about that
what about the forge event? or can you not listen to that one with ForgeEvents.onEvent ?
thats a mod bus event, so ForgeEvents doesnt work
don't use it enough to know what is and isn't available, learn something new every day
may be able to grab the event bus and subscribe to it, but its very generic heavy so rhino will probably have issues
I think assets should be after init
ClientEvents.highPriorityAssets
no.... wait.... that wouldn't make sense
thats fired when one of the assets is called for
startup postinit ?
could work with a server check
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
if (Java.loadClass('net.minecraftforge.fml.loading.FMLEnvironment').dist == "DEDICATED_SERVER") return
@river fossil Houston, we have a problem
https://github.com/KubeJS-Mods/KubeJS/blob/1.19/main/forge/src/main/java/dev/latvian/mods/kubejs/forge/BuiltinKubeJSForgePlugin.java#L27
Client has isLocalServer() and isMultiplayerServer() that should work yeah?
minecraft itself, which client wraps.... multiplayer is private, but local should work
Minecraft doesnt exist on servers
sigh
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())
})
oh nice
don't forget your loot table to make it drop a regular vine with shears
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
Does the f3 screen not list them when you look at it?