Java Code Examples for net.minecraftforge.fml.common.eventhandler.SubscribeEvent

The following are top voted examples for showing how to use net.minecraftforge.fml.common.eventhandler.SubscribeEvent. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: Melodium   File: ItemCompositionPaper.java   View source code 6 votes vote down vote up
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void handleHearingSounds(PlaySoundEvent event) {
	EntityPlayer p = Minecraft.getMinecraft().player;
	if (p != null)
	{
		Tuple<SoundType, Double> result = getTypeFromSound(event.getName(), event.getSound());
		if (p.getHeldItemMainhand().getItem() == this)
		{
			if (addSound(p.getHeldItemMainhand(), result.getFirst(), result.getSecond())){
				PacketHandler.INSTANCE.sendToServer(new MessageCompositionUpdate(p.getUniqueID(),p.getHeldItemMainhand().getTagCompound(),true));
			}
		} else if (p.getHeldItemOffhand().getItem() == this) {
			if (addSound(p.getHeldItemOffhand(), result.getFirst(), result.getSecond())){
				PacketHandler.INSTANCE.sendToServer(new MessageCompositionUpdate(p.getUniqueID(),p.getHeldItemOffhand().getTagCompound(),false));
			}
		}
	}
}
 
Example 2
Project: Loot-Slash-Conquer   File: GuiMana.java   View source code 6 votes vote down vote up
@SubscribeEvent
public void onRenderOverlayText(RenderGameOverlayEvent.Text event)
{
	ScaledResolution sr = event.getResolution();
	EntityPlayer player = Minecraft.getMinecraft().player;
	Stats statsCap = (Stats) player.getCapability(CapabilityPlayerStats.STATS, null);
	
	if (!player.capabilities.isCreativeMode && statsCap != null)
	{
		String mana = statsCap.getMana() + " / " + statsCap.getMaxMana();
		
		GL11.glPushMatrix();
		GL11.glScalef(0.5F, 0.5F, 0.5F);
		Minecraft.getMinecraft().fontRenderer.drawStringWithShadow(mana, (sr.getScaledWidth() / 2 + 37) * 2, (sr.getScaledHeight() - 37) * 2, 0xFFFFFF);
		GL11.glPopMatrix();
	}
}
 
Example 3
Project: Defier   File: CommonProxy.java   View source code 6 votes vote down vote up
@SubscribeEvent
public static void itemRegistry(RegistryEvent.Register<Item> e) {
	IForgeRegistry<Item> reg = e.getRegistry();
	registerItemBlock(reg, ModItems.compressor);
	registerItemBlock(reg, ModItems.defier);
	registerItemBlock(reg, ModItems.patternmolder);
	registerItemBlock(reg, ModItems.energyprovider);

	reg.register(new DefierItem("largemass"));
	reg.register(new DefierItem("defiercore"));
	reg.register(new DefierItem("defierstar"));
	reg.register(new EnergyStarItem());
	reg.register(new DefierItem("strongstar"));
	reg.register(new DefierItem("speedstar"));
	reg.register(new PatternItem());
}
 
Example 4
Project: Proyecto-DASI   File: ScreenHelper.java   View source code 6 votes vote down vote up
@SubscribeEvent
public void onRenderTick(TickEvent.RenderTickEvent ev)
{
    purgeExpiredFragments(null);
    if (Minecraft.getMinecraft().currentScreen != null && !(Minecraft.getMinecraft().currentScreen instanceof GuiMainMenu))
        return;

    int displayWidth = Minecraft.getMinecraft().displayWidth;
    int displayHeight = Minecraft.getMinecraft().displayHeight;
    ScaledResolution res = new ScaledResolution(Minecraft.getMinecraft(), displayWidth, displayHeight);
    int width = res.getScaledWidth();
    int height = res.getScaledHeight();
    float rx = (float) width / 1000f;
    float ry = (float) height / 1000f;

    synchronized(this.fragments)
    {
        for (TextCategory cat : TextCategory.values())
        {
            TextCategoryAttributes atts = this.attributes.get(cat);
            if (atts != null && (!atts.flashing || ((System.currentTimeMillis() / 500) % 3 != 0)) && shouldDisplay(atts.displayLevel))
            {
                int x = Math.round(rx * (float) atts.xOrg);
                int y = Math.round(ry * (float) atts.yOrg);
                ArrayList<TextFragment> frags = this.fragments.get(cat);
                if (frags != null && !frags.isEmpty())
                {
                    for (TextFragment frag : frags)
                    {
                        drawText(frag.text, x, y, atts.colour);
                        y += 10;
                    }
                }
            }
        }
    }
}
 
Example 5
Project: DebugServerInfo   File: ServerHelper.java   View source code 6 votes vote down vote up
@SubscribeEvent
public void onTickPlayerTick(TickEvent.PlayerTickEvent event)
{
    if (event.side.isClient() || event.phase != TickEvent.Phase.START || !hasPermission(event.player)) return;
    int count = event.player.getEntityData().getInteger(NBT_COUNTER);
    if (count <= 0) return;
    event.player.getEntityData().setInteger(NBT_COUNTER, count - 1);
    Data data = ServerHelper.getData();
    if (data != null)
    {
        try
        {
            DebugServerInfo.getSnw().sendTo(data, (EntityPlayerMP) event.player);
        }
        catch (Exception e)
        {
            getLogger().info("Caught error in sendTo. {} ({})", e.getMessage(), e.getClass().getName());
        }
    }
}
 
Example 6
Project: pnc-repressurized   File: EventHandlerPneumaticCraft.java   View source code 6 votes vote down vote up
@SubscribeEvent
public void onLootTableLoad(LootTableLoadEvent event) {
    if (ConfigHandler.general.enableDungeonLoot) {
        String prefix = "minecraft:chests/";
        String name = event.getName().toString();
        if (name.startsWith(prefix)) {
            String file = name.substring(name.indexOf(prefix) + prefix.length());
            switch (file) {
                case "abandoned_mineshaft":
                case "desert_pyramid":
                case "jungle_temple":
                case "simple_dungeon":
                case "spawn_bonus_chest":
                case "stronghold_corridor":
                case "village_blacksmith":
                    LootEntry entry = new LootEntryTable(RL("inject/simple_dungeon_loot"), 1, 0,  new LootCondition[0], "pneumaticcraft_inject_entry");
                    LootPool pool = new LootPool(new LootEntry[]{entry}, new LootCondition[0], new RandomValueRange(1), new RandomValueRange(0, 1), "pneumaticcraft_inject_pool");
                    event.getTable().addPool(pool);
                    break;
                default:
                    break;
            }
        }
    }
}
 
Example 7
Project: minecraft-territorialdealings   File: EventListener.java   View source code 6 votes vote down vote up
@SubscribeEvent
public void onItemCrafted(ItemCraftedEvent event)
{
	if (event.player.worldObj.isRemote) { return; }	// Server side only

	if (event.crafting.getItem() instanceof LeaderRequiredItem)	// Only leaders can craft this item
	{
		if (TerritoryHandler.getFactionPlayerIsLeaderOf(event.player) == null)
		{
			Main.console("Item is leader-only, but the player is not a leader. Removing the item.");
			event.crafting.stackSize = 0;	// Not having it

			//event.setCanceled(true);	// That event cannot be cancelled. How do I reliably stop the creation of this item? Setting the stack size itself seems to be delayed until the metadata changes,
										// or some time passes and a sync is started
			//TODO: Refund the items used?
		}
		// else, is leader of at least one faction. Checks out.
	}
}
 
Example 8
Project: Mods   File: TF2EventsClient.java   View source code 6 votes vote down vote up
@SubscribeEvent
public void guiPostInit(GuiScreenEvent.InitGuiEvent.Post event) {
	if (Minecraft.getMinecraft().player != null) {
		if ((event.getGui() instanceof GuiInventory || event.getGui() instanceof GuiContainerCreative || event.getGui() instanceof GuiWearables)
				&& !Minecraft.getMinecraft().player.getCapability(TF2weapons.INVENTORY_CAP, null).isEmpty()) {
			// GuiContainer gui = (GuiContainer) event.getGui();
			event.getButtonList().add(new GuiButton(97535627, event.getGui().width / 2 - 10, event.getGui().height / 2 + 95, 20, 20, "W"));
		}

		if (event.getGui() instanceof GuiMerchant)
			if (((GuiMerchant) event.getGui()).getMerchant().getDisplayName().getUnformattedText().equals(I18n.format("entity.hale.name"))) {
				event.getButtonList().add(new GuiButton(7578, event.getGui().width / 2 - 100, event.getGui().height / 2 - 110, 100, 20, "Change Team"));
				event.getButtonList().add(new GuiButton(7579, event.getGui().width / 2, event.getGui().height / 2 - 110, 100, 20, "Recover Lost Items"));
			}
		Minecraft.getMinecraft().player.getCapability(TF2weapons.WEAPONS_CAP, null).state &= 8;
	}
}
 
Example 9
Project: Mods   File: TF2EventsCommon.java   View source code 6 votes vote down vote up
@SubscribeEvent(priority = EventPriority.LOWEST)
public void craftItem(net.minecraftforge.fml.common.gameevent.PlayerEvent.ItemCraftedEvent event) {
	ItemStack withPattern=ItemStack.EMPTY;
	ItemStack noPattern=ItemStack.EMPTY;
	for(int i=0; i<event.craftMatrix.getSizeInventory();i++){
		ItemStack stack=event.craftMatrix.getStackInSlot(i);
		if(!stack.isEmpty() && stack.getItem() instanceof ItemBanner){
			if(TileEntityBanner.getPatterns(stack)>0){
				withPattern=stack;
			}
			else{
				noPattern=stack;
			}
			if(!withPattern.isEmpty()&&!noPattern.isEmpty()){
				withPattern.shrink(1);
			}
		}
	}
}
 
Example 10
Project: uniquecrops   File: UCEventHandlerServer.java   View source code 6 votes vote down vote up
@SubscribeEvent
public void checkPlayerNBT(PlayerEvent.Clone event) {
	
	if (!event.isWasDeath())
		return;
	
	EntityPlayer old = event.getOriginal();
	EntityPlayer player = event.getEntityPlayer();
	
	NBTTagCompound oldtag = old.getEntityData();
	NBTTagCompound tag = player.getEntityData();
	if (oldtag.hasKey(GrowthSteps.TAG_GROWTHSTAGES)) {
		tag.setTag(GrowthSteps.TAG_GROWTHSTAGES, oldtag.getTagList(GrowthSteps.TAG_GROWTHSTAGES, 10).copy());
	}
	if (oldtag.hasKey("hasSacrificed"))
		tag.setBoolean("hasSacrificed", oldtag.getBoolean("hasSacrificed"));
	if (oldtag.hasKey(SeedBehavior.TAG_ABSTRACT))
		tag.setInteger(SeedBehavior.TAG_ABSTRACT, oldtag.getInteger(SeedBehavior.TAG_ABSTRACT));
}
 
Example 11
Project: ForgeHax   File: XrayMod.java   View source code 6 votes vote down vote up
@SubscribeEvent
public void onPreRenderBlockLayer(RenderBlockLayerEvent.Pre event) {
    if(!isInternalCall) {
        if (!event.getRenderLayer().equals(BlockRenderLayer.TRANSLUCENT)) {
            event.setCanceled(true);
        } else if (event.getRenderLayer().equals(BlockRenderLayer.TRANSLUCENT)) {
            isInternalCall = true;
            Entity renderEntity = MC.getRenderViewEntity();
            GlStateManager.disableAlpha();
            MC.renderGlobal.renderBlockLayer(BlockRenderLayer.SOLID, event.getPartialTicks(), 0, renderEntity);
            GlStateManager.enableAlpha();
            MC.renderGlobal.renderBlockLayer(BlockRenderLayer.CUTOUT_MIPPED, event.getPartialTicks(), 0, renderEntity);
            MC.getTextureManager().getTexture(TextureMap.LOCATION_BLOCKS_TEXTURE).setBlurMipmap(false, false);
            MC.renderGlobal.renderBlockLayer(BlockRenderLayer.CUTOUT, event.getPartialTicks(), 0, renderEntity);
            MC.getTextureManager().getTexture(TextureMap.LOCATION_BLOCKS_TEXTURE).restoreLastBlurMipmap();
            GlStateManager.disableAlpha();
            isInternalCall = false;
        }
    }
}
 
Example 12
Project: BetterThanWeagles   File: LootTableInjector.java   View source code 6 votes vote down vote up
@SubscribeEvent
public void lootTableLoaded(LootTableLoadEvent event)
{
	ResourceLocation poolName = event.getName();

	String injectTablePath = "inject/" + poolName.getResourceDomain() + "/" + poolName.getResourcePath();

	if (!LootTableInjector.INJECTED_LOOT_TABLES.contains(injectTablePath))
	{
		return;
	}

	LootTable injectTable = event.getLootTableManager().getLootTableFromLocation(new ResourceLocation(BetterThanWeagles.MODID, injectTablePath));
	for (int i = 0; i < LootTableInjector.MAX_POOLS; i++)
	{
		LootPool pool = injectTable.getPool(String.format("inject%d", i));
		if (pool != null)
		{
			event.getTable().addPool(pool);
		}
	}
}
 
Example 13
Project: craftsman   File: Turtle.java   View source code 6 votes vote down vote up
@SubscribeEvent
public void track(PlayerTickEvent event) {
    EntityPlayer player = event.player;
    
    Item heldItem = player.getHeldItemMainhand().getItem();
    if (!(heldItem instanceof ItemBlock)) {
        return;
    }    
    
    IBlockState heldBlockState = Block.getBlockFromItem(heldItem).getDefaultState();
    BlockPos basePos = player.getPosition().add(0, -1, 0);
    IBlockState baseState = player.getEntityWorld().getBlockState(basePos);
    
    if (heldBlockState.equals(baseState)) {
        return;
    }

    player.getEntityWorld().setBlockState(basePos, heldBlockState);
}
 
Example 14
Project: ModularMachinery   File: ClientScheduler.java   View source code 6 votes vote down vote up
@SubscribeEvent
public void tick(TickEvent.ClientTickEvent event) {
    clientTick++;
    ClientProxy.renderHelper.tick();

    inTick = true;
    synchronized (lock) {
        inTick = true;
        Iterator<Runnable> iterator = queuedRunnables.keySet().iterator();
        while (iterator.hasNext()) {
            Runnable r = iterator.next();
            Counter delay = queuedRunnables.get(r);
            delay.decrement();
            if(delay.value <= 0) {
                r.run();
                iterator.remove();
            }
        }
        inTick = false;
        for (Map.Entry<Runnable, Integer> waiting : waitingRunnables.entrySet()) {
            queuedRunnables.put(waiting.getKey(), new Counter(waiting.getValue()));
        }
    }
    waitingRunnables.clear();
}
 
Example 15
Project: uniquecrops   File: UCEventHandlerServer.java   View source code 6 votes vote down vote up
@SubscribeEvent
public void setUpgradeChance(AnvilRepairEvent event) {
	
	ItemStack output = event.getItemResult();
	EntityPlayer player = event.getEntityPlayer();
	if (output == null)
		return;
	if (player == null)
		return;
	
	if (player.worldObj.isRemote)
		return;
	
	if (output.getItem() instanceof IBookUpgradeable) {
		int upgradelevel = NBTUtils.getInt(output, ItemGeneric.TAG_UPGRADE, -1);
		if (upgradelevel == 10) {
			Random rand = new Random();
			if (rand.nextBoolean() == false && !player.worldObj.isRemote) {
				player.addChatMessage(new TextComponentString(TextFormatting.RED + "You attempt to refine this item, but it breaks.."));
				output.stackSize = 0;
			}
		}
	}
}
 
Example 16
Project: PurificatiMagicae   File: BlockRegistry.java   View source code 6 votes vote down vote up
@SubscribeEvent
public static void onRegisterBlocks(RegistryEvent.Register<Block> e)
{
    IForgeRegistry<Block> reg = e.getRegistry();
    register(new BlockCrystal(), reg);
    register(new BlockCrystalGlass(), reg);
    Block ore_crysagnetite = new BlockBase("ore_crysagnetite", Material.ROCK).setHardness(3).setLightLevel(0.1f);
    ore_crysagnetite.setHarvestLevel("pickaxe", 2);
    register(ore_crysagnetite, reg);
    register(new BlockTranslationDesk(), reg);
    register(new BlockCrystalSmall(), reg);
    register(new BlockWallIfTablet(), reg);
    register(new BlockBrokenWallIfTablet(), reg);
    register(new BlockMicroscope(), reg);
    register(new BlockLuminousCrystalGlass(), reg);
    register(new BlockTest(), reg);
    register(new BlockBrulantaFlower(), reg);
    register(new BlockCodeStorage(), reg);
    register(new BlockMagibench(), reg);
    register(new BlockRopeCoil(), reg);
    register(new BlockStoneCrusher(), reg);
}
 
Example 17
Project: CreeperHostGui   File: EventHandler.java   View source code 5 votes vote down vote up
@SubscribeEvent
public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent eventArgs)
{
    if (!CreeperHost.MOD_ID.equals(eventArgs.getModID()))
    {
        return;
    }

    CreeperHost.instance.saveConfig();
}
 
Example 18
Project: FirstAid   File: EventHandler.java   View source code 5 votes vote down vote up
@SubscribeEvent
public static void onItemCraft(PlayerEvent.ItemCraftedEvent event) {
    ItemStack stack = event.crafting;
    if (stack.getItem() == FirstAidItems.BANDAGE) {
        String username = event.player.getName();
        if (username.equalsIgnoreCase("ichun"))
            stack.setStackDisplayName("MediChun's Healthkit"); //Yup, I *had* to do this
    }
}
 
Example 19
Project: TheOink   File: OinkEntityEvents.java   View source code 5 votes vote down vote up
@SubscribeEvent
public static void applyEffectSausage(LivingEvent.LivingUpdateEvent e) {
    if (e.getEntity() instanceof OinkSausage) {
        OinkSausage piggy = (OinkSausage) e.getEntity();
        if (sausageGlow) {
            piggy.addPotionEffect(new PotionEffect(MobEffects.GLOWING, 5, 10, false, false));
        }
    }
}
 
Example 20
Project: harshencastle   File: HandlerHarshenInventory.java   View source code 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onPlayerRespawn(PlayerRespawnEvent event)
{
	if(stackMap.containsKey(event.player.getUniqueID()))
	{
		event.player.getEntityData().setTag("harshenInventory", stackMap.get(event.player.getUniqueID()).serializeNBT());
		for(int i = 0; i < stackMap.get(event.player.getUniqueID()).getSlots(); i++)
			if(stackMap.get(event.player.getUniqueID()).getStackInSlot(i).getItem() instanceof IHarshenProvider)
				((IHarshenProvider)stackMap.get(event.player.getUniqueID()).getStackInSlot(i).getItem()).onAdd(event.player, i);

	}
}
 
Example 21
Project: Mods   File: TF2EventsCommon.java   View source code 5 votes vote down vote up
@SubscribeEvent
public void stopUsing(PlayerInteractEvent.LeftClickBlock event) {
	if (!TF2Util.canInteract(event.getEntityLiving())) {
		event.setCanceled(true);
	}
	event.getEntityPlayer().removePotionEffect(TF2weapons.charging);
}
 
Example 22
Project: CraftingParadiseMod   File: EntityHandler.java   View source code 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.LOW)
public void onEntityConstruction(EntityEvent.EntityConstructing event)
{
    Entity entity = event.getEntity();
    if(entity instanceof EntityPlayer)
    {
        if(entity.world != null)
        {
            if(event.getEntity().world.isRemote)
            {
                CraftingParadise.proxy.registerCustomSky();
            }
        }
    }
}
 
Example 23
Project: FundamentalChemistry   File: ForgeEventHandler.java   View source code 5 votes vote down vote up
@SubscribeEvent
public void entityConstruct(EntityEvent.EntityConstructing e){
	//add custom properties to players
  if(e.entity instanceof EntityPlayer){
    if(e.entity.getExtendedProperties(PlayerProperties.ID) == null){
      e.entity.registerExtendedProperties(PlayerProperties.ID, new PlayerProperties());
    }
  }
}
 
Example 24
Project: TheOink   File: OinkEntityEvents.java   View source code 5 votes vote down vote up
@SubscribeEvent
public static void applyEffectBacon(LivingEvent.LivingUpdateEvent e) {
    if (e.getEntity() instanceof OinkBacon) {
        OinkBacon piggy = (OinkBacon) e.getEntity();
        if (baconGlow) {
            piggy.addPotionEffect(new PotionEffect(MobEffects.GLOWING, 5, 10, false, false));
        }
    }

}
 
Example 25
Project: harshencastle   File: HandlerFlatPlateRenderer.java   View source code 5 votes vote down vote up
@SubscribeEvent
public void lastRender(RenderWorldLastEvent event)
{
	if(!Minecraft.getMinecraft().player.capabilities.isCreativeMode && !Minecraft.getMinecraft().player.isSpectator())
		return;
	ArrayList<BlockPos> nonRemovedPlates = new ArrayList<>();
	int time = platePositions.size();
	for(int i = 0; i < time; i++)
		if(Minecraft.getMinecraft().world.getBlockState(platePositions.get(i)).getBlock() instanceof HarshenDimensionalFlatPlate)
			nonRemovedPlates.add(renderAt(platePositions.get(i), event.getPartialTicks()));
	platePositions = nonRemovedPlates;
}
 
Example 26
Project: ForgeHax   File: AntiOverlayMod.java   View source code 5 votes vote down vote up
@SubscribeEvent
public void onRender(RenderEvent event) {
    ItemStack item = FastReflection.Fields.EntityRenderer_itemActivationItem.get(MC.entityRenderer);

    if (item != null && item.getItem() == Items.TOTEM_OF_UNDYING) {
        FastReflection.Fields.EntityRenderer_itemActivationItem.set(MC.entityRenderer, null);
    }
}
 
Example 27
Project: ForgeHax   File: SpawnerEspMod.java   View source code 5 votes vote down vote up
@SubscribeEvent
public void onRender(RenderEvent event) {
    event.getBuffer().begin(GL11.GL_LINES, DefaultVertexFormats.POSITION_COLOR);

    for(TileEntity tileEntity : getWorld().loadedTileEntityList) {
        if(tileEntity instanceof TileEntityMobSpawner) {
            BlockPos pos = tileEntity.getPos();
            GeometryTessellator.drawCuboid(event.getBuffer(), pos, GeometryMasks.Line.ALL, Utils.Colors.RED);
        }
    }

    event.getTessellator().draw();
}
 
Example 28
Project: Anima-Mundi   File: ParticleManager.java   View source code 5 votes vote down vote up
@SubscribeEvent
public static void registerParticles(TextureStitchEvent.Pre event)
{
	stitchParticle("particle/glow_par", event.getMap());
	stitchParticle("items/sword_glow_top", event.getMap());
	stitchParticle("items/sword_glow_bottom", event.getMap());
}
 
Example 29
Project: harshencastle   File: HandlerKeyBinding.java   View source code 5 votes vote down vote up
@SubscribeEvent
public void onKeyInput(KeyInputEvent event)
{
	for(KeyBinding key : ringEvents)
		if(key.isPressed())
			sendRingEvent(ringEvents.indexOf(key));
	if(openInventory.isPressed())
		HarshenClientUtils.openInventory();
}
 
Example 30
Project: Teleporting-XP   File: ModConfig.java   View source code 5 votes vote down vote up
@SubscribeEvent
public static void configChanged(ConfigChangedEvent.OnConfigChangedEvent event)
{
    if(event.getModID().equals(Reference.MOD_ID))
    {
        ConfigManager.sync(Reference.MOD_ID, Config.Type.INSTANCE);
    }
}
 
Example 31
Project: Loot-Slash-Conquer   File: EventInput.java   View source code 5 votes vote down vote up
@SubscribeEvent
public void onInput(InputEvent event)
{
	KeyBinding p = ClientProxy.bindingP;
	EntityPlayer player = Minecraft.getMinecraft().player;
	
	if (player != null && p.isPressed())
	{
		player.openGui(LootSlashConquer.instance, GuiHandler.PLAYER_INFORMATION, player.getEntityWorld(), player.getPosition().getX(), player.getPosition().getY(), player.getPosition().getZ());
	}
	
	// if ability key is pressed.
	// send server packet calling ability start.
}
 
Example 32
Project: refinedstorageaddons   File: ProxyCommon.java   View source code 5 votes vote down vote up
@SubscribeEvent
public void onPickupItem(EntityItemPickupEvent e) {
    if (!e.getEntityPlayer().world.isRemote) {
        for (int i = 0; i < 9 * 4; ++i) {
            ItemStack stack = e.getEntityPlayer().inventory.getStackInSlot(i);

            if (stack.getItem() == RSAddonsItems.NETWORK_BAG) {
                ((ItemNetworkBag) stack.getItem()).onPlayerPickup(e, stack);

                break;
            }
        }
    }
}
 
Example 33
Project: Proyecto-DASI   File: RewardForDiscardingItemImplementation.java   View source code 5 votes vote down vote up
@SubscribeEvent
public void onLoseItem(LoseItemEvent event)
{
    if (event.stack != null)
    {
        accumulateReward(this.params.getDimension(), event.stack);
    }
}
 
Example 34
Project: Proyecto-DASI   File: BuildBattleDecoratorImplementation.java   View source code 5 votes vote down vote up
@SubscribeEvent
public void onPlaceBlock(PlaceEvent event)
{
    if (blockInBounds(event.pos,this.destBounds))
    {
        this.valid = false;
        this.dest.set(blockPosToIndex(event.pos, this.destBounds), event.state);
    }
}
 
Example 35
Project: HardcoreRevival   File: RestrictionHandler.java   View source code 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onPlayerInteract(PlayerInteractEvent event) {
	EntityPlayer player = event.getEntityPlayer();
	if (player != null && player.getHealth() <= 0f) {
		if (!(event instanceof PlayerInteractEvent.RightClickEmpty || event instanceof PlayerInteractEvent.LeftClickEmpty)) {
			event.setCanceled(true);
		}
	}
}
 
Example 36
Project: PurificatiMagicae   File: SifEvents.java   View source code 5 votes vote down vote up
@SubscribeEvent
public static void onChunkWatch(ChunkWatchEvent.Watch e)
{
    try
    {
        GlobalChunkPos pos = new GlobalChunkPos(e.getChunk().x, e.getChunk().z, e.getPlayer().dimension);
        NetworkManager.sendTo(new CPacketSyncSif(pos, PurMag.INSTANCE.sif_storage.get(pos)), e.getPlayer());
    }
    catch (Exception ex)
    {
        PurMag.INSTANCE.log.error("Can't sync the SIF chunk data with player!", ex);
    }
}
 
Example 37
Project: Adventurers-Toolbox   File: SpecialToolAbilityHandler.java   View source code 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.LOWEST)
public void onEndRodToolHarvestEvent(BlockEvent.HarvestDropsEvent event) {
	if (event.getHarvester() == null) {
		return;
	}

	ItemStack stack = event.getHarvester().getHeldItemMainhand();

	boolean flag = false;

	if (stack.getItem() instanceof IHaftTool) {
		if (IHaftTool.getHaftMat(stack) == ModMaterials.HAFT_END_ROD) {
			flag = true;
		}
	}

	if (flag) {
		if (!event.getWorld().isRemote) {
			BlockPos pos = event.getPos();
			for (ItemStack itemstack : event.getDrops()) {
				if (rand.nextFloat() < event.getDropChance()) {
					EntityItem entity = new EntityItem(event.getWorld(), pos.getX() + 0.5, pos.getY() + 0.25,
							pos.getZ() + 0.5, itemstack);
					entity.setNoGravity(true);
					entity.motionX = 0;
					entity.motionY = 0;
					entity.motionZ = 0;
					entity.velocityChanged = true;
					event.getWorld().spawnEntity(entity);
				}
			}
		}
		event.getDrops().clear();
	}
}
 
Example 38
Project: Bewitchment   File: BrewEvents.java   View source code 5 votes vote down vote up
@SubscribeEvent
public void onBlockDestroy(LivingDestroyBlockEvent event) {
	Collection<BrewEffect> effects = BrewStorageHandler.getBrewEffects(event.getEntityLiving());
	effects.stream().filter(effect -> effect.getBrew() instanceof IBrewBlockDestroy).forEach(effect -> {
		if (event.isCanceled()) return;
		((IBrewBlockDestroy) effect.getBrew()).onBlockDestroy(event, event.getEntityLiving(), effect.getAmplifier());
	});
}
 
Example 39
Project: Lanolin   File: EventHandlerCommon.java   View source code 5 votes vote down vote up
@SubscribeEvent
public void updateEntity(LivingEvent.LivingUpdateEvent event){
    if(event.getEntity() instanceof EntityPlayer && event.getEntity().getAir() <= 300 - Config.ARMOR_TICKS_PER_LANOLIN){
        // The entity is a player and is not at full air
        if(event.getEntity().isInsideOfMaterial(Material.WATER)){
            for(int i = 0; i < 4; i++){
                ItemStack armorPiece = ((EntityPlayer) event.getEntity()).inventory.armorInventory.get(i);
                if(armorPiece != ItemStack.EMPTY){
                    NBTTagCompound tags = armorPiece.getTagCompound();
                    if(tags != null && tags.hasKey("lanolin")){
                        // Found armor with lanolin. Reset air and remove a piece of lanolin.
                        event.getEntity().setAir(300);
                        if(tags.getInteger("lanolin") == 1){
                            // No more lanolin on this item, remove the tag
                            tags.removeTag("lanolin");
                        }
                        else{
                            tags.setInteger("lanolin", tags.getInteger("lanolin")-1);
                        }
                        armorPiece.setTagCompound(tags);
                        ((EntityPlayer) event.getEntity()).inventory.armorInventory.set(i, armorPiece);
                        break;
                    }
                }
            }
        }
    }
}
 
Example 40
Project: Thermionics   File: ClientProxy.java   View source code 5 votes vote down vote up
@SubscribeEvent
public void onPostRender(RenderWorldLastEvent evt) {
	if (!Loader.isModLoaded("baubles")) return;
	
	EntityPlayer thePlayer = Minecraft.getMinecraft().player;
	
	for(EntityPlayer entity : Minecraft.getMinecraft().world.playerEntities) {
		IBaublesItemHandler baubles = BaublesApi.getBaublesHandler(entity);
		ItemStack scarfStack = baubles.getStackInSlot(BAUBLE_AMULET);
		if (scarfStack==null || scarfStack.isEmpty() || scarfStack.getItem()!=ThermionicsItems.SCARF) return;
		Scarf scarf = scarfCache.getIfPresent(entity);
		if (scarf==null) {
			scarf = new Scarf();
			scarfCache.put(entity, scarf);
			scarf.readFromNBT(scarfStack.getTagCompound());
			//System.out.println("Created scarf:"+(scarf.leftScarf.size()+scarf.rightScarf.size())+" nodes.");
		} else {
			
			scarf.updateFromNBT(scarfStack.getTagCompound());
			//System.out.println("Updated scarf:"+(scarf.leftScarf.size()+scarf.rightScarf.size())+" nodes.");
		}
		
		double dx = thePlayer.prevPosX + (thePlayer.posX - thePlayer.prevPosX) * evt.getPartialTicks();
		double dy = thePlayer.prevPosY + (thePlayer.posY - thePlayer.prevPosY) * evt.getPartialTicks();
		double dz = thePlayer.prevPosZ + (thePlayer.posZ - thePlayer.prevPosZ) * evt.getPartialTicks();
		
		LayerScarf.renderScarf(
				dx, dy, dz,
				entity, null, scarf, evt.getPartialTicks(),
				Minecraft.getMinecraft().world);
	}
}