<commit_before>package crazypants.enderio.machine.obelisk.inhibitor;

import java.util.Map;
import java.util.Map.Entry;

import com.enderio.core.client.render.BoundingBox;
import com.enderio.core.common.util.BlockCoord;
import com.google.common.collect.Maps;

import crazypants.enderio.GuiID;
import crazypants.enderio.ModObject;
import crazypants.enderio.api.teleport.TeleportEntityEvent;
import crazypants.enderio.machine.obelisk.AbstractBlockObelisk;
import crazypants.enderio.machine.obelisk.GuiRangedObelisk;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

public class BlockInhibitorObelisk extends AbstractBlockObelisk<TileInhibitorObelisk> {

  public static BlockInhibitorObelisk instance;

  public static BlockInhibitorObelisk create() {
    BlockInhibitorObelisk res = new BlockInhibitorObelisk();
    res.init();
    MinecraftForge.EVENT_BUS.register(res);
    return instance = res;
  }

  protected BlockInhibitorObelisk() {
    super(ModObject.blockInhibitorObelisk, TileInhibitorObelisk.class);
  }

  @Override
  public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
    TileInhibitorObelisk te = getTileEntity(world, new BlockPos(x, y, z));
    if (te != null) {
      return new ContainerInhibitorObelisk(player.inventory, te);
    }
    return null;
  }

  @Override
  public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
    TileInhibitorObelisk te = getTileEntity(world, new BlockPos(x, y, z));
    if (te != null) {
      return new GuiRangedObelisk(player.inventory, te, new ContainerInhibitorObelisk(player.inventory, te), "inhibitor");
    }
    return null;
  }

  @Override
  protected GuiID getGuiId() {
    return GuiID.GUI_ID_INHIBITOR;
  }


  public Map<BlockCoord, BoundingBox> activeInhibitors = Maps.newHashMap();

  @SubscribeEvent
  public void onTeleport(TeleportEntityEvent event) {
    Vec3d pos = new Vec3d(event.targetX,event.targetY,event.targetZ);
    for (Entry<BlockCoord, BoundingBox> e : activeInhibitors.entrySet()) {
      if (e.getValue().isVecInside(pos)) {
        BlockCoord bc = e.getKey();
        TileEntity te = bc.getTileEntity(event.getEntity().worldObj);
        if (te instanceof TileInhibitorObelisk && ((TileInhibitorObelisk) te).isActive() && te.getWorld().provider.getDimension() == event.dimension) {
          event.setCanceled(true);
        }
      }
    }
  }
}<commit_msg>Inhibitor Obelisk now also prevents Endermen and players using ender pearls from teleporting and checks source and target location<commit_after>package crazypants.enderio.machine.obelisk.inhibitor;

import java.util.Map;
import java.util.Map.Entry;

import com.enderio.core.client.render.BoundingBox;
import com.enderio.core.common.util.BlockCoord;
import com.google.common.collect.Maps;

import crazypants.enderio.GuiID;
import crazypants.enderio.ModObject;
import crazypants.enderio.api.teleport.TeleportEntityEvent;
import crazypants.enderio.machine.obelisk.AbstractBlockObelisk;
import crazypants.enderio.machine.obelisk.GuiRangedObelisk;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.living.EnderTeleportEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

public class BlockInhibitorObelisk extends AbstractBlockObelisk<TileInhibitorObelisk> {

  public static BlockInhibitorObelisk instance;

  public static BlockInhibitorObelisk create() {
    BlockInhibitorObelisk res = new BlockInhibitorObelisk();
    res.init();
    MinecraftForge.EVENT_BUS.register(res);
    return instance = res;
  }

  protected BlockInhibitorObelisk() {
    super(ModObject.blockInhibitorObelisk, TileInhibitorObelisk.class);
  }

  @Override
  public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
    TileInhibitorObelisk te = getTileEntity(world, new BlockPos(x, y, z));
    if (te != null) {
      return new ContainerInhibitorObelisk(player.inventory, te);
    }
    return null;
  }

  @Override
  public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
    TileInhibitorObelisk te = getTileEntity(world, new BlockPos(x, y, z));
    if (te != null) {
      return new GuiRangedObelisk(player.inventory, te, new ContainerInhibitorObelisk(player.inventory, te), "inhibitor");
    }
    return null;
  }

  @Override
  protected GuiID getGuiId() {
    return GuiID.GUI_ID_INHIBITOR;
  }


  public Map<BlockCoord, BoundingBox> activeInhibitors = Maps.newHashMap();

  // Ender IO's teleporting
  @SubscribeEvent
  public void onTeleport(TeleportEntityEvent event) {
    if (isTeleportPrevented(event.getEntity().worldObj, event.getEntity().posX, event.getEntity().posY, event.getEntity().posZ)) {
      event.setCanceled(true);
    }
    if (isTeleportPrevented(event.getEntity().worldObj, event.targetX, event.targetY, event.targetZ)) {
      event.setCanceled(true);
    }
  }

  // Forge's event for endermen and enderpearl teleporting
  @SubscribeEvent
  public void onEnderTeleport(EnderTeleportEvent event) {
    if (isTeleportPrevented(event.getEntity().worldObj, event.getEntity().posX, event.getEntity().posY, event.getEntity().posZ)) {
      event.setCanceled(true);
    }
    if (isTeleportPrevented(event.getEntity().worldObj, event.getTargetX(), event.getTargetY(), event.getTargetZ())) {
      event.setCanceled(true);
    }
  }

  private boolean isTeleportPrevented(World entityWorld, double d, double f, double g) {
    if (!activeInhibitors.isEmpty()) {
      Vec3d pos = new Vec3d(d, f, g);
      for (Entry<BlockCoord, BoundingBox> e : activeInhibitors.entrySet()) {
        if (e.getValue().isVecInside(pos)) {
          BlockCoord bc = e.getKey();
          if (entityWorld.isBlockLoaded(bc.getBlockPos())) {
            TileEntity te = bc.getTileEntity(entityWorld);
            if (te instanceof TileInhibitorObelisk && ((TileInhibitorObelisk) te).isActive() && ((TileInhibitorObelisk) te).getBounds().isVecInside(pos)) {
              return true;
            }
          }
        }
      }
    }
    return false;
  }

}
{'fraction_non_alphanumeric': 0.10645063597819503, 'fraction_numerical': 0.0009085402786190188, 'mean_word_length': 4.391836734693878, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5455740', 'n_tokens_mistral': 2197, 'n_tokens_neox': 2169, 'n_words': 418}