use of net.minecraftforge.fml.common.eventhandler.SubscribeEvent in project ConvenientAdditions by Necr0.
the class EventHandlerLuck method luck.
@SubscribeEvent
public void luck(HarvestDropsEvent e) {
//e.getState().getBlock().getDrops(e.getWorld(), e.getPos(), e.getState(), 3);
if (e.getHarvester() != null && !e.getHarvester().isSneaking() && !e.getHarvester().getHeldItemMainhand().isEmpty() && e.getHarvester().getHeldItemMainhand().getItem() == ModItems.itemAdventurersPickaxe) {
int luck = (int) ModItems.itemAdventurersPickaxe.getToolProperty(e.getHarvester().getHeldItemMainhand(), "mining_luck");
if (Helper.doesOreDictMatch(e.getState(), "ore", true) && luck > 0) {
e.setDropChance(0f);
for (ItemStack s : e.getState().getBlock().getDrops(e.getWorld(), e.getPos(), e.getState(), luck)) {
double x = e.getPos().getX() + .5, y = e.getPos().getY() + .5, z = e.getPos().getZ() + .5;
e.getWorld().spawnEntity(new EntityItem(e.getWorld(), x, y, z, s));
}
}
}
}
use of net.minecraftforge.fml.common.eventhandler.SubscribeEvent in project ConvenientAdditions by Necr0.
the class EventHandlerSoulbound method onPlayerClone.
@SubscribeEvent
public void onPlayerClone(PlayerEvent.Clone e) {
if (e.getEntityPlayer().getEntityWorld().isRemote || e.getEntityPlayer().getEntityWorld().getGameRules().getBoolean("keepInventory"))
return;
EntityPlayer original = e.getOriginal();
EntityPlayer clone = e.getEntityPlayer();
IItemHandler h = original.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.DOWN);
for (int slot = 0; slot < h.getSlots(); slot++) {
ItemStack stack = h.getStackInSlot(slot);
if (stack != null && stack.getItem() instanceof ISoulbound && ((ISoulbound) stack.getItem()).isSoulbound(stack, original)) {
IItemHandler h2 = clone.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.DOWN);
ItemStack out = tryInsert(stack, h2);
if (out == null) {
h.extractItem(slot, 64, false);
} else {
stack.setCount(out.getCount());
}
}
}
}
use of net.minecraftforge.fml.common.eventhandler.SubscribeEvent in project ConvenientAdditions by Necr0.
the class ItemClimbingClaws method onLivingUpdate.
@SubscribeEvent
public void onLivingUpdate(LivingEvent.LivingUpdateEvent event) {
if (event.getEntityLiving() instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) event.getEntityLiving();
for (SlotNotation slot : InventoryIterator.getIterable(player, EnumInventory.BAUBLES)) {
ItemStack stack = slot.getItem();
if (!stack.isEmpty() && stack.getItem() instanceof ItemClimbingClaws) {
ItemClimbingClaws item = (ItemClimbingClaws) stack.getItem();
if (item.wallClimbSpeed > 0) {
Vec3d ppos = new Vec3d(player.posX, player.posY, player.posZ);
Vec3d plook = player.getLookVec();
plook = plook.subtract(0, plook.yCoord, 0).normalize();
RayTraceResult r = player.world.rayTraceBlocks(ppos, ppos.add(plook.scale(.425)), false, true, false);
if (r != null && r.typeOfHit == RayTraceResult.Type.BLOCK) {
IBlockState state = player.world.getBlockState(r.getBlockPos());
if (state.isSideSolid(player.world, r.getBlockPos(), r.sideHit)) {
if (player.isSneaking()) {
if (player.moveForward > 0F) {
player.motionY = Math.max(item.wallClimbSpeed, player.motionY);
} else {
player.motionY = Math.max(0d, player.motionY);
}
player.fallDistance = 0;
} else {
player.motionY = Math.max(player.motionY, Math.min(player.motionY + .1d, -.15d));
if (player.motionY > -.666)
player.fallDistance = 0;
}
}
}
break;
}
}
}
for (SlotNotation slot : InventoryIterator.getIterable(player, EnumInventory.BAUBLES)) {
ItemStack stack = slot.getItem();
if (!stack.isEmpty() && stack.getItem() instanceof ItemClimbingClaws) {
ItemClimbingClaws item = (ItemClimbingClaws) stack.getItem();
if (item.stepHeightBoost > 0) {
if (player.isSneaking())
player.stepHeight = .6f;
else
player.stepHeight = .6f + item.stepHeightBoost;
break;
}
}
}
}
}
use of net.minecraftforge.fml.common.eventhandler.SubscribeEvent in project VoodooCraft by Mod-DevCafeTeam.
the class CapabilityHandler method onClonePlayer.
@SuppressWarnings("all")
@SubscribeEvent
public static void onClonePlayer(net.minecraftforge.event.entity.player.PlayerEvent.Clone event) {
//Copy capability on player death to new player
if (event.isWasDeath() && (event.getEntityPlayer() instanceof EntityPlayerMP)) {
EntityPlayerMP player = (EntityPlayerMP) event.getEntityPlayer();
for (Capability<? extends ICapability> cap : VCCapabilities.getCapabilities()) {
ICapability oldicap = event.getOriginal().getCapability(cap, null);
ICapability icap = player.getCapability(cap, null);
if (oldicap == null || icap == null)
continue;
icap.deserializeNBT(oldicap.serializeNBT());
icap.dataChanged(player);
}
}
}
use of net.minecraftforge.fml.common.eventhandler.SubscribeEvent in project VoodooCraft by Mod-DevCafeTeam.
the class HexHandler method hurtEvent.
/**
* Protection Hex
*/
@SubscribeEvent
public static void hurtEvent(LivingHurtEvent event) {
EntityLivingBase entity = event.getEntityLiving();
ItemStack stack;
//Protection - Absorbs some damage, with a 10s cooldown
if (event.getSource().getSourceOfDamage() != null && (stack = getDollWithHex(entity, "protection")) != null) {
UUID uuid = entity.getUniqueID();
Long cooldownStart = protectionCooldowns.get(uuid);
long worldTime = entity.world.getTotalWorldTime();
//Check if hex is ready to protect
if (//200 ticks == 10 seconds
cooldownStart == null || (worldTime - cooldownStart) >= 200) {
//Protect from up to 5 hearts of damage
float protection = 10f;
float damage = event.getAmount();
event.setAmount(damage <= protection ? 0 : damage - protection);
//Sets the new cooldown start
protectionCooldowns.put(uuid, worldTime);
//Damage the doll
stack.damageItem(1, entity);
}
}
}
Aggregations