-
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.
Bottle with ship block renders water and oak plank
- Loading branch information
1 parent
16f8e6d
commit 432cd52
Showing
10 changed files
with
213 additions
and
7 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
src/main/java/g_mungus/ship_in_a_bottle/ShipInABottleClient.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 |
---|---|---|
@@ -1,14 +1,20 @@ | ||
package g_mungus.ship_in_a_bottle; | ||
|
||
import g_mungus.ship_in_a_bottle.block.ModBlocks; | ||
import g_mungus.ship_in_a_bottle.block.entity.BottleShipEntityRenderer; | ||
import net.fabricmc.api.ClientModInitializer; | ||
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap; | ||
import net.minecraft.client.render.RenderLayer; | ||
import net.minecraft.client.render.block.entity.BlockEntityRendererFactories; | ||
|
||
public class ShipInABottleClient implements ClientModInitializer { | ||
|
||
@Override | ||
public void onInitializeClient() { | ||
BlockRenderLayerMap.INSTANCE.putBlock(ModBlocks.BOTTLEWITHOUTSHIP, RenderLayer.getTranslucent()); | ||
BlockRenderLayerMap.INSTANCE.putBlock(ModBlocks.BOTTLEWITHSHIP, RenderLayer.getTranslucent()); | ||
BlockRenderLayerMap.INSTANCE.putBlock(ModBlocks.WATERBLOCK, RenderLayer.getTranslucent()); | ||
|
||
BlockEntityRendererFactories.register(ModBlocks.BOTTLEWITHSHIPENTITY, BottleShipEntityRenderer::new); | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
src/main/java/g_mungus/ship_in_a_bottle/block/BottleWithShip.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,90 @@ | ||
package g_mungus.ship_in_a_bottle.block; | ||
|
||
import g_mungus.ship_in_a_bottle.block.entity.BottleWithShipEntity; | ||
import net.minecraft.block.*; | ||
import net.minecraft.block.entity.BlockEntity; | ||
import net.minecraft.fluid.FluidState; | ||
import net.minecraft.fluid.Fluids; | ||
import net.minecraft.item.ItemPlacementContext; | ||
import net.minecraft.state.StateManager; | ||
import net.minecraft.state.property.BooleanProperty; | ||
import net.minecraft.state.property.Properties; | ||
import net.minecraft.util.BlockMirror; | ||
import net.minecraft.util.BlockRotation; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.Direction; | ||
import net.minecraft.util.shape.VoxelShape; | ||
import net.minecraft.world.BlockView; | ||
import net.minecraft.world.WorldAccess; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class BottleWithShip extends BlockWithEntity implements Waterloggable{ | ||
|
||
public BottleWithShip(Settings settings) { | ||
super(settings); | ||
setDefaultState(getDefaultState() | ||
.with(Properties.FACING, Direction.NORTH) | ||
.with(WATERLOGGED, false)); | ||
} | ||
|
||
|
||
|
||
public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED; | ||
|
||
protected static final VoxelShape SHAPE_X = Block.createCuboidShape(0.0, 0.0, 2.0, 16.0, 12.0, 14.0); | ||
protected static final VoxelShape SHAPE_Z = Block.createCuboidShape(2.0, 0.0, 0.0, 14.0, 12.0, 16.0); | ||
|
||
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { | ||
return switch (state.get(Properties.FACING)) { | ||
default -> SHAPE_Z; | ||
case WEST, EAST -> SHAPE_X; | ||
}; | ||
} | ||
|
||
@Override | ||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) { | ||
builder.add(Properties.FACING, WATERLOGGED); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public BlockState getPlacementState(ItemPlacementContext ctx) { | ||
return this.getDefaultState().with(Properties.FACING,ctx.getHorizontalPlayerFacing()).with(WATERLOGGED, ctx.getWorld().getFluidState(ctx.getBlockPos()).isOf(Fluids.WATER)); | ||
} | ||
|
||
@Override | ||
public FluidState getFluidState(BlockState state) { | ||
return state.get(WATERLOGGED) ? Fluids.WATER.getStill(false) : super.getFluidState(state); | ||
} | ||
|
||
@Override | ||
public BlockState rotate(BlockState state, BlockRotation rotation) { | ||
return state.with(Properties.FACING, rotation.rotate(state.get(Properties.FACING))); | ||
} | ||
|
||
@Override | ||
public BlockState mirror(BlockState state, BlockMirror mirror) { | ||
return state.rotate(mirror.getRotation(state.get(Properties.FACING))); | ||
} | ||
|
||
@Override | ||
public BlockRenderType getRenderType(BlockState state) { | ||
return BlockRenderType.MODEL; | ||
} | ||
|
||
@Override | ||
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) { | ||
if (state.get(WATERLOGGED)) { | ||
// This is for 1.17 and below: world.getFluidTickScheduler().schedule(pos, Fluids.WATER, Fluids.WATER.getTickRate(world)); | ||
world.scheduleFluidTick(pos, Fluids.WATER, Fluids.WATER.getTickRate(world)); | ||
} | ||
|
||
return super.getStateForNeighborUpdate(state, direction, neighborState, world, pos, neighborPos); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) { | ||
return new BottleWithShipEntity(pos, 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
9 changes: 9 additions & 0 deletions
9
src/main/java/g_mungus/ship_in_a_bottle/block/WaterBlock.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,9 @@ | ||
package g_mungus.ship_in_a_bottle.block; | ||
|
||
import net.minecraft.block.Block; | ||
|
||
public class WaterBlock extends Block { | ||
public WaterBlock(Settings settings) { | ||
super(settings); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
src/main/java/g_mungus/ship_in_a_bottle/block/entity/BottleShipEntityRenderer.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,55 @@ | ||
package g_mungus.ship_in_a_bottle.block.entity; | ||
|
||
import g_mungus.ship_in_a_bottle.block.ModBlocks; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.block.Blocks; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.render.*; | ||
import net.minecraft.client.render.block.BlockRenderManager; | ||
import net.minecraft.client.render.block.entity.BlockEntityRenderer; | ||
import net.minecraft.client.render.block.entity.BlockEntityRendererFactory; | ||
import net.minecraft.client.render.entity.EntityRenderer; | ||
import net.minecraft.client.util.math.MatrixStack; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.state.property.Properties; | ||
import net.minecraft.util.math.Direction; | ||
|
||
public class BottleShipEntityRenderer implements BlockEntityRenderer<BottleWithShipEntity> { | ||
|
||
public BottleShipEntityRenderer(BlockEntityRendererFactory.Context context){} | ||
|
||
@Override | ||
public void render(BottleWithShipEntity entity, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) { | ||
BlockRenderManager blockRenderManager = MinecraftClient.getInstance().getBlockRenderManager(); | ||
|
||
BlockState state = entity.getCachedState(); | ||
Direction direction = state.get(Properties.FACING); | ||
|
||
matrices.push(); | ||
|
||
if (direction == Direction.NORTH) { | ||
matrices.translate(0.15, 0.031, 0.025); | ||
} else if (direction == Direction.SOUTH) { | ||
matrices.translate(0.15, 0.031, 0.275); | ||
} else if (direction == Direction.WEST) { | ||
matrices.translate(0.025, 0.031, 0.15); | ||
} else if (direction == Direction.EAST){ | ||
matrices.translate(0.275, 0.031, 0.15); | ||
} | ||
|
||
float waterHeight = 2.0F / 16.0F; | ||
|
||
matrices.scale(0.7F, waterHeight, 0.7F); | ||
|
||
blockRenderManager.renderBlockAsEntity(ModBlocks.WATERBLOCK.getDefaultState(), matrices, vertexConsumers, light, overlay); | ||
|
||
matrices.translate(0.15, 0.08, 0.15); | ||
matrices.scale(0.7F, (float) 0.49 / waterHeight, 0.7F); | ||
|
||
|
||
blockRenderManager.renderBlockAsEntity(Blocks.OAK_PLANKS.getDefaultState(), matrices, vertexConsumers, light, overlay); | ||
|
||
|
||
matrices.pop(); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/g_mungus/ship_in_a_bottle/block/entity/BottleWithShipEntity.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,13 @@ | ||
package g_mungus.ship_in_a_bottle.block.entity; | ||
|
||
import g_mungus.ship_in_a_bottle.block.ModBlocks; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.block.entity.BlockEntity; | ||
import net.minecraft.util.math.BlockPos; | ||
|
||
public class BottleWithShipEntity extends BlockEntity { | ||
|
||
public BottleWithShipEntity(BlockPos pos, BlockState state) { | ||
super(ModBlocks.BOTTLEWITHSHIPENTITY, pos, state); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/resources/assets/ship-in-a-bottle/blockstates/bottle_with_ship.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,19 @@ | ||
{ | ||
"variants": { | ||
"facing=east": { | ||
"model": "ship-in-a-bottle:block/bottle_without_ship", | ||
"y": 270 | ||
}, | ||
"facing=north": { | ||
"model": "ship-in-a-bottle:block/bottle_without_ship", | ||
"y": 180 | ||
}, | ||
"facing=south": { | ||
"model": "ship-in-a-bottle:block/bottle_without_ship" | ||
}, | ||
"facing=west": { | ||
"model": "ship-in-a-bottle:block/bottle_without_ship", | ||
"y": 90 | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/resources/assets/ship-in-a-bottle/blockstates/water_block_util.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,7 @@ | ||
{ | ||
"variants": { | ||
"": { | ||
"model": "ship-in-a-bottle:block/water_block_util" | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/resources/assets/ship-in-a-bottle/models/block/water_block_util.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,6 @@ | ||
{ | ||
"parent": "minecraft:block/cube_all", | ||
"textures": { | ||
"all": "ship-in-a-bottle:block/underwater" | ||
} | ||
} |
Binary file added
BIN
+217 Bytes
src/main/resources/assets/ship-in-a-bottle/textures/block/underwater.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.