use of net.minecraftforge.fml.common.eventhandler.SubscribeEvent in project Railcraft by Railcraft.
the class MinecartHooks method onMinecartInteract.
@SubscribeEvent
public void onMinecartInteract(MinecartInteractEvent event) {
EntityMinecart cart = event.getMinecart();
EntityPlayer player = event.getPlayer();
if (!CartToolsAPI.doesCartHaveOwner(cart))
CartToolsAPI.setCartOwner(cart, player);
if (!(cart instanceof EntityTunnelBore) && player.getDistanceSqToEntity(cart) > MAX_INTERACT_DIST_SQ) {
event.setCanceled(true);
return;
}
if (cart.isDead) {
event.setCanceled(true);
return;
}
if (cart.canBeRidden()) {
//TODO: this will interfere with carts that multiple players can ride, re-evaluate
if (cart.isBeingRidden() && player.getRidingEntity() != cart) {
event.setCanceled(true);
return;
}
if (player.getRidingEntity() != null && player.getRidingEntity() != cart) {
event.setCanceled(true);
return;
}
if (player.getRidingEntity() != cart && player.isOnLadder()) {
event.setCanceled(true);
return;
}
}
if (!player.canEntityBeSeen(cart)) {
event.setCanceled(true);
}
}
use of net.minecraftforge.fml.common.eventhandler.SubscribeEvent in project Overloaded by CJ-MC-Mods.
the class ItemMultiTool method teleportDrops.
@SubscribeEvent(priority = EventPriority.LOWEST)
public void teleportDrops(@Nonnull BlockEvent.HarvestDropsEvent event) {
if (event.isCanceled())
return;
EntityPlayer player = event.getHarvester();
if (player == null || event.getHarvester().getHeldItemMainhand().getItem() != this)
return;
World world = event.getWorld();
float chance = event.getDropChance();
for (ItemStack stack : event.getDrops()) {
if (world.rand.nextFloat() <= chance) {
EntityItem toSpawn = new EntityItem(world, player.posX, player.posY, player.posZ, stack);
world.spawnEntity(toSpawn);
}
}
event.getDrops().clear();
}
use of net.minecraftforge.fml.common.eventhandler.SubscribeEvent in project AgriCraft by AgriCraft.
the class ItemToolTipHandler method addProductInfo.
@SubscribeEvent
public void addProductInfo(ItemTooltipEvent event) {
if (StackHelper.hasTag(event.getItemStack())) {
final NBTTagCompound tag = StackHelper.getTag(event.getItemStack());
if (tag.hasKey(IAgriHarvestProduct.PRODUCT_MARKER_TAG)) {
final int minAmount = tag.getInteger(IAgriHarvestProduct.PRODUCT_MIN_TAG);
final int maxAmount = tag.getInteger(IAgriHarvestProduct.PRODUCT_MAX_TAG);
final double chance = tag.getDouble(IAgriHarvestProduct.PRODUCT_CHANCE_TAG);
event.getToolTip().add(ChatFormatting.GRAY + "Chance: " + DecimalFormat.getPercentInstance().format(chance));
event.getToolTip().add(ChatFormatting.GRAY + "Min. Amount: " + minAmount);
event.getToolTip().add(ChatFormatting.GRAY + "Max. Amount: " + maxAmount);
}
}
}
use of net.minecraftforge.fml.common.eventhandler.SubscribeEvent in project ConvenientAdditions by Necr0.
the class ModLoot method onLootTableLoad.
@SubscribeEvent
public void onLootTableLoad(LootTableLoadEvent event) {
ResourceLocation n = event.getName();
if (n.equals(LootTableList.CHESTS_END_CITY_TREASURE)) {
if (ModConfigTools.mobCatcher_loot)
event.getTable().getPool("main").addEntry(new LootEntryItem(ModItems.itemMobCatcherMega, 1, 3, new LootFunction[0], new LootCondition[0], ModConstants.Mod.MODID + ":megaMCD"));
} else if (n.equals(LootTableList.CHESTS_STRONGHOLD_CORRIDOR)) {
if (ModConfigTools.mobCatcher_loot)
event.getTable().getPool("main").addEntry(new LootEntryItem(ModItems.itemMobCatcherHyper, 1, 3, new LootFunction[0], new LootCondition[0], ModConstants.Mod.MODID + ":hyperMCD"));
} else if (n.equals(LootTableList.CHESTS_SIMPLE_DUNGEON)) {
if (ModConfigTools.mobCatcher_loot) {
event.getTable().getPool("main").addEntry(new LootEntryItem(ModItems.itemMobCatcherSuper, 1, 3, new LootFunction[0], new LootCondition[0], ModConstants.Mod.MODID + ":superMCD"));
event.getTable().getPool("main").addEntry(new LootEntryItem(ModItems.itemMobCatcherRegular, 3, -2, new LootFunction[0], new LootCondition[0], ModConstants.Mod.MODID + ":regularMCD"));
}
}
}
use of net.minecraftforge.fml.common.eventhandler.SubscribeEvent in project ConvenientAdditions by Necr0.
the class PlayerInventoryTickHandler method onPlayerInventoryTick.
@SubscribeEvent
public void onPlayerInventoryTick(TickEvent.PlayerTickEvent e) {
EntityPlayer player = e.player;
Iterable<SlotNotation> iter = InventoryIterator.getIterable(player, EnumInventory.MAIN);
for (SlotNotation slot : iter) {
ItemStack stack = slot.getItem();
if (stack != null && stack.getItem() instanceof IPlayerInventoryTick) {
((IPlayerInventoryTick) stack.getItem()).onPlayerInventoryTick(stack, slot, player);
;
}
}
}
Aggregations