#Deployer interacting with player using item
20 messages · Page 1 of 1 (latest)
Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!
The XY problem is when you really want to do X, and you think that Y can achieve X. However, you can't get Y to work, and so ask for help exclusively about Y.
This can lead to a lot of confusion from the people trying to help you, as Y can seem like a very random thing to want to do, and a lot of the time isn't the best way to achieve X anyway.
Its fine to ask about Y, just always include some context about X so you can be put on the right track if Y won't do X well, or there is an easier way to do X.
Well in that case, I'll ask this one bit at a time
Can a deployer interact with an entity outside of normal minecraft interactions using these mods?
Since what I'm wanting to do is get milk from player using deployers
look...
there's a very scuffed way to do this...
which i do not recommend in the slightest
but it is possible
this example uses item entities
i MUST warn you that you shouldn't use this in any serious modpack
Although with players it might run a tad better
Oh sweet!
Although I'm very new at making modpacks (that's why I wanna do the small silly things lol), so how would I make it interract with players instead of items?
PlayerEvents.tick(event =>{
// if (entity.age % 20 !== 0) return;
const {entity} = event;
let x = entity.getBlockX()
let y = entity.getBlockY()
let z = entity.getBlockZ()
const level = entity.level
let entityNBT = entity.nbt
const possibleDeployers = {
1: [-2, 0, 0, Direction.EAST],
2: [0, 0, -2, Direction.SOUTH],
3: [2, 0, 0, Direction.WEST],
4: [0, 0, 2, Direction.north],
5: [0, 2, 0, Direction.DOWN],
6: [0, -2, 0, Direction.UP]
}
const directions = {
up: Direction.UP,
down: Direction.DOWN,
north: Direction.NORTH,
south: Direction.SOUTH,
east: Direction.EAST,
west: Direction.WEST,
}
for (let i = 1; i < 7; i++) {
let sumX = possibleDeployers[i][0] + x
let sumY = possibleDeployers[i][1] + y
let sumZ = possibleDeployers[i][2] + z
let correctDirection = possibleDeployers[i][3]
let block = level.getBlock(sumX, sumY, sumZ)
let blockFacing = block.properties.facing
if (blockFacing === undefined) continue
let nbt = block.entityData
const margin = 1000 - Math.abs(nbt.Speed)
if (
block.id == 'create:deployer' &&
directions[blockFacing] == correctDirection &&
nbt.Source &&
nbt.HeldItem.id == 'minecraft:diamond_sword' && // Adds a held item requirement for the dpeloyer
(nbt.Speed <= -128 || nbt.Speed >= 128) // Speed Requirement for the deployer to perform the recipe
// Time margin to match the deployer animation
nbt.State === "RETRACTING" &&
nbt.Timer >= margin
){
// resulting code here
}
}
})
I think that should do
i didn't test it though, wrote it all on discord
Awesome, thank you!
Ticket closed!
I saw this earlier but didn't have time to respond. There is a much simpler way to do this because deployers trigger events when right clicking:
let $DeployerFakePlayer = Java.loadClass("com.simibubi.create.content.kinetics.deployer.DeployerFakePlayer");
ItemEvents.entityInteracted("minecraft:iron_ingot", event => {
const {item, target: player, player: deployerPlayer} = event;
if (!(deployerPlayer instanceof $DeployerFakePlayer) || !player.isPlayer()) return;
player.tell("You've just been clicked!");
item.count--;
deployerPlayer.give("minecraft:gold_ingot");
})
Simply listen to ItemEvents.entityInteracted and check if its a DeployerFakePlayer player clicking another player.