Jump to content

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


Recommended Posts

Posted

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

Posted

Yep, that was the problem and if I think about it again, it makes sense because toString() gives a lowercase String back :-[.

Posted

Ok, it seems to not have solved it. For two blocks, it tells me, the same thing again although the syntax and all the references of filenames are correct. I am pretty much at the end of my ideas right now.

Posted

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 ] }
            }
        }
    ]
}

Posted

I just realized that while looking at it again. I didn't read your comment attentive enough and thought that I should remove all the spaces... :-[

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Honestly, the forums are a back burner thing. Not many people use it. Best option is discord. I know that I haven't looked at the forums for more then admin tasks in quite a while. You're also best off not following tutorials which give you code. Knowing programming and reading the MC/Forge code yourself would be the best way to go.
    • on my last computer, i had a similar problem with forge/ neoforge mods but instead them launcher screen was black
    • I am trying to make a mod, all it is, a config folder that tells another mod to not require a dependency, pretty simple right.. well, I dont want whoever downloads my mod to have to download 4 other mods and then decide if they want 2 more that they kinda really need.. i want to make my mod basically implement all of these mods, i really dont care how it does it, ive tried putting them in every file location you can think of, ive downloaded intellij, mcreator, and tried vmware but thats eh (had it from school). I downloaded them in hopes theyd create the correct file i needed but honestly im only more lost now. I have gotten my config file to work, if i put all these mods into my own mods folder and the config file into the config and it works (unvbelievably) but i want to share this to everyone else, lets just say this mod will legitimately get 7M downloads.  I tried putting them in a run folder then having it create all the contents in that for a game (mods,config..etc) then i drop the mods in and all the sudden i cant even open the game, like it literally works with my own world i play on, but i cant get it to work on any coding platform, they all have like built in java versions you cant switch, its a nightmare. I am on 1.20.1 I need Java 17 (i dont think the specific versions of 17 matter) I have even tried recreating the mods i want to implement and deleting import things like net.adamsandler.themodsname and replacing it with what mine is. that only creates other problems, where im at right now is i got the thing to start opening then it crashes, closest ive gotten it, then it just says this  exception in thread "main" cpw.mods.niofs.union.unionfilesystem$uncheckedioexception: java.util.zip.zipexception: zip end header not found caused by: java.util.zip.zipexception: zip end header not found basically saying theres something wrong with my java.exe file, so i tried downloading so many different versions of java and putting them all in so many different spots, nothing, someone online says its just a mod that isnt built right so i put the mod into an editor and bunch of errors came up, id post it but i deleted it on accident, i just need help integrating mods
    • Vanilla 1.16.5 Crash Report [#L2KYKaK] - mclo.gs  
    • Hello, probably the last update, if anyone has the same problem or this can be of any help, the answer was pretty simple, textures started rendering just using a Tesselator instead of a VertexConsumer given by a MultibufferSource and a RenderType, pretty simple
  • Topics

×
×
  • Create New...

Important Information

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