/** * This is the main event ticker. It only ticks when the player has an open container so we can rule out other ticks. * The player usually has an open container (the inventory) but we can simple check for that and return. * This also ticks once per player rather than once per World or once per MinecraftServer, so it provides an extra layer of convenience. */ @SubscribeEvent public void playerHasContainerOpen(PlayerOpenContainerEvent event){ UUID uuid = event.getEntityPlayer().getUniqueID(); // If the inventory is not a crafting inventory then clear stuff. if (!(event.getEntityPlayer().openContainer instanceof ContainerEnchantment)){ purgeUUID(uuid); return; } ContainerEnchantment container = (ContainerEnchantment)event.getEntityPlayer().openContainer; if (!tickTimes.containsKey(uuid)){ tickTimes.put(uuid, 0L); } // We set it to zero and immediately increment it so waiting a second // is guaranteed. This is simpler than just setting it to one. tickTimes.put(uuid, tickTimes.get(uuid) + 1L); // We have to check for OnCraftMatrixChanged manually. TableState state = new TableState(container); if (!prevTableStates.containsKey(uuid) || !prevTableStates.get(uuid).equals(state)){ prevTableStates.put(uuid, state); tableUpdated(event.getEntityPlayer()); } // 20 ticks is one second. if (tickTimes.get(uuid) % 20L == 0L){ cycleHint(event.getEntityPlayer()); } }
@SubscribeEvent public void playerOpenContainerEvent(PlayerOpenContainerEvent event) { if (CoreClaim.claimManager.checkEventCancel(event.entityPlayer, (int) event.entity.posX, (int) event.entity.posZ)) { event.setCanceled(true); Utils.messageToPlayer(event.entityPlayer, EnumChatFormatting.RED + "Oh snap, you are not allowed to open this!"); } }
@SubscribeEvent public void containerOpen(PlayerOpenContainerEvent event) { //event.entityPlayer.openContainer if(canPlayerBypassInvChecks(event.entityPlayer)) if(event.entityPlayer.openContainer.windowId == 0) removePlayerFromInventoryBypass(event.entityPlayer); else event.setResult(Result.ALLOW); }
@SubscribeEvent public void onPlayerOpenContainer(PlayerOpenContainerEvent parEvent) { World world = parEvent.entity.worldObj; if ((int)world.getWorldTime() % TICK != 0) return; Container container = parEvent.entityPlayer.openContainer; for(int i = 0; i < container.inventorySlots.size(); ++i) { Slot slot = container.getSlot(i); ItemStack itemstack = slot.getStack(); if (itemstack != null && isRotItem(itemstack.getItem())) { int time = getTime(world); NBTTagCompound tagcompound = itemstack.getTagCompound(); if (tagcompound == null) itemstack.setTagCompound(tagcompound = new NBTTagCompound()); if (!tagcompound.hasKey("rottime")) { tagcompound.setInteger("rottime", time); } else { int newTime = getTotalRotTime(world, itemstack); if (newTime < 0) { tagcompound.setInteger("rottime", newTime = newTime - getSavedRotTime(world, itemstack)); } } tagcompound.setInteger("worldtime", time); } } }
public static boolean canInteractWith(EntityPlayer player, Container openContainer) { PlayerOpenContainerEvent event = new PlayerOpenContainerEvent(player, openContainer); MinecraftForge.EVENT_BUS.post(event); return event.getResult() == Event.Result.DEFAULT ? event.canInteractWith : event.getResult() == Event.Result.ALLOW ? true : false; }
@SubscribeEvent public void open (PlayerOpenContainerEvent event) { }