use of net.minecraftforge.common.util.FakePlayer in project MinecraftForge by MinecraftForge.
the class FMLNetworkHandler method openGui.
public static void openGui(EntityPlayer entityPlayer, Object mod, int modGuiId, World world, int x, int y, int z) {
ModContainer mc = FMLCommonHandler.instance().findContainerFor(mod);
if (entityPlayer instanceof EntityPlayerMP && !(entityPlayer instanceof FakePlayer)) {
EntityPlayerMP entityPlayerMP = (EntityPlayerMP) entityPlayer;
Container remoteGuiContainer = NetworkRegistry.INSTANCE.getRemoteGuiContainer(mc, entityPlayerMP, modGuiId, world, x, y, z);
if (remoteGuiContainer != null) {
entityPlayerMP.getNextWindowId();
entityPlayerMP.closeContainer();
int windowId = entityPlayerMP.currentWindowId;
FMLMessage.OpenGui openGui = new FMLMessage.OpenGui(windowId, mc.getModId(), modGuiId, x, y, z);
EmbeddedChannel embeddedChannel = channelPair.get(Side.SERVER);
embeddedChannel.attr(FMLOutboundHandler.FML_MESSAGETARGET).set(OutboundTarget.PLAYER);
embeddedChannel.attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(entityPlayerMP);
embeddedChannel.writeOutbound(openGui);
entityPlayerMP.openContainer = remoteGuiContainer;
entityPlayerMP.openContainer.windowId = windowId;
entityPlayerMP.openContainer.addListener(entityPlayerMP);
net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.player.PlayerContainerEvent.Open(entityPlayer, entityPlayer.openContainer));
}
} else if (entityPlayer instanceof FakePlayer) {
// NO OP - I won't even log a message!
} else if (FMLCommonHandler.instance().getSide().equals(Side.CLIENT)) {
Object guiContainer = NetworkRegistry.INSTANCE.getLocalGuiContainer(mc, entityPlayer, modGuiId, world, x, y, z);
FMLCommonHandler.instance().showGuiScreen(guiContainer);
} else {
FMLLog.fine("Invalid attempt to open a local GUI on a dedicated server. This is likely a bug. GUI ID: %s,%d", mc.getModId(), modGuiId);
}
}
use of net.minecraftforge.common.util.FakePlayer in project NetherEx by LogicTechCorp.
the class EventHandler method onBlockBreak.
@SubscribeEvent
public static void onBlockBreak(BlockEvent.BreakEvent event) {
World world = event.getWorld();
BlockPos pos = event.getPos();
IBlockState state = event.getState();
if (!(event.getPlayer() instanceof FakePlayer)) {
EntityPlayer player = event.getPlayer();
if (state.getBlock() == Blocks.MAGMA) {
if (ConfigHandler.block.magma.turnIntoLava) {
if (EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, player.getHeldItemMainhand()) == 0) {
world.setBlockState(pos, Blocks.LAVA.getDefaultState(), 3);
player.getHeldItemMainhand().damageItem(1, player);
event.setCanceled(true);
}
}
}
if (player.dimension == -1) {
boolean canSpawn = Arrays.asList(ConfigHandler.entity.nethermite.whitelist).contains(state.getBlock().getRegistryName().toString());
if (canSpawn && world.rand.nextInt(ConfigHandler.entity.nethermite.chanceOfSpawning) == 0) {
EntityNethermite nethermite = new EntityNethermite(world);
nethermite.setPosition((double) pos.getX() + 0.5D, (double) pos.getY(), (double) pos.getZ() + 0.5D);
world.spawnEntity(nethermite);
}
}
}
}
use of net.minecraftforge.common.util.FakePlayer in project ForestryMC by ForestryMC.
the class BreedingTracker method synchToPlayer.
@Override
public void synchToPlayer(EntityPlayer player) {
if (player instanceof EntityPlayerMP && !(player instanceof FakePlayer)) {
IBreedingTracker breedingTracker = getBreedingTracker(player);
String modeName = breedingTracker.getModeName();
setModeName(modeName);
NBTTagCompound nbttagcompound = new NBTTagCompound();
encodeToNBT(nbttagcompound);
PacketGenomeTrackerSync packet = new PacketGenomeTrackerSync(nbttagcompound);
NetworkUtil.sendToPlayer(packet, player);
}
}
use of net.minecraftforge.common.util.FakePlayer in project EnderIO by SleepyTrousers.
the class ItemDarkSteelSword method handleBeheadingWeapons.
private boolean handleBeheadingWeapons(EntityPlayer player, LivingDropsEvent evt) {
if (player == null) {
return false;
}
ItemStack equipped = player.getHeldItemMainhand();
NBTTagCompound tagCompound = equipped.getTagCompound();
if (tagCompound == null) {
return false;
}
int beheading = TicUtil.getModifier(tagCompound, TicUtil.BEHEADING);
int cleaver = TicUtil.getModifier(tagCompound, TicUtil.CLEAVER);
if (beheading == 0 && cleaver == 0) {
// Use default behavior if it is not a cleaver and doesn't have beheading
return false;
}
if (!(evt.getEntityLiving() instanceof EntityEnderman)) {
// We wont modify head drops at all
return true;
}
float chance = Math.max(Config.vanillaSwordSkullChance, cleaver * Config.ticCleaverSkullDropChance) + (Config.ticBeheadingSkullModifier * beheading);
if (player instanceof FakePlayer) {
chance *= Config.fakePlayerSkullChance;
}
while (chance >= 1) {
dropSkull(evt, player);
chance--;
}
if (chance > 0 && Math.random() <= chance) {
dropSkull(evt, player);
}
return true;
}
use of net.minecraftforge.common.util.FakePlayer in project EnderIO by SleepyTrousers.
the class HandlerSoulBound method onPlayerDeathLate.
/*
* Do a second (late) pass. If any mod has added items to the list in the meantime, this gives us a chance to save them, too. If some gravestone mod has
* removed drops, we'll get nothing here.
*/
@SubscribeEvent(priority = EventPriority.LOWEST)
public static void onPlayerDeathLate(PlayerDropsEvent evt) {
if (evt.getEntityPlayer() == null || evt.getEntityPlayer() instanceof FakePlayer || evt.isCanceled()) {
return;
}
if (evt.getEntityPlayer().world.getGameRules().getBoolean("keepInventory")) {
return;
}
Log.debug("Running onPlayerDeathLate 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();
}
}
}
}
Aggregations