Proper faces
This commit is contained in:
parent
e93451b595
commit
bdc34d673c
3 changed files with 127 additions and 66 deletions
|
@ -1,16 +1,22 @@
|
||||||
package techreborn.blocks;
|
package techreborn.blocks;
|
||||||
|
|
||||||
import net.minecraft.block.BlockContainer;
|
|
||||||
import net.minecraft.block.material.Material;
|
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.block.state.IBlockState;
|
||||||
|
import net.minecraft.entity.EntityLivingBase;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.EnumBlockRenderType;
|
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.AxisAlignedBB;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.IBlockAccess;
|
import net.minecraft.world.IBlockAccess;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import prospector.shootingstar.ShootingStar;
|
import prospector.shootingstar.ShootingStar;
|
||||||
import prospector.shootingstar.model.ModelCompound;
|
import prospector.shootingstar.model.ModelCompound;
|
||||||
|
import reborncore.common.BaseTileBlock;
|
||||||
import techreborn.client.TechRebornCreativeTab;
|
import techreborn.client.TechRebornCreativeTab;
|
||||||
import techreborn.lib.ModInfo;
|
import techreborn.lib.ModInfo;
|
||||||
import techreborn.tiles.TileAlarm;
|
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.
|
//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() {
|
public BlockAlarm() {
|
||||||
super(Material.ROCK);
|
super(Material.ROCK);
|
||||||
setUnlocalizedName("techreborn.alarm");
|
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);
|
setCreativeTab(TechRebornCreativeTab.instance);
|
||||||
ShootingStar.registerModel(new ModelCompound(ModInfo.MOD_ID, this, "machines/lighting"));
|
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
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public TileEntity createNewTileEntity(World worldIn, int meta) {
|
public TileEntity createNewTileEntity(World worldIn, int meta) {
|
||||||
return new TileAlarm();
|
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
|
@Override
|
||||||
public EnumBlockRenderType getRenderType(IBlockState state) {
|
public EnumBlockRenderType getRenderType(IBlockState state) {
|
||||||
return EnumBlockRenderType.MODEL;
|
return EnumBlockRenderType.MODEL;
|
||||||
|
@ -55,8 +123,8 @@ public class BlockAlarm extends BlockContainer {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AxisAlignedBB getBoundingBox(IBlockState blockState, IBlockAccess worldIn, BlockPos pos) {
|
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
|
||||||
return new AxisAlignedBB(0.19, 0.0, 0.19, 0.81, 0.18, 0.81);
|
return this.bbs[getFacing(state).getIndex()];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,22 +1,48 @@
|
||||||
{
|
{
|
||||||
"forge_marker": 1,
|
"forge_marker": 1,
|
||||||
"defaults": {
|
"defaults": {
|
||||||
"transform": "forge:default-block",
|
"transform": "forge:default-block",
|
||||||
"model": "techreborn:alarm"
|
"model": "techreborn:alarm"
|
||||||
},
|
},
|
||||||
"variants": {
|
"variants": {
|
||||||
"inventory": {
|
"inventory": {
|
||||||
"transform": "forge:default-block",
|
"transform": "forge:default-block",
|
||||||
"model": "techreborn:alarm",
|
"model": "techreborn:alarm",
|
||||||
"textures": {}
|
"textures": {}
|
||||||
},
|
},
|
||||||
"normal": {
|
"facing": {
|
||||||
"transform": "forge:default-block",
|
"down": {
|
||||||
"model": "techreborn:alarm",
|
"x": 180
|
||||||
"textures": {
|
},
|
||||||
"alarm": "techreborn:blocks/machines/lighting/alarm_off"
|
"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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -9,46 +9,13 @@
|
||||||
"from": [3, 0, 3],
|
"from": [3, 0, 3],
|
||||||
"to": [13, 3, 13],
|
"to": [13, 3, 13],
|
||||||
"faces": {
|
"faces": {
|
||||||
"north": {
|
"down": { "texture": "#0", "uv": [0.0, 0.0, 1.0, 1.0] },
|
||||||
"uv": [
|
"up": { "texture": "#0", "uv": [1.0,1.0,15.0,15.0] },
|
||||||
0.37890625,
|
"north": { "texture": "#0", "uv": [1.0,2.0,15.0,0.0] },
|
||||||
0.5171875,
|
"south": { "texture": "#0", "uv": [1.0,2.0,15.0,0.0] },
|
||||||
15.240625,
|
"west": { "texture": "#0", "uv": [1.0,2.0,15.0,0.0] },
|
||||||
3.3093749999999997
|
"east": { "texture": "#0", "uv": [1.0,2.0,15.0,0.0] }
|
||||||
],
|
}
|
||||||
"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"
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue