замена блока не работает

Версия Minecraft
1.12.2
API
Forge
51
8
5
Когда я пытаюсь заменить блок с сохранением ротации у меня ничего не происходит, вот что пишет в логах
Java:
Caused by: java.lang.IllegalArgumentException: Cannot get property PropertyDirection{name=facing, clazz=class net.minecraft.util.EnumFacing, values=[down, up, north, south, west, east]} as it does not exist in BlockStateContainer{block=fpa:endo_level_two, properties=[facing, level]}

вот класс в котором происходит замена (смотрите метод onBlockActivated)

Java:
package com.fpa.block;

import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.client.event.ModelRegistryEvent;

import net.minecraft.world.World;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.Rotation;
import net.minecraft.util.NonNullList;
import net.minecraft.util.Mirror;
import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.tileentity.TileEntityLockableLoot;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
import net.minecraft.network.NetworkManager;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.Item;
import net.minecraft.inventory.ItemStackHelper;
import net.minecraft.inventory.ContainerChest;
import net.minecraft.inventory.Container;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.block.state.IBlockState;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.material.Material;
import net.minecraft.block.SoundType;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.BlockHorizontal;
import net.minecraft.block.Block;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.ResourceLocation;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.world.IBlockAccess;
import net.minecraft.block.state.BlockStateContainer;
import com.fpa.block.EndoShiftController;
import com.fpa.ElementsFPA;

import java.util.Map;
import java.util.HashMap;

@ElementsFPA.ModElement.Tag
public class endo_level_two extends ElementsFPA.ModElement {
    @GameRegistry.ObjectHolder("fpa:endo_level_two")
    public static final Block block = null;

    public endo_level_two(ElementsFPA instance) {
        super(instance, 1);
    }

    @Override
    public void initElements() {
        elements.blocks.add(() -> new BlockCustom().setRegistryName("endo_level_two"));
        elements.items.add(() -> new ItemBlock(block).setRegistryName(block.getRegistryName()));
    }

    @Override
    public void init(FMLInitializationEvent event) {
        GameRegistry.registerTileEntity(TileEntityCustom.class, "fpa:tileentityendo_level_two");
    }

    @SideOnly(Side.CLIENT)
    @Override
    public void registerModels(ModelRegistryEvent event) {
        ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), 0,
                new ModelResourceLocation("fpa:endo_null_chestplate", "inventory"));
    }

    public static class BlockCustom extends Block implements ITileEntityProvider {
        public static final PropertyDirection FACING = BlockHorizontal.FACING;
        public static final PropertyBool LEVEL = PropertyBool.create("level");

        public BlockCustom() {
            super(Material.ROCK);
            setUnlocalizedName("endo_level_two");
            setSoundType(SoundType.METAL);
            setHardness(22F);
            setResistance(10F);
            setLightLevel(0F);
            setLightOpacity(0);
            setCreativeTab(null);
            setDefaultState(this.blockState.getBaseState()
                    .withProperty(FACING, EnumFacing.NORTH)
                    .withProperty(LEVEL, false));
        }

        @SideOnly(Side.CLIENT)
        @Override
        public BlockRenderLayer getBlockLayer() {
            return BlockRenderLayer.CUTOUT_MIPPED;
        }

        @Override
        public boolean isFullCube(IBlockState state) {
            return false;
        }

        @Override
        public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
            return state.getValue(LEVEL) ? FULL_BLOCK_AABB : new AxisAlignedBB(0, 0, 0, 1, 0.5, 1);
        }

        @Override
        protected BlockStateContainer createBlockState() {
            return new BlockStateContainer(this, FACING, LEVEL);
        }

        @Override
        public IBlockState withRotation(IBlockState state, Rotation rot) {
            return state.withProperty(FACING, rot.rotate(state.getValue(FACING)));
        }

        @Override
        public IBlockState withMirror(IBlockState state, Mirror mirrorIn) {
            return state.withRotation(mirrorIn.toRotation(state.getValue(FACING)));
        }

        @Override
        public IBlockState getStateFromMeta(int meta) {
            EnumFacing facing = EnumFacing.getHorizontal(meta & 3);
            boolean level = (meta & 8) != 0;
            return this.getDefaultState().withProperty(FACING, facing).withProperty(LEVEL, level);
        }

        @Override
        public int getMetaFromState(IBlockState state) {
            int meta = state.getValue(FACING).getHorizontalIndex();
            if (state.getValue(LEVEL)) {
                meta |= 8;
            }
            return meta;
        }

        @Override
        public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta,
                                                EntityLivingBase placer) {
            return getDefaultState()
                    .withProperty(FACING, placer.getHorizontalFacing().getOpposite())
                    .withProperty(LEVEL, false);
        }

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

        @Override
        public void getDrops(NonNullList<ItemStack> drops, IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {
        }

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

        @Override
        public boolean eventReceived(IBlockState state, World worldIn, BlockPos pos, int eventID, int eventParam) {
            super.eventReceived(state, worldIn, pos, eventID, eventParam);
            TileEntity tileentity = worldIn.getTileEntity(pos);
            return tileentity != null && tileentity.receiveClientEvent(eventID, eventParam);
        }

        @Override
        public EnumBlockRenderType getRenderType(IBlockState state) {
            if (state.getValue(LEVEL)) {
                return EnumBlockRenderType.INVISIBLE;
            }
            return EnumBlockRenderType.MODEL;
        }

        @Override
        public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing direction,
                                        float hitX, float hitY, float hitZ) {
            if (hand != EnumHand.MAIN_HAND) return false;

            ItemStack heldItem = player.getHeldItem(hand);
            if (world.isRemote) return true;

            if (player.isSneaking()) {
                Map<String, Object> dependencies = new HashMap<>();
                dependencies.put("world", world);
                dependencies.put("entity", player);
                dependencies.put("x", pos.getX());
                dependencies.put("y", pos.getY());
                dependencies.put("z", pos.getZ());

                EndoShiftController.executeProcedure(dependencies);
                return true;
            }

            if (heldItem.getItem() == Item.getByNameOrId("fpa:endo_helmet") && !state.getValue(LEVEL)) {
                world.setBlockState(pos, state.withProperty(LEVEL, true), 2);

                EnumFacing currentFacing = state.getValue(BlockCustomBase.FACING);
                IBlockState newState = Block.getBlockFromName("fpa:endo_null_full").getDefaultState()
                        .withProperty(EndoNullFull.BlockCustom.FACING, currentFacing);
                world.setBlockState(pos.down(), newState, 2);

                if (!player.capabilities.isCreativeMode) {
                    heldItem.shrink(1);
                }
                world.playSound(null, pos, net.minecraft.util.SoundEvent.REGISTRY.getObject(new ResourceLocation("fpa:endo_click")),
                        SoundCategory.BLOCKS, 1, 1);
                return true;
            }

            if (heldItem.isEmpty()) {
                if (state.getValue(LEVEL)) {
                    IBlockState newState = Block.getBlockFromName("fpa:endo_level_one").getDefaultState()
                            .withProperty(FACING, state.getValue(FACING));
                    world.setBlockState(pos.down(), newState, 1);
                    world.setBlockState(pos, state.withProperty(LEVEL, false), 2);
                    player.setHeldItem(hand, new ItemStack(Item.getByNameOrId("fpa:endo_helmet")));
                } else {
                    world.setBlockToAir(pos);
                    player.setHeldItem(hand, new ItemStack(Item.getByNameOrId("fpa:endo_chestplate")));
                }
                world.playSound(null, pos, net.minecraft.util.SoundEvent.REGISTRY.getObject(new ResourceLocation("fpa:endo_click")),
                        SoundCategory.BLOCKS, 1, 1);
                return true;
            }
            return false;
        }
    }

    public static class TileEntityCustom extends TileEntityLockableLoot {
        private NonNullList<ItemStack> stacks = NonNullList.<ItemStack>withSize(10, ItemStack.EMPTY);

        @Override
        public int getSizeInventory() {
            return 10;
        }

        @Override
        public boolean isEmpty() {
            for (ItemStack itemstack : this.stacks) {
                if (!itemstack.isEmpty()) {
                    return false;
                }
            }
            return true;
        }

        @Override
        public boolean isItemValidForSlot(int index, ItemStack stack) {
            return true;
        }

        @Override
        public ItemStack getStackInSlot(int slot) {
            return stacks.get(slot);
        }

        @Override
        public String getName() {
            return "container.endo_level_two";
        }

        @Override
        public void readFromNBT(NBTTagCompound compound) {
            super.readFromNBT(compound);
            this.stacks = NonNullList.<ItemStack>withSize(this.getSizeInventory(), ItemStack.EMPTY);
            if (!this.checkLootAndRead(compound)) {
                ItemStackHelper.loadAllItems(compound, this.stacks);
            }
        }

        @Override
        public NBTTagCompound writeToNBT(NBTTagCompound compound) {
            super.writeToNBT(compound);
            if (!this.checkLootAndWrite(compound)) {
                ItemStackHelper.saveAllItems(compound, this.stacks);
            }
            return compound;
        }

        @Override
        public SPacketUpdateTileEntity getUpdatePacket() {
            return new SPacketUpdateTileEntity(this.pos, 0, this.getUpdateTag());
        }

        @Override
        public NBTTagCompound getUpdateTag() {
            return this.writeToNBT(new NBTTagCompound());
        }

        @Override
        public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) {
            this.readFromNBT(pkt.getNbtCompound());
        }

        @Override
        public void handleUpdateTag(NBTTagCompound tag) {
            this.readFromNBT(tag);
        }

        @Override
        public int getInventoryStackLimit() {
            return 1;
        }

        @Override
        public String getGuiID() {
            return "fpa:endo_level_two";
        }

        @Override
        public Container createContainer(InventoryPlayer playerInventory, EntityPlayer playerIn) {
            this.fillWithLoot(playerIn);
            return new ContainerChest(playerInventory, this, playerIn);
        }

        @Override
        protected NonNullList<ItemStack> getItems() {
            return this.stacks;
        }
    }
}

вот класс блока на который заменяют

Java:
package com.fpa.block;

import net.minecraft.block.state.BlockStateContainer;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.client.event.ModelRegistryEvent;

import net.minecraft.world.World;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.Rotation;
import net.minecraft.util.Mirror;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.Item;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.block.state.IBlockState;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.material.Material;
import net.minecraft.block.SoundType;
import net.minecraft.block.Block;

import com.fpa.ElementsFPA;

@ElementsFPA.ModElement.Tag
public class EndoNullFull extends ElementsFPA.ModElement {
    @GameRegistry.ObjectHolder("fpa:endo_null_full")
    public static final Block block = null;
    public EndoNullFull(ElementsFPA instance) {
        super(instance, 3);
    }

    @Override
    public void initElements() {
        elements.blocks.add(() -> new BlockCustom().setRegistryName("endo_null_full"));
        elements.items.add(() -> new ItemBlock(block).setRegistryName(block.getRegistryName()));
    }

    @SideOnly(Side.CLIENT)
    @Override
    public void registerModels(ModelRegistryEvent event) {
        ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), 0, new ModelResourceLocation("fpa:endo_null_full", "inventory"));
    }
    public static class BlockCustom extends Block {
        public static final PropertyDirection FACING = PropertyDirection.create("facing");

        public BlockCustom() {
            super(Material.ROCK);
            setUnlocalizedName("endo_null_full");
            setSoundType(SoundType.METAL);
            setHardness(1F);
            setResistance(10F);
            setLightLevel(0F);
            setLightOpacity(0);
            setCreativeTab(null);
            this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
        }

        @SideOnly(Side.CLIENT)
        @Override
        public BlockRenderLayer getBlockLayer() {
            return BlockRenderLayer.CUTOUT_MIPPED;
        }

        @Override
        protected BlockStateContainer createBlockState() {
            return new BlockStateContainer(this, FACING);
        }
        @Override
        public IBlockState withRotation(IBlockState state, Rotation rot) {
            return state.withProperty(FACING, rot.rotate((EnumFacing) state.getValue(FACING)));
        }

        @Override
        public IBlockState withMirror(IBlockState state, Mirror mirrorIn) {
            return state.withRotation(mirrorIn.toRotation((EnumFacing) state.getValue(FACING)));
        }

        @Override
        public IBlockState getStateFromMeta(int meta) {
            return this.getDefaultState().withProperty(FACING, EnumFacing.getFront(meta));
        }

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

        @Override
        public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta,
                                                EntityLivingBase placer) {
            return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
        }

        @Override
        public boolean isOpaqueCube(IBlockState state) {
            return false;
        }
    }
}
 
Последнее редактирование:
Назад
Сверху