Search in sources :

Example 1 with ItemMaterial

use of pl.asie.charset.lib.material.ItemMaterial in project Charset by CharsetMC.

the class SubCommandHand method execute.

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) {
    Entity e = sender.getCommandSenderEntity();
    if (e instanceof EntityPlayer) {
        ItemStack stack = ((EntityPlayer) e).getHeldItemMainhand();
        if (stack.isEmpty()) {
            sender.sendMessage(new TextComponentString(TextFormatting.RED + "Empty hand!"));
            return;
        }
        if (args.length > 0 && "ore".equalsIgnoreCase(args[0])) {
            Collection<String> names = new ArrayList<>();
            for (int id : OreDictionary.getOreIDs(stack)) {
                String name = OreDictionary.getOreName(id);
                names.add(name);
            }
            sender.sendMessage(new TextComponentString("Ores: [" + CommandCharset.COMMAS.join(names) + "]"));
        } else if (args.length > 0 && "material".equalsIgnoreCase(args[0])) {
            ItemMaterial material = ItemMaterialRegistry.INSTANCE.getMaterialIfPresent(stack);
            if (material == null) {
                sender.sendMessage(new TextComponentString(TextFormatting.RED + "Not a material!"));
            } else {
                sender.sendMessage(new TextComponentString(TextFormatting.GREEN + material.getId()));
                sender.sendMessage(new TextComponentString("[" + CommandCharset.COMMAS.join(material.getTypes()) + "]"));
                for (Map.Entry<String, ItemMaterial> entry : material.getRelations().entrySet()) {
                    sender.sendMessage(new TextComponentString("-> " + entry.getKey() + ": " + entry.getValue().getId()));
                }
            }
        } else {
            sender.sendMessage(new TextComponentString(TextFormatting.YELLOW + stack.toString() + " " + TextFormatting.GRAY + "(" + stack.getItem().getRegistryName() + ")"));
            if (stack.hasTagCompound()) {
                sender.sendMessage(new TextComponentString(stack.getTagCompound().toString()));
            }
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) ArrayList(java.util.ArrayList) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemMaterial(pl.asie.charset.lib.material.ItemMaterial) TextComponentString(net.minecraft.util.text.TextComponentString) ItemStack(net.minecraft.item.ItemStack) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 2 with ItemMaterial

use of pl.asie.charset.lib.material.ItemMaterial in project Charset by CharsetMC.

the class ItemBlockAxle method canPlaceBlockOnSide.

@Override
@SideOnly(Side.CLIENT)
public boolean canPlaceBlockOnSide(World worldIn, BlockPos pos, EnumFacing side, EntityPlayer player, ItemStack stack) {
    Block block = worldIn.getBlockState(pos).getBlock();
    if (block == Blocks.SNOW_LAYER && block.isReplaceable(worldIn, pos)) {
        side = EnumFacing.UP;
    } else if (!block.isReplaceable(worldIn, pos)) {
        pos = pos.offset(side);
    }
    TileEntity tile = worldIn.getTileEntity(pos.offset(side.getOpposite()));
    if (tile instanceof TileAxle) {
        IBlockState state = worldIn.getBlockState(pos.offset(side.getOpposite()));
        if (state.getBlock() instanceof BlockAxle) {
            EnumFacing.Axis axis = state.getValue(Properties.AXIS);
            ItemMaterial other = ((TileAxle) tile).getMaterial();
            if (axis == side.getAxis() && other == ItemMaterialRegistry.INSTANCE.getMaterial(stack.getTagCompound(), "material", "plank")) {
            // pass
            } else {
                return false;
            }
        }
    } else if (tile != null) {
        if (tile.hasCapability(CharsetPowerMechanical.POWER_PRODUCER, side)) {
        // pass
        } else if (tile.hasCapability(CharsetPowerMechanical.POWER_CONSUMER, side)) {
        // pass
        } else {
            return false;
        }
    } else {
        return false;
    }
    return worldIn.mayPlace(this.block, pos, false, side, (Entity) null);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) Block(net.minecraft.block.Block) ItemMaterial(pl.asie.charset.lib.material.ItemMaterial) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 3 with ItemMaterial

use of pl.asie.charset.lib.material.ItemMaterial in project Charset by CharsetMC.

the class BlockStacks method getDrops.

@Override
public void getDrops(NonNullList<ItemStack> drops, IBlockAccess world, BlockPos pos, IBlockState state, @Nullable TileEntity te, int fortune, boolean silkTouch) {
    if (te instanceof TileEntityStacks) {
        TObjectIntMap<ItemMaterial> materials = new TObjectIntHashMap<>();
        for (ItemMaterial material : ((TileEntityStacks) te).stacks) {
            materials.adjustOrPutValue(material, 1, 1);
        }
        for (ItemMaterial material : materials.keySet()) {
            ItemStack stack = material.getStack();
            if (!stack.isEmpty()) {
                int count = materials.get(material);
                for (int i = 0; i < count; i += stack.getMaxStackSize()) {
                    stack = stack.copy();
                    stack.setCount(Math.min(count - i, stack.getMaxStackSize()));
                    drops.add(stack);
                }
            }
        }
    }
}
Also used : TObjectIntHashMap(gnu.trove.map.hash.TObjectIntHashMap) ItemMaterial(pl.asie.charset.lib.material.ItemMaterial) ItemStack(net.minecraft.item.ItemStack)

Example 4 with ItemMaterial

use of pl.asie.charset.lib.material.ItemMaterial in project Charset by CharsetMC.

the class RenderTileEntityStacks method getParticleTexture.

@Override
public TextureAtlasSprite getParticleTexture(IBlockState state, @Nullable EnumFacing facing) {
    TextureAtlasSprite sprite = null;
    TileEntityStacks stacks = ((IExtendedBlockState) state).getValue(BlockStacks.PROPERTY_TILE);
    if (stacks != null && !stacks.stacks.isEmpty()) {
        ItemMaterial material = stacks.stacks.get(stacks.stacks.size() - 1);
        sprite = RenderUtils.getItemSprite(material.getStack());
    }
    return sprite != null ? sprite : getParticleTexture();
}
Also used : TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) ItemMaterial(pl.asie.charset.lib.material.ItemMaterial)

Example 5 with ItemMaterial

use of pl.asie.charset.lib.material.ItemMaterial in project Charset by CharsetMC.

the class MaterialRegistry method registerTypes.

@ZenMethod
public static boolean registerTypes(IItemStack stack, String... tags) {
    ItemStack mcStack = CraftTweakerMC.getItemStack(stack);
    if (mcStack.isEmpty()) {
        return false;
    }
    CraftTweakerAPI.apply(new IAction() {

        @Override
        public void apply() {
            ItemMaterial material = ItemMaterialRegistry.INSTANCE.getOrCreateMaterial(mcStack);
            ItemMaterialRegistry.INSTANCE.registerTypes(material, tags);
        }

        @Override
        public String describe() {
            return "Registering stack " + stack + " as material with types " + JOINER.join(tags);
        }
    });
    return true;
}
Also used : IAction(crafttweaker.IAction) ItemMaterial(pl.asie.charset.lib.material.ItemMaterial) ItemStack(net.minecraft.item.ItemStack) IItemStack(crafttweaker.api.item.IItemStack) ZenMethod(stanhebben.zenscript.annotations.ZenMethod)

Aggregations

ItemMaterial (pl.asie.charset.lib.material.ItemMaterial)11 ItemStack (net.minecraft.item.ItemStack)7 ArrayList (java.util.ArrayList)3 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)2 EnumFacing (net.minecraft.util.EnumFacing)2 IExtendedBlockState (net.minecraftforge.common.property.IExtendedBlockState)2 IAction (crafttweaker.IAction)1 IItemStack (crafttweaker.api.item.IItemStack)1 TObjectIntHashMap (gnu.trove.map.hash.TObjectIntHashMap)1 Block (net.minecraft.block.Block)1 IBlockState (net.minecraft.block.state.IBlockState)1 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)1 VertexFormatElement (net.minecraft.client.renderer.vertex.VertexFormatElement)1 Entity (net.minecraft.entity.Entity)1 EntityBoat (net.minecraft.entity.item.EntityBoat)1 EntityItem (net.minecraft.entity.item.EntityItem)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 NBTTagList (net.minecraft.nbt.NBTTagList)1 TileEntity (net.minecraft.tileentity.TileEntity)1