From bb9f282a24cc44d032f2c5320474efd9f592a966 Mon Sep 17 00:00:00 2001 From: Daniel Richardt Date: Tue, 19 Dec 2023 23:00:42 +0100 Subject: [PATCH] add TV Block --- .../decorations/Richardts_decorations.java | 3 + .../java/de/richardt/decorations/TVBlock.java | 114 ++++++++++++++++++ .../java/de/richardt/decorations/TvBlock,java | 0 .../blockstates/tv_block.json | 12 ++ .../models/block/tv_block.json | 112 +++++++++++++++++ .../models/block/tv_block_on.json | 112 +++++++++++++++++ .../models/item/tv_block.json | 3 + .../textures/block/tv_block/display.png | Bin 0 -> 688 bytes .../textures/block/tv_block/display_off.png | Bin 0 -> 469 bytes .../textures/block/tv_block/rahmen.png | Bin 0 -> 828 bytes .../recipes/tv_block.json | 20 +++ 11 files changed, 376 insertions(+) create mode 100644 src/main/java/de/richardt/decorations/TVBlock.java delete mode 100644 src/main/java/de/richardt/decorations/TvBlock,java create mode 100644 src/main/resources/assets/richardts_decorations/blockstates/tv_block.json create mode 100644 src/main/resources/assets/richardts_decorations/models/block/tv_block.json create mode 100644 src/main/resources/assets/richardts_decorations/models/block/tv_block_on.json create mode 100644 src/main/resources/assets/richardts_decorations/models/item/tv_block.json create mode 100644 src/main/resources/assets/richardts_decorations/textures/block/tv_block/display.png create mode 100644 src/main/resources/assets/richardts_decorations/textures/block/tv_block/display_off.png create mode 100644 src/main/resources/assets/richardts_decorations/textures/block/tv_block/rahmen.png create mode 100644 src/main/resources/data/richardts_decorations/recipes/tv_block.json diff --git a/src/main/java/de/richardt/decorations/Richardts_decorations.java b/src/main/java/de/richardt/decorations/Richardts_decorations.java index 13a0aa0..5ec2959 100644 --- a/src/main/java/de/richardt/decorations/Richardts_decorations.java +++ b/src/main/java/de/richardt/decorations/Richardts_decorations.java @@ -47,6 +47,7 @@ public class Richardts_decorations implements ModInitializer { entries.add(NOTEBOOKBLOCK); entries.add(LIGHT_BULB_ITEM); entries.add(QUAD_BLADE_ITEM); + entries.add(TV_BLOCK); }) .build(); @@ -73,6 +74,8 @@ public void onInitialize() { Registry.register(Registries.ITEM, new Identifier("richardts_decorations", "chargeable_block"), new BlockItem(ChargeableBlock.CHARGEABLE_BLOCK, new FabricItemSettings())); Registry.register(Registries.BLOCK, new Identifier("richardts_decorations", "floor_lamp_block"), FLOORLAMPBLOCK); Registry.register(Registries.ITEM, new Identifier("richardts_decorations", "floor_lamp_block"), new BlockItem(FLOORLAMPBLOCK, new FabricItemSettings())); + Registry.register(Registries.BLOCK, new Identifier("richardts_decorations", "tv_block"), TV_BLOCK); + Registry.register(Registries.ITEM, new Identifier("richardts_decorations", "tv_block"), new BlockItem(TV_BLOCK, new FabricItemSettings())); Registry.register(Registries.BLOCK, new Identifier("richardts_decorations", "thermo_mix_block"), THERMOMIXBLOCK); Registry.register(Registries.ITEM, new Identifier("richardts_decorations", "thermo_mix_block"), new BlockItem(THERMOMIXBLOCK, new FabricItemSettings())); Registry.register(Registries.BLOCK, new Identifier("richardts_decorations", "notebook_block"), NOTEBOOKBLOCK); diff --git a/src/main/java/de/richardt/decorations/TVBlock.java b/src/main/java/de/richardt/decorations/TVBlock.java new file mode 100644 index 0000000..f16e473 --- /dev/null +++ b/src/main/java/de/richardt/decorations/TVBlock.java @@ -0,0 +1,114 @@ +package de.richardt.decorations; + + +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.HorizontalFacingBlock; +import net.minecraft.block.ShapeContext; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemPlacementContext; +import net.minecraft.sound.SoundEvents; +import net.minecraft.state.StateManager; +import net.minecraft.state.property.BooleanProperty; +import net.minecraft.state.property.Properties; +import net.minecraft.util.ActionResult; +import net.minecraft.util.Hand; +import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Box; +import net.minecraft.util.math.Direction; +import net.minecraft.util.shape.VoxelShape; +import net.minecraft.util.shape.VoxelShapes; +import net.minecraft.world.BlockView; +import net.minecraft.world.World; + + +public class TVBlock extends HorizontalFacingBlock { + public static final BooleanProperty POWER = BooleanProperty.of("power"); + public TVBlock(Settings settings) { + super(settings); + setDefaultState(getDefaultState().with(Properties.HORIZONTAL_FACING, Direction.NORTH)); + setDefaultState(getDefaultState().with(POWER, false)); + } + + @Override + protected void appendProperties(StateManager.Builder builder){ + builder.add(Properties.HORIZONTAL_FACING); + builder.add(POWER); + } + + + @Override + public BlockState getPlacementState(ItemPlacementContext ctx) { + return super.getPlacementState(ctx).with(Properties.HORIZONTAL_FACING, ctx.getHorizontalPlayerFacing().getOpposite()); + } + + @Override + public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { + player.playSound(SoundEvents.BLOCK_LEVER_CLICK, 1, 1); + if(!world.isClient() && hand == Hand.MAIN_HAND) { + world.setBlockState(pos, state.cycle(POWER)); + } + return ActionResult.SUCCESS; + } + + @Override + public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext context) { + Direction direction = state.get(Properties.HORIZONTAL_FACING); + VoxelShape baseShape = createBaseShape(); + VoxelShape mirroredShape = mirrorShape(baseShape); + // VoxelShape mirroredShape = baseShape; + + return rotateShape(mirroredShape, direction); + } + + private VoxelShape createBaseShape() { + return VoxelShapes.union( + VoxelShapes.cuboid(2/16f, 2/16f, 0f, 4/16f, 7/16f, 2/16f), + VoxelShapes.cuboid(2/16f, 0f, 0f, 14/16f, 2/16f, 2/16f), + VoxelShapes.cuboid(2/16f, 7/16f, 0f, 14/16f, 9/16f, 2/16f), + VoxelShapes.cuboid(12/16f, 2/16f, 0f, 14/16f, 7/16f, 2/16f), + VoxelShapes.cuboid(4/16f, 2/16f, 0f, 12/16f, 7/16f, 1/16f) + ); + } + + private VoxelShape mirrorShape(VoxelShape shape) { + VoxelShape mirroredShape = VoxelShapes.empty(); + + for (Box box : shape.getBoundingBoxes()) { + // Spiegeln entlang der Z-Achse + mirroredShape = VoxelShapes.union(mirroredShape, VoxelShapes.cuboid( + box.minX, box.minY, 1 - box.maxZ, box.maxX, box.maxY, 1 - box.minZ)); + } + + return mirroredShape; + } + + + private VoxelShape rotateShape(VoxelShape shape, Direction direction) { + VoxelShape rotatedShape = VoxelShapes.empty(); + + for (Box box : shape.getBoundingBoxes()) { + double minX = box.minX; + double minY = box.minY; + double minZ = box.minZ; + double maxX = box.maxX; + double maxY = box.maxY; + double maxZ = box.maxZ; + + if (direction == Direction.SOUTH) { + rotatedShape = VoxelShapes.union(rotatedShape, VoxelShapes.cuboid(1 - maxX, minY, 1 - maxZ, 1 - minX, maxY, 1 - minZ)); + } else if (direction == Direction.WEST) { + rotatedShape = VoxelShapes.union(rotatedShape, VoxelShapes.cuboid(minZ, minY, 1 - maxX, maxZ, maxY, 1 - minX)); + } else if (direction == Direction.EAST) { + rotatedShape = VoxelShapes.union(rotatedShape, VoxelShapes.cuboid(1 - maxZ, minY, minX, 1 - minZ, maxY, maxX)); + } else { + rotatedShape = VoxelShapes.union(rotatedShape, VoxelShapes.cuboid(minX, minY, minZ, maxX, maxY, maxZ)); + } + } + + return rotatedShape; + } + + +} diff --git a/src/main/java/de/richardt/decorations/TvBlock,java b/src/main/java/de/richardt/decorations/TvBlock,java deleted file mode 100644 index e69de29..0000000 diff --git a/src/main/resources/assets/richardts_decorations/blockstates/tv_block.json b/src/main/resources/assets/richardts_decorations/blockstates/tv_block.json new file mode 100644 index 0000000..b8db799 --- /dev/null +++ b/src/main/resources/assets/richardts_decorations/blockstates/tv_block.json @@ -0,0 +1,12 @@ +{ + "variants": { + "facing=north,power=false": { "model": "richardts_decorations:block/tv_block" }, + "facing=east,power=false" : { "model": "richardts_decorations:block/tv_block", "y": 90 }, + "facing=south,power=false": { "model": "richardts_decorations:block/tv_block", "y": 180 }, + "facing=west,power=false" : { "model": "richardts_decorations:block/tv_block", "y": 270 }, + "facing=north,power=true" : { "model": "richardts_decorations:block/tv_block_on" }, + "facing=east,power=true" : { "model": "richardts_decorations:block/tv_block_on", "y": 90 }, + "facing=south,power=true": { "model": "richardts_decorations:block/tv_block_on", "y": 180 }, + "facing=west,power=true" : { "model": "richardts_decorations:block/tv_block_on", "y": 270 } + } +} diff --git a/src/main/resources/assets/richardts_decorations/models/block/tv_block.json b/src/main/resources/assets/richardts_decorations/models/block/tv_block.json new file mode 100644 index 0000000..2fb4650 --- /dev/null +++ b/src/main/resources/assets/richardts_decorations/models/block/tv_block.json @@ -0,0 +1,112 @@ +{ + "credit": "Made with Blockbench", + "texture_size": [32, 32], + "textures": { + "1": "richardts_decorations:block/tv_block/rahmen", + "2": "richardts_decorations:block/tv_block/display_off", + "3": "richardts_decorations:block/tv_block/display", + "particle": "richardts_decorations:block/tv_block/rahmen" + }, + "elements": [ + { + "from": [12, 2, 14], + "to": [14, 7, 16], + "faces": { + "north": {"uv": [6, 1, 7, 3.5], "texture": "#1"}, + "east": {"uv": [6, 3.5, 7, 6], "texture": "#1"}, + "south": {"uv": [6, 6, 7, 8.5], "texture": "#1"}, + "west": {"uv": [0, 7, 1, 9.5], "texture": "#1"}, + "up": {"uv": [8, 4.5, 7, 3.5], "texture": "#1"}, + "down": {"uv": [5, 7, 4, 8], "texture": "#1"} + } + }, + { + "from": [2, 0, 14], + "to": [14, 2, 16], + "faces": { + "north": {"uv": [0, 0, 6, 1], "texture": "#1"}, + "east": {"uv": [7, 4.5, 8, 5.5], "texture": "#1"}, + "south": {"uv": [0, 1, 6, 2], "texture": "#1"}, + "west": {"uv": [5, 7, 6, 8], "texture": "#1"}, + "up": {"uv": [6, 3, 0, 2], "texture": "#1"}, + "down": {"uv": [6, 3, 0, 4], "texture": "#1"} + } + }, + { + "from": [2, 7, 14], + "to": [14, 9, 16], + "faces": { + "north": {"uv": [0, 4, 6, 5], "texture": "#1"}, + "east": {"uv": [7, 5.5, 8, 6.5], "texture": "#1"}, + "south": {"uv": [0, 5, 6, 6], "texture": "#1"}, + "west": {"uv": [7, 6.5, 8, 7.5], "texture": "#1"}, + "up": {"uv": [6, 7, 0, 6], "texture": "#1"}, + "down": {"uv": [12, 0, 6, 1], "texture": "#1"} + } + }, + { + "from": [2, 2, 14], + "to": [4, 7, 16], + "faces": { + "north": {"uv": [1, 7, 2, 9.5], "texture": "#1"}, + "east": {"uv": [7, 1, 8, 3.5], "texture": "#1"}, + "south": {"uv": [2, 7, 3, 9.5], "texture": "#1"}, + "west": {"uv": [3, 7, 4, 9.5], "texture": "#1"}, + "up": {"uv": [8, 8.5, 7, 7.5], "texture": "#1"}, + "down": {"uv": [9, 1, 8, 2], "texture": "#1"} + } + }, + { + "name": "Display", + "from": [4, 2, 15], + "to": [12, 7, 16], + "faces": { + "north": {"uv": [0, 0, 8, 5], "texture": "#2"}, + "east": {"uv": [8, 2, 9, 7], "texture": "#2"}, + "south": {"uv": [0, 5, 8, 10], "texture": "#2"}, + "west": {"uv": [8, 7, 9, 12], "texture": "#2"}, + "up": {"uv": [16, 1, 8, 0], "texture": "#2"}, + "down": {"uv": [16, 1, 8, 2], "texture": "#2"} + } + } + ], + "gui_light": "front", + "display": { + "thirdperson_righthand": { + "rotation": [20, 180, 0], + "translation": [2.75, 4.25, 9.25] + }, + "thirdperson_lefthand": { + "rotation": [-169, 0, 0], + "translation": [-11, -2, 7.25] + }, + "firstperson_righthand": { + "rotation": [157, 3, -180], + "translation": [9, 2, -7.25] + }, + "firstperson_lefthand": { + "rotation": [-180, 17, -180], + "translation": [8, 0.5, -3.75], + "scale": [0.97, 1, 1] + }, + "ground": { + "translation": [0, 4.75, 0] + }, + "gui": { + "rotation": [4, 180, 0], + "translation": [0, 2.75, 0] + }, + "fixed": { + "translation": [0.25, 3.5, -7.75] + } + }, + "groups": [ + { + "name": "Aussen", + "origin": [0, 0, 0], + "color": 0, + "children": [0, 1, 2, 3] + }, + 4 + ] +} diff --git a/src/main/resources/assets/richardts_decorations/models/block/tv_block_on.json b/src/main/resources/assets/richardts_decorations/models/block/tv_block_on.json new file mode 100644 index 0000000..166dce0 --- /dev/null +++ b/src/main/resources/assets/richardts_decorations/models/block/tv_block_on.json @@ -0,0 +1,112 @@ +{ + "credit": "Made with Blockbench", + "texture_size": [32, 32], + "textures": { + "1": "richardts_decorations:block/tv_block/rahmen", + "2": "richardts_decorations:block/tv_block/display_off", + "3": "richardts_decorations:block/tv_block/display", + "particle": "richardts_decorations:block/tv_block/rahmen" + }, + "elements": [ + { + "from": [12, 2, 14], + "to": [14, 7, 16], + "faces": { + "north": {"uv": [6, 1, 7, 3.5], "texture": "#1"}, + "east": {"uv": [6, 3.5, 7, 6], "texture": "#1"}, + "south": {"uv": [6, 6, 7, 8.5], "texture": "#1"}, + "west": {"uv": [0, 7, 1, 9.5], "texture": "#1"}, + "up": {"uv": [8, 4.5, 7, 3.5], "texture": "#1"}, + "down": {"uv": [5, 7, 4, 8], "texture": "#1"} + } + }, + { + "from": [2, 0, 14], + "to": [14, 2, 16], + "faces": { + "north": {"uv": [0, 0, 6, 1], "texture": "#1"}, + "east": {"uv": [7, 4.5, 8, 5.5], "texture": "#1"}, + "south": {"uv": [0, 1, 6, 2], "texture": "#1"}, + "west": {"uv": [5, 7, 6, 8], "texture": "#1"}, + "up": {"uv": [6, 3, 0, 2], "texture": "#1"}, + "down": {"uv": [6, 3, 0, 4], "texture": "#1"} + } + }, + { + "from": [2, 7, 14], + "to": [14, 9, 16], + "faces": { + "north": {"uv": [0, 4, 6, 5], "texture": "#1"}, + "east": {"uv": [7, 5.5, 8, 6.5], "texture": "#1"}, + "south": {"uv": [0, 5, 6, 6], "texture": "#1"}, + "west": {"uv": [7, 6.5, 8, 7.5], "texture": "#1"}, + "up": {"uv": [6, 7, 0, 6], "texture": "#1"}, + "down": {"uv": [12, 0, 6, 1], "texture": "#1"} + } + }, + { + "from": [2, 2, 14], + "to": [4, 7, 16], + "faces": { + "north": {"uv": [1, 7, 2, 9.5], "texture": "#1"}, + "east": {"uv": [7, 1, 8, 3.5], "texture": "#1"}, + "south": {"uv": [2, 7, 3, 9.5], "texture": "#1"}, + "west": {"uv": [3, 7, 4, 9.5], "texture": "#1"}, + "up": {"uv": [8, 8.5, 7, 7.5], "texture": "#1"}, + "down": {"uv": [9, 1, 8, 2], "texture": "#1"} + } + }, + { + "name": "Display", + "from": [4, 2, 15], + "to": [12, 7, 16], + "faces": { + "north": {"uv": [0, 0, 8, 5], "texture": "#3"}, + "east": {"uv": [8, 2, 9, 7], "texture": "#3"}, + "south": {"uv": [0, 5, 8, 10], "texture": "#3"}, + "west": {"uv": [8, 7, 9, 12], "texture": "#3"}, + "up": {"uv": [16, 1, 8, 0], "texture": "#3"}, + "down": {"uv": [16, 1, 8, 2], "texture": "#3"} + } + } + ], + "gui_light": "front", + "display": { + "thirdperson_righthand": { + "rotation": [20, 180, 0], + "translation": [2.75, 4.25, 9.25] + }, + "thirdperson_lefthand": { + "rotation": [-169, 0, 0], + "translation": [-11, -2, 7.25] + }, + "firstperson_righthand": { + "rotation": [157, 3, -180], + "translation": [9, 2, -7.25] + }, + "firstperson_lefthand": { + "rotation": [-180, 17, -180], + "translation": [8, 0.5, -3.75], + "scale": [0.97, 1, 1] + }, + "ground": { + "translation": [0, 4.75, 0] + }, + "gui": { + "rotation": [4, 180, 0], + "translation": [0, 2.75, 0] + }, + "fixed": { + "translation": [0.25, 3.5, -7.75] + } + }, + "groups": [ + { + "name": "Aussen", + "origin": [0, 0, 0], + "color": 0, + "children": [0, 1, 2, 3] + }, + 4 + ] +} diff --git a/src/main/resources/assets/richardts_decorations/models/item/tv_block.json b/src/main/resources/assets/richardts_decorations/models/item/tv_block.json new file mode 100644 index 0000000..5418f90 --- /dev/null +++ b/src/main/resources/assets/richardts_decorations/models/item/tv_block.json @@ -0,0 +1,3 @@ +{ + "parent": "richardts_decorations:block/tv_block_on" +} diff --git a/src/main/resources/assets/richardts_decorations/textures/block/tv_block/display.png b/src/main/resources/assets/richardts_decorations/textures/block/tv_block/display.png new file mode 100644 index 0000000000000000000000000000000000000000..0e9fd487ff00ea47782320f4f8ad807e4221e941 GIT binary patch literal 688 zcmV;h0#E&kP)o z2$E=J7a@o-d2i-k3*BXRvl}#TvDyQVdGo>CbI-YV==M#TAf}{%GIuy1XZv?NRd)t_V59gzx^P{ zSfk(ov91h_LRC2_WpXamwNuvy6sQU@I(T9B=s0Fd&Y4_0#GU2@L_tM(vr!=-P@jBE zIFex-q9?XKULphmbCx#?GY6fO?~VjOVsip7U)^Qy$~1)nUdXvZ17r$hr)1;x(gINv z=g(c{?KXh$et8iQX_s3(C4_)GNPsW%?+C#;F@J#&1R;f$DG;>-N9B?B$n1f)HQYa;31}RpU2{G2q38WN30;*6D zQc9Q`Pw#&sNI=X`3B(i;RaA^Ay#~P$5mvd{jDQs=R#BIl>5Wb5Vu*lc!!U3mh2OO> zJ$4;0JM5GS6=98g%@vT~IG_kIL`*WP#}1J!qaxtKOuB`8MGzyavCbV3Ck&wrWMX2% zTN8Khe@LYL?b`b@?zaoH^I}!)3eqoN=lY=ieFKS5$Vbrc4s~)sJqjYLR*1OUps@SDyrR14YLN?eKaWRPVaj$3yjkG@0000W(G(B3KX@) zQHXgoMyTKW=jX@x_)`d}e44ZqoItji#5N4c&p;4`MW7^${cacT9Bxaoyci%N*eJ47<;(ou^`{7o6TK$bDq_2zkKK_4z}nY!l87LNwtHp`^j5aF>b3VH&QPEeSgcs$p5Q-r#Sv_@T}%5_ zU7Swfk*ACAOHC|2Vyu^=sJ9ot;|m`BQ$B<9er+xS7cN}5@FM;KC@R%R2`oC600000 LNkvXXu0mjfb)3;3 literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/richardts_decorations/textures/block/tv_block/rahmen.png b/src/main/resources/assets/richardts_decorations/textures/block/tv_block/rahmen.png new file mode 100644 index 0000000000000000000000000000000000000000..066d2bc95929c03320add3f427a60bcca8975f4b GIT binary patch literal 828 zcmV-C1H=4@P)yFyp!OD4<`L6BJ1c?fh3oZ-@9%G< zlwO(N>cpHg?)N)ljNN3pATCnNi5|zlA0Hn`DOJCC0C1<%DSPh$0N#5vO#?nV=a5qB zEbG1RJ%DQn8UQhTgla=+gZLO{+Lx7%&dzx6w>8F;|kf53Zq@8O*5c9)u%i~;YWZQI$n zu@|eGgqE*12CV%9%n!z5z}{@;0RXCu0jtj_=iJotUyFnrEaV~G2;1wtp0M&h%pYT z%o-LC0Fjj%FrV*hN+(9NwEX^9;Hx1!>}`W{72gykui=LQF@(?sNP5oR6r+;%ge3}? z@)%}<@;Ht1y@|l^a8n1VpStRlH&9lC^#LGGo!tI(;nEA()?1%GN8FoDiXr_9)na{M zBLxs0P-{@c>NAjsA+_xNl7R;t4u{_J2NK|D0+ar8JeQh zuXhtE(^+N>3_L*I5S5~|-YTaU>tA}mumz(rfY#D35A?IdrPQ$45(5vAwL9B#^7Ial znLF2)|9?=U5(WyO)p;;N8Swf7{)7T_4A6m$?WOE}^E1cjE}(C6N;f+-Mf2ZMQ~>wx zscLPm|F1Ba2h@