use of net.minecraftforge.common.util.FakePlayer in project BloodMagic by WayofTime.
the class ItemDaggerOfSacrifice method hitEntity.
@Override
public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker) {
if (attacker instanceof FakePlayer)
return false;
if (target == null || attacker == null || attacker.getEntityWorld().isRemote || (attacker instanceof EntityPlayer && !(attacker instanceof EntityPlayerMP)))
return false;
if (!target.isNonBoss())
return false;
if (target instanceof EntityPlayer)
return false;
if (target.isChild() && !(target instanceof IMob))
return false;
if (target.isDead || target.getHealth() < 0.5F)
return false;
EntityEntry entityEntry = EntityRegistry.getEntry(target.getClass());
if (entityEntry == null)
return false;
int lifeEssenceRatio = BloodMagicAPI.INSTANCE.getValueManager().getSacrificial().getOrDefault(entityEntry.getRegistryName(), 25);
if (lifeEssenceRatio <= 0)
return false;
int lifeEssence = (int) (lifeEssenceRatio * target.getHealth());
if (target instanceof EntityAnimal) {
lifeEssence = (int) (lifeEssence * (1 + PurificationHelper.getCurrentPurity((EntityAnimal) target)));
}
if (target.isChild()) {
lifeEssence *= 0.5F;
}
if (PlayerSacrificeHelper.findAndFillAltar(attacker.getEntityWorld(), target, lifeEssence, true)) {
target.getEntityWorld().playSound(null, target.posX, target.posY, target.posZ, SoundEvents.BLOCK_FIRE_EXTINGUISH, SoundCategory.BLOCKS, 0.5F, 2.6F + (target.getEntityWorld().rand.nextFloat() - target.getEntityWorld().rand.nextFloat()) * 0.8F);
target.setHealth(-1);
target.onDeath(DamageSourceBloodMagic.INSTANCE);
}
return false;
}
use of net.minecraftforge.common.util.FakePlayer in project GregTech by GregTechCE.
the class UIFactory method openUI.
public final void openUI(E holder, EntityPlayerMP player) {
if (player instanceof FakePlayer) {
return;
}
ModularUI uiTemplate = createUITemplate(holder, player);
uiTemplate.initWidgets();
player.getNextWindowId();
player.closeContainer();
int currentWindowId = player.currentWindowId;
PacketBuffer serializedHolder = new PacketBuffer(Unpooled.buffer());
writeHolderToSyncData(serializedHolder, holder);
int uiFactoryId = FACTORY_REGISTRY.getIDForObject(this);
ModularUIContainer container = new ModularUIContainer(uiTemplate);
container.windowId = currentWindowId;
// accumulate all initial updates of widgets in open packet
container.accumulateWidgetUpdateData = true;
uiTemplate.guiWidgets.values().forEach(Widget::detectAndSendChanges);
container.accumulateWidgetUpdateData = false;
ArrayList<PacketUIWidgetUpdate> updateData = new ArrayList<>(container.accumulatedUpdates);
container.accumulatedUpdates.clear();
PacketUIOpen packet = new PacketUIOpen(uiFactoryId, serializedHolder, currentWindowId, updateData);
NetworkHandler.channel.sendTo(NetworkHandler.packet2proxy(packet), player);
container.addListener(player);
player.openContainer = container;
// and fire forge event only in the end
MinecraftForge.EVENT_BUS.post(new PlayerContainerEvent.Open(player, container));
}
use of net.minecraftforge.common.util.FakePlayer in project GregTech by GregTechCE.
the class ToolUtility method applyTimberAxe.
public static boolean applyTimberAxe(ItemStack itemStack, World world, BlockPos blockPos, EntityPlayer player) {
if (player instanceof FakePlayer) {
return false;
}
IBlockState blockState = world.getBlockState(blockPos);
if (TreeChopTask.isLogBlock(blockState) == 1) {
if (!world.isRemote) {
EntityPlayerMP playerMP = (EntityPlayerMP) player;
TreeChopTask treeChopTask = new TreeChopTask(blockPos, world, playerMP, itemStack);
TaskScheduler.scheduleTask(world, treeChopTask);
}
return true;
}
return false;
}
use of net.minecraftforge.common.util.FakePlayer in project GregTech by GregTechCE.
the class ToolUtility method applyHammerDrops.
public static void applyHammerDrops(Random random, IBlockState blockState, List<ItemStack> drops, int fortuneLevel, EntityPlayer player) {
ItemStack itemStack = new ItemStack(blockState.getBlock(), 1, blockState.getBlock().getMetaFromState(blockState));
Recipe recipe = RecipeMaps.FORGE_HAMMER_RECIPES.findRecipe(Long.MAX_VALUE, Collections.singletonList(itemStack), Collections.emptyList(), 0);
if (recipe != null && !recipe.getOutputs().isEmpty()) {
drops.clear();
for (ItemStack outputStack : recipe.getResultItemOutputs(Integer.MAX_VALUE, random, 0)) {
outputStack = outputStack.copy();
if (!(player instanceof FakePlayer) && OreDictUnifier.getPrefix(outputStack) == OrePrefix.crushed) {
int growAmount = Math.round(outputStack.getCount() * random.nextFloat());
if (fortuneLevel > 0) {
int i = Math.max(0, random.nextInt(fortuneLevel + 2) - 1);
growAmount += outputStack.getCount() * i;
}
outputStack.grow(growAmount);
}
drops.add(outputStack);
}
}
}
use of net.minecraftforge.common.util.FakePlayer in project GregTech by GregTechCE.
the class ToolJackHammer method onBlockDestroyed.
@Override
public void onBlockDestroyed(ItemStack stack, World world, IBlockState state, BlockPos pos, EntityLivingBase entity) {
if (entity instanceof EntityPlayer && !(entity instanceof FakePlayer)) {
EntityPlayer entityPlayer = (EntityPlayer) entity;
EnumFacing sideHit = ToolUtility.getSideHit(world, pos, entityPlayer);
int damagePerBlockBreak = getToolDamagePerBlockBreak(stack);
JackHammerMode jackHammerMode = MODE_SWITCH_BEHAVIOR.getModeFromItemStack(stack);
EnumFacing horizontalFacing = entity.getHorizontalFacing();
int xSizeExtend = (jackHammerMode.getHorizontalSize() - 1) / 2;
int ySizeExtend = (jackHammerMode.getVerticalSize() - 1) / 2;
for (int x = -xSizeExtend; x <= xSizeExtend; x++) {
for (int y = -ySizeExtend; y <= ySizeExtend; y++) {
// do not check center block - it's handled now
if (x == 0 && y == 0)
continue;
BlockPos offsetPos = rotate(pos, x, y, sideHit, horizontalFacing);
IBlockState blockState = world.getBlockState(offsetPos);
if (world.isBlockModifiable(entityPlayer, offsetPos) && blockState.getBlock().canHarvestBlock(world, offsetPos, entityPlayer) && blockState.getPlayerRelativeBlockHardness(entityPlayer, world, offsetPos) > 0.0f && stack.canHarvestBlock(blockState)) {
GTUtility.harvestBlock(world, offsetPos, entityPlayer);
((ToolMetaItem) stack.getItem()).damageItem(stack, damagePerBlockBreak, false);
}
}
}
}
}
Aggregations