Skip to content

Commit

Permalink
Merge branch 'v1.0.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
Richie1710 committed Jan 5, 2024
2 parents f867b20 + 4786e7e commit bf97263
Show file tree
Hide file tree
Showing 11 changed files with 386 additions and 1 deletion.
166 changes: 166 additions & 0 deletions src/main/java/de/richardt/decorations/MicrowaveBlock.java
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 src/main/java/de/richardt/decorations/MicrowaveBlockEntity.java
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");
}
}
10 changes: 10 additions & 0 deletions src/main/java/de/richardt/decorations/Richardts_decorations.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder;
import net.fabricmc.fabric.api.registry.CompostingChanceRegistry;
import net.fabricmc.fabric.api.registry.FuelRegistry;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
Expand Down Expand Up @@ -34,6 +36,11 @@ public class Richardts_decorations implements ModInitializer {
public static final FloorLampBlock FLOORLAMPBLOCK = new FloorLampBlock(FabricBlockSettings.create().strength(4.0f).luminance(state -> state.get(FloorLampBlock.GLOWING) ? 15 : 0));
public static final ThermoMixBlock THERMOMIXBLOCK = new ThermoMixBlock(FabricBlockSettings.create().strength(4.0f));
public static final NotebookBlock NOTEBOOKBLOCK = new NotebookBlock(FabricBlockSettings.create().strength(4.0f));
public static final MicrowaveBlock MICROWAVE_BLOCK = new MicrowaveBlock(FabricBlockSettings.create().strength(4.0f).luminance(state -> state.get(MicrowaveBlock.POWER) ? 8 : 0));;
public static final BlockEntityType<MicrowaveBlockEntity> MICROWAVE_BLOCK_ENTITY = Registry.register(
Registries.BLOCK_ENTITY_TYPE, new Identifier("richardts_decorations", "microwave_block_entity"),
FabricBlockEntityTypeBuilder.create(MicrowaveBlockEntity::new, MICROWAVE_BLOCK).build()
);
private static final ItemGroup ITEM_GROUP = FabricItemGroup.builder()
.icon(() -> new ItemStack(THERMOMIXBLOCK))
.displayName(Text.translatable("itemGroup.richardts_decorations.test_group"))
Expand All @@ -51,6 +58,7 @@ public class Richardts_decorations implements ModInitializer {
entries.add(QUAD_BLADE_ITEM);
entries.add(TV_BLOCK);
entries.add(TV_BLOCK_LARGE);
entries.add(MICROWAVE_BLOCK);

})
.build();
Expand Down Expand Up @@ -85,5 +93,7 @@ public void onInitialize() {
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);
Registry.register(Registries.ITEM, new Identifier("richardts_decorations", "notebook_block"), new BlockItem(NOTEBOOKBLOCK, new FabricItemSettings()));
Registry.register(Registries.BLOCK, new Identifier("richardts_decorations", "microwave_block"), MICROWAVE_BLOCK);
Registry.register(Registries.ITEM, new Identifier("richardts_decorations", "microwave_block"), new BlockItem(MICROWAVE_BLOCK, new FabricItemSettings()));
}
}
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 }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
"itemGroup.richardts_decorations.test_group": "Richardts Decorations",
"item.richardts_decorations.custom_item.tooltip": "My Tooltip",
"block.richardts_decorations.tv_block_large": "TV(Large)",
"block.richardts_decorations.tv_block": "TV"
"block.richardts_decorations.tv_block": "TV",
"block.richardts_decorations.microwave_block": "Microwave"
}
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]
}
}
}
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]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "richardts_decorations:block/microwave_block_off"
}
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

0 comments on commit bf97263

Please sign in to comment.