#Can you prevent hopper output on a specified block entity?

82 messages · Page 1 of 1 (latest)

plush merlin
#

Is there any way to prevent hopper output on a block entity with kubejs? Hypothetically like preventing a hopper from pulling from minecraft:barrel but everything else would work normally

Figured id ask if its possible

tiny waveBOT
#

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

plush merlin
#

I can also be okay with preventing placing hoppers next to the block, and the block vise versa

slow rose
# plush merlin I can also be okay with preventing placing hoppers next to the block, and the bl...

try this js BlockEvents.rightClicked(event => { const {block,player,server,block: {id},player: {offHandItem,mainHandItem}} = event if (offHandItem.id != "minecraft:hopper" || offHandItem.id != "minecraft:barrel" || mainHandItem.id != "minecraft:hopper" || mainHandItem.id != "minecraft:barrel") return if (id == "minecraft:hopper" || id == "minecraft:barrel") { event.cancel() player.tell(`You can't place that here.`) } })

#

server script

plush merlin
slow rose
#

ah

#

sec

slow rose
# plush merlin no errors but its not working for some reason

so this version works ```js
BlockEvents.rightClicked(event => {
const { block, player, server, block: { id }, player: { offHandItem, mainHandItem } } = event

if (id == "minecraft:hopper" || id == "minecraft:barrel") {
    if (mainHandItem.id == 'minecraft:barrel' || offHandItem.id == 'minecraft:barrel'){
    player.tell(`You can't place that here.`)
    event.cancel()
    }else if (mainHandItem.id == 'minecraft:hopper' || offHandItem.id == 'minecraft:hopper'){
        player.tell(`You can't place that here.`)
        event.cancel()
        }
}

})```

#

however ive noticed a bit of an issue here

#

i doesnt matter if we block them from being placed on each other since we can place them on other blocks to achieve the same outcome

#

hmm

unique aspen
#

placed maybe better

slow rose
#

placed doesnt detect the block youre placing on

#

tho in the end if you place them on grass and place the barrel down next to the hopper itll still work

#

i wonder if theres a way to break the hopper if its by a barrel

#

mango youre the expert here how do we do it

unique aspen
#

simply like ```js
BlockEvents.placed("minecraft:hopper", (event) => {
const { block, player } = event;

if (block.up.id === "minecraft:barrel") {
player.tell(You can't place that here.);
event.cancel();
}
})
BlockEvents.placed("minecraft:barrel", (event) => {
const { block, player } = event;

if (block.down.id === "minecraft:hopper") {
player.tell(You can't place that here.);
event.cancel();
}
});

slow rose
#

block.up?

#

is that what detects the block placed on?

agile terraceBOT
#

[Quote ➤](#1167245175563759616 message) i doesnt matter if we block them from being placed on each other since we can place them on other blocks to achieve the same outcome

unique aspen
plush merlin
#

Thats perfect for what i need it for! thank you!

slow rose
#

what about side to side

#

block right click is better imo

#

though we're still missing the point

#

this is with both of our scripts right now

plush merlin
#

I mainly just dont want to be able to take things out of it with a hopper, so it works for my use case

slow rose
#

does it now?

#

not really sure if its possible tbh

plush merlin
#

Its working for me?

slow rose
#

youd have to stop the block from ticking if its by the barrel

#

yeah but did you see the video?

#

both of our scripts are pointless from preventing players from doing this

#

but hey i mean its up to you if youre fine with it

plush merlin
slow rose
#

oh

#

im just dumb and didnt try out mangos script

#

fair enough, you win this round

#

good job mango

#

but wait

#

what about blocks that place blocks?

#

or pistons for that matter?

plush merlin
#

Pistons cant move block entities

slow rose
#

hmm i see

#

i guess that would work then

plush merlin
#

Not too worried about someone trying to use a deployer to place a block

slow rose
#

you dont care about that?

plush merlin
#

I dont think it will be done

slow rose
#

maybe

#

well anyways

#

??closeticket

agile terraceBOT
# slow rose ??closeticket

Please close your ticket (with </ticket close:1054771505520717835> or the button atop this thread) once you resolved your issue! This also helps others that would like to help out, as they don't have to look into this thread to check if it has been resolved by now.

Do you have any other questions regarding your issue? Feel free to ask!
Note: You generally should create a new post for unrelated issues.

slow rose
#

if youre satisfied

plush merlin
# slow rose if youre satisfied

Hold on before i close it can i ask one more quick question, i want to replace minecraft:barrel now with a const but it doesnt seem to work properly

, it works once for the "up" but not the "down"

const hopperblocked = [
    'minecraft:barrel',
    'minecraft:chest'
    // placeholders
]

BlockEvents.placed("minecraft:hopper", (event) => {
    const { block, player } = event;
    
    if (block.up.id === hopperblocked) {
      player.tell(`You can't place that here.`);
      event.cancel();
    }
  })
  BlockEvents.placed(hopperblocked, (event) => {
    const { block, player } = event;
  
    if (block.down.id === "minecraft:hopper") {
      player.tell(`You can't place that here.`);
      event.cancel();
    }
  });

did I do something wrong?
// js noob here

slow rose
#

hopperblocked returns an array

plush merlin
slow rose
# plush merlin ?
const block = [
    'minecraft:barrel',
    'minecraft:chest'
]
function hopperblocks() {
    for (let i = 0; i < block.length; i++ ) {
        return block
    }
}
BlockEvents.rightClicked(hopperblocks(),event => {
    const { block, player, server, block: { id }, player: { offHandItem, mainHandItem } } = event
    player.tell('test')
})```
#

so itd be ```js
const block = [
'minecraft:barrel',
'minecraft:chest'
]
function hopperblocks() {
for (let i = 0; i < block.length; i++ ) {
return block
}
}
BlockEvents.placed("minecraft:hopper", (event) => {
const { block, player } = event;

if (block.up.id === hopperblocks()) {
  player.tell(`You can't place that here.`);
  event.cancel();
}

})
BlockEvents.placed(hopperblocks(), (event) => {
const { block, player } = event;

if (block.down.id === "minecraft:hopper") {
  player.tell(`You can't place that here.`);
  event.cancel();
}

});```

#

woops there fixed it

plush merlin
#

Doesnt work for some reason, no error

slow rose
#

oh hmm

#

sec

#

weird that placing the barrel on the hopper is prevented but not the hopper under the barrel

plush merlin
#

In fact it seems to break the script altogether, once one is placed below, you can place ones above

slow rose
#

oh i know whats going on here

#

well it doesnt break the script its just we need to do it differently, im working on it sec

slow rose
# plush merlin In fact it seems to break the script altogether, once one is placed below, you c...
const block = [
    'minecraft:barrel',
    'minecraft:chest'
]
function hopperblocks() {
    for (let i = 0; i < block.length; i++ ) {
        return block[i]

    }
}


  BlockEvents.placed("minecraft:hopper", (event) => {
    const { block, player } = event;
    player.tell(hopperblocks())
    if (block.up.id === hopperblocks()) {
      player.tell(`You can't place that here.`);
      event.cancel();
    }
  })
  BlockEvents.placed(hopperblocks(), (event) => {
    const { block, player } = event;
  
    if (block.down.id === "minecraft:hopper") {
      player.tell(`You can't place that here.`);
      event.cancel();
    }
  });```try this
#

wait that one doesnt detect chestsdespair gimme min

#

@plush merlin this one works ```js
const hopperblocked = [
'minecraft:barrel',
'minecraft:chest'
]
ServerEvents.tags('block', event => { event.add("kubejs:hopperblocked", hopperblocked) })

BlockEvents.placed((event) => {
const { block, player } = event;
if (block.id == 'minecraft:hopper'){
if (block.up.hasTag('kubejs:hopperblocked')) {
player.tell(You can't place that here.);
event.cancel();
}}else if (block.hasTag('kubejs:hopperblocked')){
if (block.down.id === "minecraft:hopper") {
player.tell(You can't place that here.);
event.cancel();
}
}
})``` just make sure to do /reload to reload the tag event

plush merlin
#

Ahh thats perfect! thank you so much

#

Thank you so much for the help :) youre very kind, i hope you have a good day/night

unique aspen
#
const hopperblocked = ["minecraft:barrel", "minecraft:chest"];

ServerEvents.tags("block", (event) => {
  event.add("kubejs:hopperblocked", hopperblocked);
});

BlockEvents.placed("minecraft:hopper", (event) => {
  const { block, player } = event;
  if (block.up.hasTag("kubejs:hopperblocked")) {
    player.tell(`You can't place that here.`);
    event.cancel();
  }
});
hopperblocked.forEach((blockId) => {
  BlockEvents.placed(blockId, (event) => {
    const { block, player } = event;

    if (block.down.id === "minecraft:hopper") {
      player.tell(`You can't place that here.`);
      event.cancel();
    }
  });
});
slow rose
#

just always gotta one up me dontchacatshake