Skip to content

Commit

Permalink
add TV Block
Browse files Browse the repository at this point in the history
  • Loading branch information
Richie1710 committed Dec 19, 2023
1 parent 4daa641 commit bb9f282
Show file tree
Hide file tree
Showing 11 changed files with 376 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down
114 changes: 114 additions & 0 deletions src/main/java/de/richardt/decorations/TVBlock.java
Original file line number Diff line number Diff line change
@@ -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<Block, BlockState> 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;
}


}
Empty file.
Original file line number Diff line number Diff line change
@@ -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 }
}
}
Original file line number Diff line number Diff line change
@@ -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
]
}
Original file line number Diff line number Diff line change
@@ -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
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "richardts_decorations:block/tv_block_on"
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"type": "minecraft:crafting_shaped",
"pattern": [
"PPP",
"PRP",
"PPP"
],
"key": {
"R":{
"item": "minecraft:redstone"
},
"P": {
"item": "richardts_decorations:plastic_item"
}
},
"result": {
"item": "richardts_decorations:tv_block",
"count": 1
}
}

0 comments on commit bb9f282

Please sign in to comment.