use of net.minecraftforge.common.util.FakePlayer in project BuildCraft by BuildCraft.
the class BlockUtil method breakBlock.
public static boolean breakBlock(WorldServer world, BlockPos pos, NonNullList<ItemStack> drops, BlockPos ownerPos, GameProfile owner) {
FakePlayer fakePlayer = BuildCraftAPI.fakePlayerProvider.getFakePlayer(world, owner, ownerPos);
BreakEvent breakEvent = new BreakEvent(world, pos, world.getBlockState(pos), fakePlayer);
MinecraftForge.EVENT_BUS.post(breakEvent);
if (breakEvent.isCanceled()) {
return false;
}
if (!world.isAirBlock(pos) && !world.isRemote && world.getGameRules().getBoolean("doTileDrops")) {
drops.addAll(getItemStackFromBlock(world, pos, owner));
}
world.setBlockToAir(pos);
return true;
}
use of net.minecraftforge.common.util.FakePlayer in project BuildCraft by BuildCraft.
the class BlockUtil method harvestBlock.
public static boolean harvestBlock(WorldServer world, BlockPos pos, @Nonnull ItemStack tool, GameProfile owner) {
FakePlayer fakePlayer = getFakePlayerWithTool(world, tool, owner);
BreakEvent breakEvent = new BreakEvent(world, pos, world.getBlockState(pos), fakePlayer);
MinecraftForge.EVENT_BUS.post(breakEvent);
if (breakEvent.isCanceled()) {
return false;
}
IBlockState state = world.getBlockState(pos);
if (!state.getBlock().canHarvestBlock(world, pos, fakePlayer)) {
return false;
}
state.getBlock().onBlockHarvested(world, pos, state, fakePlayer);
state.getBlock().harvestBlock(world, fakePlayer, pos, state, world.getTileEntity(pos), tool);
world.setBlockToAir(pos);
return true;
}
use of net.minecraftforge.common.util.FakePlayer in project BuildCraft by BuildCraft.
the class BlockUtil method getFakePlayerWithTool.
public static FakePlayer getFakePlayerWithTool(WorldServer world, @Nonnull ItemStack tool, GameProfile owner) {
FakePlayer player = BuildCraftAPI.fakePlayerProvider.getFakePlayer(world, owner);
int i = 0;
while (player.getHeldItemMainhand() != tool && i < 9) {
if (i > 0) {
player.inventory.setInventorySlotContents(i - 1, StackUtil.EMPTY);
}
player.inventory.setInventorySlotContents(i, tool);
i++;
}
return player;
}
use of net.minecraftforge.common.util.FakePlayer in project BuildCraft by BuildCraft.
the class TileFloodGate method update.
// ITickable
@Override
public void update() {
if (world.isRemote) {
return;
}
if (tank.getFluidAmount() < Fluid.BUCKET_VOLUME) {
return;
}
tick++;
if (tick % 16 == 0) {
if (!tank.isEmpty() && !queue.isEmpty()) {
FluidStack fluid = tank.drain(Fluid.BUCKET_VOLUME, false);
if (fluid != null && fluid.amount >= Fluid.BUCKET_VOLUME) {
BlockPos currentPos = queue.removeLast();
List<BlockPos> path = paths.get(currentPos);
boolean canFill = true;
if (path != null) {
for (BlockPos p : path) {
if (p.equals(currentPos)) {
continue;
}
if (!canFillThrough(currentPos)) {
canFill = false;
break;
}
}
}
if (canFill && canFill(currentPos)) {
FakePlayer fakePlayer = BuildCraftAPI.fakePlayerProvider.getFakePlayer((WorldServer) world, getOwner(), currentPos);
if (FluidUtil.tryPlaceFluid(fakePlayer, world, currentPos, tank, fluid)) {
for (EnumFacing side : EnumFacing.VALUES) {
world.notifyNeighborsOfStateChange(currentPos.offset(side), BCFactoryBlocks.floodGate, false);
}
delayIndex = 0;
tick = 0;
}
} else {
buildQueue();
}
}
}
}
if (queue.isEmpty() && tick % getCurrentDelay() == 0) {
delayIndex = Math.min(delayIndex + 1, REBUILD_DELAYS.length - 1);
tick = 0;
buildQueue();
}
}
use of net.minecraftforge.common.util.FakePlayer in project BiomesOPlenty by Glitchfiend.
the class ItemJarEmpty method itemInteractionForEntity.
@Override
public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer player, EntityLivingBase target, EnumHand hand) {
// right clicking a pixie with an empty jar catches it in the jar
if (target instanceof EntityPixie) {
EntityPixie pixie = (EntityPixie) target;
pixie.setDead();
stack.setCount(stack.getCount() - 1);
ItemStack pixieJar = new ItemStack(BOPItems.jar_filled, 1, ItemJarFilled.JarContents.PIXIE.ordinal());
EntityItem pixieJarEntity = new EntityItem(player.world, player.posX, player.posY, player.posZ, pixieJar);
if (!player.world.isRemote) {
player.world.spawnEntity(pixieJarEntity);
if (!(player instanceof FakePlayer)) {
pixieJarEntity.onCollideWithPlayer(player);
}
}
return true;
}
return false;
}
Aggregations