-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
386 additions
and
1 deletion.
There are no files selected for viewing
166 changes: 166 additions & 0 deletions
166
src/main/java/de/richardt/decorations/MicrowaveBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
package de.richardt.decorations; | ||
|
||
|
||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.minecraft.block.*; | ||
import net.minecraft.block.entity.BlockEntity; | ||
import net.minecraft.block.entity.BlockEntityTicker; | ||
import net.minecraft.block.entity.BlockEntityType; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.item.ItemPlacementContext; | ||
import net.minecraft.particle.ParticleTypes; | ||
import net.minecraft.screen.NamedScreenHandlerFactory; | ||
import net.minecraft.sound.SoundCategory; | ||
import net.minecraft.sound.SoundEvents; | ||
import net.minecraft.stat.Stats; | ||
import net.minecraft.state.StateManager; | ||
import net.minecraft.state.property.BooleanProperty; | ||
import net.minecraft.state.property.DirectionProperty; | ||
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.math.random.Random; | ||
import net.minecraft.util.shape.VoxelShape; | ||
import net.minecraft.util.shape.VoxelShapes; | ||
import net.minecraft.world.BlockView; | ||
import net.minecraft.world.World; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
|
||
//public class MicrowaveBlock extends HorizontalFacingBlock implements BlockEntityProvider { | ||
public class MicrowaveBlock extends BlockWithEntity { | ||
public static final BooleanProperty POWER = BooleanProperty.of("power"); | ||
private static final DirectionProperty FACING = HorizontalFacingBlock.FACING; | ||
|
||
public MicrowaveBlock(Settings settings) { | ||
super(settings); | ||
setDefaultState(getDefaultState().with(Properties.HORIZONTAL_FACING, Direction.NORTH).with(POWER, false)); | ||
} | ||
@Nullable | ||
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state, BlockEntityType<T> type) { | ||
return checkType(world, type, Richardts_decorations.MICROWAVE_BLOCK_ENTITY); | ||
} | ||
@Nullable | ||
@Override | ||
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) { | ||
return new MicrowaveBlockEntity(pos, state); | ||
} | ||
|
||
@Override | ||
public BlockRenderType getRenderType(BlockState state) { | ||
// With inheriting from BlockWithEntity this defaults to INVISIBLE, so we need to change that! | ||
return BlockRenderType.MODEL; | ||
} | ||
|
||
@Override | ||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder){ | ||
builder.add(Properties.HORIZONTAL_FACING); | ||
builder.add(POWER); | ||
} | ||
|
||
@Environment(EnvType.CLIENT) | ||
@Override | ||
public void randomDisplayTick(BlockState state, World world, BlockPos pos, Random random) { | ||
if (state.get(POWER)) { | ||
double x = (double) pos.getX() + 0.5D; | ||
double y = (double) pos.getY(); | ||
double z = (double) pos.getZ() + 0.5D; | ||
|
||
if (random.nextDouble() < 0.1D) { | ||
world.playSound(x, y, z, SoundEvents.BLOCK_FURNACE_FIRE_CRACKLE, SoundCategory.BLOCKS, 1.0F, 1.0F, false); | ||
} | ||
|
||
Direction direction_1 = state.get(FACING); | ||
Direction.Axis direction$Axis_1 = direction_1.getAxis(); | ||
|
||
double double_5 = random.nextDouble() * 0.6D - 0.3D; | ||
double double_6 = direction$Axis_1 == Direction.Axis.X ? (double) direction_1.getOffsetX() * 0.52D : double_5; | ||
double double_7 = random.nextDouble() * 6.0D / 16.0D; | ||
double double_8 = direction$Axis_1 == Direction.Axis.Z ? (double) direction_1.getOffsetZ() * 0.52D : double_5; | ||
|
||
world.addParticle(ParticleTypes.SMOKE, x + double_6, y + double_7, z + double_8, 0.0D, 0.0D, 0.0D); | ||
} | ||
} | ||
@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 ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { | ||
if (!world.isClient) { | ||
player.playSound(SoundEvents.BLOCK_LEVER_CLICK, 1, 1); | ||
world.setBlockState(pos, state.cycle(POWER)); | ||
this.openContainer(world, pos, player); | ||
} | ||
|
||
return ActionResult.SUCCESS; | ||
} | ||
|
||
private void openContainer(World world, BlockPos blockPos, PlayerEntity playerEntity) { | ||
BlockEntity blockEntity = world.getBlockEntity(blockPos); | ||
|
||
if (blockEntity instanceof MicrowaveBlockEntity) { | ||
playerEntity.openHandledScreen((NamedScreenHandlerFactory) blockEntity); | ||
playerEntity.increaseStat(Stats.INTERACT_WITH_FURNACE, 1); | ||
} | ||
} | ||
@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(baseShape, direction); | ||
} | ||
|
||
private VoxelShape createBaseShape() { | ||
return VoxelShapes.union( | ||
VoxelShapes.cuboid(3 / 16f, 0 / 16f, 4 / 16f, 14 / 16f, 7 / 16f, 11 / 16f), | ||
VoxelShapes.cuboid(7 / 16f, 1 / 16f, 3 / 16f, 8 / 16f, 6 / 16f, 4 / 16f) | ||
); | ||
} | ||
|
||
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; | ||
} | ||
@Nullable | ||
protected static <T extends BlockEntity> BlockEntityTicker<T> checkType(World world, BlockEntityType<T> givenType, BlockEntityType<? extends MicrowaveBlockEntity> expectedType) { | ||
return world.isClient ? null : checkType(givenType, expectedType, MicrowaveBlockEntity::tick); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/de/richardt/decorations/MicrowaveBlockEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package de.richardt.decorations; | ||
|
||
import net.minecraft.block.BlockState; | ||
import net.minecraft.block.entity.AbstractFurnaceBlockEntity; | ||
import net.minecraft.entity.player.PlayerInventory; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.recipe.RecipeType; | ||
import net.minecraft.screen.FurnaceScreenHandler; | ||
import net.minecraft.screen.ScreenHandler; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.math.BlockPos; | ||
|
||
public class MicrowaveBlockEntity extends AbstractFurnaceBlockEntity { | ||
|
||
public MicrowaveBlockEntity(BlockPos pos, BlockState state) { | ||
super(Richardts_decorations.MICROWAVE_BLOCK_ENTITY, pos, state, RecipeType.SMELTING); | ||
} | ||
|
||
@Override | ||
public int getFuelTime(ItemStack fuel) { | ||
return super.getFuelTime(fuel); | ||
} | ||
|
||
|
||
@Override | ||
public ScreenHandler createScreenHandler(int syncId, PlayerInventory playerInventory) { | ||
return new FurnaceScreenHandler(syncId, playerInventory, this, this.propertyDelegate); | ||
} | ||
|
||
@Override | ||
public Text getContainerName() { | ||
return Text.translatable("block.richardts_decorations.microwave_block"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/main/resources/assets/richardts_decorations/blockstates/microwave_block.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"variants": { | ||
"facing=north,power=false": { "model": "richardts_decorations:block/microwave_block_off" }, | ||
"facing=east,power=false" : { "model": "richardts_decorations:block/microwave_block_off", "y": 90 }, | ||
"facing=south,power=false": { "model": "richardts_decorations:block/microwave_block_off", "y": 180 }, | ||
"facing=west,power=false" : { "model": "richardts_decorations:block/microwave_block_off", "y": 270 }, | ||
"facing=north,power=true" : { "model": "richardts_decorations:block/microwave_block_on" }, | ||
"facing=east,power=true" : { "model": "richardts_decorations:block/microwave_block_on", "y": 90 }, | ||
"facing=south,power=true": { "model": "richardts_decorations:block/microwave_block_on", "y": 180 }, | ||
"facing=west,power=true" : { "model": "richardts_decorations:block/microwave_block_on", "y": 270 } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/main/resources/assets/richardts_decorations/models/block/microwave_block_off.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
{ | ||
"credit": "Made with Blockbench", | ||
"texture_size": [32, 32], | ||
"textures": { | ||
"0": "richardts_decorations:block/microwave/microwave_block_off", | ||
"particle": "richardts_decorations:block/microwave/microwave_block_off" | ||
}, | ||
"elements": [ | ||
{ | ||
"from": [3, 0, 4], | ||
"to": [14, 7, 11], | ||
"faces": { | ||
"north": {"uv": [0, 0, 5.5, 3.5], "texture": "#0"}, | ||
"east": {"uv": [0, 7, 3.5, 10.5], "texture": "#0"}, | ||
"south": {"uv": [0, 3.5, 5.5, 7], "texture": "#0"}, | ||
"west": {"uv": [3.5, 7, 7, 10.5], "texture": "#0"}, | ||
"up": {"uv": [11, 3.5, 5.5, 0], "texture": "#0"}, | ||
"down": {"uv": [11, 3.5, 5.5, 7], "texture": "#0"} | ||
} | ||
}, | ||
{ | ||
"from": [7, 1, 3], | ||
"to": [8, 6, 4], | ||
"faces": { | ||
"north": {"uv": [7, 7, 7.5, 9.5], "texture": "#0"}, | ||
"east": {"uv": [7.5, 7, 8, 9.5], "texture": "#0"}, | ||
"south": {"uv": [8, 7, 8.5, 9.5], "texture": "#0"}, | ||
"west": {"uv": [8.5, 7, 9, 9.5], "texture": "#0"}, | ||
"up": {"uv": [9.5, 7.5, 9, 7], "texture": "#0"}, | ||
"down": {"uv": [9.5, 7.5, 9, 8], "texture": "#0"} | ||
} | ||
} | ||
], | ||
"display": { | ||
"thirdperson_righthand": { | ||
"rotation": [0, 180, 0], | ||
"translation": [1.25, 4.25, -1.75], | ||
"scale": [0.75, 0.75, 0.75] | ||
}, | ||
"thirdperson_lefthand": { | ||
"rotation": [0, 180, 0], | ||
"translation": [1, 4.5, -1], | ||
"scale": [0.75, 0.75, 0.75] | ||
}, | ||
"firstperson_righthand": { | ||
"rotation": [0, 180, 0], | ||
"translation": [1.25, 5.25, 1.25], | ||
"scale": [0.5, 0.5, 0.25] | ||
}, | ||
"firstperson_lefthand": { | ||
"rotation": [0, 180, 0], | ||
"translation": [0, 5.25, 1.25], | ||
"scale": [0.5, 0.5, 0.3] | ||
}, | ||
"ground": { | ||
"translation": [0, 4, 0] | ||
}, | ||
"gui": { | ||
"rotation": [0, 180, 0], | ||
"translation": [0.5, 4.25, 0] | ||
}, | ||
"fixed": { | ||
"translation": [-1.5, 5, 0] | ||
} | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
src/main/resources/assets/richardts_decorations/models/block/microwave_block_on.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
{ | ||
"credit": "Made with Blockbench", | ||
"texture_size": [32, 32], | ||
"textures": { | ||
"0": "richardts_decorations:block/microwave/microwave_block_on", | ||
"particle": "richardts_decorations:block/microwave/microwave_block_on" | ||
}, | ||
"elements": [ | ||
{ | ||
"from": [3, 0, 4], | ||
"to": [14, 7, 11], | ||
"faces": { | ||
"north": {"uv": [0, 0, 5.5, 3.5], "texture": "#0"}, | ||
"east": {"uv": [0, 7, 3.5, 10.5], "texture": "#0"}, | ||
"south": {"uv": [0, 3.5, 5.5, 7], "texture": "#0"}, | ||
"west": {"uv": [3.5, 7, 7, 10.5], "texture": "#0"}, | ||
"up": {"uv": [11, 3.5, 5.5, 0], "texture": "#0"}, | ||
"down": {"uv": [11, 3.5, 5.5, 7], "texture": "#0"} | ||
} | ||
}, | ||
{ | ||
"from": [7, 1, 3], | ||
"to": [8, 6, 4], | ||
"faces": { | ||
"north": {"uv": [7, 7, 7.5, 9.5], "texture": "#0"}, | ||
"east": {"uv": [7.5, 7, 8, 9.5], "texture": "#0"}, | ||
"south": {"uv": [8, 7, 8.5, 9.5], "texture": "#0"}, | ||
"west": {"uv": [8.5, 7, 9, 9.5], "texture": "#0"}, | ||
"up": {"uv": [9.5, 7.5, 9, 7], "texture": "#0"}, | ||
"down": {"uv": [9.5, 7.5, 9, 8], "texture": "#0"} | ||
} | ||
} | ||
], | ||
"display": { | ||
"thirdperson_righthand": { | ||
"rotation": [0, 180, 0], | ||
"translation": [1.25, 4.25, -1.75], | ||
"scale": [0.75, 0.75, 0.75] | ||
}, | ||
"thirdperson_lefthand": { | ||
"rotation": [0, 180, 0], | ||
"translation": [1, 4.5, -1], | ||
"scale": [0.75, 0.75, 0.75] | ||
}, | ||
"firstperson_righthand": { | ||
"rotation": [0, 180, 0], | ||
"translation": [1.25, 5.25, 1.25], | ||
"scale": [0.5, 0.5, 0.25] | ||
}, | ||
"firstperson_lefthand": { | ||
"rotation": [0, 180, 0], | ||
"translation": [0, 5.25, 1.25], | ||
"scale": [0.5, 0.5, 0.3] | ||
}, | ||
"ground": { | ||
"translation": [0, 4, 0] | ||
}, | ||
"gui": { | ||
"rotation": [0, 180, 0], | ||
"translation": [0.5, 4.25, 0] | ||
}, | ||
"fixed": { | ||
"translation": [-1.5, 5, 0] | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
src/main/resources/assets/richardts_decorations/models/item/microwave_block.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"parent": "richardts_decorations:block/microwave_block_off" | ||
} |
Binary file added
BIN
+3.57 KB
...s/assets/richardts_decorations/textures/block/microwave/microwave_block_off.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.72 KB
...es/assets/richardts_decorations/textures/block/microwave/microwave_block_on.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.