Proper faces

This commit is contained in:
Dimmerworld 2017-12-29 16:50:35 +11:00
parent e93451b595
commit bdc34d673c
3 changed files with 127 additions and 66 deletions

View file

@ -1,16 +1,22 @@
package techreborn.blocks;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyBool;
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.tileentity.TileEntity;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import prospector.shootingstar.ShootingStar;
import prospector.shootingstar.model.ModelCompound;
import reborncore.common.BaseTileBlock;
import techreborn.client.TechRebornCreativeTab;
import techreborn.lib.ModInfo;
import techreborn.tiles.TileAlarm;
@ -19,21 +25,83 @@ import javax.annotation.Nullable;
//TODO: On/off variants, Placeable on walls/roofs(faces), Visible when holding in hand, and recipe.
public class BlockAlarm extends BlockContainer {
public class BlockAlarm extends BaseTileBlock {
public static PropertyDirection FACING;
public static PropertyBool ACTIVE;
private static AxisAlignedBB[] GenBoundingBoxes(double depth, double width) {
AxisAlignedBB[] bb = {
new AxisAlignedBB(width, 1.0 - depth, width, 1.0 - width, 1.0D, 1.0 - width),
new AxisAlignedBB(width, 0.0D, width, 1.0 - width, depth, 1.0 - width),
new AxisAlignedBB(width, width, 1.0 - depth, 1.0 - width, 1.0 - width, 1.0D),
new AxisAlignedBB(width, width, 0.0D, 1.0 - width, 1.0 - width, depth),
new AxisAlignedBB(1.0 - depth, width, width, 1.0D, 1.0 - width, 1.0 - width),
new AxisAlignedBB(0.0D, width, width, depth, 1.0 - width, 1.0 - width),
};
return bb;
}
private AxisAlignedBB[] bbs;
public BlockAlarm() {
super(Material.ROCK);
setUnlocalizedName("techreborn.alarm");
this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH).withProperty(ACTIVE, false));
this.bbs = GenBoundingBoxes(0.19, 0.81);
setCreativeTab(TechRebornCreativeTab.instance);
ShootingStar.registerModel(new ModelCompound(ModInfo.MOD_ID, this, "machines/lighting"));
}
@Override
protected BlockStateContainer createBlockState() {
FACING = PropertyDirection.create("facing");
ACTIVE = PropertyBool.create("active");
return new BlockStateContainer(this, FACING, ACTIVE);
}
@Override
public int getMetaFromState(IBlockState state) {
int facingInt = state.getValue(FACING).getIndex();
int activeInt = state.getValue(ACTIVE) ? 8 : 0;
return facingInt + activeInt;
}
@Override
public IBlockState getStateFromMeta(int meta) {
Boolean active = (meta&8)==8;
EnumFacing facing = EnumFacing.getFront(meta&7);
return this.getDefaultState().withProperty(FACING, facing).withProperty(ACTIVE, active);
}
public static boolean isActive(IBlockState state) {
return state.getValue(ACTIVE);
}
public static EnumFacing getFacing(IBlockState state) {
return (EnumFacing)state.getValue(FACING);
}
public static void setFacing(EnumFacing facing, World world, BlockPos pos) {
world.setBlockState(pos, world.getBlockState(pos).withProperty(FACING, facing));
}
public static void setActive(Boolean active, World world, BlockPos pos) {
EnumFacing facing = (EnumFacing)world.getBlockState(pos).getValue(FACING);
IBlockState state = world.getBlockState(pos).withProperty(ACTIVE, active).withProperty(FACING, facing);
world.setBlockState(pos, state, 3);
}
@Nullable
@Override
public TileEntity createNewTileEntity(World worldIn, int meta) {
return new TileAlarm();
}
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);
}
@Override
public EnumBlockRenderType getRenderType(IBlockState state) {
return EnumBlockRenderType.MODEL;
@ -55,8 +123,8 @@ public class BlockAlarm extends BlockContainer {
}
@Override
public AxisAlignedBB getBoundingBox(IBlockState blockState, IBlockAccess worldIn, BlockPos pos) {
return new AxisAlignedBB(0.19, 0.0, 0.19, 0.81, 0.18, 0.81);
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
return this.bbs[getFacing(state).getIndex()];
}
}

View file

@ -1,22 +1,48 @@
{
"forge_marker": 1,
"defaults": {
"transform": "forge:default-block",
"model": "techreborn:alarm"
},
"variants": {
"inventory": {
"transform": "forge:default-block",
"model": "techreborn:alarm",
"textures": {}
},
"normal": {
"transform": "forge:default-block",
"model": "techreborn:alarm",
"textures": {
"alarm": "techreborn:blocks/machines/lighting/alarm_off"
}
}
}
"forge_marker": 1,
"defaults": {
"transform": "forge:default-block",
"model": "techreborn:alarm"
},
"variants": {
"inventory": {
"transform": "forge:default-block",
"model": "techreborn:alarm",
"textures": {}
},
"facing": {
"down": {
"x": 180
},
"up": {
"transform": "forge:default-block"
},
"north": {
"x": 90
},
"south": {
"x": 270
},
"west": {
"x": 90,
"y": 270
},
"east": {
"x": 90,
"y": 90
}
},
"active": {
"true": {
"textures": {
"alarm": "techreborn:blocks/machines/lighting/alarm_off"
}
},
"false": {
"textures": {
"alarm": "techreborn:blocks/machines/lighting/alarm_off"
}
}
}
}
}

View file

@ -9,46 +9,13 @@
"from": [3, 0, 3],
"to": [13, 3, 13],
"faces": {
"north": {
"uv": [
0.37890625,
0.5171875,
15.240625,
3.3093749999999997
],
"texture": "#0"
},
"east": {
"uv": [
0.37890625,
0.5171875,
15.240625,
3.3093749999999997
],
"texture": "#0"
},
"south": {
"uv": [
0.37890625,
0.5171875,
15.240625,
3.3093749999999997
],
"texture": "#0"
},
"west": {
"uv": [
0.37890625,
0.5171875,
15.240625,
3.3093749999999997
],
"texture": "#0"
},
"up": {"uv": [0, 0, 16, 16], "texture": "#0"},
"down": {"uv": [5, 2, 6, 3], "texture": "#0"}
},
"type": "cube"
}
"down": { "texture": "#0", "uv": [0.0, 0.0, 1.0, 1.0] },
"up": { "texture": "#0", "uv": [1.0,1.0,15.0,15.0] },
"north": { "texture": "#0", "uv": [1.0,2.0,15.0,0.0] },
"south": { "texture": "#0", "uv": [1.0,2.0,15.0,0.0] },
"west": { "texture": "#0", "uv": [1.0,2.0,15.0,0.0] },
"east": { "texture": "#0", "uv": [1.0,2.0,15.0,0.0] }
}
}
]
}
}