use of net.minecraftforge.common.util.FakePlayer in project EnderIO by SleepyTrousers.
the class TileFarmStation method executeBonemeal.
private void executeBonemeal(@Nonnull IFarmer farmer, @Nonnull BlockPos farmingPos, @Nonnull Block block) {
if (hasBonemeal() && bonemealCooldown-- <= 0 && random.nextFloat() <= FarmConfig.farmBonemealChance.get() && farmer.checkAction(FarmingAction.FERTILIZE, FarmingTool.HAND)) {
final ItemStack fertStack = getStackInSlot(minFirtSlot);
IFertilizer fertilizer = Fertilizer.getInstance(fertStack);
boolean doApply;
if (fertilizer.applyOnPlant() && fertilizer.applyOnAir()) {
doApply = !isOpen(farmingPos, block) || world.isAirBlock(farmingPos);
} else if (fertilizer.applyOnPlant()) {
doApply = !isOpen(farmingPos, block);
} else if (fertilizer.applyOnAir()) {
doApply = world.isAirBlock(farmingPos);
} else {
doApply = true;
}
if (doApply) {
FakePlayer farmerJoe = farmer.startUsingItem(Prep.getEmpty());
final IFertilizerResult result = fertilizer.apply(fertStack, farmerJoe, world, farmingPos);
if (result.wasApplied()) {
setInventorySlotContents(minFirtSlot, result.getStack());
PacketHandler.sendToAllAround(new PacketFarmAction(farmingPos), this);
bonemealCooldown = FarmConfig.farmBonemealDelaySuccess.get();
farmer.registerAction(FarmingAction.FERTILIZE, FarmingTool.HAND);
} else {
usePower(FarmConfig.farmBonemealEnergyUseFail.get());
bonemealCooldown = FarmConfig.farmBonemealDelayFail.get();
}
farmer.handleExtraItems(farmer.endUsingItem(false), farmingPos);
}
}
}
use of net.minecraftforge.common.util.FakePlayer in project EnderIO by SleepyTrousers.
the class ItemDarkSteelSword method onEntityDrop.
// Set priority to lowest in the hope any other mod adding head drops will have already added them
// by the time this is called to prevent multiple head drops
@SubscribeEvent(priority = EventPriority.LOWEST)
public void onEntityDrop(LivingDropsEvent evt) {
final Entity entity = evt.getSource().getTrueSource();
final EntityLivingBase entityLiving = evt.getEntityLiving();
if (!(entity instanceof EntityPlayer) || entityLiving == null) {
return;
}
EntityPlayer player = (EntityPlayer) entity;
// Handle TiC weapons with beheading differently
if (handleBeheadingWeapons(player, evt)) {
return;
}
double skullDropChance = getSkullDropChance(player, evt);
if (player instanceof FakePlayer) {
skullDropChance *= Config.fakePlayerSkullChance;
}
if (Math.random() <= skullDropChance) {
dropSkull(evt, player);
}
// Special handling for ender pearl drops
if (isEquipped(player)) {
ResourceLocation name = EntityList.getKey(entityLiving);
if (entityLiving instanceof EntityEnderman || ENDERZOO_ENDERMINY.equals(name)) {
int numPearls = 0;
double chance = Config.darkSteelSwordEnderPearlDropChance;
while (chance >= 1) {
numPearls++;
chance--;
}
if (chance > 0 && Math.random() <= chance) {
numPearls++;
}
for (int i = 0; i < evt.getLootingLevel(); i++) {
chance = Config.darkSteelSwordEnderPearlDropChancePerLooting;
while (chance >= 1) {
numPearls++;
chance--;
}
if (chance > 0 && Math.random() <= chance) {
numPearls++;
}
}
int existing = 0;
for (EntityItem stack : evt.getDrops()) {
if (stack.getItem().getItem() == Items.ENDER_PEARL) {
existing += stack.getItem().getCount();
}
}
int toDrop = numPearls - existing;
if (toDrop > 0) {
evt.getDrops().add(Util.createDrop(player.world, new ItemStack(Items.ENDER_PEARL, toDrop, 0), entityLiving.posX, entityLiving.posY, entityLiving.posZ, false));
}
}
}
}
use of net.minecraftforge.common.util.FakePlayer in project EnderIO by SleepyTrousers.
the class HandlerSoulBound method onPlayerDeath.
/*
* This is called the moment the player dies and drops his stuff.
*
* We go early, so we can get our items before other mods put them into some grave. Also remove them from the list so they won't get duped. If the inventory
* overflows, e.g. because everything there and the armor is soulbound, let the remainder be dropped/graved.
*/
@SubscribeEvent(priority = EventPriority.HIGHEST)
public static void onPlayerDeath(PlayerDropsEvent evt) {
if (evt.getEntityPlayer() == null || evt.getEntityPlayer() instanceof FakePlayer || evt.isCanceled()) {
return;
}
if (evt.getEntityPlayer().world.getGameRules().getBoolean("keepInventory")) {
return;
}
Log.debug("Running onPlayerDeathEarly logic for " + evt.getEntityPlayer().getName());
ListIterator<EntityItem> iter = evt.getDrops().listIterator();
while (iter.hasNext()) {
EntityItem ei = iter.next();
ItemStack item = ei.getItem();
if (isSoulBound(item)) {
if (addToPlayerInventory(evt.getEntityPlayer(), item)) {
iter.remove();
}
}
}
// Note: Baubles will also add its items to evt.drops, but later. We cannot
// wait for that because gravestone mods also listen to this event. So we have
// to fetch Baubles items ourselves here.
// For the same reason we cannot put the items into Baubles slots.
IInventory baubles = BaublesUtil.instance().getBaubles(evt.getEntityPlayer());
if (baubles != null) {
for (int i = 0; i < baubles.getSizeInventory(); i++) {
ItemStack item = baubles.getStackInSlot(i);
if (isSoulBound(item)) {
if (addToPlayerInventory(evt.getEntityPlayer(), item)) {
baubles.setInventorySlotContents(i, Prep.getEmpty());
}
}
}
}
// stuff into the normal inventory to not have to keep a separate list.
if (evt.getEntityPlayer() instanceof EntityPlayerMP) {
IInventory galacticraft = GalacticraftUtil.getGCInventoryForPlayer((EntityPlayerMP) evt.getEntityPlayer());
if (galacticraft != null) {
for (int i = 0; i < galacticraft.getSizeInventory(); i++) {
ItemStack item = galacticraft.getStackInSlot(i);
if (isSoulBound(item)) {
if (addToPlayerInventory(evt.getEntityPlayer(), item)) {
galacticraft.setInventorySlotContents(i, Prep.getEmpty());
}
}
}
}
}
}
use of net.minecraftforge.common.util.FakePlayer in project ForestryMC by ForestryMC.
the class BreedingTracker method syncToPlayer.
private void syncToPlayer(Collection<String> discoveredSpecies, Collection<String> discoveredMutations, Collection<String> researchedMutations) {
if (world != null && username != null && username.getName() != null) {
EntityPlayer player = world.getPlayerEntityByName(username.getName());
if (player instanceof EntityPlayerMP && !(player instanceof FakePlayer)) {
IBreedingTracker breedingTracker = getBreedingTracker(player);
String modeName = breedingTracker.getModeName();
setModeName(modeName);
NBTTagCompound nbtTagCompound = new NBTTagCompound();
writeToNBT(nbtTagCompound, discoveredSpecies, discoveredMutations, researchedMutations);
PacketGenomeTrackerSync packet = new PacketGenomeTrackerSync(nbtTagCompound);
NetworkUtil.sendToPlayer(packet, player);
for (String species : discoveredSpecies) {
SpeciesDiscoveredTrigger.INSTANCE.trigger((EntityPlayerMP) player, AlleleManager.alleleRegistry.getAllele(species));
}
}
}
}
use of net.minecraftforge.common.util.FakePlayer in project ForestryMC by ForestryMC.
the class NetworkUtil method sendToPlayer.
public static void sendToPlayer(IForestryPacketClient packet, EntityPlayer entityplayer) {
if (!(entityplayer instanceof EntityPlayerMP) || entityplayer instanceof FakePlayer) {
return;
}
EntityPlayerMP player = (EntityPlayerMP) entityplayer;
Forestry.getPacketHandler().sendPacket(packet.getPacket(), player);
}
Aggregations