mirror of
https://gitlab.com/cable-mc/cobblemon.git
synced 2026-10-31 22:38:52 -04:00
implement waterloggable pc
This commit is contained in:
1 parent
26a9d8d07f
commit
ea46a2973f
2 files changed
+32
-2
No files matched your search
@@ -22,6 +22,7 @@
|
||||
- Wild Pokémon now heal if you are defeated by them or flee from them.
|
||||
- Doubled the default time between ambient Pokémon cries (they have cries if you're using a resource pack to add them)
|
||||
- Moved spawn attempts per tick to a config option (ticksBetweenSpawnAttempts)
|
||||
- PCs can now be waterlogged
|
||||
- Cobblemon items can now all have their own tooltips via resourcepacks, to add a tooltip simply add a lang entry like "item.cobblemon.{item_id}.tooltip", if you want to add multiple tooltip lines you can do so with "item.cobblemon.{item_id}.tooltip_1" and upwards.
|
||||
|
||||
### Fixes
|
||||
|
||||
@@ -26,6 +26,8 @@ import net.minecraft.block.entity.BlockEntityType
|
||||
import net.minecraft.entity.LivingEntity
|
||||
import net.minecraft.entity.ai.pathing.NavigationType
|
||||
import net.minecraft.entity.player.PlayerEntity
|
||||
import net.minecraft.fluid.FluidState
|
||||
import net.minecraft.fluid.Fluids
|
||||
import net.minecraft.item.ItemPlacementContext
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.server.network.ServerPlayerEntity
|
||||
@@ -40,12 +42,14 @@ import net.minecraft.util.shape.VoxelShape
|
||||
import net.minecraft.util.shape.VoxelShapes
|
||||
import net.minecraft.world.BlockView
|
||||
import net.minecraft.world.World
|
||||
import net.minecraft.world.WorldAccess
|
||||
import net.minecraft.world.WorldView
|
||||
|
||||
class PCBlock(properties: Settings): BlockWithEntity(properties) {
|
||||
class PCBlock(properties: Settings): BlockWithEntity(properties), Waterloggable {
|
||||
companion object {
|
||||
val PART = EnumProperty.of("part", PCPart::class.java)
|
||||
val ON = BooleanProperty.of("on")
|
||||
val WATERLOGGED = BooleanProperty.of("waterlogged")
|
||||
|
||||
private val NORTH_AABB_TOP = VoxelShapes.union(
|
||||
VoxelShapes.cuboid(0.1875, 0.0, 0.0, 0.8125, 0.875, 0.125),
|
||||
@@ -173,7 +177,10 @@ class PCBlock(properties: Settings): BlockWithEntity(properties) {
|
||||
}
|
||||
|
||||
override fun onPlaced(world: World, pos: BlockPos, state: BlockState, placer: LivingEntity?, itemStack: ItemStack?) {
|
||||
world.setBlockState(pos.up(), state.with(PART, PCPart.TOP) as BlockState, 3)
|
||||
world.setBlockState(pos.up(), state
|
||||
.with(PART, PCPart.TOP)
|
||||
.with(WATERLOGGED, world.getFluidState((pos.up())).fluid == Fluids.WATER)
|
||||
as BlockState, 3)
|
||||
world.updateNeighbors(pos, Blocks.AIR)
|
||||
state.updateNeighbors(world, pos, 3)
|
||||
}
|
||||
@@ -185,6 +192,7 @@ class PCBlock(properties: Settings): BlockWithEntity(properties) {
|
||||
return defaultState
|
||||
.with(HorizontalFacingBlock.FACING, blockPlaceContext.horizontalPlayerFacing)
|
||||
.with(PART, PCPart.BOTTOM)
|
||||
.with(WATERLOGGED, blockPlaceContext.world.getFluidState(blockPlaceContext.blockPos).fluid == Fluids.WATER)
|
||||
}
|
||||
|
||||
return null
|
||||
@@ -203,6 +211,7 @@ class PCBlock(properties: Settings): BlockWithEntity(properties) {
|
||||
builder.add(HorizontalFacingBlock.FACING)
|
||||
builder.add(PART)
|
||||
builder.add(ON)
|
||||
builder.add(WATERLOGGED)
|
||||
}
|
||||
|
||||
@Deprecated("Deprecated in Java")
|
||||
@@ -262,4 +271,24 @@ class PCBlock(properties: Settings): BlockWithEntity(properties) {
|
||||
override fun getRenderType(blockState: BlockState): BlockRenderType {
|
||||
return BlockRenderType.MODEL
|
||||
}
|
||||
|
||||
override fun getFluidState(state: BlockState): FluidState? {
|
||||
return if (state.get(WATERLOGGED)) {
|
||||
Fluids.WATER.getStill(false)
|
||||
} else super.getFluidState(state)
|
||||
}
|
||||
|
||||
override fun getStateForNeighborUpdate(
|
||||
state: BlockState,
|
||||
direction: Direction?,
|
||||
neighborState: BlockState?,
|
||||
world: WorldAccess,
|
||||
pos: BlockPos?,
|
||||
neighborPos: BlockPos?
|
||||
): BlockState? {
|
||||
if (state.get(WATERLOGGED)) {
|
||||
world.scheduleFluidTick(pos, Fluids.WATER, Fluids.WATER.getTickRate(world))
|
||||
}
|
||||
return super.getStateForNeighborUpdate(state, direction, neighborState, world, pos, neighborPos)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user