use of net.minecraft.world.storage.MapData in project ImmersiveEngineering by BluSunrize.
the class TileEntityCoresample method interact.
@Override
public boolean interact(EnumFacing side, EntityPlayer player, EnumHand hand, ItemStack heldItem, float hitX, float hitY, float hitZ) {
if (player.isSneaking()) {
if (!getWorld().isRemote) {
EntityItem entityitem = new EntityItem(getWorld(), getPos().getX() + .5, getPos().getY() + .5, getPos().getZ() + .5, getTileDrop(player, getWorld().getBlockState(getPos())));
entityitem.setDefaultPickupDelay();
getWorld().setBlockToAir(getPos());
getWorld().spawnEntityInWorld(entityitem);
}
return true;
} else if (heldItem != null && heldItem.getItem() == Items.FILLED_MAP && ItemNBTHelper.hasKey(coresample, "coords")) {
if (!getWorld().isRemote) {
MapData mapData = ((ItemMap) heldItem.getItem()).getMapData(heldItem, player.getEntityWorld());
if (mapData != null) {
int[] coords = ItemNBTHelper.getIntArray(coresample, "coords");
String ident = "ie:coresample_" + coords[0] + ";" + coords[1] + ";" + coords[2];
if (mapData.mapDecorations.containsKey(ident)) {
mapData.mapDecorations.remove(ident);
return true;
}
double sampleX = coords[1] * 16 + 8.5;
double sampleZ = coords[2] * 16 + 8.5;
int mapScale = 1 << mapData.scale;
float distX = (float) (sampleX - mapData.xCenter) / (float) mapScale;
float distZ = (float) (sampleZ - mapData.zCenter) / (float) mapScale;
byte mapX = (byte) ((int) ((double) (distX * 2.0F) + 0.5D));
byte mapZ = (byte) ((int) ((double) (distZ * 2.0F) + 0.5D));
byte b2 = (byte) 8;
if (distX >= -63 && distX <= 63 && distZ >= -63 && distZ <= 63)
mapData.mapDecorations.put(ident, new Vec4b((byte) 5, mapX, mapZ, b2));
else
player.addChatMessage(new TextComponentTranslation(Lib.CHAT_INFO + "coresample.mapFail"));
}
}
return true;
}
return false;
}
Aggregations