Skip to content

Commit

Permalink
Entity observations now return unlocalised entity names to match the …
Browse files Browse the repository at this point in the history
…types.xsd
  • Loading branch information
DaveyBiggers committed Jun 13, 2017
1 parent 1f44a34 commit 6c3a7c4
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;

Expand Down Expand Up @@ -118,7 +120,7 @@ public void writeObservationsToJSON(JsonObject json, MissionInit missionInit)
jsent.addProperty("y", e.posY);
jsent.addProperty("z", e.posZ);
jsent.addProperty("pitch", e.rotationPitch);
String name = e.getName();
String name = MinecraftTypeHelper.getUnlocalisedEntityName(e);
if (e instanceof EntityItem)
{
ItemStack is = ((EntityItem)e).getEntityItem();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ else if (mop.typeOfHit == RayTraceResult.Type.ENTITY)
jsonMop.addProperty("z", entity.posZ);
jsonMop.addProperty("yaw", entity.rotationYaw);
jsonMop.addProperty("pitch", entity.rotationPitch);
String name = entity.getName();
String name = MinecraftTypeHelper.getUnlocalisedEntityName(entity);
String hitType = "entity";
if (entity instanceof EntityItem)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
import net.minecraft.block.BlockLever.EnumOrientation;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
Expand Down Expand Up @@ -578,30 +581,57 @@ static IBlockState applyColour(IBlockState state, Colour colour)
* @param facing The new direction (N/S/E/W/U/D)
* @return A new blockstate with the facing attribute edited
*/
static IBlockState applyFacing(IBlockState state, Facing facing)
{
for (IProperty prop : state.getProperties().keySet())
{
if (prop.getName().equals("facing"))
{
if(prop.getValueClass() == EnumFacing.class)
{
EnumFacing current = (EnumFacing)state.getValue(prop);
if (!current.getName().equalsIgnoreCase(facing.name()))
{
return state.withProperty(prop, EnumFacing.valueOf(facing.name()));
}
}
else if(prop.getValueClass() == EnumOrientation.class)
{
EnumOrientation current = (EnumOrientation)state.getValue(prop);
if (!current.getName().equalsIgnoreCase(facing.name()))
{
return state.withProperty(prop, EnumOrientation.valueOf(facing.name()));
}
}
}
}
return state;
}
static IBlockState applyFacing(IBlockState state, Facing facing)
{
for (IProperty prop : state.getProperties().keySet())
{
if (prop.getName().equals("facing"))
{
if (prop.getValueClass() == EnumFacing.class)
{
EnumFacing current = (EnumFacing) state.getValue(prop);
if (!current.getName().equalsIgnoreCase(facing.name()))
{
return state.withProperty(prop, EnumFacing.valueOf(facing.name()));
}
}
else if (prop.getValueClass() == EnumOrientation.class)
{
EnumOrientation current = (EnumOrientation) state.getValue(prop);
if (!current.getName().equalsIgnoreCase(facing.name()))
{
return state.withProperty(prop, EnumOrientation.valueOf(facing.name()));
}
}
}
}
return state;
}

/** 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 ent 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;
}
}

0 comments on commit 6c3a7c4

Please sign in to comment.