From 443c8800b7b08726d429130cad85de9ebdd0264c Mon Sep 17 00:00:00 2001 From: WenXin2 Date: Mon, 2 Sep 2024 22:24:20 -0500 Subject: [PATCH] Add coin block --- .../marioverse/blocks/ClearWarpPipeBlock.java | 2 +- .../wenxin2/marioverse/blocks/CoinBlock.java | 129 ++++++++++++++++++ .../marioverse/init/BlockRegistry.java | 7 + .../assets/marioverse/blockstates/coin.json | 64 +++++++++ .../marioverse/models/block/coin/coin.json | 25 ++++ .../marioverse/models/block/coin/coin_22.json | 25 ++++ .../marioverse/models/block/coin/coin_45.json | 25 ++++ .../marioverse/models/block/coin/coin_67.json | 25 ++++ .../assets/marioverse/models/item/coin.json | 6 + .../assets/marioverse/textures/block/coin.png | Bin 0 -> 262 bytes .../assets/marioverse/textures/item/coin.png | Bin 0 -> 255 bytes 11 files changed, 307 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/wenxin2/marioverse/blocks/CoinBlock.java create mode 100644 src/main/resources/assets/marioverse/blockstates/coin.json create mode 100644 src/main/resources/assets/marioverse/models/block/coin/coin.json create mode 100644 src/main/resources/assets/marioverse/models/block/coin/coin_22.json create mode 100644 src/main/resources/assets/marioverse/models/block/coin/coin_45.json create mode 100644 src/main/resources/assets/marioverse/models/block/coin/coin_67.json create mode 100644 src/main/resources/assets/marioverse/models/item/coin.json create mode 100644 src/main/resources/assets/marioverse/textures/block/coin.png create mode 100644 src/main/resources/assets/marioverse/textures/item/coin.png diff --git a/src/main/java/com/wenxin2/marioverse/blocks/ClearWarpPipeBlock.java b/src/main/java/com/wenxin2/marioverse/blocks/ClearWarpPipeBlock.java index 9baa9f81..d6b63c48 100644 --- a/src/main/java/com/wenxin2/marioverse/blocks/ClearWarpPipeBlock.java +++ b/src/main/java/com/wenxin2/marioverse/blocks/ClearWarpPipeBlock.java @@ -312,7 +312,7 @@ public boolean skipRendering(BlockState state, BlockState neighborState, Directi } @Override - public BlockState updateShape(BlockState state, Direction direction, BlockState neighborState, LevelAccessor worldAccessor, BlockPos pos, BlockPos pos2) { + public BlockState updateShape(BlockState state, Direction direction, BlockState neighborState, LevelAccessor worldAccessor, BlockPos pos, BlockPos neighborPos) { Block blockAbove = worldAccessor.getBlockState(pos.above()).getBlock(); Block blockBelow = worldAccessor.getBlockState(pos.below()).getBlock(); Block blockNorth = worldAccessor.getBlockState(pos.north()).getBlock(); diff --git a/src/main/java/com/wenxin2/marioverse/blocks/CoinBlock.java b/src/main/java/com/wenxin2/marioverse/blocks/CoinBlock.java new file mode 100644 index 00000000..9d199db5 --- /dev/null +++ b/src/main/java/com/wenxin2/marioverse/blocks/CoinBlock.java @@ -0,0 +1,129 @@ +package com.wenxin2.marioverse.blocks; + +import com.wenxin2.marioverse.init.BlockRegistry; +import java.util.Properties; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.tags.FluidTags; +import net.minecraft.util.RandomSource; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.context.BlockPlaceContext; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Mirror; +import net.minecraft.world.level.block.Rotation; +import net.minecraft.world.level.block.SimpleWaterloggedBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; +import net.minecraft.world.level.block.state.properties.BooleanProperty; +import net.minecraft.world.level.block.state.properties.IntegerProperty; +import net.minecraft.world.level.block.state.properties.RotationSegment; +import net.minecraft.world.level.material.FluidState; +import net.minecraft.world.level.material.Fluids; +import net.minecraft.world.phys.shapes.VoxelShape; +import org.jetbrains.annotations.NotNull; + +public class CoinBlock extends Block implements SimpleWaterloggedBlock { + public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; + public static final IntegerProperty ROTATION = BlockStateProperties.ROTATION_16; + public static final int MAX = RotationSegment.getMaxSegmentIndex(); + private static final int ROTATIONS = MAX + 1; + + protected static final VoxelShape SHAPE = Block.box(4.0, 0.0, 4.0, 12.0, 8.0, 12.0); + protected static final VoxelShape ANGLED = Block.box(4.0, 0.0, 4.0, 12.0, 8.0, 12.0); + + public CoinBlock(Properties properties) { + super(properties); + this.registerDefaultState(this.stateDefinition.any().setValue(WATERLOGGED, Boolean.FALSE).setValue(ROTATION, 0)); + } + + @Override + protected void createBlockStateDefinition(StateDefinition.Builder stateBuilder) { + stateBuilder.add(ROTATION, WATERLOGGED); + } + + @Override + public BlockState getStateForPlacement(BlockPlaceContext placeContext) { + FluidState fluidState = placeContext.getLevel().getFluidState(placeContext.getClickedPos()); + + return this.defaultBlockState().setValue(WATERLOGGED, fluidState.is(FluidTags.WATER) && fluidState.getAmount() == 8) + .setValue(ROTATION, RotationSegment.convertToSegment(placeContext.getRotation())); + } + + @Override + public void onPlace(BlockState state, Level world, BlockPos pos, BlockState oldState, boolean notify) { + if (!world.isClientSide()) { + world.scheduleTick(pos, this, 1); + } + super.onPlace(state, world, pos, oldState, notify); + } + + @Override + protected void neighborChanged(BlockState state, Level world, BlockPos pos, Block blockNeighbor, BlockPos posNeighbor, boolean isMoving) { + if (!world.isClientSide()) { + world.scheduleTick(pos, this, 1); + } + super.neighborChanged(state, world, pos, blockNeighbor, posNeighbor, isMoving); + } + + @NotNull + @Override + public BlockState updateShape(BlockState state, Direction direction, BlockState neighborState, LevelAccessor worldAccessor, BlockPos pos, BlockPos neighborPos) { + if (state.getValue(WATERLOGGED)) { + worldAccessor.scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(worldAccessor)); + } + + return super.updateShape(state, direction, neighborState, worldAccessor, pos, neighborPos); + } + + @Override + protected void tick(BlockState state, ServerLevel serverWorld, BlockPos pos, RandomSource random) { + int currentRotation = state.getValue(ROTATION); + int nextRotation = (currentRotation + 1) % 16; // Cycle through all 16 rotation states + + serverWorld.setBlock(pos, state.setValue(ROTATION, nextRotation), 3); + + serverWorld.scheduleTick(pos, this, 1); + super.tick(state, serverWorld, pos, random); + } + + @NotNull + @Override + protected BlockState rotate(BlockState state, Rotation rotation) { + return state.setValue(ROTATION, rotation.rotate(state.getValue(ROTATION), ROTATIONS)); + } + + @NotNull + @Override + protected BlockState mirror(BlockState state, Mirror mirror) { + return state.setValue(ROTATION, mirror.mirror(state.getValue(ROTATION), ROTATIONS)); + } + + @Override + protected void entityInside(BlockState state, Level world, BlockPos pos, Entity entity) { + ItemStack coinItem = new ItemStack(this.asItem()); + + if (entity instanceof Player player) { + world.removeBlock(pos, Boolean.TRUE); + player.addItem(coinItem); + + if (!player.addItem(coinItem)) { + player.drop(coinItem, false); + } + } + super.entityInside(state, world, pos, entity); + } + + @NotNull + @Override + public FluidState getFluidState(final BlockState state) + { + return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state); + } +} diff --git a/src/main/java/com/wenxin2/marioverse/init/BlockRegistry.java b/src/main/java/com/wenxin2/marioverse/init/BlockRegistry.java index bcc2ee09..6a6c2a79 100644 --- a/src/main/java/com/wenxin2/marioverse/init/BlockRegistry.java +++ b/src/main/java/com/wenxin2/marioverse/init/BlockRegistry.java @@ -2,6 +2,7 @@ import com.wenxin2.marioverse.Marioverse; import com.wenxin2.marioverse.blocks.ClearWarpPipeBlock; +import com.wenxin2.marioverse.blocks.CoinBlock; import com.wenxin2.marioverse.blocks.PipeBubblesBlock; import com.wenxin2.marioverse.blocks.WarpPipeBlock; import com.wenxin2.marioverse.blocks.WaterSpoutBlock; @@ -34,12 +35,18 @@ public class BlockRegistry { public static final EnumMap> WARP_PIPES = new EnumMap<>(DyeColor.class); + public static final DeferredBlock COIN; public static final DeferredBlock CLEAR_WARP_PIPE; public static final DeferredBlock PIPE_BUBBLES; public static final DeferredBlock WATER_SPOUT; static { + COIN = registerBlock("coin", + () -> new CoinBlock(BlockBehaviour.Properties.of().mapColor(MapColor.GOLD) + .sound(SoundType.NETHERITE_BLOCK).isSuffocating(BlockRegistry::never).isViewBlocking(BlockRegistry::never) + .strength(0.5F, 0.5F).instabreak().noCollission())); + CLEAR_WARP_PIPE = registerBlock("clear_warp_pipe", () -> new ClearWarpPipeBlock(BlockBehaviour.Properties.of().mapColor(MapColor.NONE) .sound(SoundType.GLASS).isSuffocating(BlockRegistry::never).isViewBlocking(BlockRegistry::never) diff --git a/src/main/resources/assets/marioverse/blockstates/coin.json b/src/main/resources/assets/marioverse/blockstates/coin.json new file mode 100644 index 00000000..e8f06ece --- /dev/null +++ b/src/main/resources/assets/marioverse/blockstates/coin.json @@ -0,0 +1,64 @@ +{ + "variants": { + "rotation=0": { + "model": "marioverse:block/coin/coin" + }, + "rotation=1": { + "model": "marioverse:block/coin/coin_22" + }, + "rotation=2": { + "model": "marioverse:block/coin/coin_45" + }, + "rotation=3": { + "model": "marioverse:block/coin/coin_67" + }, + "rotation=4": { + "model": "marioverse:block/coin/coin", + "y": 90 + }, + "rotation=5": { + "model": "marioverse:block/coin/coin_22", + "y": 90 + }, + "rotation=6": { + "model": "marioverse:block/coin/coin_45", + "y": 90 + }, + "rotation=7": { + "model": "marioverse:block/coin/coin_67", + "y": 90 + }, + "rotation=8": { + "model": "marioverse:block/coin/coin", + "y": 180 + }, + "rotation=9": { + "model": "marioverse:block/coin/coin_22", + "y": 180 + }, + "rotation=10": { + "model": "marioverse:block/coin/coin_45", + "y": 180 + }, + "rotation=11": { + "model": "marioverse:block/coin/coin_67", + "y": 180 + }, + "rotation=12": { + "model": "marioverse:block/coin/coin", + "y": 270 + }, + "rotation=13": { + "model": "marioverse:block/coin/coin_22", + "y": 270 + }, + "rotation=14": { + "model": "marioverse:block/coin/coin_45", + "y": 270 + }, + "rotation=15": { + "model": "marioverse:block/coin/coin_67", + "y": 270 + } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/marioverse/models/block/coin/coin.json b/src/main/resources/assets/marioverse/models/block/coin/coin.json new file mode 100644 index 00000000..b15ff87a --- /dev/null +++ b/src/main/resources/assets/marioverse/models/block/coin/coin.json @@ -0,0 +1,25 @@ +{ + "credit": "Made with Blockbench", + "parent": "minecraft:block/cube_bottom_top", + "render_type": "cutout", + "textures": { + "particle": "marioverse:block/coin", + "coin": "marioverse:block/coin" + }, + "elements": [ + { + "name": "coin", + "from": [3, 3, 7], + "to": [13, 15, 9], + "rotation": {"angle": 0, "axis": "y", "origin": [8, 9, 8]}, + "faces": { + "north": {"uv": [3, 2, 13, 14], "texture": "#coin"}, + "east": {"uv": [0, 2, 2, 14], "texture": "#coin"}, + "south": {"uv": [13, 2, 3, 14], "texture": "#coin"}, + "west": {"uv": [14, 2, 16, 14], "texture": "#coin"}, + "up": {"uv": [3, 0, 13, 2], "rotation": 180, "texture": "#coin"}, + "down": {"uv": [3, 14, 13, 16], "rotation": 180, "texture": "#coin"} + } + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/marioverse/models/block/coin/coin_22.json b/src/main/resources/assets/marioverse/models/block/coin/coin_22.json new file mode 100644 index 00000000..b679d5df --- /dev/null +++ b/src/main/resources/assets/marioverse/models/block/coin/coin_22.json @@ -0,0 +1,25 @@ +{ + "credit": "Made with Blockbench", + "parent": "minecraft:block/cube_bottom_top", + "render_type": "cutout", + "textures": { + "particle": "marioverse:block/coin", + "coin": "marioverse:block/coin" + }, + "elements": [ + { + "name": "coin", + "from": [3, 3, 7], + "to": [13, 15, 9], + "rotation": {"angle": -22.5, "axis": "y", "origin": [8, 9, 8]}, + "faces": { + "north": {"uv": [3, 2, 13, 14], "texture": "#coin"}, + "east": {"uv": [0, 2, 2, 14], "texture": "#coin"}, + "south": {"uv": [13, 2, 3, 14], "texture": "#coin"}, + "west": {"uv": [14, 2, 16, 14], "texture": "#coin"}, + "up": {"uv": [3, 0, 13, 2], "rotation": 180, "texture": "#coin"}, + "down": {"uv": [3, 14, 13, 16], "rotation": 180, "texture": "#coin"} + } + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/marioverse/models/block/coin/coin_45.json b/src/main/resources/assets/marioverse/models/block/coin/coin_45.json new file mode 100644 index 00000000..6c4f2bde --- /dev/null +++ b/src/main/resources/assets/marioverse/models/block/coin/coin_45.json @@ -0,0 +1,25 @@ +{ + "credit": "Made with Blockbench", + "parent": "minecraft:block/cube_bottom_top", + "render_type": "cutout", + "textures": { + "particle": "marioverse:block/coin", + "coin": "marioverse:block/coin" + }, + "elements": [ + { + "name": "coin", + "from": [3, 3, 7], + "to": [13, 15, 9], + "rotation": {"angle": -45, "axis": "y", "origin": [8, 9, 8]}, + "faces": { + "north": {"uv": [3, 2, 13, 14], "texture": "#coin"}, + "east": {"uv": [0, 2, 2, 14], "texture": "#coin"}, + "south": {"uv": [13, 2, 3, 14], "texture": "#coin"}, + "west": {"uv": [14, 2, 16, 14], "texture": "#coin"}, + "up": {"uv": [3, 0, 13, 2], "rotation": 180, "texture": "#coin"}, + "down": {"uv": [3, 14, 13, 16], "rotation": 180, "texture": "#coin"} + } + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/marioverse/models/block/coin/coin_67.json b/src/main/resources/assets/marioverse/models/block/coin/coin_67.json new file mode 100644 index 00000000..cb3202d2 --- /dev/null +++ b/src/main/resources/assets/marioverse/models/block/coin/coin_67.json @@ -0,0 +1,25 @@ +{ + "credit": "Made with Blockbench", + "parent": "minecraft:block/cube_bottom_top", + "render_type": "cutout", + "textures": { + "particle": "marioverse:block/coin", + "coin": "marioverse:block/coin" + }, + "elements": [ + { + "name": "coin", + "from": [7, 3, 3], + "to": [9, 15, 13], + "rotation": {"angle": 22.5, "axis": "y", "origin": [8, 9, 8]}, + "faces": { + "north": {"uv": [14, 2, 16, 14], "texture": "#coin"}, + "east": {"uv": [3, 2, 13, 14], "texture": "#coin"}, + "south": {"uv": [0, 2, 2, 14], "texture": "#coin"}, + "west": {"uv": [13, 2, 3, 14], "texture": "#coin"}, + "up": {"uv": [3, 0, 13, 2], "rotation": 270, "texture": "#coin"}, + "down": {"uv": [3, 14, 13, 16], "rotation": 90, "texture": "#coin"} + } + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/marioverse/models/item/coin.json b/src/main/resources/assets/marioverse/models/item/coin.json new file mode 100644 index 00000000..7fd11bf9 --- /dev/null +++ b/src/main/resources/assets/marioverse/models/item/coin.json @@ -0,0 +1,6 @@ +{ + "parent": "minecraft:item/generated", + "textures": { + "layer0": "marioverse:item/coin" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/marioverse/textures/block/coin.png b/src/main/resources/assets/marioverse/textures/block/coin.png new file mode 100644 index 0000000000000000000000000000000000000000..ce116624de927eeafa9ca163597ac8e7bb07381a GIT binary patch literal 262 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbKJV{wqX6T`Z5GB1G~mUKs7M+SzC z{oH>NS%G|s0G|-o|KAV(dZqVniPZNihTo4Ep6roXm#YSppsd(5w7HbLCa-M#20ze<_e7yTcM0Tw($&$1d`xrII3uJ|OIr(^rUt20D@ wGT(f8N8z5L_>F4YndcntZ+;NFd%-K__59510)x4h1Fd85boFyt=akR{0NO5J4gdfE literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/marioverse/textures/item/coin.png b/src/main/resources/assets/marioverse/textures/item/coin.png new file mode 100644 index 0000000000000000000000000000000000000000..a619140a2e05648d4ca10e1cc8ca7bd2bb6e897c GIT binary patch literal 255 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbKJV{wqX6T`Z5GB1G~mUKs7M+SzC z{oH>NS%G|s0G|-o|KAV(dZqXMisAPohVPb0o$QfWm#YSpe5~}E4M=g61o;L3hX96q z&3hw(Vw?pYk;M!Qd`Hp~zq9tF7j94i+QZ=K>gTe~DWM4fQ=eCG literal 0 HcmV?d00001