Jump to content

[SOLVED] [1.8.9] Model definition for location * not found


XFactHD

Recommended Posts

I have a block with two properties, one for the rotation and one to dertermine the model based on an internal state. When I load the game, I get those kinds of errors:

Model definition for location rfutilities:blockCapacitor#facing=south,type=4 not found

 

This is my block class:

package XFactHD.rfutilities.common.blocks.block;

import XFactHD.rfutilities.common.blocks.itemBlock.ItemBlockRFCapacitor;
import XFactHD.rfutilities.common.blocks.tileEntity.TileEntityCapacitor;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.block.state.BlockState;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.*;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

import java.util.Arrays;

public class BlockCapacitor extends BlockBaseRFU
{
    public static PropertyDirection ORIENTATION = PropertyDirection.create("facing", Arrays.asList(EnumFacing.NORTH, EnumFacing.EAST, EnumFacing.SOUTH, EnumFacing.WEST));
    private static PropertyInteger TYPE = PropertyInteger.create("type", 1, 7);

    public BlockCapacitor()
    {
        super("blockCapacitor", Material.iron, ItemBlockRFCapacitor.class, "");
    }

    @Override
    public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase entity, ItemStack stack)
    {
        int l = MathHelper.floor_double((double) (entity.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;

        if (l == 0)
        {
            world.setBlockState(pos, state.withProperty(ORIENTATION, EnumFacing.NORTH), 2);
        }

        if (l == 1)
        {
            world.setBlockState(pos, state.withProperty(ORIENTATION, EnumFacing.EAST), 2);
        }

        if (l == 2)
        {
            world.setBlockState(pos, state.withProperty(ORIENTATION, EnumFacing.SOUTH), 2);
        }

        if (l == 3)
        {
            world.setBlockState(pos, state.withProperty(ORIENTATION, EnumFacing.WEST), 2);
        }

        TileEntity te = world.getTileEntity(pos);
        if (entity instanceof EntityPlayer && te instanceof TileEntityCapacitor)
        {
            if ((stack.getTagCompound()) != null)
            {
                ((TileEntityCapacitor)te).type = stack.getTagCompound().getInteger("type");
                world.markBlockForUpdate(pos);
                //LogHelper.info("Type on stack: " + type + "; Type on tile: " + ((TileEntityCapacitor)world.getTileEntity(x, y, z)).type);
                te.markDirty();
            }
        }
    }

    @Override
    public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumFacing side, float hitX, float hitY, float hitZ)
    {
        TileEntity te = world.getTileEntity(pos);
        if (te instanceof TileEntityCapacitor /*&& player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() instanceof ItemMultimeter*/ && !world.isRemote)
        {
            player.addChatComponentMessage(new ChatComponentText(StatCollector.translateToLocal("desc.rfutilities:stored.name") + " " + ((TileEntityCapacitor)te).getEnergyStored(EnumFacing.DOWN) + " " + StatCollector.translateToLocal("desc.rfutilities:rf.name") + " / " + ((TileEntityCapacitor)te).getMaxEnergyStored(EnumFacing.DOWN) + " " + StatCollector.translateToLocal("desc.rfutilities:rf.name")));
            //LogHelper.info(((TileEntityCapacitor)world.getTileEntity(x, y, z)).type);
            return true;
        }
        return false;
    }

    @Override
    protected BlockState createBlockState()
    {
        return new BlockState(this, ORIENTATION, TYPE);
    }

    @Override
    public IBlockState getStateFromMeta(int meta)
    {
        if (EnumFacing.getFront(meta) == EnumFacing.UP || EnumFacing.getFront(meta) == EnumFacing.DOWN)
        {
            return getDefaultState().withProperty(ORIENTATION, EnumFacing.NORTH);
        }
        return getDefaultState().withProperty(ORIENTATION, EnumFacing.getFront(meta));
    }

    @Override
    public int getMetaFromState(IBlockState state)
    {
        return state.getValue(ORIENTATION).getIndex();
    }

    @Override
    public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos)
    {
        EnumFacing dir = state.getValue(ORIENTATION);
        TileEntity te = world.getTileEntity(pos);
        int cap = 1;
        if (te instanceof TileEntityCapacitor)
        {
            cap = ((TileEntityCapacitor)te).type;
        }
        if (cap == 0)
        {
            return state.withProperty(ORIENTATION, dir).withProperty(TYPE, 1);
        }
        return state.withProperty(ORIENTATION, dir).withProperty(TYPE, cap);
    }

    @Override
    public ItemStack getPickBlock(MovingObjectPosition target, World world, BlockPos pos, EntityPlayer player)
    {
        ItemStack stack = new ItemStack(this, 1);
        NBTTagCompound compound = new NBTTagCompound();
        compound.setInteger("TYPE", ((TileEntityCapacitor)world.getTileEntity(pos)).type);
        stack.setTagCompound(compound);
        return stack;
    }

    //I know that this is the wrong method but createTileEntity(World world, IBlockState state) is for not called for some reason, even if I do not implement ITileEntityProvider
    @Override
    public TileEntity createNewTileEntity(World world, int meta)
    {
        return new TileEntityCapacitor();
    }

    @Override
    public boolean isOpaqueCube()
    {
        return false;
    }
}

 

This is the blockstate file:

{
"variants": {
	"facing=EAST, type=1": { "model":"rfutilities:blockCapacitor", "y": 90 },
	"facing=EAST, type=2": { "model":"rfutilities:blockCapacitorHardened", "y": 90 },
	"facing=EAST, type=3": { "model":"rfutilities:blockCapacitorReinforced", "y": 90 },
	"facing=EAST, type=4": { "model":"rfutilities:blockCapacitorResonant", "y": 90 },
	"facing=EAST, type=5": { "model":"rfutilities:blockCapacitorBasic", "y": 90 },
	"facing=EAST, type=6": { "model":"rfutilities:blockCapacitorDouble", "y": 90 },
	"facing=EAST, type=7": { "model":"rfutilities:blockCapacitorOctadic", "y": 90 },

	"facing=NORTH, type=1": { "model":"rfutilities:blockCapacitor" },
	"facing=NORTH, type=2": { "model":"rfutilities:blockCapacitorHardened" },
	"facing=NORTH, type=3": { "model":"rfutilities:blockCapacitorReinforced" },
	"facing=NORTH, type=4": { "model":"rfutilities:blockCapacitorResonant" },
	"facing=NORTH, type=5": { "model":"rfutilities:blockCapacitorBasic" },
	"facing=NORTH, type=6": { "model":"rfutilities:blockCapacitorDouble" },
	"facing=NORTH, type=7": { "model":"rfutilities:blockCapacitorOctadic" },

	"facing=SOUTH, type=1": { "model":"rfutilities:blockCapacitor", "y": 180 },
	"facing=SOUTH, type=2": { "model":"rfutilities:blockCapacitorHardened", "y": 180 },
	"facing=SOUTH, type=3": { "model":"rfutilities:blockCapacitorReinforced", "y": 180 },
	"facing=SOUTH, type=4": { "model":"rfutilities:blockCapacitorResonant", "y": 180 },
	"facing=SOUTH, type=5": { "model":"rfutilities:blockCapacitorBasic", "y": 180 },
	"facing=SOUTH, type=6": { "model":"rfutilities:blockCapacitorDouble", "y": 180 },
	"facing=SOUTH, type=7": { "model":"rfutilities:blockCapacitorOctadic", "y": 180 },

	"facing=WEST, type=1": { "model":"rfutilities:blockCapacitor", "y": 270 },
	"facing=WEST, type=2": { "model":"rfutilities:blockCapacitorHardened", "y": 270 },
	"facing=WEST, type=3": { "model":"rfutilities:blockCapacitorReinforced", "y": 270 },
	"facing=WEST, type=4": { "model":"rfutilities:blockCapacitorResonant", "y": 270 },
	"facing=WEST, type=5": { "model":"rfutilities:blockCapacitorBasic", "y": 270 },
	"facing=WEST, type=6": { "model":"rfutilities:blockCapacitorDouble", "y": 270 },
	"facing=WEST, type=7": { "model":"rfutilities:blockCapacitorOctadic", "y": 270 }
}
}

 

I have already looked at some of the topics that are similar or equal to mine but the solutions provided there didn't fix it.

For example, I tried putting

sourceSets { main { output.resourcesDir = output.classesDir } }

and/or

idea { module { inheritOutputDirs = true } }

into my build.gradle

Link to comment
Share on other sites

First block:

package XFactHD.rfutilities.common.blocks.block;

import XFactHD.rfutilities.common.blocks.itemBlock.ItemBlockRFCapacitor;
import XFactHD.rfutilities.common.blocks.tileEntity.TileEntityCapacitor;
//import cofh.thermalexpansion.item.tool.ItemMultimeter;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.block.state.BlockState;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.*;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

import java.util.Arrays;

public class BlockCapacitor extends BlockBaseRFU
{
    public static PropertyDirection ORIENTATION = PropertyDirection.create("facing", Arrays.asList(EnumFacing.NORTH, EnumFacing.EAST, EnumFacing.SOUTH, EnumFacing.WEST));
    private static PropertyInteger TYPE = PropertyInteger.create("type", 1, 7);

    public BlockCapacitor()
    {
        super("blockCapacitor", Material.iron, ItemBlockRFCapacitor.class, "");
    }

    @Override
    public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase entity, ItemStack stack)
    {
        int l = MathHelper.floor_double((double) (entity.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;

        if (l == 0)
        {
            world.setBlockState(pos, state.withProperty(ORIENTATION, EnumFacing.NORTH), 2);
        }

        if (l == 1)
        {
            world.setBlockState(pos, state.withProperty(ORIENTATION, EnumFacing.EAST), 2);
        }

        if (l == 2)
        {
            world.setBlockState(pos, state.withProperty(ORIENTATION, EnumFacing.SOUTH), 2);
        }

        if (l == 3)
        {
            world.setBlockState(pos, state.withProperty(ORIENTATION, EnumFacing.WEST), 2);
        }

        TileEntity te = world.getTileEntity(pos);
        if (entity instanceof EntityPlayer && te instanceof TileEntityCapacitor)
        {
            if ((stack.getTagCompound()) != null)
            {
                ((TileEntityCapacitor)te).type = stack.getTagCompound().getInteger("type");
                world.markBlockForUpdate(pos);
                //LogHelper.info("Type on stack: " + type + "; Type on tile: " + ((TileEntityCapacitor)world.getTileEntity(x, y, z)).type);
                te.markDirty();
            }
        }
    }

    @Override
    public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumFacing side, float hitX, float hitY, float hitZ)
    {
        TileEntity te = world.getTileEntity(pos);
        if (te instanceof TileEntityCapacitor /*&& player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() instanceof ItemMultimeter*/ && !world.isRemote)
        {
            player.addChatComponentMessage(new ChatComponentText(StatCollector.translateToLocal("desc.rfutilities:stored.name") + " " + ((TileEntityCapacitor)te).getEnergyStored(EnumFacing.DOWN) + " " + StatCollector.translateToLocal("desc.rfutilities:rf.name") + " / " + ((TileEntityCapacitor)te).getMaxEnergyStored(EnumFacing.DOWN) + " " + StatCollector.translateToLocal("desc.rfutilities:rf.name")));
            //LogHelper.info(((TileEntityCapacitor)world.getTileEntity(x, y, z)).type);
            return true;
        }
        return false;
    }

    @Override
    protected BlockState createBlockState()
    {
        return new BlockState(this, ORIENTATION, TYPE);
    }

    @Override
    public IBlockState getStateFromMeta(int meta)
    {
        if (EnumFacing.getFront(meta) == EnumFacing.UP || EnumFacing.getFront(meta) == EnumFacing.DOWN)
        {
            return getDefaultState().withProperty(ORIENTATION, EnumFacing.NORTH);
        }
        return getDefaultState().withProperty(ORIENTATION, EnumFacing.getFront(meta));
    }

    @Override
    public int getMetaFromState(IBlockState state)
    {
        return state.getValue(ORIENTATION).getIndex();
    }

    @Override
    public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos)
    {
        EnumFacing dir = state.getValue(ORIENTATION);
        TileEntity te = world.getTileEntity(pos);
        int cap = 1;
        if (te instanceof TileEntityCapacitor)
        {
            cap = ((TileEntityCapacitor)te).type;
        }
        if (cap == 0)
        {
            return state.withProperty(ORIENTATION, dir).withProperty(TYPE, 1);
        }
        return state.withProperty(ORIENTATION, dir).withProperty(TYPE, cap);
    }

    @Override
    public ItemStack getPickBlock(MovingObjectPosition target, World world, BlockPos pos, EntityPlayer player)
    {
        ItemStack stack = new ItemStack(this, 1);
        NBTTagCompound compound = new NBTTagCompound();
        compound.setInteger("TYPE", ((TileEntityCapacitor)world.getTileEntity(pos)).type);
        stack.setTagCompound(compound);
        return stack;
    }

    @Override
    public TileEntity createNewTileEntity(World world, int meta)
    {
        return new TileEntityCapacitor();
    }

    @Override
    public boolean isOpaqueCube()
    {
        return false;
    }
}

 

First blockstate file (file name: blockCapacitor.json):

{
"variants": {
	"facing=east, type=1": { "model":"rfutilities:blockCapacitor", "y": 90 },
	"facing=east, type=2": { "model":"rfutilities:blockCapacitorHardened", "y": 90 },
	"facing=east, type=3": { "model":"rfutilities:blockCapacitorReinforced", "y": 90 },
	"facing=east, type=4": { "model":"rfutilities:blockCapacitorResonant", "y": 90 },
	"facing=east, type=5": { "model":"rfutilities:blockCapacitorBasic", "y": 90 },
	"facing=east, type=6": { "model":"rfutilities:blockCapacitorDouble", "y": 90 },
	"facing=east, type=7": { "model":"rfutilities:blockCapacitorOctadic", "y": 90 },

	"facing=north, type=1": { "model":"rfutilities:blockCapacitor" },
	"facing=north, type=2": { "model":"rfutilities:blockCapacitorHardened" },
	"facing=north, type=3": { "model":"rfutilities:blockCapacitorReinforced" },
	"facing=north, type=4": { "model":"rfutilities:blockCapacitorResonant" },
	"facing=north, type=5": { "model":"rfutilities:blockCapacitorBasic" },
	"facing=north, type=6": { "model":"rfutilities:blockCapacitorDouble" },
	"facing=north, type=7": { "model":"rfutilities:blockCapacitorOctadic" },

	"facing=south, type=1": { "model":"rfutilities:blockCapacitor", "y": 180 },
	"facing=south, type=2": { "model":"rfutilities:blockCapacitorHardened", "y": 180 },
	"facing=south, type=3": { "model":"rfutilities:blockCapacitorReinforced", "y": 180 },
	"facing=south, type=4": { "model":"rfutilities:blockCapacitorResonant", "y": 180 },
	"facing=south, type=5": { "model":"rfutilities:blockCapacitorBasic", "y": 180 },
	"facing=south, type=6": { "model":"rfutilities:blockCapacitorDouble", "y": 180 },
	"facing=south, type=7": { "model":"rfutilities:blockCapacitorOctadic", "y": 180 },

	"facing=west, type=1": { "model":"rfutilities:blockCapacitor", "y": 270 },
	"facing=west, type=2": { "model":"rfutilities:blockCapacitorHardened", "y": 270 },
	"facing=west, type=3": { "model":"rfutilities:blockCapacitorReinforced", "y": 270 },
	"facing=west, type=4": { "model":"rfutilities:blockCapacitorResonant", "y": 270 },
	"facing=west, type=5": { "model":"rfutilities:blockCapacitorBasic", "y": 270 },
	"facing=west, type=6": { "model":"rfutilities:blockCapacitorDouble", "y": 270 },
	"facing=west, type=7": { "model":"rfutilities:blockCapacitorOctadic", "y": 270 }
}
}

 

One of the associated models (file name: blockCapacitor.json):

{
    "textures": {
        "0": "blocks/stone_slab_top",
        "1": "rfutilities:blocks/capacitor"
    },
    "elements": [
        {
            "name": "Base",
            "from": [ 0.0, 0.0, 0.0 ], 
            "to": [ 16.0, 1.0, 16.0 ], 
            "faces": {
                "north": { "texture": "#0", "uv": [ 0.0, 0.0, 16.0, 1.0 ] },
                "east": { "texture": "#0", "uv": [ 0.0, 0.0, 16.0, 1.0 ] },
                "south": { "texture": "#0", "uv": [ 0.0, 0.0, 16.0, 1.0 ] },
                "west": { "texture": "#0", "uv": [ 0.0, 0.0, 16.0, 1.0 ] },
                "up": { "texture": "#0", "uv": [ 0.0, 0.0, 16.0, 16.0 ] },
                "down": { "texture": "#0", "uv": [ 0.0, 0.0, 16.0, 16.0 ] }
            }
        },
        {
            "name": "ConnectorLeft",
            "from": [ 0.0, 1.0, 5.0 ], 
            "to": [ 1.0, 7.0, 11.0 ], 
            "faces": {
                "north": { "texture": "#1", "uv": [ 4.299999999999999, 4.499999999999998, 4.500000000000002, 6.0 ] },
                "east": { "texture": "#1", "uv": [ 7.800000000000001, 4.500000000000002, 9.2, 6.0 ] },
                "south": { "texture": "#1", "uv": [ 4.299999999999999, 4.499999999999998, 4.500000000000002, 6.0 ] },
                "west": { "texture": "#1", "uv": [ 4.299999999999999, 4.499999999999998, 5.700000000000001, 6.0 ] },
                "up": { "texture": "#1", "uv": [ 4.299999999999999, 4.499999999999998, 4.499999999999998, 6.0 ] }
            }
        },
        {
            "name": "ConnectorRight",
            "from": [ 15.0, 1.0, 5.0 ], 
            "to": [ 16.0, 7.0, 11.0 ], 
            "faces": {
                "north": { "texture": "#1", "uv": [ 4.299999999999999, 4.499999999999998, 4.500000000000002, 6.0 ] },
                "east": { "texture": "#1", "uv": [ 6.0, 4.499999999999998, 7.500000000000002, 6.0 ] },
                "south": { "texture": "#1", "uv": [ 4.299999999999999, 4.499999999999998, 4.500000000000002, 6.0 ] },
                "west": { "texture": "#1", "uv": [ 7.800000000000001, 4.500000000000002, 9.199999999999996, 6.0 ] },
                "up": { "texture": "#1", "uv": [ 4.299999999999999, 4.499999999999998, 4.500000000000002, 6.0 ] }
            }
        },
        {
            "name": "WireLeft",
            "from": [ 1.0, 3.0, 7.0 ], 
            "to": [ 7.0, 5.0, 9.0 ], 
            "faces": {
                "north": { "texture": "#1", "uv": [ 0.0, 7.0, 4.0, 8.0 ] },
                "east": { "texture": "#1", "uv": [ 0.0, 7.0, 1.0, 8.0 ] },
                "south": { "texture": "#1", "uv": [ 0.0, 7.0, 4.0, 8.0 ] },
                "up": { "texture": "#1", "uv": [ 0.0, 7.0, 4.0, 8.0 ] },
                "down": { "texture": "#1", "uv": [ 0.0, 7.0, 4.0, 8.0 ] }
            }
        },
        {
            "name": "WireRight",
            "from": [ 9.0, 3.0, 7.0 ], 
            "to": [ 15.0, 5.0, 9.0 ], 
            "faces": {
                "north": { "texture": "#1", "uv": [ 0.0, 7.0, 4.0, 8.0 ] },
                "south": { "texture": "#1", "uv": [ 0.0, 7.0, 4.0, 8.0 ] },
                "west": { "texture": "#1", "uv": [ 0.0, 7.0, 1.0, 8.0 ] },
                "up": { "texture": "#1", "uv": [ 0.0, 7.0, 4.0, 8.0 ] },
                "down": { "texture": "#1", "uv": [ 0.0, 7.0, 4.0, 8.0 ] }
            }
        },
        {
            "name": "WireLeftVert",
            "from": [ 5.0, 5.0, 7.0 ], 
            "to": [ 7.0, 6.0, 9.0 ], 
            "faces": {
                "north": { "texture": "#1", "uv": [ 0.0, 7.0, 2.0, 7.499999999999998 ] },
                "east": { "texture": "#1", "uv": [ 0.0, 7.0, 2.0, 7.499999999999998 ] },
                "south": { "texture": "#1", "uv": [ 0.0, 7.0, 2.0, 7.499999999999998 ] },
                "west": { "texture": "#1", "uv": [ 0.0, 7.0, 2.0, 7.499999999999998 ] }
            }
        },
        {
            "name": "WireRightVert",
            "from": [ 9.0, 5.0, 7.0 ], 
            "to": [ 11.0, 6.0, 9.0 ], 
            "faces": {
                "north": { "texture": "#1", "uv": [ 0.0, 7.0, 2.0, 7.500000000000002 ] },
                "east": { "texture": "#1", "uv": [ 0.0, 7.0, 2.0, 7.499999999999998 ] },
                "south": { "texture": "#1", "uv": [ 0.0, 7.0, 2.0, 7.499999999999999 ] },
                "west": { "texture": "#1", "uv": [ 0.0, 7.0, 2.0, 7.499999999999998 ] }
            }
        },
        {
            "name": "Capacitor",
            "from": [ 4.0, 6.0, 4.0 ], 
            "to": [ 12.0, 18.0, 12.0 ], 
            "faces": {
                "north": { "texture": "#1", "uv": [ 2.0, 2.0, 4.0, 5.0 ] },
                "east": { "texture": "#1", "uv": [ 2.0, 2.0, 4.0, 5.0 ] },
                "south": { "texture": "#1", "uv": [ 0.0, 2.0, 2.0, 5.0 ] },
                "west": { "texture": "#1", "uv": [ 2.0, 2.0, 4.0, 5.0 ] },
                "up": { "texture": "#1", "uv": [ 0.0, 0.0, 2.0, 2.0 ] },
                "down": { "texture": "#1", "uv": [ 2.0, 0.0, 4.0, 2.0 ] }
            }
        }
    ]
}

 

Second block:

package XFactHD.rfutilities.common.blocks.block;

import XFactHD.rfutilities.common.blocks.tileEntity.TileEntitySwitch;
//import cofh.thermalexpansion.item.tool.ItemWrench;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.BlockState;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

import java.util.Arrays;

public class BlockSwitch extends BlockBaseRFU
{
    public static PropertyDirection facing = PropertyDirection.create("facing", Arrays.asList(EnumFacing.NORTH, EnumFacing.EAST, EnumFacing.SOUTH, EnumFacing.WEST));
    private static PropertyBool status = PropertyBool.create("status");

    public BlockSwitch()
    {
        super("blockSwitch", Material.iron, ItemBlock.class, "");
        //setCreativeTab(RFUtilities.creativeTab);
    }

    @Override
    protected BlockState createBlockState()
    {
        return new BlockState(this, facing, status);
    }

    @Override
    public IBlockState getStateFromMeta(int meta)
    {
        EnumFacing f;
        switch (meta)
        {
            case 0: f = EnumFacing.NORTH; break;
            case 1: f = EnumFacing.SOUTH; break;
            case 2: f = EnumFacing.WEST; break;
            case 3: f = EnumFacing.EAST; break;
            default: return super.getStateFromMeta(meta);
        }
        return getDefaultState().withProperty(facing, f);
    }

    @Override
    public int getMetaFromState(IBlockState state)
    {
        return state.getValue(facing).getIndex();
    }

    @Override
    public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos)
    {
        EnumFacing dir = state.getValue(facing);
        TileEntity te = world.getTileEntity(pos);
        boolean on = false;
        if (te instanceof TileEntitySwitch)
        {
            on = ((TileEntitySwitch)te).getIsOn();
        }
        return state.withProperty(facing, dir).withProperty(status, on);
    }

    @Override
    public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase entityLivingBase, ItemStack stack)
    {
        int l = MathHelper.floor_double((double) (entityLivingBase.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;

        if (l == 0)
        {
            world.setBlockState(pos, state.withProperty(facing, EnumFacing.NORTH), 2);
        }

        if (l == 1)
        {
            world.setBlockState(pos, state.withProperty(facing, EnumFacing.EAST), 2);
        }

        if (l == 2)
        {
            world.setBlockState(pos, state.withProperty(facing, EnumFacing.SOUTH), 2);
        }

        if (l == 3)
        {
            world.setBlockState(pos, state.withProperty(facing, EnumFacing.WEST), 2);
        }
    }

    @Override
    public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumFacing side, float hitX, float hitY, float hitZ)
    {
        if (player.getCurrentEquippedItem() == null /*|| !(player.getCurrentEquippedItem().getItem() instanceof ItemWrench)*/)
        {
            TileEntity te = world.getTileEntity(pos);
            if (te instanceof TileEntitySwitch)
            {
                ((TileEntitySwitch)te).setIsOn(!((TileEntitySwitch)te).getIsOn());
                world.markBlockForUpdate(pos);
                if (world.isRemote)
                {
                    world.markBlockRangeForRenderUpdate(pos.add(-1, -1, -1), pos.add(1, 1, 1));
                }
            }
        }
        return true;
    }

    @Override
    public TileEntity createNewTileEntity(World world, int meta)
    {
        return new TileEntitySwitch();
    }

    @Override
    public boolean isOpaqueCube()
    {
        return false;
    }
}

 

Second blockstate file (file name:blockSwitch.json):

{
"variants": {
	"facing=north, status=false": { "model": "rfutilities:blockSwitchOff" },
	"facing=north, status=true": { "model": "rfutilities:blockSwitchOn" },

	"facing=east, status=false": { "model": "rfutilities:blockSwitchOff", "y": 90 },
	"facing=east, status=true": { "model": "rfutilities:blockSwitchOn", "y": 90 },

	"facing=south, status=false": { "model": "rfutilities:blockSwitchOff", "y": 180 },
	"facing=south, status=true": { "model": "rfutilities:blockSwitchOn", "y": 180 },

	"facing=west, status=false": { "model": "rfutilities:blockSwitchOff", "y": 270 },
	"facing=west, status=true": { "model": "rfutilities:blockSwitchOn", "y": 270 }
}
}

 

One of the associated models (file name: blockSwitchOff.json):

{
    "textures": {
        "0": "blocks/stone_slab_top",
        "1": "blocks/switch",
        "2": "blocks/cauldron_side"
    },
    "elements": [
        {
            "name": "Base",
            "from": [ 0.0, 0.0, 0.0 ], 
            "to": [ 16.0, 1.0, 16.0 ], 
            "faces": {
                "north": { "texture": "#0", "uv": [ 0.0, 0.0, 16.0, 1.0 ] },
                "east": { "texture": "#0", "uv": [ 0.0, 0.0, 16.0, 1.0 ] },
                "south": { "texture": "#0", "uv": [ 0.0, 0.0, 16.0, 1.0 ] },
                "west": { "texture": "#0", "uv": [ 0.0, 0.0, 16.0, 1.0 ] },
                "up": { "texture": "#0", "uv": [ 0.0, 0.0, 16.0, 16.0 ] },
                "down": { "texture": "#0", "uv": [ 0.0, 0.0, 16.0, 16.0 ] }
            }
        },
        {
            "name": "ConnectorLeft",
            "from": [ 0.0, 1.0, 5.0 ], 
            "to": [ 1.0, 7.0, 11.0 ], 
            "faces": {
                "north": { "texture": "#1", "uv": [ 0.0, 7.0, 1.0, 10.0 ] },
                "east": { "texture": "#1", "uv": [ 0.0, 7.0, 6.0, 10.0 ] },
                "south": { "texture": "#1", "uv": [ 0.0, 7.0, 1.0, 10.0 ] },
                "west": { "texture": "#1", "uv": [ 0.0, 7.0, 6.0, 10.0 ] },
                "up": { "texture": "#1", "uv": [ 0.0, 7.0, 1.0, 10.0 ] }
            }
        },
        {
            "name": "ConnectorRight",
            "from": [ 15.0, 1.0, 5.0 ], 
            "to": [ 16.0, 7.0, 11.0 ], 
            "faces": {
                "north": { "texture": "#1", "uv": [ 0.0, 7.0, 1.0, 10.0 ] },
                "east": { "texture": "#1", "uv": [ 0.0, 7.0, 6.0, 10.0 ] },
                "south": { "texture": "#1", "uv": [ 0.0, 7.0, 1.0, 10.0 ] },
                "west": { "texture": "#1", "uv": [ 0.0, 7.0, 6.0, 10.0 ] },
                "up": { "texture": "#1", "uv": [ 0.0, 7.0, 1.0, 10.0 ] }
            }
        },
        {
            "name": "WireLeft",
            "from": [ 1.0, 3.0, 7.0 ], 
            "to": [ 2.0, 5.0, 9.0 ], 
            "faces": {
                "north": { "texture": "#1", "uv": [ 0.0, 0.0, 1.0, 2.0 ] },
                "east": { "texture": "#1", "uv": [ 0.0, 0.0, 2.0, 2.0 ] },
                "south": { "texture": "#1", "uv": [ 0.0, 0.0, 1.0, 2.0 ] },
                "west": { "texture": "#1", "uv": [ 0.0, 0.0, 2.0, 2.0 ] },
                "up": { "texture": "#1", "uv": [ 0.0, 0.0, 1.0, 2.0 ] },
                "down": { "texture": "#1", "uv": [ 0.0, 0.0, 1.0, 2.0 ] }
            }
        },
        {
            "name": "WireRight",
            "from": [ 14.0, 3.0, 7.0 ], 
            "to": [ 15.0, 5.0, 9.0 ], 
            "faces": {
                "north": { "texture": "#1", "uv": [ 0.0, 0.0, 1.0, 2.0 ] },
                "east": { "texture": "#1", "uv": [ 0.0, 0.0, 2.0, 2.0 ] },
                "south": { "texture": "#1", "uv": [ 0.0, 0.0, 1.0, 2.0 ] },
                "west": { "texture": "#1", "uv": [ 0.0, 0.0, 2.0, 2.0 ] },
                "up": { "texture": "#1", "uv": [ 0.0, 0.0, 1.0, 2.0 ] },
                "down": { "texture": "#1", "uv": [ 0.0, 0.0, 1.0, 2.0 ] }
            }
        },
        {
            "name": "SwitchCase",
            "from": [ 2.0, 2.0, 5.0 ], 
            "to": [ 14.0, 8.0, 11.0 ], 
            "faces": {
                "north": { "texture": "#2", "uv": [ 2.0, 0.0, 14.0, 6.0 ] },
                "east": { "texture": "#2", "uv": [ 5.0, 0.0, 11.0, 6.0 ] },
                "south": { "texture": "#2", "uv": [ 2.0, 0.0, 14.0, 6.0 ] },
                "west": { "texture": "#2", "uv": [ 5.0, 0.0, 11.0, 6.0 ] },
                "up": { "texture": "#2", "uv": [ 2.0, 0.0, 14.0, 6.0 ] },
                "down": { "texture": "#2", "uv": [ 2.0, 0.0, 14.0, 6.0 ] }
            }
        },
        {
            "name": "LightFront",
            "from": [ 7.0, 4.0, 11.0 ], 
            "to": [ 9.0, 6.0, 12.0 ], 
            "faces": {
                "east": { "texture": "#1", "uv": [ 0.0, 3.0, 1.0, 4.0 ] },
                "south": { "texture": "#1", "uv": [ 0.0, 3.0, 1.0, 4.0 ] },
                "west": { "texture": "#1", "uv": [ 0.0, 3.0, 1.0, 4.0 ] },
                "up": { "texture": "#1", "uv": [ 0.0, 3.0, 1.0, 4.0 ] },
                "down": { "texture": "#1", "uv": [ 0.0, 3.0, 1.0, 4.0 ] }
            }
        },
        {
            "name": "LightBack",
            "from": [ 7.0, 4.0, 4.0 ], 
            "to": [ 9.0, 6.0, 5.0 ], 
            "faces": {
                "north": { "texture": "#1", "uv": [ 0.0, 3.0, 1.0, 4.0 ] },
                "east": { "texture": "#1", "uv": [ 0.0, 3.0, 1.0, 4.0 ] },
                "west": { "texture": "#1", "uv": [ 0.0, 3.0, 1.0, 4.0 ] },
                "up": { "texture": "#1", "uv": [ 0.0, 3.0, 1.0, 4.0 ] },
                "down": { "texture": "#1", "uv": [ 0.0, 3.0, 1.0, 4.0 ] }
            }
        },
        {
            "name": "SwitchLeft",
            "from": [ 4.500000007450581, 5.499999992549419, 6.0 ], 
            "to": [ 8.50000000745058, 8.49999999254942, 10.0 ], 
            "rotation": { "origin": [ 8.0, 8.0, 8.0 ], "axis": "z", "angle": -22.5 },
            "faces": {
                "north": { "texture": "#1", "uv": [ 5.0, 4.0, 8.0, 6.0 ] },
                "south": { "texture": "#1", "uv": [ 5.0, 4.0, 6.0, 6.0 ], "rotation": 180 },
                "west": { "texture": "#1", "uv": [ 5.0, 4.0, 8.0, 6.0 ] },
                "up": { "texture": "#1", "uv": [ 0.0, 4.500000000000002, 4.500000000000002, 6.500000000000002 ] }
            }
        },
        {
            "name": "SwitchRight",
            "from": [ 8.000000014901161, 5.499999992549419, 6.0 ], 
            "to": [ 12.000000014901161, 8.49999999254942, 10.0 ], 
            "faces": {
                "north": { "texture": "#1", "uv": [ 5.0, 4.0, 8.0, 6.0 ] },
                "east": { "texture": "#1", "uv": [ 5.0, 4.0, 8.0, 6.0 ] },
                "south": { "texture": "#1", "uv": [ 5.0, 4.0, 8.0, 6.0 ] },
                "up": { "texture": "#1", "uv": [ 0.0, 4.499999999999998, 4.000000000000002, 6.499999999999998 ] }
            }
        }
    ]
}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.