commit
425a8732a3
6 changed files with 154 additions and 76 deletions
|
@ -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,82 @@ 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[] dimm = {
|
||||
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 dimm;
|
||||
}
|
||||
|
||||
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 +122,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()];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -157,6 +157,7 @@ public class CraftingTableRecipes extends RecipeMethods {
|
|||
registerShaped(getStack(ModBlocks.SOLAR_PANEL, 1, 3), "DLD", "LDL", "CPC", 'D', "dustDiamond", 'L', getStack(ModBlocks.REINFORCED_GLASS), 'C', "circuitAdvanced", 'P', "machineBlockAdvanced");
|
||||
registerShaped(getStack(ModBlocks.SOLAR_PANEL, 1, 4), "DLD", "LDL", "CPC", 'D', "dustDiamond", 'L', getStack(ModBlocks.REINFORCED_GLASS), 'C', "circuitMaster", 'P', getStack(ModBlocks.SOLAR_PANEL, 1, 3));
|
||||
registerShaped(getStack(ModBlocks.SOLAR_PANEL, 1, 4), "DLD", "LDL", "CPC", 'D', "dustDiamond", 'L', getStack(ModBlocks.REINFORCED_GLASS), 'C', "circuitMaster", 'P', "machineBlockElite");
|
||||
registerShaped(getStack(ModBlocks.ALARM, 1, 0), "ICI", "SRS", "ICI", 'I', "ingotIron", 'C', getMaterial("copper", Type.CABLE), 'S', getMaterial("insulatedcopper", Type.CABLE), 'R', "blockRedstone" );
|
||||
|
||||
if (!IC2Duplicates.deduplicate()) {
|
||||
registerShaped(getStack(IC2Duplicates.HVT), " H ", " M ", " H ", 'M', getStack(IC2Duplicates.MVT), 'H', getStack(IC2Duplicates.CABLE_IHV));
|
||||
|
|
|
@ -3,13 +3,21 @@ package techreborn.tiles;
|
|||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ITickable;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import techreborn.blocks.BlockAlarm;
|
||||
import techreborn.init.ModSounds;
|
||||
|
||||
public class TileAlarm extends TileEntity implements ITickable{
|
||||
@Override
|
||||
public void update() {
|
||||
if(!world.isRemote && world.getTotalWorldTime() % 25 == 0 && world.isBlockPowered(getPos())){
|
||||
world.playSound(null, getPos().getX(), getPos().getY(), getPos().getZ(), ModSounds.ALARM, SoundCategory.BLOCKS, 4F, 1F);
|
||||
}
|
||||
}
|
||||
public class TileAlarm extends TileEntity implements ITickable {
|
||||
boolean state = false;
|
||||
int selectedSound;
|
||||
@Override
|
||||
public void update() {
|
||||
if (!world.isRemote && world.getTotalWorldTime() % 25 == 0 && world.isBlockPowered(getPos())) {
|
||||
BlockAlarm.setActive(true, world, pos);
|
||||
world.playSound(null, getPos().getX(), getPos().getY(), getPos().getZ(), ModSounds.ALARM, SoundCategory.BLOCKS, 4F, 1F);
|
||||
state = true;
|
||||
} else if(!world.isRemote && world.getTotalWorldTime() % 25 == 0 ) {
|
||||
BlockAlarm.setActive(false, world, pos);
|
||||
state = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,22 +1,53 @@
|
|||
{
|
||||
"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",
|
||||
"textures": {
|
||||
"particle": "#alarm"
|
||||
}
|
||||
},
|
||||
"variants": {
|
||||
"inventory": {
|
||||
"transform": "forge:default-block",
|
||||
"model": "techreborn:alarm",
|
||||
"textures": {
|
||||
"alarm": "techreborn:blocks/machines/lighting/alarm_off"
|
||||
}
|
||||
},
|
||||
"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_on"
|
||||
}
|
||||
},
|
||||
"false": {
|
||||
"textures": {
|
||||
"alarm": "techreborn:blocks/machines/lighting/alarm_off"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,54 +1,20 @@
|
|||
{
|
||||
"textures": {
|
||||
"0": "techreborn:blocks/machines/lighting/alarm_off",
|
||||
"particle": "techreborn:blocks/machines/lighting/alarm_off"
|
||||
"0": "#alarm"
|
||||
},
|
||||
"elements": [
|
||||
{
|
||||
"name": "cube",
|
||||
"name": "Alarm",
|
||||
"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] }
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"animation": {
|
||||
"frametime": 5
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue