Skip to content

Commit

Permalink
feat(block): new stone chest done!
Browse files Browse the repository at this point in the history
  • Loading branch information
CallMeEchoCodes committed Dec 16, 2024
1 parent 0d1659f commit 9171545
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.minecraft.world.WorldAccess;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -109,6 +110,18 @@ && getFacing(neighborState) == direction.getOpposite()) {
return super.getStateForNeighborUpdate(state, direction, neighborState, world, pos, neighborPos);
}

@Override
protected void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
super.onStateReplaced(state, world, pos, newState, moved);
if (state.isOf(newState.getBlock())) return;
ChestType type = state.get(CHEST_TYPE);
if (type == ChestType.SINGLE) return;

Direction facing = state.get(FACING);
BlockPos otherPos = pos.offset(type == ChestType.LEFT ? facing.rotateYClockwise() : facing.rotateYCounterclockwise());
world.breakBlock(otherPos, false);
}

public static Direction getFacing(BlockState state) {
Direction direction = state.get(FACING);
return state.get(CHEST_TYPE) == ChestType.LEFT ? direction.rotateYClockwise() : direction.rotateYCounterclockwise();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import dev.spiritstudios.hollow.registry.HollowBlockEntityTypes;
import dev.spiritstudios.hollow.registry.HollowBlocks;
import dev.spiritstudios.hollow.registry.HollowSoundEvents;
import dev.spiritstudios.specter.api.block.entity.LootableInventoryBlockEntity;
import net.minecraft.advancement.criterion.Criteria;
import net.minecraft.block.BlockState;
Expand All @@ -14,6 +15,7 @@
import net.minecraft.loot.context.LootContextParameters;
import net.minecraft.loot.context.LootContextTypes;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.registry.RegistryWrapper;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
Expand Down Expand Up @@ -57,20 +59,34 @@ public void checkLootInteraction(@Nullable PlayerEntity player, boolean randomSe

public void aboveBroken() {
if (world == null) return;
if (world.isClient()) return;
checkLootInteraction(null, true);
Vec3d centerPos = pos.toCenterPos();
inventory.stream()
.filter(stack -> !stack.isEmpty())
.map(stack -> new ItemEntity(world, centerPos.getX(), centerPos.getY() + 0.5, centerPos.getZ(), stack))
.forEach(itemEntity -> world.spawnEntity(itemEntity));

((ServerWorld) world).spawnParticles(
ParticleTypes.DUST_PLUME,
(double)pos.getX() + 0.5,
(double)pos.getY() + 0.9,
(double)pos.getZ() + 0.5,
7, 0.0, 0.0, 0.0, 0.0
);

world.playSound(null, pos, HollowSoundEvents.STONE_CHEST_EXTRACT, SoundCategory.BLOCKS);

inventory.clear();
}

public ItemActionResult use(PlayerEntity player, Hand hand, Direction side) {
if (world == null) return ItemActionResult.SKIP_DEFAULT_BLOCK_INTERACTION;
if (player.getStackInHand(hand).isEmpty() || player.getStackInHand(hand).isOf(HollowBlocks.STONE_CHEST_LID.asItem()) && side.equals(Direction.UP))
return ItemActionResult.SKIP_DEFAULT_BLOCK_INTERACTION;

if (!world.isAir(pos.up())) return ItemActionResult.SKIP_DEFAULT_BLOCK_INTERACTION;


int slot = -1;
for (int i = 0; i < inventory.size(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ public final class HollowSoundEvents {

@Name("block.sculk_jaw.bite")
public static final SoundEvent SCULK_JAW_BITE = SoundEvent.of(Hollow.id("block.sculk_jaw.bite"));

@Name("block.stone_chest.extract")
public static final SoundEvent STONE_CHEST_EXTRACT = SoundEvent.of(Hollow.id("block.stone_chest.extract"));
}
38 changes: 38 additions & 0 deletions src/main/resources/assets/hollow/models/block/stone_chest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"credit": "Made with Blockbench",
"parent": "block/block",
"texture_size": [64, 64],
"textures": {
"0": "hollow:block/stone_chest_single",
"particle": "block/chiseled_deepslate"
},
"elements": [
{
"name": "chest",
"from": [1, 1, 1],
"to": [15, 16, 15],
"rotation": {"angle": 0, "axis": "y", "origin": [16, 0, 0]},
"faces": {
"north": {"uv": [3.5, 3.5, 7, 7.25], "texture": "#0"},
"east": {"uv": [0, 3.5, 3.5, 7.25], "texture": "#0"},
"south": {"uv": [7, 3.5, 10.5, 7.25], "texture": "#0"},
"west": {"uv": [10.5, 3.5, 14, 7.25], "texture": "#0"},
"up": {"uv": [7, 3.5, 3.5, 0], "texture": "#0", "cullface": "up"}
}
},
{
"name": "base",
"from": [0, 0, 0],
"to": [16, 1, 16],
"rotation": {"angle": 0, "axis": "y", "origin": [16, 0, 0]},
"faces": {
"north": {"uv": [0, 8, 4, 8.25], "texture": "#0", "cullface": "north"},
"east": {"uv": [0, 8, 4, 8.25], "texture": "#0", "cullface": "east"},
"south": {"uv": [0, 8, 4, 8.25], "texture": "#0", "cullface": "south"},
"west": {"uv": [0, 8, 4, 8.25], "texture": "#0", "cullface": "west"},
"up": {"uv": [4, 12, 0, 8], "texture": "#0"},
"down": {"uv": [4, 12, 0, 16], "texture": "#0", "cullface": "down"}
}
}
]
}
24 changes: 24 additions & 0 deletions src/main/resources/assets/hollow/models/block/stone_chest_lid.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"credit": "Made with Blockbench",
"parent": "block/block",
"texture_size": [32, 32],
"textures": {
"2": "hollow:block/stone_chest_lid_single",
"particle": "block/chiseled_deepslate"
},
"elements": [
{
"from": [1, 0, 1],
"to": [15, 4, 15],
"rotation": {"angle": 0, "axis": "y", "origin": [16, -22, 0]},
"faces": {
"north": {"uv": [7, 0, 14, 2], "texture": "#2"},
"east": {"uv": [7, 6, 14, 8], "texture": "#2"},
"south": {"uv": [7, 2, 14, 4], "texture": "#2"},
"west": {"uv": [7, 4, 14, 6], "texture": "#2"},
"up": {"uv": [7, 7, 0, 0], "texture": "#2"},
"down": {"uv": [7, 7, 0, 14], "texture": "#2", "cullface": "down"}
}
}
]
}
20 changes: 20 additions & 0 deletions src/main/resources/assets/hollow/sounds.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,26 @@
}
]
},
"block.stone_chest.extract": {
"sounds": [
{
"name": "block/decorated_pot/insert1",
"volume": 0.9
},
{
"name": "block/decorated_pot/insert2",
"volume": 0.9
},
{
"name": "block/decorated_pot/insert3",
"volume": 0.9
},
{
"name": "block/decorated_pot/insert4",
"volume": 0.9
}
]
},
"block.sculk_jaw.bite": {
"subtitle": "subtitles.block.sculk_jaw.bite",
"sounds": [
Expand Down
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.

0 comments on commit 9171545

Please sign in to comment.