#Can you prevent hopper output on a specified block entity?
82 messages · Page 1 of 1 (latest)
Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!
I can also be okay with preventing placing hoppers next to the block, and the block vise versa
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
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
placed maybe better
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
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();
}
});
[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
This will return the block above it when it was placed
Thats perfect for what i need it for! thank you!
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

I mainly just dont want to be able to take things out of it with a hopper, so it works for my use case
Its working for me?
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
https://gyazo.com/a0579c0884456f8451288ce3e5889b28 works for me?
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?
Pistons cant move block entities
Not too worried about someone trying to use a deployer to place a block
you dont care about that?
I dont think it will be done
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.
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
hopperblocked returns an array
?
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
Doesnt work for some reason, no error
oh hmm
sec
weird that placing the barrel on the hopper is prevented but not the hopper under the barrel
In fact it seems to break the script altogether, once one is placed below, you can place ones above
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
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 chests
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
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
Ticket closed!
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();
}
});
});

just always gotta one up me dontcha

