123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- package me.km.effects.passive;
- import java.util.HashMap;
- import me.km.KajetansMod;
- import me.km.api.Location;
- import me.km.api.Module;
- import me.km.api.ModuleListener;
- import me.km.api.Utils;
- import me.km.effects.Effect;
- import me.km.effects.EffectUtils;
- import net.minecraft.block.Block;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.entity.player.EntityPlayerMP;
- import net.minecraft.init.Blocks;
- import net.minecraft.world.World;
- import net.minecraftforge.event.entity.player.PlayerInteractEvent;
- import net.minecraftforge.event.world.BlockEvent;
- import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
- public class BlockClickEffects extends ModuleListener
- {
- private final HashMap<Location, Data> blocks;
-
- private class Data
- {
- protected EntityPlayerMP p;
- protected int guild;
- protected int taskId;
-
- public Data(EntityPlayerMP p, int taskId)
- {
- this.p = p;
- this.guild = KajetansMod.playerbank.getGuildId(p);
- this.taskId = taskId;
- }
- }
-
- public BlockClickEffects(Module m)
- {
- super(m);
- blocks = new HashMap<>();
- }
-
- public void registerTeleportBlock(Location l, EntityPlayerMP p, int time)
- {
- int i = KajetansMod.scheduler.scheduleTask(() ->
- {
- blocks.remove(l);
- l.getWorld().setBlockToAir(l.getBlockPos());
- }, time);
- blocks.put(l, new Data(p, i));
- l.getWorld().setBlockState(l.getBlockPos(), Blocks.SEA_LANTERN.getDefaultState());
-
- }
-
- @SubscribeEvent
- public void interact(BlockEvent.BreakEvent e)
- {
- Block b = e.getWorld().getBlockState(e.getPos()).getBlock();
- if(b == Blocks.SEA_LANTERN ||
- !KajetansMod.worldManager.getWorldPreferences(e.getWorld()).skills)
- {
- return;
- }
- if(blocks.containsKey(new Location(e.getWorld(), e.getPos())))
- {
- e.setCanceled(true);
- }
- }
-
- @SubscribeEvent
- public void interact(PlayerInteractEvent.RightClickBlock e)
- {
- Block b = e.getWorld().getBlockState(e.getPos()).getBlock();
- if(KajetansMod.worldManager.getWorldPreferences(e.getWorld()).skills)
- {
- if(b == Blocks.SEA_LANTERN)
- {
- handleTeleportBlock(e);
- }
- else if(b == Blocks.CAULDRON)
- {
- handleCauldronFilling(e);
- }
- }
- }
-
- private void handleTeleportBlock(PlayerInteractEvent.RightClickBlock e)
- {
- Location l = new Location(e.getWorld(), e.getPos());
- Data data = blocks.get(l);
- if(data == null)
- {
- return;
- }
- EntityPlayer p = e.getEntityPlayer();
- if(data.guild == KajetansMod.playerbank.getGuildId(p))
- {
- if(data.p.isEntityAlive())
- {
- Utils.teleportEntity(p, data.p);
- }
- blocks.remove(l);
- KajetansMod.scheduler.cancelTask(data.taskId);
- l.getWorld().setBlockToAir(l.getBlockPos());
- }
- }
-
- private void handleCauldronFilling(PlayerInteractEvent.RightClickBlock e)
- {
- if(EffectUtils.getEffectLevel(e.getEntityPlayer(), Effect.CAULDRON_FILLING) >= 1)
- {
- World w = e.getWorld();
- Blocks.CAULDRON.setWaterLevel(w, e.getPos(), w.getBlockState(e.getPos()), 3);
- }
- }
- }
|