From e01e9398eae9bfce3e5fa23ea455caac92d1ee02 Mon Sep 17 00:00:00 2001 From: drcrazy Date: Tue, 30 Apr 2019 16:48:43 +0300 Subject: [PATCH] Model for alarm --- .../java/techreborn/blocks/BlockAlarm.java | 18 ++++++- .../blocks/storage/BlockEnergyStorage.java | 2 +- .../assets/techreborn/blockstates/alarm.json | 16 ++++++ .../blockstates/machines/lighting/alarm.json | 51 ------------------- .../block/{ => machines/lighting}/alarm.json | 2 +- .../block/machines/lighting/alarm_on.json | 38 ++++++++++++++ .../assets/techreborn/models/item/alarm.json | 3 ++ 7 files changed, 75 insertions(+), 55 deletions(-) create mode 100644 src/main/resources/assets/techreborn/blockstates/alarm.json delete mode 100644 src/main/resources/assets/techreborn/blockstates/machines/lighting/alarm.json rename src/main/resources/assets/techreborn/models/block/{ => machines/lighting}/alarm.json (94%) create mode 100644 src/main/resources/assets/techreborn/models/block/machines/lighting/alarm_on.json create mode 100644 src/main/resources/assets/techreborn/models/item/alarm.json diff --git a/src/main/java/techreborn/blocks/BlockAlarm.java b/src/main/java/techreborn/blocks/BlockAlarm.java index 491b4075d..d180066a1 100644 --- a/src/main/java/techreborn/blocks/BlockAlarm.java +++ b/src/main/java/techreborn/blocks/BlockAlarm.java @@ -29,10 +29,12 @@ import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.client.util.ITooltipFlag; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.BlockItemUseContext; import net.minecraft.item.ItemStack; import net.minecraft.state.BooleanProperty; import net.minecraft.state.DirectionProperty; import net.minecraft.state.StateContainer; +import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumBlockRenderType; import net.minecraft.util.EnumFacing; @@ -57,7 +59,7 @@ import javax.annotation.Nullable; import java.util.List; public class BlockAlarm extends BaseTileBlock { - public static DirectionProperty FACING; + public static DirectionProperty FACING = BlockStateProperties.FACING; public static BooleanProperty ACTIVE; protected final VoxelShape[] shape; @@ -102,10 +104,21 @@ public class BlockAlarm extends BaseTileBlock { // Block @Override protected void fillStateContainer(StateContainer.Builder builder) { - FACING = DirectionProperty.create("facing", EnumFacing.Plane.HORIZONTAL); ACTIVE = BooleanProperty.create("active"); builder.add(FACING, ACTIVE); } + + @Nullable + @Override + public IBlockState getStateForPlacement(BlockItemUseContext context) { + for (EnumFacing enumfacing : context.getNearestLookingDirections()) { + IBlockState iblockstate = this.getDefaultState().with(FACING, enumfacing.getOpposite()); + if (iblockstate.isValidPosition(context.getWorld(), context.getPos())) { + return iblockstate; + } + } + return null; + } @SuppressWarnings("deprecation") @Override @@ -156,6 +169,7 @@ public class BlockAlarm extends BaseTileBlock { @Override public VoxelShape getShape(IBlockState state, IBlockReader worldIn, BlockPos pos) { + // TODO: Fix this return shape[getFacing(state).getIndex()]; } } diff --git a/src/main/java/techreborn/blocks/storage/BlockEnergyStorage.java b/src/main/java/techreborn/blocks/storage/BlockEnergyStorage.java index fcdecc3e0..29234204f 100644 --- a/src/main/java/techreborn/blocks/storage/BlockEnergyStorage.java +++ b/src/main/java/techreborn/blocks/storage/BlockEnergyStorage.java @@ -51,7 +51,7 @@ import techreborn.TechReborn; * Created by Rushmead */ public abstract class BlockEnergyStorage extends BaseTileBlock { - public static DirectionProperty FACING = BlockStateProperties.FACING;; + public static DirectionProperty FACING = BlockStateProperties.FACING; public String name; public IMachineGuiHandler gui; diff --git a/src/main/resources/assets/techreborn/blockstates/alarm.json b/src/main/resources/assets/techreborn/blockstates/alarm.json new file mode 100644 index 000000000..7042ca0c8 --- /dev/null +++ b/src/main/resources/assets/techreborn/blockstates/alarm.json @@ -0,0 +1,16 @@ +{ + "variants": { + "facing=north,active=false": { "model": "techreborn:block/machines/lighting/alarm", "x": 90 }, + "facing=south,active=false": { "model": "techreborn:block/machines/lighting/alarm", "x": 270 }, + "facing=west,active=false": { "model": "techreborn:block/machines/lighting/alarm", "x": 90, "y": 270 }, + "facing=east,active=false": { "model": "techreborn:block/machines/lighting/alarm", "x": 90, "y": 90 }, + "facing=down,active=false": { "model": "techreborn:block/machines/lighting/alarm", "x": 180 }, + "facing=up,active=false": { "model": "techreborn:block/machines/lighting/alarm" }, + "facing=north,active=true": { "model": "techreborn:block/machines/lighting/alarm_on", "x": 90 }, + "facing=south,active=true": { "model": "techreborn:block/machines/lighting/alarm_on", "x": 270 }, + "facing=west,active=true": { "model": "techreborn:block/machines/lighting/alarm_on", "x": 90, "y": 270 }, + "facing=east,active=true": { "model": "techreborn:block/machines/lighting/alarm_on", "x": 90, "y": 90 }, + "facing=down,active=true": { "model": "techreborn:block/machines/lighting/alarm_on", "x": 180 }, + "facing=up,active=true": { "model": "techreborn:block/machines/lighting/alarm_on"} + } +} diff --git a/src/main/resources/assets/techreborn/blockstates/machines/lighting/alarm.json b/src/main/resources/assets/techreborn/blockstates/machines/lighting/alarm.json deleted file mode 100644 index dd4c20c92..000000000 --- a/src/main/resources/assets/techreborn/blockstates/machines/lighting/alarm.json +++ /dev/null @@ -1,51 +0,0 @@ -{ - "forge_marker": 1, - "defaults": { - "model": "techreborn:alarm", - "textures": { - "particle": "#alarm" - } -}, -"variants": { - "inventory": { - "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" - } - } - } -} -} \ No newline at end of file diff --git a/src/main/resources/assets/techreborn/models/block/alarm.json b/src/main/resources/assets/techreborn/models/block/machines/lighting/alarm.json similarity index 94% rename from src/main/resources/assets/techreborn/models/block/alarm.json rename to src/main/resources/assets/techreborn/models/block/machines/lighting/alarm.json index b7164f99d..5a4542a7e 100644 --- a/src/main/resources/assets/techreborn/models/block/alarm.json +++ b/src/main/resources/assets/techreborn/models/block/machines/lighting/alarm.json @@ -18,7 +18,7 @@ } }, "textures": { - "0": "#alarm" + "0": "techreborn:block/machines/lighting/alarm_off" }, "elements": [ { diff --git a/src/main/resources/assets/techreborn/models/block/machines/lighting/alarm_on.json b/src/main/resources/assets/techreborn/models/block/machines/lighting/alarm_on.json new file mode 100644 index 000000000..3588f0343 --- /dev/null +++ b/src/main/resources/assets/techreborn/models/block/machines/lighting/alarm_on.json @@ -0,0 +1,38 @@ +{ + "parent": "block/block", + "display": { + "thirdperson_righthand": { + "rotation": [ 75, 45, 0 ], + "translation": [ 0, 2.5, 2], + "scale": [ 0.375, 0.375, 0.375 ] + }, + "firstperson_righthand": { + "rotation": [ 0, 35, 0 ], + "translation": [ 0, 5.5, 0 ], + "scale": [ 0.60, 0.60, 0.60 ] + }, + "firstperson_lefthand": { + "rotation": [ 0, 225, 0 ], + "translation": [ 0, 4.2, 0 ], + "scale": [ 0.40, 0.40, 0.40 ] + } + }, + "textures": { + "0": "techreborn:block/machines/lighting/alarm_on" + }, + "elements": [ + { + "name": "Alarm", + "from": [3, 0, 3], + "to": [13, 3, 13], + "faces": { + "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] } + } + } + ] +} diff --git a/src/main/resources/assets/techreborn/models/item/alarm.json b/src/main/resources/assets/techreborn/models/item/alarm.json new file mode 100644 index 000000000..27e8f3d6b --- /dev/null +++ b/src/main/resources/assets/techreborn/models/item/alarm.json @@ -0,0 +1,3 @@ +{ + "parent": "techreborn:block/machines/lighting/alarm" +} \ No newline at end of file