-
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
307 additions
and
1 deletion.
There are no files selected for viewing
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
129 changes: 129 additions & 0 deletions
129
src/main/java/com/wenxin2/marioverse/blocks/CoinBlock.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,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<Block, BlockState> 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); | ||
} | ||
} |
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
64 changes: 64 additions & 0 deletions
64
src/main/resources/assets/marioverse/blockstates/coin.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,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 | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/resources/assets/marioverse/models/block/coin/coin.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,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"} | ||
} | ||
} | ||
] | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/resources/assets/marioverse/models/block/coin/coin_22.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,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"} | ||
} | ||
} | ||
] | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/resources/assets/marioverse/models/block/coin/coin_45.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,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"} | ||
} | ||
} | ||
] | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/resources/assets/marioverse/models/block/coin/coin_67.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,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"} | ||
} | ||
} | ||
] | ||
} |
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,6 @@ | ||
{ | ||
"parent": "minecraft:item/generated", | ||
"textures": { | ||
"layer0": "marioverse:item/coin" | ||
} | ||
} |
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.