Search in sources :

Example 1 with MapData

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;
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) MapData(net.minecraft.world.storage.MapData) Vec4b(net.minecraft.util.math.Vec4b) TextComponentString(net.minecraft.util.text.TextComponentString) EntityItem(net.minecraft.entity.item.EntityItem)

Aggregations

EntityItem (net.minecraft.entity.item.EntityItem)1 Vec4b (net.minecraft.util.math.Vec4b)1 TextComponentString (net.minecraft.util.text.TextComponentString)1 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)1 MapData (net.minecraft.world.storage.MapData)1