Search in sources :

Example 6 with IBlockState

use of net.minecraft.block.state.IBlockState in project malmo by Microsoft.

the class MinecraftTypeHelper method ParseItemType.

/**
     * Attempts to parse the item type string.
     * @param s The string to parse.
     * @param checkBlocks if string can't be parsed as an item, attempt to parse as a block, if checkBlocks is true
     * @return The item type, or null if the string is not recognised.
     */
public static Item ParseItemType(String s, boolean checkBlocks) {
    if (s == null)
        return null;
    // Minecraft returns null when it doesn't recognise the string
    Item item = (Item) Item.itemRegistry.getObject(new ResourceLocation(s));
    if (item == null && checkBlocks) {
        // Maybe this is a request for a block item?
        IBlockState block = MinecraftTypeHelper.ParseBlockType(s);
        item = (block != null && block.getBlock() != null) ? Item.getItemFromBlock(block.getBlock()) : null;
    }
    return item;
}
Also used : DrawItem(com.microsoft.Malmo.Schemas.DrawItem) Item(net.minecraft.item.Item) IBlockState(net.minecraft.block.state.IBlockState) ResourceLocation(net.minecraft.util.ResourceLocation)

Example 7 with IBlockState

use of net.minecraft.block.state.IBlockState in project malmo by Microsoft.

the class JSONWorldDataHelper method buildGridData.

/**
     * Build a signal for the cubic block grid centred on the player.<br>
     * Default is 3x3x4. (One cube all around the player.)<br>
     * Blocks are returned as a 1D array, in order
     * along the x, then z, then y axes.<br>
     * Data will be returned in an array called "Cells"
     * @param json a JSON object into which the info for the object under the mouse will be added.
     * @param environmentDimensions object which specifies the required dimensions of the grid to be returned.
     * @param jsonName name to use for identifying the returned JSON array.
     */
public static void buildGridData(JsonObject json, GridDimensions environmentDimensions, EntityPlayerMP player, String jsonName) {
    if (player == null || json == null)
        return;
    JsonArray arr = new JsonArray();
    BlockPos pos = new BlockPos(player.posX, player.posY, player.posZ);
    for (int y = environmentDimensions.yMin; y <= environmentDimensions.yMax; y++) {
        for (int z = environmentDimensions.zMin; z <= environmentDimensions.zMax; z++) {
            for (int x = environmentDimensions.xMin; x <= environmentDimensions.xMax; x++) {
                BlockPos p;
                if (environmentDimensions.absoluteCoords)
                    p = new BlockPos(x, y, z);
                else
                    p = pos.add(x, y, z);
                String name = "";
                IBlockState state = player.worldObj.getBlockState(p);
                Object blockName = Block.blockRegistry.getNameForObject(state.getBlock());
                if (blockName instanceof ResourceLocation) {
                    name = ((ResourceLocation) blockName).getResourcePath();
                }
                JsonElement element = new JsonPrimitive(name);
                arr.add(element);
            }
        }
    }
    json.add(jsonName, arr);
}
Also used : JsonArray(com.google.gson.JsonArray) IBlockState(net.minecraft.block.state.IBlockState) JsonPrimitive(com.google.gson.JsonPrimitive) JsonElement(com.google.gson.JsonElement) ResourceLocation(net.minecraft.util.ResourceLocation) BlockPos(net.minecraft.util.BlockPos) JsonObject(com.google.gson.JsonObject)

Example 8 with IBlockState

use of net.minecraft.block.state.IBlockState in project MinecraftForge by MinecraftForge.

the class ModelLoader method onPostBakeEvent.

/**
     * Internal, do not use.
     */
public void onPostBakeEvent(IRegistry<ModelResourceLocation, IBakedModel> modelRegistry) {
    IBakedModel missingModel = modelRegistry.getObject(MODEL_MISSING);
    Map<String, Integer> modelErrors = Maps.newHashMap();
    Set<ResourceLocation> printedBlockStateErrors = Sets.newHashSet();
    Multimap<ModelResourceLocation, IBlockState> reverseBlockMap = null;
    Multimap<ModelResourceLocation, String> reverseItemMap = null;
    if (enableVerboseMissingInfo) {
        reverseBlockMap = HashMultimap.create();
        for (Map.Entry<IBlockState, ModelResourceLocation> entry : blockModelShapes.getBlockStateMapper().putAllStateModelLocations().entrySet()) {
            reverseBlockMap.put(entry.getValue(), entry.getKey());
        }
        reverseItemMap = HashMultimap.create();
        for (Item item : GameData.getItemRegistry().typeSafeIterable()) {
            for (String s : getVariantNames(item)) {
                ModelResourceLocation memory = getInventoryVariant(s);
                reverseItemMap.put(memory, item.getRegistryName().toString());
            }
        }
    }
    for (Map.Entry<ResourceLocation, Exception> entry : loadingExceptions.entrySet()) {
        // ignoring pure ResourceLocation arguments, all things we care about pass ModelResourceLocation
        if (entry.getKey() instanceof ModelResourceLocation) {
            ModelResourceLocation location = (ModelResourceLocation) entry.getKey();
            IBakedModel model = modelRegistry.getObject(location);
            if (model == null || model == missingModel) {
                String domain = entry.getKey().getResourceDomain();
                Integer errorCountBox = modelErrors.get(domain);
                int errorCount = errorCountBox == null ? 0 : errorCountBox;
                errorCount++;
                if (errorCount < verboseMissingInfoCount) {
                    String errorMsg = "Exception loading model for variant " + entry.getKey();
                    if (enableVerboseMissingInfo) {
                        Collection<IBlockState> blocks = reverseBlockMap.get(location);
                        if (!blocks.isEmpty()) {
                            if (blocks.size() == 1) {
                                errorMsg += " for blockstate \"" + blocks.iterator().next() + "\"";
                            } else {
                                errorMsg += " for blockstates [\"" + Joiner.on("\", \"").join(blocks) + "\"]";
                            }
                        }
                        Collection<String> items = reverseItemMap.get(location);
                        if (!items.isEmpty()) {
                            if (!blocks.isEmpty())
                                errorMsg += " and";
                            if (items.size() == 1) {
                                errorMsg += " for item \"" + items.iterator().next() + "\"";
                            } else {
                                errorMsg += " for items [\"" + Joiner.on("\", \"").join(items) + "\"]";
                            }
                        }
                    }
                    if (entry.getValue() instanceof ItemLoadingException) {
                        ItemLoadingException ex = (ItemLoadingException) entry.getValue();
                        FMLLog.getLogger().error(errorMsg + ", normal location exception: ", ex.normalException);
                        FMLLog.getLogger().error(errorMsg + ", blockstate location exception: ", ex.blockstateException);
                    } else {
                        FMLLog.getLogger().error(errorMsg, entry.getValue());
                    }
                    ResourceLocation blockstateLocation = new ResourceLocation(location.getResourceDomain(), location.getResourcePath());
                    if (loadingExceptions.containsKey(blockstateLocation) && !printedBlockStateErrors.contains(blockstateLocation)) {
                        FMLLog.getLogger().error("Exception loading blockstate for the variant " + location + ": ", loadingExceptions.get(blockstateLocation));
                        printedBlockStateErrors.add(blockstateLocation);
                    }
                }
                modelErrors.put(domain, errorCount);
            }
            if (model == null) {
                modelRegistry.putObject(location, missingModel);
            }
        }
    }
    for (ModelResourceLocation missing : missingVariants) {
        IBakedModel model = modelRegistry.getObject(missing);
        if (model == null || model == missingModel) {
            String domain = missing.getResourceDomain();
            Integer errorCountBox = modelErrors.get(domain);
            int errorCount = errorCountBox == null ? 0 : errorCountBox;
            errorCount++;
            if (errorCount < verboseMissingInfoCount) {
                FMLLog.severe("Model definition for location %s not found", missing);
            }
            modelErrors.put(domain, errorCount);
        }
        if (model == null) {
            modelRegistry.putObject(missing, missingModel);
        }
    }
    for (Map.Entry<String, Integer> e : modelErrors.entrySet()) {
        if (e.getValue() >= verboseMissingInfoCount) {
            FMLLog.severe("Suppressed additional %s model loading errors for domain %s", e.getValue() - verboseMissingInfoCount, e.getKey());
        }
    }
    isLoading = false;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) MissingVariantException(net.minecraft.client.renderer.block.model.ModelBlockDefinition.MissingVariantException) Item(net.minecraft.item.Item) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ResourceLocation(net.minecraft.util.ResourceLocation) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) Map(java.util.Map) TextureMap(net.minecraft.client.renderer.texture.TextureMap) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 9 with IBlockState

use of net.minecraft.block.state.IBlockState in project MinecraftForge by MinecraftForge.

the class AnimationTESR method renderTileEntityFast.

public void renderTileEntityFast(@Nonnull T te, double x, double y, double z, float partialTick, int breakStage, @Nonnull VertexBuffer renderer) {
    if (!te.hasCapability(CapabilityAnimation.ANIMATION_CAPABILITY, null)) {
        return;
    }
    if (blockRenderer == null)
        blockRenderer = Minecraft.getMinecraft().getBlockRendererDispatcher();
    BlockPos pos = te.getPos();
    IBlockAccess world = MinecraftForgeClient.getRegionRenderCache(te.getWorld(), pos);
    IBlockState state = world.getBlockState(pos);
    if (state.getPropertyKeys().contains(Properties.StaticProperty)) {
        state = state.withProperty(Properties.StaticProperty, false);
    }
    if (state instanceof IExtendedBlockState) {
        IExtendedBlockState exState = (IExtendedBlockState) state;
        if (exState.getUnlistedNames().contains(Properties.AnimationProperty)) {
            float time = Animation.getWorldTime(getWorld(), partialTick);
            IAnimationStateMachine capability = te.getCapability(CapabilityAnimation.ANIMATION_CAPABILITY, null);
            if (capability != null) {
                Pair<IModelState, Iterable<Event>> pair = capability.apply(time);
                handleEvents(te, time, pair.getRight());
                // TODO: caching?
                IBakedModel model = blockRenderer.getBlockModelShapes().getModelForState(exState.getClean());
                exState = exState.withProperty(Properties.AnimationProperty, pair.getLeft());
                renderer.setTranslation(x - pos.getX(), y - pos.getY(), z - pos.getZ());
                blockRenderer.getBlockModelRenderer().renderModel(world, model, exState, pos, renderer, false);
            }
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) IBlockAccess(net.minecraft.world.IBlockAccess) IModelState(net.minecraftforge.common.model.IModelState) BlockPos(net.minecraft.util.math.BlockPos) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) IAnimationStateMachine(net.minecraftforge.common.model.animation.IAnimationStateMachine)

Example 10 with IBlockState

use of net.minecraft.block.state.IBlockState in project MinecraftForge by MinecraftForge.

the class BlockInfo method updateLightMatrix.

public void updateLightMatrix() {
    boolean full = false;
    for (int x = 0; x <= 2; x++) {
        for (int y = 0; y <= 2; y++) {
            for (int z = 0; z <= 2; z++) {
                BlockPos pos = blockPos.add(x - 1, y - 1, z - 1);
                IBlockState state = world.getBlockState(pos);
                translucent[x][y][z] = state.isTranslucent();
                //translucent[x][y][z] = world.getBlockState(pos).getBlock().getLightOpacity(world, pos) == 0;
                int brightness = state.getPackedLightmapCoords(world, pos);
                s[x][y][z] = (brightness >> 0x14) & 0xF;
                b[x][y][z] = (brightness >> 0x04) & 0xF;
                ao[x][y][z] = state.getAmbientOcclusionLightValue();
                if (x == 1 && y == 1 && z == 1) {
                    full = state.isFullCube();
                }
            }
        }
    }
    if (!full) {
        for (EnumFacing side : EnumFacing.values()) {
            int x = side.getFrontOffsetX() + 1;
            int y = side.getFrontOffsetY() + 1;
            int z = side.getFrontOffsetZ() + 1;
            s[x][y][z] = Math.max(s[1][1][1] - 1, s[x][y][z]);
            b[x][y][z] = Math.max(b[1][1][1] - 1, b[x][y][z]);
        }
    }
    for (int x = 0; x < 2; x++) {
        for (int y = 0; y < 2; y++) {
            for (int z = 0; z < 2; z++) {
                int x1 = x * 2;
                int y1 = y * 2;
                int z1 = z * 2;
                boolean tx = translucent[x1][1][z1] || translucent[x1][y1][1];
                skyLight[0][x][y][z] = combine(s[x1][1][1], s[x1][1][z1], s[x1][y1][1], tx ? s[x1][y1][z1] : s[x1][1][1]);
                blockLight[0][x][y][z] = combine(b[x1][1][1], b[x1][1][z1], b[x1][y1][1], tx ? b[x1][y1][z1] : b[x1][1][1]);
                boolean ty = translucent[x1][y1][1] || translucent[1][y1][z1];
                skyLight[1][x][y][z] = combine(s[1][y1][1], s[x1][y1][1], s[1][y1][z1], ty ? s[x1][y1][z1] : s[1][y1][1]);
                blockLight[1][x][y][z] = combine(b[1][y1][1], b[x1][y1][1], b[1][y1][z1], ty ? b[x1][y1][z1] : b[1][y1][1]);
                boolean tz = translucent[1][y1][z1] || translucent[x1][1][z1];
                skyLight[2][x][y][z] = combine(s[1][1][z1], s[1][y1][z1], s[x1][1][z1], tz ? s[x1][y1][z1] : s[1][1][z1]);
                blockLight[2][x][y][z] = combine(b[1][1][z1], b[1][y1][z1], b[x1][1][z1], tz ? b[x1][y1][z1] : b[1][1][z1]);
            }
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

IBlockState (net.minecraft.block.state.IBlockState)546 BlockPos (net.minecraft.util.math.BlockPos)217 Block (net.minecraft.block.Block)165 ItemStack (net.minecraft.item.ItemStack)69 TileEntity (net.minecraft.tileentity.TileEntity)65 EnumFacing (net.minecraft.util.EnumFacing)58 World (net.minecraft.world.World)36 EntityPlayer (net.minecraft.entity.player.EntityPlayer)25 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)23 Vec3d (net.minecraft.util.math.Vec3d)21 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)21 Entity (net.minecraft.entity.Entity)20 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)18 ArrayList (java.util.ArrayList)16 Random (java.util.Random)16 ResourceLocation (net.minecraft.util.ResourceLocation)16 EntityLivingBase (net.minecraft.entity.EntityLivingBase)15 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)15 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)14 RayTraceResult (net.minecraft.util.math.RayTraceResult)13