Search in sources :

Example 1 with BlockTile

use of com.builtbroken.mc.prefab.tile.BlockTile in project Engine by VoltzEngine-Project.

the class TestTile method testPlacement.

public void testPlacement() {
    FakeWorld world = FakeWorld.newWorld("TileTest");
    world.setBlock(0, 0, 0, getBlock());
    Block block = world.getBlock(0, 0, 0);
    TileEntity tile = world.getTileEntity(0, 0, 0);
    assertNotNull("Test block failed to place", block);
    assertTrue("Test block did not place as an instance of BlockTile", block instanceof BlockTile);
    assertNotNull("Test block did not place with a tile", tile);
    assertTrue("Test block's tile is not an instance of Tile", tile instanceof Tile);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) FakeWorld(com.builtbroken.mc.testing.junit.world.FakeWorld) Block(net.minecraft.block.Block) BlockTile(com.builtbroken.mc.prefab.tile.BlockTile) BlockTile(com.builtbroken.mc.prefab.tile.BlockTile) Tile(com.builtbroken.mc.prefab.tile.Tile)

Example 2 with BlockTile

use of com.builtbroken.mc.prefab.tile.BlockTile in project Engine by VoltzEngine-Project.

the class CommandDebugRecipes method handleConsoleCommand.

@Override
public boolean handleConsoleCommand(ICommandSender sender, String[] args) {
    if (args != null && args.length > 0 && !"help".equalsIgnoreCase(args[0])) {
        String modID = args[0];
        if (Loader.isModLoaded(modID)) {
            sender.addChatMessage(new ChatComponentText("Checking data...."));
            List<Item> items = InventoryUtility.getItemsForMod(modID);
            if (items != null && !items.isEmpty()) {
                HashMap<Item, List<IRecipe>> itemToRecipes = new HashMap();
                sender.addChatMessage(new ChatComponentText("Found " + items.size() + " items for the mod " + modID + " moving on to processing recipes"));
                for (Item item : items) {
                    List<IRecipe> recipes = InventoryUtility.getRecipesWithOutput(item);
                    if (recipes != null && recipes.size() > 0) {
                        itemToRecipes.put(item, recipes);
                    }
                }
                sender.addChatMessage(new ChatComponentText("Mapped " + itemToRecipes.size() + " entries with recipes"));
                if (args.length == 1 || args[1].equalsIgnoreCase("conflict")) {
                    sender.addChatMessage(new ChatComponentText("Not implemented yet"));
                    return true;
                } else if (args[1].equalsIgnoreCase("missing")) {
                    //TODO add handling for subtypes
                    for (Item item : items) {
                        if (!itemToRecipes.containsKey(item)) {
                            if (item instanceof ItemBlock) {
                                Block block = ((ItemBlock) item).field_150939_a;
                                if (block instanceof BlockTile) {
                                    sender.addChatMessage(new ChatComponentText("Tile[" + ((BlockTile) block).staticTile.name + "] has no recipes for any subtype"));
                                } else {
                                    sender.addChatMessage(new ChatComponentText("Block[" + block.getLocalizedName() + "] has no recipes for any subtype"));
                                }
                            } else {
                                sender.addChatMessage(new ChatComponentText("Item[" + item.getItemStackDisplayName(new ItemStack(item)) + "] has no recipes for any subtype"));
                            }
                        }
                    }
                }
            } else {
                sender.addChatMessage(new ChatComponentText("No items are mapped for the mod[" + modID + "]"));
            }
            return true;
        } else {
            //TODO maybe show closest spelling
            sender.addChatMessage(new ChatComponentText("Failed to find mod[" + modID + "]"));
            return true;
        }
    }
    return handleHelp(sender, args);
}
Also used : HashMap(java.util.HashMap) IRecipe(net.minecraft.item.crafting.IRecipe) BlockTile(com.builtbroken.mc.prefab.tile.BlockTile) ItemBlock(net.minecraft.item.ItemBlock) Item(net.minecraft.item.Item) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) List(java.util.List) ItemStack(net.minecraft.item.ItemStack) ChatComponentText(net.minecraft.util.ChatComponentText)

Example 3 with BlockTile

use of com.builtbroken.mc.prefab.tile.BlockTile in project Engine by VoltzEngine-Project.

the class ModManager method newBlock.

/**
     * Creates a new block based on the Tile instance provided.
     * Handles most common registration and data input tasks for the creation of the block.
     * This includes registering the block, tile, built in item & tile renders. It also inits
     * the instance used for the block itself.
     *
     * @param spatial - instance of the spatial block used to provide all the data for the block
     * @param name    - name the block will use for look up map, registry, texture, etc
     */
public BlockTile newBlock(String name, Tile spatial) {
    String actual_name = name;
    debug("-----------------------------------------------------------");
    debug(" Creating new spatial block name='" + name + "'  Tile='" + spatial + "'");
    if (actual_name == null || actual_name.isEmpty()) {
        if (spatial.name != null && !spatial.name.isEmpty()) {
            actual_name = spatial.name;
        } else {
            Engine.instance.logger().warn(name() + " Tile: " + spatial + " has no defined name to register with and could cause issues with world loading. In order to prevent the game from crashing we are falling back to using the class name.");
            actual_name = LanguageUtility.decapitalizeFirst(spatial.getClass().getSimpleName().replace("Tile", ""));
        }
    }
    BlockTile block = new BlockTile(spatial, modPrefix, defaultTab);
    spatial.setBlock(block);
    block = newBlock(actual_name, block, spatial.itemBlock);
    temp_registry_list.add(spatial);
    Tile newTile = spatial.newTile();
    debug("\t NewTile='" + newTile + "'");
    if (newTile != null) {
        registerTile(actual_name, block, spatial, newTile);
    }
    debug("-----------------------------------------------------------");
    return block;
}
Also used : BlockTile(com.builtbroken.mc.prefab.tile.BlockTile) BlockTile(com.builtbroken.mc.prefab.tile.BlockTile) Tile(com.builtbroken.mc.prefab.tile.Tile)

Example 4 with BlockTile

use of com.builtbroken.mc.prefab.tile.BlockTile in project Engine by VoltzEngine-Project.

the class BlockRenderHandler method renderWorldBlock.

@Override
public boolean renderWorldBlock(IBlockAccess access, int x, int y, int z, Block block, int modelId, RenderBlocks renderBlocks) {
    /**
         * Try TileEntity rendering
         */
    TileEntity tile = access.getTileEntity(x, y, z);
    if (tile instanceof Tile) {
        if (((Tile) tile).renderStatic(renderBlocks, new Pos(x, y, z), 0)) {
            return true;
        }
    }
    /**
         * Try Block rendering
         */
    if (block instanceof BlockTile) {
        BlockTile dummy = (BlockTile) block;
        tile = dummy.inject(access, x, y, z);
        boolean b = ((Tile) tile).renderStatic(renderBlocks, new Pos(x, y, z), 0);
        dummy.eject();
        return b;
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Pos(com.builtbroken.mc.imp.transform.vector.Pos) BlockTile(com.builtbroken.mc.prefab.tile.BlockTile) Tile(com.builtbroken.mc.prefab.tile.Tile) BlockTile(com.builtbroken.mc.prefab.tile.BlockTile)

Example 5 with BlockTile

use of com.builtbroken.mc.prefab.tile.BlockTile in project Engine by VoltzEngine-Project.

the class ModManager method newBlock.

/**
     * Creates a new block based on the Tile class provided
     * Handles most common registration and data input tasks for the creation of the block.
     * This includes registering the block, tile, built in item & tile renders. It also inits
     * the instance used for the block itself.
     *
     * @param spatialClass - class that will provide all the data to be used when creating the block.
     * @param args         - arguments needed to create a new instance of the spatial class
     */
public BlockTile newBlock(String name, Class<? extends Tile> spatialClass, Object... args) {
    try {
        Tile spatial;
        if (args != null && args.length > 0) {
            List<Class> paramTypes = new ArrayList();
            for (Object arg : args) {
                paramTypes.add(arg.getClass());
            }
            spatial = spatialClass.getConstructor(paramTypes.toArray(new Class[paramTypes.size()])).newInstance();
        } else {
            spatial = spatialClass.newInstance();
        }
        return newBlock(name, spatial);
    } catch (Exception e) {
        throw new RuntimeException(name() + " Tile [" + spatialClass.getSimpleName() + "] failed to be created:", e);
    }
}
Also used : ArrayList(java.util.ArrayList) BlockTile(com.builtbroken.mc.prefab.tile.BlockTile) Tile(com.builtbroken.mc.prefab.tile.Tile) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

BlockTile (com.builtbroken.mc.prefab.tile.BlockTile)6 Tile (com.builtbroken.mc.prefab.tile.Tile)5 Block (net.minecraft.block.Block)2 ItemStack (net.minecraft.item.ItemStack)2 TileEntity (net.minecraft.tileentity.TileEntity)2 Pos (com.builtbroken.mc.imp.transform.vector.Pos)1 FakeWorld (com.builtbroken.mc.testing.junit.world.FakeWorld)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Item (net.minecraft.item.Item)1 ItemBlock (net.minecraft.item.ItemBlock)1 IRecipe (net.minecraft.item.crafting.IRecipe)1 ChatComponentText (net.minecraft.util.ChatComponentText)1