net.minecraftforge.event.entity.player.PlayerEvent Java Examples

The following examples show how to use net.minecraftforge.event.entity.player.PlayerEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ServerEventHandler.java    From Et-Futurum with The Unlicense 6 votes vote down vote up
@SubscribeEvent
public void onPlayerLoadFromFileEvent(PlayerEvent.LoadFromFile event) {
	if (!EtFuturum.enableEnchants)
		return;
	try {
		File file = event.getPlayerFile(Reference.MOD_ID);
		if (!file.exists()) {
			file.createNewFile();
			return;
		}

		BufferedReader br = new BufferedReader(new FileReader(file));
		String line = br.readLine();
		if (line != null) {
			int seed = Integer.parseInt(line);
			ContainerEnchantment.seeds.put(event.playerUUID, seed);
			br.close();
		}
	} catch (Exception e) {
	}
}
 
Example #2
Source File: ServerEventHandler.java    From Et-Futurum with The Unlicense 6 votes vote down vote up
@SubscribeEvent
public void onPlayerSaveFromFileEvent(PlayerEvent.SaveToFile event) {
	if (!EtFuturum.enableEnchants)
		return;
	try {
		File file = event.getPlayerFile(Reference.MOD_ID);
		if (!file.exists()) {
			file.createNewFile();
			return;
		}

		Integer seed = ContainerEnchantment.seeds.get(event.playerUUID);
		if (seed != null) {
			BufferedWriter bw = new BufferedWriter(new FileWriter(file));
			bw.write(seed.toString());
			bw.close();
		}
	} catch (IOException e) {
	}
}
 
Example #3
Source File: CivilizationHandlers.java    From ToroQuest with GNU General Public License v3.0 6 votes vote down vote up
@SubscribeEvent
public void onDeath(PlayerEvent.Clone event) {
	if (event.getEntityPlayer().getEntityWorld().isRemote) {
		return;
	}

	PlayerCivilizationCapability newCap = PlayerCivilizationCapabilityImpl.get(event.getEntityPlayer());
	PlayerCivilizationCapability originalCap = PlayerCivilizationCapabilityImpl.get(event.getOriginal());

	if (originalCap == null) {
		return;
	}

	if (newCap == null) {
		throw new NullPointerException("missing player capability during clone");
	}

	// System.out.println("CLONE: " + originalCap.writeNBT());

	newCap.readNBT(originalCap.writeNBT());
}
 
Example #4
Source File: CivilizationHandlers.java    From ToroQuest with GNU General Public License v3.0 6 votes vote down vote up
@SubscribeEvent
public void onSave(PlayerEvent.SaveToFile event) {
	if (event.getEntityPlayer().getEntityWorld().isRemote) {
		return;
	}
	PlayerCivilizationCapability cap = PlayerCivilizationCapabilityImpl.get(event.getEntityPlayer());
	if (cap == null) {
		return;
	}

	NBTTagCompound civData = cap.writeNBT();

	// System.out.println("SAVE: " + civData);

	if (civData == null || civData.getTag("reputations") == null || ((NBTTagList) civData.getTag("reputations")).tagCount() < 1) {
		// System.out.println("******************Not writing empty ToroQuest
		// data for player " + event.getEntityPlayer().getName());
		return;
	}

	event.getEntityPlayer().getEntityData().setTag(ToroQuest.MODID + ".playerCivilization", civData);
}
 
Example #5
Source File: CivilizationHandlers.java    From ToroQuest with GNU General Public License v3.0 6 votes vote down vote up
@SubscribeEvent
public void onLoad(PlayerEvent.LoadFromFile event) {
	if (event.getEntityPlayer().getEntityWorld().isRemote) {
		return;
	}

	PlayerCivilizationCapability cap = PlayerCivilizationCapabilityImpl.get(event.getEntityPlayer());
	if (cap == null) {
		return;
	}

	NBTTagCompound c = event.getEntityPlayer().getEntityData().getCompoundTag(ToroQuest.MODID + ".playerCivilization");

	if (c == null) {
		// System.out.println("******************Missing civ data on load");
	} else {
		System.out.println("LOAD: " + c.toString());
	}

	cap.readNBT(c);
}
 
Example #6
Source File: CyberwareDataHandler.java    From Cyberware with MIT License 6 votes vote down vote up
@SubscribeEvent
public void playerDeathEvent(PlayerEvent.Clone event)
{
	EntityPlayer p = event.getEntityPlayer();
	EntityPlayer o = event.getOriginal();
	if (event.isWasDeath())
	{
		if (p.worldObj.getWorldInfo().getGameRulesInstance().getBoolean(KEEP_WARE_GAMERULE))
		{
			if (CyberwareAPI.hasCapability(o) && CyberwareAPI.hasCapability(o))
			{
				CyberwareAPI.getCapability(p).deserializeNBT(CyberwareAPI.getCapability(o).serializeNBT());
			}
		}
	}
	else
	{
		if (CyberwareAPI.hasCapability(o) && CyberwareAPI.hasCapability(o))
		{
			CyberwareAPI.getCapability(p).deserializeNBT(CyberwareAPI.getCapability(o).serializeNBT());
		}
	}
}
 
Example #7
Source File: CommonHandler.java    From GokiStats with MIT License 5 votes vote down vote up
@SubscribeEvent
public void playerBreakSpeed(PlayerEvent.BreakSpeed event) {
    ItemStack heldItem = event.getEntityPlayer().getHeldItemMainhand();
    EntityPlayer player = event.getEntityPlayer();

    float multiplier = 1.0F;

    if (Stats.MINING.isEffectiveOn(heldItem,
            event.getPos(),
            player.world)) {
        multiplier += Stats.MINING.getBonus(player);
    }
    if (Stats.DIGGING.isEffectiveOn(heldItem,
            event.getPos(),
            player.world)) {
        multiplier += Stats.DIGGING.getBonus(player);
    }
    if (Stats.CHOPPING.isEffectiveOn(heldItem,
            event.getPos(),
            player.world)) {
        multiplier += Stats.CHOPPING.getBonus(player);
    }
    if (Stats.TRIMMING.isEffectiveOn(heldItem,
            event.getPos(),
            player.world)) {
        multiplier += Stats.TRIMMING.getBonus(player);
    }

    event.setNewSpeed(event.getOriginalSpeed() * multiplier);
}
 
Example #8
Source File: SquashableMod.java    From CommunityMod with GNU Lesser General Public License v2.1 5 votes vote down vote up
@SubscribeEvent
public static void onEntityTrack(PlayerEvent.StartTracking event) {
    Entity target = event.getTarget();
    Squashable squashable = target.getCapability(squashableCap(), null);
    if (squashable == null) {
        return;
    }

    EnumFacing.Axis squashedAxis = squashable.getSquashedAxis();
    if (squashedAxis != null) {
        NETWORK.sendTo(new SquashEntityMessage(target, squashedAxis), (EntityPlayerMP) event.getEntityPlayer());
    }
}
 
Example #9
Source File: EventSoulBound.java    From Levels with GNU General Public License v2.0 5 votes vote down vote up
@SubscribeEvent
public void onPlayerClone(PlayerEvent.Clone event)
{
	if (event.isWasDeath())
	{
		EntityPlayer player = event.getEntityPlayer();
		player.inventory.copyInventory(event.getOriginal().inventory);
	}
}
 
Example #10
Source File: PlayerEventSensor.java    From Framez with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int emitRedstoneOnEvent(Event event, TileEntity sensor, int range, String textboxText){
    if(event instanceof PlayerEvent) {
        EntityPlayer player = ((PlayerEvent)event).entityPlayer;
        if(Math.abs(player.posX - sensor.xCoord + 0.5D) < range + 0.5D && Math.abs(player.posY - sensor.yCoord + 0.5D) < range + 0.5D && Math.abs(player.posZ - sensor.zCoord + 0.5D) < range + 0.5D) {
            return emitRedstoneOnEvent((PlayerEvent)event, sensor, range);
        }
    }
    return 0;
}
 
Example #11
Source File: EventsCommon.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onEntityUntrack(PlayerEvent.StopTracking event) {
    if (!event.getEntityPlayer().world.isRemote) {
        Entity ent = event.getTarget();
        if (ent instanceof PhysicsWrapperEntity) {
            ((PhysicsWrapperEntity) ent).getPhysicsObject()
                .onPlayerUntracking(event.getEntityPlayer());
        }
    }
}
 
Example #12
Source File: ItemBrainUpgrade.java    From Cyberware with MIT License 5 votes vote down vote up
@SubscribeEvent
public void handleClone(PlayerEvent.Clone event)
{
	if (event.isWasDeath())
	{
		EntityPlayer p = event.getOriginal();
		
		if (CyberwareAPI.isCyberwareInstalled(p, new ItemStack(this, 1, 0)) && !p.worldObj.getGameRules().getBoolean("keepInventory"))
		{
			/*float range = 5F;
			List<EntityXPOrb> orbs = p.worldObj.getEntitiesWithinAABB(EntityXPOrb.class, new AxisAlignedBB(p.posX - range, p.posY - range, p.posZ - range, p.posX + p.width + range, p.posY + p.height + range, p.posZ + p.width + range));
			for (EntityXPOrb orb : orbs)
			{
				orb.setDead();
			}*/

			if (!p.worldObj.isRemote)
			{
				ItemStack stack = new ItemStack(CyberwareContent.expCapsule);
				NBTTagCompound c = new NBTTagCompound();
				c.setInteger("xp", p.experienceTotal);
				stack.setTagCompound(c);
				EntityItem item = new EntityItem(p.worldObj, p.posX, p.posY, p.posZ, stack);
				p.worldObj.spawnEntityInWorld(item);
			}
		}
		else if (CyberwareAPI.isCyberwareInstalled(p, new ItemStack(this, 1, 2)) && !p.worldObj.getGameRules().getBoolean("keepInventory"))
		{
			event.getEntityPlayer().addExperience((int) (Math.min(100, p.experienceLevel * 7) * .9F));
		}
	}
}
 
Example #13
Source File: PlayerPropertyEvents.java    From YouTubeModdingTutorial with MIT License 5 votes vote down vote up
@SubscribeEvent
public void onPlayerCloned(PlayerEvent.Clone event) {
    if (event.isWasDeath()) {
        // We need to copyFrom the capabilities
        if (event.getOriginal().hasCapability(PlayerProperties.PLAYER_MANA, null)) {
            PlayerMana oldStore = event.getOriginal().getCapability(PlayerProperties.PLAYER_MANA, null);
            PlayerMana newStore = PlayerProperties.getPlayerMana(event.getEntityPlayer());
            newStore.copyFrom(oldStore);
        }
    }
}
 
Example #14
Source File: ProxyCommon.java    From WearableBackpacks with MIT License 5 votes vote down vote up
@SubscribeEvent
public void onPlayerClone(PlayerEvent.Clone event) {
	// This comes into play when the "keepInventory" gamerule is on.
	// In that case, onLivingDeath will keep the backpack information,
	// so we can transfer it to the new player entity.
	IBackpack originalBackpack = BackpackHelper.getBackpack(event.getOriginal());
	if (originalBackpack == null) return;

	EntityPlayer player = event.getEntityPlayer();
	IBackpack clonedBackpack = player.getCapability(IBackpack.CAPABILITY, null);
	clonedBackpack.setStack(originalBackpack.getStack());
	clonedBackpack.setData(originalBackpack.getData());
}
 
Example #15
Source File: PlayerEventSensor.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int emitRedstoneOnEvent(Event event, TileEntity sensor, int range, String textboxText){
    if(event instanceof PlayerEvent) {
        EntityPlayer player = ((PlayerEvent)event).entityPlayer;
        if(Math.abs(player.posX - sensor.xCoord + 0.5D) < range + 0.5D && Math.abs(player.posY - sensor.yCoord + 0.5D) < range + 0.5D && Math.abs(player.posZ - sensor.zCoord + 0.5D) < range + 0.5D) {
            return emitRedstoneOnEvent((PlayerEvent)event, sensor, range);
        }
    }
    return 0;
}
 
Example #16
Source File: PlayerAttackSensor.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int emitRedstoneOnEvent(PlayerEvent event, TileEntity sensor, int range){
    if(event instanceof AttackEntityEvent) {
        return 15;
    }
    return 0;
}
 
Example #17
Source File: PlayerItemPickupSensor.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int emitRedstoneOnEvent(PlayerEvent event, TileEntity sensor, int range){
    if(event instanceof EntityItemPickupEvent) {
        return 15;
    }
    return 0;
}
 
Example #18
Source File: ProxyCommon.java    From WearableBackpacks with MIT License 4 votes vote down vote up
@SubscribeEvent
public void onPlayerStartTracking(PlayerEvent.StartTracking event)
	{ sendBackpackStack(event.getTarget(), event.getEntityPlayer()); }
 
Example #19
Source File: TankSynchroniser.java    From EnderStorage with MIT License 4 votes vote down vote up
@SubscribeEvent
public void onPlayerChangedDimension(PlayerEvent.PlayerChangedDimensionEvent event) {
    playerItemTankStates.put(event.getPlayer().getUniqueID(), new PlayerItemTankCache((ServerPlayerEntity) event.getPlayer()));
}
 
Example #20
Source File: EnderStorageManager.java    From EnderStorage with MIT License 4 votes vote down vote up
@SubscribeEvent
public void onPlayerChangedDimension(PlayerEvent.PlayerChangedDimensionEvent event) {
    instance(false).sendClientInfo((ServerPlayerEntity) event.getPlayer());
}
 
Example #21
Source File: EnderStorageManager.java    From EnderStorage with MIT License 4 votes vote down vote up
@SubscribeEvent
public void onPlayerLogin(PlayerEvent.PlayerLoggedInEvent event) {
    instance(false).sendClientInfo((ServerPlayerEntity) event.getPlayer());
}
 
Example #22
Source File: TankSynchroniser.java    From EnderStorage with MIT License 4 votes vote down vote up
@SubscribeEvent
public void onPlayerLogout(PlayerEvent.PlayerLoggedOutEvent event) {
    if (playerItemTankStates != null) { //sometimes world unloads before players logout
        playerItemTankStates.remove(event.getPlayer().getUniqueID());
    }
}
 
Example #23
Source File: TankSynchroniser.java    From EnderStorage with MIT License 4 votes vote down vote up
@SubscribeEvent
public void onPlayerLogin(PlayerEvent.PlayerLoggedInEvent event) {
    playerItemTankStates.put(event.getPlayer().getUniqueID(), new PlayerItemTankCache((ServerPlayerEntity) event.getPlayer()));
}
 
Example #24
Source File: AnimatedMachineTileBase.java    From EmergingTechnology with MIT License 4 votes vote down vote up
@SubscribeEvent
public void onStartTracking(PlayerEvent.StartTracking event) {
    if (event.getEntityPlayer() instanceof EntityPlayerMP) {
        notifyPlayer((EntityPlayerMP) event.getEntityPlayer());
    }
}
 
Example #25
Source File: MixinEntityTrackerEntry.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Inject(method = "stopTracking", at = @At("TAIL"))
private void hookEventStopTracking(ServerPlayerEntity player, CallbackInfo callback) {
	MinecraftForge.EVENT_BUS.post(new PlayerEvent.StopTracking(player, entity));
}
 
Example #26
Source File: MixinEntityTrackerEntry.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Inject(method = "startTracking", at = @At("TAIL"))
private void hookEventStartTracking(ServerPlayerEntity player, CallbackInfo callback) {
	MinecraftForge.EVENT_BUS.post(new PlayerEvent.StartTracking(player, entity));
}
 
Example #27
Source File: MixinServerPlayerEntity.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Inject(method = "copyFrom", at = @At("TAIL"))
private void hookCopyFromForCloneEvent(ServerPlayerEntity oldPlayer, boolean alive, CallbackInfo info) {
	@SuppressWarnings("ConstantConditions")
	ServerPlayerEntity speThis = (ServerPlayerEntity) (Object) this;
	MinecraftForge.EVENT_BUS.post(new PlayerEvent.Clone(speThis, oldPlayer, !alive));
}
 
Example #28
Source File: EntityEvents.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static void onPlayerLoggedIn(ServerPlayerEntity playerEntity) {
	MinecraftForge.EVENT_BUS.post(new PlayerEvent.PlayerLoggedInEvent(playerEntity));
}
 
Example #29
Source File: PlayerEventSensor.java    From Framez with GNU General Public License v3.0 votes vote down vote up
public abstract int emitRedstoneOnEvent(PlayerEvent event, TileEntity sensor, int range); 
Example #30
Source File: PlayerEventSensor.java    From PneumaticCraft with GNU General Public License v3.0 votes vote down vote up
public abstract int emitRedstoneOnEvent(PlayerEvent event, TileEntity sensor, int range);