Java Code Examples for net.minecraft.entity.EntityList#getEntityString()

The following examples show how to use net.minecraft.entity.EntityList#getEntityString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MinecraftTypeHelper.java    From malmo with MIT License 6 votes vote down vote up
/** Does essentially the same as entity.getName(), but without pushing the result
 * through the translation layer. This ensures the result matches what we use in Types.XSD,
 * and prevents things like "entity.ShulkerBullet.name" being returned, where there is no
 * translation provided in the .lang file.
 * @param e The entity
 * @return The entity's name.
 */
public static String getUnlocalisedEntityName(Entity e)
{
    String name;
    if (e.hasCustomName())
    {
        name = e.getCustomNameTag();
    }
    else if (e instanceof EntityPlayer)
    {
        name = e.getName(); // Just returns the user name
    }
    else
    {
        name = EntityList.getEntityString(e);
        if (name == null)
            name = "unknown";
    }
    return name;
}
 
Example 2
Source File: ItemPetContract.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void signContract(ItemStack stack, EntityPlayer oldOwner, EntityLivingBase target)
{
    NBTTagCompound nbt = NBTUtils.getCompoundTag(stack, null, true);
    UUID uuidOwner = oldOwner.getUniqueID();
    nbt.setLong("OwnerM", uuidOwner.getMostSignificantBits());
    nbt.setLong("OwnerL", uuidOwner.getLeastSignificantBits());

    UUID uuidTarget = target.getUniqueID();
    nbt.setLong("OwnableM", uuidTarget.getMostSignificantBits());
    nbt.setLong("OwnableL", uuidTarget.getLeastSignificantBits());

    nbt.setFloat("Health", target.getHealth());
    String str = EntityList.getEntityString(target);

    if (str != null)
    {
        nbt.setString("EntityString", str);
    }

    if (target.hasCustomName())
    {
        nbt.setString("CustomName", target.getCustomNameTag());
    }

    oldOwner.getEntityWorld().playSound(null, oldOwner.getPosition(), SoundEvents.BLOCK_ENCHANTMENT_TABLE_USE, SoundCategory.PLAYERS, 0.5f, 1f);
}
 
Example 3
Source File: EntityHandler.java    From wailanbt with MIT License 6 votes vote down vote up
@Override
public List<String> getWailaBody(Entity entity, List<String> currenttip, IWailaEntityAccessor accessor, IWailaConfigHandler config) {
    Entity currentEntity = accessor.getEntity();
    Class currentEntityClass = currentEntity.getClass();
    if (EntityList.classToStringMapping.containsKey(currentEntityClass)) {
        NBTTagCompound n = accessor.getNBTData();
        //LogHelper.info(n.toString());
        EntityPlayer player = accessor.getPlayer();
        ItemStack holdItemReal = player.getHeldItem();
        String holdItemNameReal = "";
        if (holdItemReal != null) {
            holdItemNameReal = Item.itemRegistry.getNameForObject(holdItemReal.getItem());
        }
        NBTHandler.flag=1;
        NBTHandler.id= EntityList.getEntityString(currentEntity);
        //currenttip.add(NBTHandler.id);
        List<String> tips = NBTHandler.getTipsFromNBT(n, holdItemNameReal);
        currenttip.addAll(tips);
    }
    return currenttip;
}
 
Example 4
Source File: MobSpawnEventHandler.java    From EnderZoo with Creative Commons Zero v1.0 Universal 6 votes vote down vote up
@SubscribeEvent
public void onCheckSpawn(CheckSpawn evt) {
  if (evt.getEntityLiving() == null) {
    return;
  }
  String name = EntityList.getEntityString(evt.getEntityLiving());
  if (name == null) {
    return;
  }
  for (ISpawnEntry ent : MobSpawns.instance.getEntries()) {
    if (name.equals(ent.getMobName())) {
      if (!ent.canSpawnInDimension(evt.getWorld())) {
        evt.setResult(Result.DENY);
      }
    }
  }

}
 
Example 5
Source File: EnchantmentEnderDamage.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onEntityDamaged(EntityLivingBase hurtEntity, Entity damagingEntity, int level) {
    String entityName = EntityList.getEntityString(hurtEntity);
    if (hurtEntity instanceof EntityEnderman || hurtEntity instanceof EntityDragon || (entityName != null && entityName.toLowerCase().contains("ender"))) {
        hurtEntity.addPotionEffect(new PotionEffect(MobEffects.WEAKNESS, level * 200, Math.max(1, (5 * level) / 7)));
        hurtEntity.addPotionEffect(new PotionEffect(MobEffects.POISON, level * 200, Math.max(1, (5 * level) / 7)));
    }
}
 
Example 6
Source File: ServerStateMachine.java    From malmo with MIT License 5 votes vote down vote up
/** Called by Forge - return ALLOW, DENY or DEFAULT to control spawning in our world.*/
@SubscribeEvent
public void onCheckSpawn(CheckSpawn cs)
{
    // Decide whether or not to allow spawning.
    // We shouldn't allow spawning unless it has been specifically turned on - whether
    // a mission is running or not. (Otherwise spawning may happen in between missions.)
    boolean allowSpawning = false;
    if (currentMissionInit() != null && currentMissionInit().getMission() != null)
    {
        // There is a mission running - does it allow spawning?
        ServerSection ss = currentMissionInit().getMission().getServerSection();
        ServerInitialConditions sic = (ss != null) ? ss.getServerInitialConditions() : null;
        if (sic != null)
            allowSpawning = (sic.isAllowSpawning() == Boolean.TRUE);

        if (allowSpawning && sic.getAllowedMobs() != null && !sic.getAllowedMobs().isEmpty())
        {
            // Spawning is allowed, but restricted to our list.
            // Is this mob on our list?
            String mobName = EntityList.getEntityString(cs.getEntity());
            allowSpawning = false;
            for (EntityTypes mob : sic.getAllowedMobs())
            {
                if (mob.value().equals(mobName))
                {
                    allowSpawning = true;
                    break;
                }
            }
        }
    }
    if (allowSpawning)
        cs.setResult(Result.DEFAULT);
    else
        cs.setResult(Result.DENY);
}
 
Example 7
Source File: ItemLivingManipulator.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
private EnumActionResult storeEntity(ItemStack containerStack, EntityLivingBase livingBase, EntityPlayer player)
{
    ItemStack moduleStack = this.getSelectedModuleStack(containerStack, ModuleType.TYPE_MEMORY_CARD_MISC);

    if (moduleStack.isEmpty() || this.canStoreEntity(livingBase) == false)
    {
        return EnumActionResult.PASS;
    }

    // Dismount the entity from its rider and the entity it's riding, if any
    livingBase.dismountRidingEntity();
    livingBase.removePassengers();

    NBTTagCompound nbtEntity = new NBTTagCompound();

    if (livingBase.writeToNBTOptional(nbtEntity) == false)
    {
        return EnumActionResult.FAIL;
    }

    String str = EntityList.getEntityString(livingBase);

    if (str != null)
    {
        nbtEntity.setString("EntityString", str);
    }

    // Store the player's yaw rotation, for applying a relative rotation to the entity's rotation upon release
    nbtEntity.setFloat("playerYaw", player.rotationYaw);

    NBTTagList tagList = NBTUtils.getTagList(moduleStack, WRAPPER_TAG_NAME, "Entities", Constants.NBT.TAG_COMPOUND, true);

    tagList = NBTUtils.insertToTagList(tagList, nbtEntity, NBTUtils.getByte(moduleStack, WRAPPER_TAG_NAME, "Current"));
    NBTUtils.setTagList(moduleStack, WRAPPER_TAG_NAME, "Entities", tagList);

    this.setSelectedModuleStack(containerStack, ModuleType.TYPE_MEMORY_CARD_MISC, moduleStack);

    livingBase.isDead = true;

    return EnumActionResult.SUCCESS;
}
 
Example 8
Source File: LocatedEntity.java    From IGW-mod with GNU General Public License v2.0 4 votes vote down vote up
@Override
public String getLinkAddress(){
    return "entity/" + EntityList.getEntityString(entity);
}