use of net.minecraftforge.common.util.FakePlayer in project Overloaded by CJ-MC-Mods.
the class TileItemManipulator method update.
@Override
public void update() {
ItemStack currentItem = itemStack.getStackInSlot(0);
if (currentItem.isEmpty())
return;
FakePlayer player = getPlayer();
BlockPos.MutableBlockPos blockPos = new BlockPos.MutableBlockPos(this.getPos());
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, EnumHand.MAIN_HAND, facing.getOpposite(), 0.5f, 0.5f, 0.5f);
// blockPos,this.facing.getOpposite(),0.5f,0.5f,0.5f);
break;
}
}
}
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((WorldServer) this.getWorld(), FAKEPLAYER);
this.player = new WeakReference<>(fakePlayer);
fakePlayer.setLocationAndAngles(this.getPos().getX(), this.getPos().getY(), this.getPos().getZ(), 0f, 0f);
fakePlayer.inventory.clear();
}
return this.player.get();
}
use of net.minecraftforge.common.util.FakePlayer in project Pearcel-Mod by MiningMark48.
the class EventOnPlayerAttack method onPlayerAttack.
@SubscribeEvent
public void onPlayerAttack(LivingHurtEvent e) {
if (e.getEntityLiving() instanceof FakePlayer) {
return;
}
if (e.getSource().getEntity() instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) e.getSource().getEntity();
if (!player.isCreative()) {
if (e.getEntityLiving().getHealth() - e.getAmount() <= 0) {
if (player.getHeldItemMainhand() != null && player.getHeldItemMainhand().getItem() == ModItems.pearcel_blood_dagger) {
ItemStack stack = player.getHeldItemMainhand();
if (!stack.hasTagCompound()) {
stack.setTagCompound(new NBTTagCompound());
stack.getTagCompound().setInteger("level", 1);
} else {
if (stack.getTagCompound().getInteger("level") <= 8) {
stack.getTagCompound().setInteger("level", stack.getTagCompound().getInteger("level") + 1);
} else {
stack.getTagCompound().setInteger("level", 0);
EntityItem item = new EntityItem(player.getEntityWorld(), player.posX, player.posY + 0.5, player.posZ);
item.setEntityItemStack(new ItemStack(ModItems.blood_drop));
Random rand = new Random();
int num = rand.nextInt(2) + 1;
for (int i = 0; i <= num; i++) {
player.getEntityWorld().spawnEntity(item);
}
}
}
}
}
}
}
}
Aggregations