use of cpw.mods.fml.common.eventhandler.SubscribeEvent in project BetterStorage by copygirl.
the class ChristmasEventHandler method onPlayerLogin.
@SubscribeEvent
public void onPlayerLogin(PlayerLoggedInEvent event) {
List<ItemStack> items = getItemsForYear(getYear(), event.player);
BetterChristmasProperties properties = EntityUtils.getProperties(event.player, BetterChristmasProperties.class);
if (items == null)
return;
if (isBeforeChristmas() && (properties.year < getYear())) {
ItemStack book = new ItemStack(BetterStorageItems.presentBook);
StackUtils.set(book, getYear(), "year");
StackUtils.set(book, event.player.getUniqueID().toString(), "uuid");
StackUtils.set(book, event.player.getCommandSenderName(), "name");
event.player.inventory.addItemStackToInventory(book);
properties.year = getYear();
properties.gotPresent = false;
}
if (isPresentTime() && !properties.gotPresent) {
IInventory inv = event.player.inventory;
for (int i = 0; i < inv.getSizeInventory(); i++) {
ItemStack stack = inv.getStackInSlot(i);
if ((stack != null) && (stack.getItem() == BetterStorageItems.presentBook) && (StackUtils.get(stack, 9001, "year") == getYear()) && event.player.getUniqueID().toString().equals(StackUtils.get(stack, null, "uuid"))) {
ItemStack present = new ItemStack(BetterStorageTiles.present);
present.setStackDisplayName("Christmas Present " + getYear());
StackUtils.set(present, event.player.getCommandSenderName(), TileEntityPresent.TAG_NAMETAG);
int color = DyeUtils.getDyeColor(new ItemStack(Items.dye, 1, 1));
StackUtils.set(present, color, "color");
StackUtils.set(present, (byte) 14, TileEntityPresent.TAG_COLOR_INNER);
StackUtils.set(present, (byte) 16, TileEntityPresent.TAG_COLOR_OUTER);
ItemStack[] contents = new ItemStack[ItemCardboardBox.getRows() * 9];
for (int j = 0; ((j < contents.length) && !items.isEmpty()); j++) if (RandomUtils.getBoolean((double) items.size() / (contents.length - j)))
contents[j] = items.remove(RandomUtils.getInt(items.size()));
StackUtils.setStackContents(present, contents);
if (event.player.getCommandSenderName().equalsIgnoreCase("xXxCJxXx")) {
StackUtils.set(present, (byte) 1, TileEntityPresent.TAG_SKOJANZA_MODE);
StackUtils.set(present, NbtUtils.createList("Just for you!", "skojanzaMode = true"), "display", "Lore");
}
inv.setInventorySlotContents(i, present);
properties.gotPresent = true;
break;
}
}
}
}
use of cpw.mods.fml.common.eventhandler.SubscribeEvent in project SimplyJetpacks by Tonius.
the class LivingTickHandler method onLivingTick.
@SubscribeEvent
public void onLivingTick(LivingUpdateEvent evt) {
if (!evt.entityLiving.worldObj.isRemote) {
ParticleType jetpackState = null;
ItemStack armor = evt.entityLiving.getEquipmentInSlot(3);
Jetpack jetpack = null;
if (armor != null && armor.getItem() instanceof ItemJetpack) {
jetpack = ((ItemJetpack) armor.getItem()).getPack(armor);
if (jetpack != null) {
jetpackState = jetpack.getDisplayParticleType(armor, (ItemJetpack) armor.getItem(), evt.entityLiving);
}
}
if (jetpackState != lastJetpackState.get(evt.entityLiving.getEntityId())) {
if (jetpackState == null) {
lastJetpackState.remove(evt.entityLiving.getEntityId());
} else {
lastJetpackState.put(evt.entityLiving.getEntityId(), jetpackState);
}
PacketHandler.instance.sendToAllAround(new MessageJetpackSync(evt.entityLiving.getEntityId(), jetpackState != null ? jetpackState.ordinal() : -1), new TargetPoint(evt.entityLiving.dimension, evt.entityLiving.posX, evt.entityLiving.posY, evt.entityLiving.posZ, 256));
} else if (jetpack != null && evt.entityLiving.worldObj.getTotalWorldTime() % 160L == 0) {
PacketHandler.instance.sendToAllAround(new MessageJetpackSync(evt.entityLiving.getEntityId(), jetpackState != null ? jetpackState.ordinal() : -1), new TargetPoint(evt.entityLiving.dimension, evt.entityLiving.posX, evt.entityLiving.posY, evt.entityLiving.posZ, 256));
}
if (evt.entityLiving.worldObj.getTotalWorldTime() % 200L == 0) {
Iterator<Integer> itr = lastJetpackState.keySet().iterator();
while (itr.hasNext()) {
int entityId = itr.next();
if (evt.entityLiving.worldObj.getEntityByID(entityId) == null) {
itr.remove();
}
}
}
}
}
use of cpw.mods.fml.common.eventhandler.SubscribeEvent in project LogisticsPipes by RS485.
the class LogisticsEventListener method onPlayerInteract.
@SubscribeEvent
public void onPlayerInteract(final PlayerInteractEvent event) {
if (MainProxy.isServer(event.entityPlayer.worldObj)) {
if (event.action == Action.LEFT_CLICK_BLOCK) {
final TileEntity tile = event.entityPlayer.worldObj.getTileEntity(event.x, event.y, event.z);
if (tile instanceof LogisticsTileGenericPipe) {
if (((LogisticsTileGenericPipe) tile).pipe instanceof CoreRoutedPipe) {
if (!((CoreRoutedPipe) ((LogisticsTileGenericPipe) tile).pipe).canBeDestroyedByPlayer(event.entityPlayer)) {
event.setCanceled(true);
event.entityPlayer.addChatComponentMessage(new ChatComponentTranslation("lp.chat.permissiondenied"));
((LogisticsTileGenericPipe) tile).scheduleNeighborChange();
event.entityPlayer.worldObj.markBlockForUpdate(tile.xCoord, tile.yCoord, tile.zCoord);
((CoreRoutedPipe) ((LogisticsTileGenericPipe) tile).pipe).delayTo = System.currentTimeMillis() + 200;
((CoreRoutedPipe) ((LogisticsTileGenericPipe) tile).pipe).repeatFor = 10;
} else {
((CoreRoutedPipe) ((LogisticsTileGenericPipe) tile).pipe).setDestroyByPlayer();
}
}
}
}
if (event.action == Action.RIGHT_CLICK_BLOCK) {
WorldCoordinatesWrapper worldCoordinates = new WorldCoordinatesWrapper(event.entityPlayer.worldObj, event.x, event.y, event.z);
TileEntity tileEntity = worldCoordinates.getTileEntity();
if (tileEntity instanceof TileEntityChest || SimpleServiceLocator.ironChestProxy.isIronChest(tileEntity)) {
//@formatter:off
List<WeakReference<ModuleQuickSort>> list = worldCoordinates.getAdjacentTileEntities().filter(adjacent -> adjacent.tileEntity instanceof LogisticsTileGenericPipe).filter(adjacent -> ((LogisticsTileGenericPipe) adjacent.tileEntity).pipe instanceof PipeLogisticsChassi).filter(adjacent -> ((PipeLogisticsChassi) ((LogisticsTileGenericPipe) adjacent.tileEntity).pipe).getPointedOrientation() == adjacent.direction.getOpposite()).map(adjacent -> (PipeLogisticsChassi) ((LogisticsTileGenericPipe) adjacent.tileEntity).pipe).flatMap(pipeLogisticsChassi -> Arrays.stream(pipeLogisticsChassi.getModules().getModules())).filter(logisticsModule -> logisticsModule instanceof ModuleQuickSort).map(logisticsModule -> new WeakReference<>((ModuleQuickSort) logisticsModule)).collect(Collectors.toList());
if (!list.isEmpty()) {
LogisticsEventListener.chestQuickSortConnection.put(event.entityPlayer, list);
}
}
}
}
}
use of cpw.mods.fml.common.eventhandler.SubscribeEvent in project LogisticsPipes by RS485.
the class LogisticsEventListener method onPlayerLogout.
@SubscribeEvent
public void onPlayerLogout(PlayerLoggedOutEvent event) {
SimpleServiceLocator.serverBufferHandler.clear(event.player);
PlayerIdentifier ident = PlayerIdentifier.get(event.player);
PlayerConfig config = LogisticsEventListener.playerConfigs.get(ident);
if (config != null) {
config.writeToFile();
}
LogisticsEventListener.playerConfigs.remove(ident);
}
use of cpw.mods.fml.common.eventhandler.SubscribeEvent in project SecurityCraft by Geforce132.
the class ForgeEventHandler method onBlockBroken.
@SubscribeEvent
public void onBlockBroken(BreakEvent event) {
if (!event.world.isRemote) {
if (event.world.getTileEntity(event.x, event.y, event.z) != null && event.world.getTileEntity(event.x, event.y, event.z) instanceof CustomizableSCTE) {
for (int i = 0; i < ((CustomizableSCTE) event.world.getTileEntity(event.x, event.y, event.z)).getNumberOfCustomizableOptions(); i++) {
if (((CustomizableSCTE) event.world.getTileEntity(event.x, event.y, event.z)).itemStacks[i] != null) {
EntityItem item = new EntityItem(event.world, (double) event.x, (double) event.y, (double) event.z, ((CustomizableSCTE) event.world.getTileEntity(event.x, event.y, event.z)).itemStacks[i]);
event.world.spawnEntityInWorld(item);
}
}
}
}
}
Aggregations