
net.minecraft.server.BlockCommand Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of walk-server Show documentation
Show all versions of walk-server Show documentation
A spigot fork to kotlin structure and news.
package net.minecraft.server;
import org.bukkit.event.block.BlockRedstoneEvent;
import java.util.Random;
public class BlockCommand extends BlockContainer {
public static final BlockStateBoolean TRIGGERED = BlockStateBoolean.of("triggered");
public BlockCommand() {
super(Material.ORE, MaterialMapColor.q);
this.j(this.blockStateList.getBlockData().set(BlockCommand.TRIGGERED, false));
}
public TileEntity a(World world, int i) {
return new TileEntityCommand();
}
public void doPhysics(World world, BlockPosition blockposition, IBlockData iblockdata, Block block) {
if (!world.isClientSide) {
boolean flag = world.isBlockIndirectlyPowered(blockposition);
boolean flag1 = iblockdata.get(BlockCommand.TRIGGERED);
// CraftBukkit start
org.bukkit.block.Block bukkitBlock = world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ());
int old = flag1 ? 15 : 0;
int current = flag ? 15 : 0;
BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(bukkitBlock, old, current);
world.getServer().getPluginManager().callEvent(eventRedstone);
// CraftBukkit end
if (eventRedstone.getNewCurrent() > 0 && !(eventRedstone.getOldCurrent() > 0)) { // CraftBukkit
world.setTypeAndData(blockposition, iblockdata.set(BlockCommand.TRIGGERED, true), 4);
world.a(blockposition, this, this.a(world));
} else if (!(eventRedstone.getNewCurrent() > 0) && eventRedstone.getOldCurrent() > 0) { // CraftBukkit
world.setTypeAndData(blockposition, iblockdata.set(BlockCommand.TRIGGERED, false), 4);
}
}
}
public void b(World world, BlockPosition blockposition, IBlockData iblockdata, Random random) {
TileEntity tileentity = world.getTileEntity(blockposition);
if (tileentity instanceof TileEntityCommand) {
((TileEntityCommand) tileentity).getCommandBlock().a(world);
world.updateAdjacentComparators(blockposition, this);
}
}
public int a(World world) {
return 1;
}
public boolean interact(World world, BlockPosition blockposition, IBlockData iblockdata, EntityHuman entityhuman, EnumDirection enumdirection, float f, float f1, float f2) {
TileEntity tileentity = world.getTileEntity(blockposition);
return tileentity instanceof TileEntityCommand && ((TileEntityCommand) tileentity).getCommandBlock().a(entityhuman);
}
public boolean isComplexRedstone() {
return true;
}
public int l(World world, BlockPosition blockposition) {
TileEntity tileentity = world.getTileEntity(blockposition);
return tileentity instanceof TileEntityCommand ? ((TileEntityCommand) tileentity).getCommandBlock().j() : 0;
}
public void postPlace(World world, BlockPosition blockposition, IBlockData iblockdata, EntityLiving entityliving, ItemStack itemstack) {
TileEntity tileentity = world.getTileEntity(blockposition);
if (tileentity instanceof TileEntityCommand) {
CommandBlockListenerAbstract commandblocklistenerabstract = ((TileEntityCommand) tileentity).getCommandBlock();
if (itemstack.hasName()) {
commandblocklistenerabstract.setName(itemstack.getName());
}
if (!world.isClientSide) {
commandblocklistenerabstract.a(world.getGameRules().getBoolean("sendCommandFeedback"));
}
}
}
public int a(Random random) {
return 0;
}
public int b() {
return 3;
}
public IBlockData fromLegacyData(int i) {
return this.getBlockData().set(BlockCommand.TRIGGERED, (i & 1) > 0);
}
public int toLegacyData(IBlockData iblockdata) {
int i = 0;
if (iblockdata.get(BlockCommand.TRIGGERED)) {
i |= 1;
}
return i;
}
protected BlockStateList getStateList() {
return new BlockStateList(this, BlockCommand.TRIGGERED);
}
public IBlockData getPlacedState(World world, BlockPosition blockposition, EnumDirection enumdirection, float f, float f1, float f2, int i, EntityLiving entityliving) {
return this.getBlockData().set(BlockCommand.TRIGGERED, false);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy