I ve tried to make a directional block with face side from side of player looking at, but unfortunately something went wrong. I't crashes on block placing. I've tried to find something about it, but all manuals i found are outdated, and they was with different outdated methods. Idk how to correctly do this, I'm newbie here =\
The Code:
package com.foserosx.immersiveindustry.blocks;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class metallurgicFurnace extends BlockBase {
public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);
public metallurgicFurnace(String name, Material material) {
super(name, material);
setSoundType(SoundType.METAL);
setHardness(5.0F);
setResistance(15.0F);
setHarvestLevel("pickaxe", 2);
this.setDefaultState(blockState.getBaseState().withProperty(FACING,EnumFacing.NORTH));
}
@Override
public IBlockState getStateFromMeta(int meta)
{
IBlockState iblockstate = this.getDefaultState();
switch (meta)
{
case 1:
iblockstate = iblockstate.withProperty(FACING, EnumFacing.EAST);
break;
case 2:
iblockstate = iblockstate.withProperty(FACING, EnumFacing.WEST);
break;
case 3:
iblockstate = iblockstate.withProperty(FACING, EnumFacing.SOUTH);
break;
case 4:
iblockstate = iblockstate.withProperty(FACING, EnumFacing.NORTH);
break;
default:
iblockstate = iblockstate.withProperty(FACING, EnumFacing.NORTH);
}
return iblockstate;
}
@Override
public int getMetaFromState(IBlockState state)
{
int i = 0;
switch ((EnumFacing)state.getValue(FACING))
{
case EAST:
i = i | 1;
break;
case WEST:
i = i | 2;
break;
case SOUTH:
i = i | 3;
break;
case NORTH:
i = i | 4;
break;
default:
i = i | 4;
}
return i;
}
@Override
protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, new IProperty[] {FACING});
}
@Override
public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer, EnumHand hand) {
return this.getDefaultState().withProperty(FACING,facing.getOpposite().getOpposite());
}
}
The Error:
[17:33:34] [Server thread/FATAL] [minecraft/MinecraftServer]: Error executing task
java.util.concurrent.ExecutionException: java.lang.IllegalArgumentException: Cannot set property PropertyDirection{name=facing, clazz=class net.minecraft.util.EnumFacing, values=[north, south, west, east]} to up on block immersiveindustry:metallurgic_furnace, it is not an allowed value
at java.util.concurrent.FutureTask.report(FutureTask.java:122) ~[?:1.8.0_51]
at java.util.concurrent.FutureTask.get(FutureTask.java:192) ~[?:1.8.0_51]
at net.minecraft.util.Util.runTask(Util.java:54) [Util.class:?]
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:798) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:743) [MinecraftServer.class:?]
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:192) [IntegratedServer.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:592) [MinecraftServer.class:?]
at java.lang.Thread.run(Thread.java:745) [?:1.8.0_51]
Caused by: java.lang.IllegalArgumentException: Cannot set property PropertyDirection{name=facing, clazz=class net.minecraft.util.EnumFacing, values=[north, south, west, east]} to up on block immersiveindustry:metallurgic_furnace, it is not an allowed value
at net.minecraft.block.state.BlockStateContainer$StateImplementation.withProperty(BlockStateContainer.java:233) ~[BlockStateContainer$StateImplementation.class:?]
at com.foserosx.immersiveindustry.blocks.metallurgicFurnace.getStateForPlacement(metallurgicFurnace.java:87) ~[metallurgicFurnace.class:?]
at net.minecraft.item.ItemBlock.onItemUse(ItemBlock.java:55) ~[ItemBlock.class:?]
at net.minecraftforge.common.ForgeHooks.onPlaceItemIntoWorld(ForgeHooks.java:876) ~[ForgeHooks.class:?]
at net.minecraft.item.ItemStack.onItemUse(ItemStack.java:200) ~[ItemStack.class:?]
at net.minecraft.server.management.PlayerInteractionManager.processRightClickBlock(PlayerInteractionManager.java:507) ~[PlayerInteractionManager.class:?]
at net.minecraft.network.NetHandlerPlayServer.processTryUseItemOnBlock(NetHandlerPlayServer.java:769) ~[NetHandlerPlayServer.class:?]
at net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock.processPacket(CPacketPlayerTryUseItemOnBlock.java:68) ~[CPacketPlayerTryUseItemOnBlock.class:?]
at net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock.processPacket(CPacketPlayerTryUseItemOnBlock.java:13) ~[CPacketPlayerTryUseItemOnBlock.class:?]
at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:21) ~[PacketThreadUtil$1.class:?]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[?:1.8.0_51]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[?:1.8.0_51]
at net.minecraft.util.Util.runTask(Util.java:53) ~[Util.class:?]
... 5 more
[17:33:35] [Server thread/INFO] [minecraft/MinecraftServer]: Stopping server
This technically belongs in the mod development section, but I'll try to help anyway. I think the problem is here:
facing.getOpposite().getOpposite()
The "facing" parameter is the side the block is being placed on, not the facing of the player, so if you place your block on the top surface of the ground, this will return the "up" facing (which fails since your block only allows horizontal facings). (not sure what the point of calling getOpposite twice is) I suggest you try this instead:
I ve tried to make a directional block with face side from side of player looking at, but unfortunately something went wrong. I't crashes on block placing. I've tried to find something about it, but all manuals i found are outdated, and they was with different outdated methods. Idk how to correctly do this, I'm newbie here =\
The Code:
The Error:
This technically belongs in the mod development section, but I'll try to help anyway. I think the problem is here:
The "facing" parameter is the side the block is being placed on, not the facing of the player, so if you place your block on the top surface of the ground, this will return the "up" facing (which fails since your block only allows horizontal facings). (not sure what the point of calling getOpposite twice is) I suggest you try this instead: