use of net.minecraftforge.common.util.FakePlayer in project ImmersiveEngineering by BluSunrize.
the class TileEntityExcavator method digBlock.
ItemStack digBlock(BlockPos pos) {
if (!(world instanceof WorldServer))
return ItemStack.EMPTY;
FakePlayer fakePlayer = FakePlayerUtil.getFakePlayer(world);
IBlockState blockstate = world.getBlockState(pos);
Block block = blockstate.getBlock();
if (block != null && !world.isAirBlock(pos) && blockstate.getPlayerRelativeBlockHardness(fakePlayer, world, pos) != 0) {
if (!block.canHarvestBlock(world, pos, fakePlayer))
return ItemStack.EMPTY;
block.onBlockHarvested(world, pos, blockstate, fakePlayer);
if (block.removedByPlayer(blockstate, world, pos, fakePlayer, true)) {
block.onPlayerDestroy(world, pos, blockstate);
if (block.canSilkHarvest(world, pos, blockstate, fakePlayer)) {
ArrayList<ItemStack> items = new ArrayList<ItemStack>();
Item bitem = Item.getItemFromBlock(block);
if (bitem == Items.AIR)
return ItemStack.EMPTY;
ItemStack itemstack = new ItemStack(bitem, 1, block.getMetaFromState(blockstate));
if (!itemstack.isEmpty())
items.add(itemstack);
ForgeEventFactory.fireBlockHarvesting(items, world, pos, blockstate, 0, 1.0f, true, fakePlayer);
for (int i = 0; i < items.size(); i++) if (i != 0) {
EntityItem ei = new EntityItem(world, pos.getX() + .5, pos.getY() + .5, pos.getZ() + .5, items.get(i).copy());
this.world.spawnEntity(ei);
}
world.playEvent(2001, pos, Block.getStateId(blockstate));
if (items.size() > 0)
return items.get(0);
} else {
block.harvestBlock(world, fakePlayer, pos, blockstate, world.getTileEntity(pos), ItemStack.EMPTY);
world.playEvent(2001, pos, Block.getStateId(blockstate));
}
}
}
return ItemStack.EMPTY;
}
use of net.minecraftforge.common.util.FakePlayer in project Overloaded by CJ-MC-Mods.
the class TileItemManipulator method getPlayer.
private FakePlayer getPlayer() {
if (this.player == null || this.player.get() == null) {
FakePlayer fakePlayer = FakePlayerFactory.get((ServerWorld) this.getLevel(), FAKEPLAYER);
this.player = new WeakReference<>(fakePlayer);
fakePlayer.moveTo(this.getBlockPos().getX(), this.getBlockPos().getY(), this.getBlockPos().getZ(), 0f, 0f);
fakePlayer.inventory.clearContent();
}
return this.player.get();
}
use of net.minecraftforge.common.util.FakePlayer in project Overloaded by CJ-MC-Mods.
the class TileItemManipulator method tick.
@Override
public void tick() {
if (this.getLevel().isClientSide) {
return;
}
ItemStack currentItem = itemStack.getStackInSlot(0);
if (currentItem.isEmpty())
return;
FakePlayer player = getPlayer();
BlockPos.Mutable blockPos = this.getBlockPos().mutable();
// for (int i = 0; i < player.interactionManager.getBlockReachDistance(); i++) {
// if (!this.getWorld().isAirBlock(blockPos.move(this.facing))) {
// EnumActionResult result = currentItem.getItem().onItemUse(player, getWorld(),
// blockPos, Hand.MAIN_HAND, facing.getOpposite(), 0.5f, 0.5f, 0.5f);
// System.out.println(result);
// currentItem.onItemUse(player,this.getWorld(),blockPos,Hand.MAIN_HAND,
// this.facing.getOpposite(),0.5f,0.5f,0.5f);
//
// player.interactionManager.processRightClickBlock(player,this.getWorld(),currentItem,Hand.MAIN_HAND,
// blockPos,this.facing.getOpposite(),0.5f,0.5f,0.5f);
// break;
// }
// }
}
use of net.minecraftforge.common.util.FakePlayer in project RecurrentComplex by Ivorforce.
the class IvGuiRegistry method openGui.
// From FMLNetworkHandler.openGui
public void openGui(EntityPlayer entityPlayer, String modid, int modGuiId, ByteBuf data) {
IvGuiHandler handler = handlers.get(modid);
if (handler == null)
return;
if (entityPlayer instanceof EntityPlayerMP && !(entityPlayer instanceof FakePlayer)) {
EntityPlayerMP entityPlayerMP = (EntityPlayerMP) entityPlayer;
ByteBuf dataCopy = data.copy();
Container remoteGuiContainer = handler.getServerGuiElement(modGuiId, entityPlayerMP, data);
entityPlayerMP.getNextWindowId();
entityPlayerMP.closeContainer();
int windowId = entityPlayerMP.currentWindowId;
RecurrentComplex.network.sendTo(new PacketOpenGui(windowId, modid, modGuiId, dataCopy), entityPlayerMP);
if (// If null, it's client only
remoteGuiContainer != null) {
entityPlayerMP.openContainer = remoteGuiContainer;
entityPlayerMP.openContainer.windowId = windowId;
entityPlayerMP.openContainer.addListener(entityPlayerMP);
}
} else if (entityPlayer instanceof FakePlayer) {
// NO OP - I won't even log a message!
} else if (FMLCommonHandler.instance().getSide().equals(Side.CLIENT)) {
RecurrentComplex.network.sendToServer(new PacketOpenGui(0, modid, modGuiId, data));
} else {
FMLLog.fine("Invalid attempt to open a local GUI on a dedicated server. This is likely a bug. GUI ID: %s,%d", modid, modGuiId);
}
}
use of net.minecraftforge.common.util.FakePlayer in project GregTech by GregTechCE.
the class GregFakePlayer method get.
public static FakePlayer get(WorldServer world) {
FakePlayer ret = GREGTECH_PLAYER != null ? GREGTECH_PLAYER.get() : null;
if (ret == null) {
ret = FakePlayerFactory.get(world, GREGTECH);
GREGTECH_PLAYER = new WeakReference<>(ret);
}
return ret;
}
Aggregations