123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- package me.km.environment;
- import me.km.KajetansMod;
- import me.km.api.Module;
- import me.km.api.ModuleListener;
- import net.minecraft.block.state.IBlockState;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.init.Blocks;
- import net.minecraft.init.Items;
- import net.minecraft.util.EnumHand;
- import net.minecraft.world.World;
- import net.minecraftforge.event.entity.living.LivingEntityUseItemEvent;
- import net.minecraftforge.event.entity.player.AttackEntityEvent;
- import net.minecraftforge.event.entity.player.PlayerInteractEvent;
- import net.minecraftforge.event.world.BlockEvent;
- import net.minecraftforge.fml.common.eventhandler.EventPriority;
- import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
- import net.minecraftforge.fml.common.gameevent.PlayerEvent;
- public class EnvironmentEvents extends ModuleListener
- {
- public EnvironmentEvents(Module m)
- {
- super(m);
- EnvironmentAPI.initStatusAPI();
- KajetansMod.scheduler.scheduleRepeatingTask(new EnvironmentTick(), 40, 30);
- }
-
- @SubscribeEvent
- public void onRespawn(PlayerEvent.PlayerRespawnEvent e)
- {
- EntityPlayer p = e.player;
- EnvironmentAPI.resetThirst(p);
- EnvironmentAPI.resetEnergy(p);
- EnvironmentAPI.resetCold(p);
- EnvironmentAPI.resetMana(p);
- }
-
- @SubscribeEvent
- public void onInteract(AttackEntityEvent e)
- {
- EntityPlayer p = e.getEntityPlayer();
- if(KajetansMod.worldManager.getWorldPreferences(p.getEntityWorld()).statusEffects &&
- !(p.isCreative() || p.isSpectator()))
- {
- EnvironmentAPI.changeThirst(p, -40);
- EnvironmentAPI.changeEnergy(p, -20);
- }
- }
-
- @SubscribeEvent
- public void onBedClick(PlayerInteractEvent.RightClickBlock e)
- {
- if(e.getHand() != EnumHand.MAIN_HAND ||
- !KajetansMod.worldManager.getWorldPreferences(e.getWorld()).statusEffects ||
- e.getWorld().getBlockState(e.getPos()).getBlock() != Blocks.BED)
- {
- return;
- }
- EntityPlayer p = e.getEntityPlayer();
- if(!(p.isCreative() || p.isSpectator()))
- {
- EnvironmentAPI.resetEnergy(p);
- }
- }
-
- @SubscribeEvent(receiveCanceled = false)
- public void onBlockBreak(BlockEvent.BreakEvent e)
- {
- if(KajetansMod.worldManager.getWorldPreferences(e.getWorld()).statusEffects)
- {
- EntityPlayer p = e.getPlayer();
- if(!(p.isCreative() || p.isSpectator()))
- {
- EnvironmentAPI.changeThirst(p, -20);
- EnvironmentAPI.changeEnergy(p, -10);
- }
- }
- }
-
- @SubscribeEvent(receiveCanceled = false)
- public void onBlockPlace(BlockEvent.PlaceEvent e)
- {
- if(KajetansMod.worldManager.getWorldPreferences(e.getWorld()).statusEffects)
- {
- EntityPlayer p = e.getPlayer();
- if(!(p.isCreative() || p.isSpectator()))
- {
- EnvironmentAPI.changeThirst(p, -20);
- EnvironmentAPI.changeEnergy(p, -10);
- }
- }
- }
-
- @SubscribeEvent(receiveCanceled = false)
- public void onWaterConsume(LivingEntityUseItemEvent.Finish e)
- {
- if(e.getItem().getItem() == Items.POTIONITEM)
- {
- if(e.getEntityLiving() instanceof EntityPlayer)
- {
- EntityPlayer p = (EntityPlayer) e.getEntityLiving();
- if(KajetansMod.worldManager.getWorldPreferences(p.getEntityWorld()).statusEffects)
- {
- EnvironmentAPI.resetThirst(p);
- }
- }
- }
- }
-
- @SubscribeEvent(priority = EventPriority.HIGH, receiveCanceled = false)
- public void onCauldronClick(PlayerInteractEvent.RightClickBlock e)
- {
- if(e.getHand() != EnumHand.MAIN_HAND ||
- !KajetansMod.worldManager.getWorldPreferences(e.getWorld()).statusEffects)
- {
- return;
- }
- EntityPlayer p = e.getEntityPlayer();
- if(p.getHeldItemMainhand().getItem() == Items.POTIONITEM)
- {
- return;
- }
- World w = e.getWorld();
- IBlockState state = w.getBlockState(e.getPos());
- if(state.getBlock() == Blocks.CAULDRON)
- {
- int meta = Blocks.CAULDRON.getMetaFromState(state) - 1;
- if(meta < 0)
- {
- return;
- }
- Blocks.CAULDRON.setWaterLevel(w, e.getPos(), state, meta);
- EnvironmentAPI.resetThirst(p);
- }
- }
- }
|