From ea46a2973f2c19f97d75101d0ee3d3d73fa8ed2c Mon Sep 17 00:00:00 2001 From: Yaseen Date: Thu, 15 Jun 2023 22:16:26 +0000 Subject: [PATCH] implement waterloggable pc --- CHANGELOG.md | 1 + .../com/cobblemon/mod/common/block/PCBlock.kt | 33 +++++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ff2ae2daca..59bf2f277a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/block/PCBlock.kt b/common/src/main/kotlin/com/cobblemon/mod/common/block/PCBlock.kt index de577ed768..586cae2454 100644 --- a/common/src/main/kotlin/com/cobblemon/mod/common/block/PCBlock.kt +++ b/common/src/main/kotlin/com/cobblemon/mod/common/block/PCBlock.kt @@ -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) + } } \ No newline at end of file