Skip to content

Commit

Permalink
Improvements to giant clams
Browse files Browse the repository at this point in the history
  • Loading branch information
MysticKoko committed Nov 21, 2024
1 parent ee9bc82 commit 31d7d23
Show file tree
Hide file tree
Showing 11 changed files with 253 additions and 192 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ object HybridAquaticClient : ClientModInitializer {
registry.putBlocks(
RenderLayer.getCutout(),
HybridAquaticBlocks.CRAB_POT,
HybridAquaticBlocks.GIANT_CLAM,
HybridAquaticBlocks.TUBE_WORM,
HybridAquaticBlocks.LOPHELIA_CORAL,
HybridAquaticBlocks.LOPHELIA_CORAL_FAN,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"state": {
"Name": "hybrid-aquatic:giant_clam",
"Properties": {
"state": "closed",
"state": "open",
"waterlogged": "true"
}
}
Expand Down
78 changes: 34 additions & 44 deletions src/main/kotlin/dev/hybridlabs/aquatic/block/GiantClamBlock.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,46 +24,50 @@ import net.minecraft.util.ActionResult
import net.minecraft.util.Hand
import net.minecraft.util.hit.BlockHitResult
import net.minecraft.util.math.BlockPos
import net.minecraft.util.math.Box
import net.minecraft.util.math.Direction
import net.minecraft.util.math.random.Random
import net.minecraft.util.shape.VoxelShape
import net.minecraft.world.BlockView
import net.minecraft.world.World
import net.minecraft.world.WorldView

@Suppress("OVERRIDE_DEPRECATION", "DEPRECATION")
class GiantClamBlock(
private val emitsParticles: Boolean,
private val biteDamage: Int,
settings: Settings
) : Block(settings), Waterloggable {

private var pearlTimer: Int = 12000
private var pearlTimer: Int = 6000

init {
defaultState = stateManager.defaultState
.with(STATE, GiantClamState.CLOSED)
.with(STATE, GiantClamState.OPEN)
.with(WATERLOGGED, true)
}

override fun canPathfindThrough(state: BlockState, world: BlockView, pos: BlockPos, type: NavigationType): Boolean {
return false
}

override fun canPlaceAt(state: BlockState, world: WorldView, pos: BlockPos): Boolean {
val supportingPos = pos.down()
val supportingState = world.getBlockState(supportingPos)
return supportingState.isSideSolidFullSquare(world, supportingPos, Direction.UP)
}

override fun scheduledTick(state: BlockState, world: ServerWorld, pos: BlockPos, random: Random?) {
val waterlogged = state.get(WATERLOGGED)
val currentState = state.get(STATE)

if (currentState == GiantClamState.DEAD) return
if (!waterlogged && currentState != GiantClamState.DEAD) {
world.setBlockState(pos, state.with(STATE, GiantClamState.DEAD), 3)
return
}

if (pearlTimer > 0) {
if (currentState != GiantClamState.DEAD && pearlTimer > 0) {
pearlTimer--

val newState = when {
!waterlogged -> GiantClamState.DEAD
pearlTimer > 0 -> GiantClamState.CLOSED
else -> GiantClamState.OPEN
}

val newState = if (pearlTimer > 0) GiantClamState.CLOSED else GiantClamState.OPEN
if (newState != currentState) {
world.setBlockState(pos, state.with(STATE, newState), 2)
}
Expand All @@ -86,6 +90,7 @@ class GiantClamBlock(
override fun getPlacementState(ctx: ItemPlacementContext): BlockState? {
val waterlogged = ctx.world.getFluidState(ctx.blockPos).fluid == Fluids.WATER
return defaultState.with(WATERLOGGED, waterlogged)
.with(STATE, if (waterlogged) GiantClamState.CLOSED else GiantClamState.DEAD)
}

override fun getFluidState(state: BlockState): FluidState {
Expand All @@ -106,23 +111,19 @@ class GiantClamBlock(
): ActionResult {
if (!world.isClient) {
val currentState = state.get(STATE)
when (currentState) {
GiantClamState.OPEN -> {
pearlTimer = 12000
world.setBlockState(pos, state.with(STATE, GiantClamState.CLOSED), 3)

val itemToDrop = if (world.random.nextFloat() < 0.25) {
ItemStack(HybridAquaticItems.BLACK_PEARL)
} else {
ItemStack(HybridAquaticItems.PEARL)
}
dropStack(world, pos, itemToDrop)
}
GiantClamState.CLOSED -> {
pearlTimer = 0
world.setBlockState(pos, state.with(STATE, GiantClamState.OPEN), 3)
if (currentState == GiantClamState.OPEN) {
pearlTimer = 6000
world.setBlockState(pos, state.with(STATE, GiantClamState.CLOSED), 3)

val itemToDrop = if (world.random.nextFloat() < 0.25) {
ItemStack(HybridAquaticItems.BLACK_PEARL)
} else {
ItemStack(HybridAquaticItems.PEARL)
}
else -> return ActionResult.PASS

dropStack(world, pos, itemToDrop)
} else {
return ActionResult.PASS
}
}
return ActionResult.SUCCESS
Expand All @@ -134,16 +135,11 @@ class GiantClamBlock(
val currentState = state.get(STATE)
if (currentState == GiantClamState.OPEN) {
world.setBlockState(pos, state.with(STATE, GiantClamState.CLOSED), 3)
pearlTimer = 12000

val boundingBox = Box(pos.x - 0.5, pos.y.toDouble(), pos.z - 0.5, pos.x + 1.5, pos.y + 3.0, pos.z + 1.5)
val entities = world.getEntitiesByClass(LivingEntity::class.java, boundingBox) { true }
pearlTimer = 6000
}

for (nearbyEntity in entities) {
if (!nearbyEntity.bypassesSteppingEffects()) {
nearbyEntity.damage(world.damageSources.genericKill(), biteDamage.toFloat())
}
}
if (!entity.bypassesSteppingEffects() && entity is LivingEntity) {
entity.damage(world.damageSources.inWall(), 4.0f)
}

super.onSteppedOn(world, pos, state, entity)
Expand All @@ -163,13 +159,7 @@ class GiantClamBlock(
}

companion object {
val STATE: EnumProperty<GiantClamState> = EnumProperty.of(
"state",
GiantClamState::class.java,
GiantClamState.OPEN,
GiantClamState.CLOSED,
GiantClamState.DEAD
)
val STATE: EnumProperty<GiantClamState> = EnumProperty.of("state", GiantClamState::class.java, GiantClamState.OPEN, GiantClamState.CLOSED, GiantClamState.DEAD)
val WATERLOGGED: BooleanProperty = Properties.WATERLOGGED
private val SHAPE: VoxelShape = createCuboidShape(2.0, 0.0, 2.0, 14.0, 8.0, 14.0)
private val COLLISION_SHAPE: VoxelShape = createCuboidShape(2.0, 0.0, 2.0, 14.0, 8.0, 14.0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,12 @@ object HybridAquaticBlocks {
val TUBE_SPONGE = register("tube_sponge", TubeSpongeBlock(FabricBlockSettings.copyOf(Blocks.WET_SPONGE)
.nonOpaque()))

val GIANT_CLAM = register("giant_clam", GiantClamBlock(true, 4, FabricBlockSettings.copyOf(Blocks.TUFF)
.nonOpaque()
.hardness(1.0F)
.pistonBehavior(PistonBehavior.DESTROY)
.drops(Identifier(HybridAquatic.MOD_ID, "blocks/giant_clam"))
val GIANT_CLAM = register("giant_clam", GiantClamBlock(
true, FabricBlockSettings.copyOf(Blocks.TUFF)
.nonOpaque()
.hardness(1.0F)
.pistonBehavior(PistonBehavior.DESTROY)
.drops(Identifier(HybridAquatic.MOD_ID, "blocks/giant_clam"))
))

val BUOY = register("buoy", BuoyBlock(FabricBlockSettings.copyOf(Blocks.OAK_PLANKS)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,55 +1,13 @@
{
"variants": {
"state=open": [
{
"state=open": {
"model": "hybrid-aquatic:block/giant_clam_open"
},
{
"model": "hybrid-aquatic:block/giant_clam_open",
"y": 45
},
{
"model": "hybrid-aquatic:block/giant_clam_open",
"y": 90
},
{
"model": "hybrid-aquatic:block/giant_clam_open",
"y": 135
}
],
"state=closed": [
{
"model": "hybrid-aquatic:block/giant_clam_closed"
},
{
"model": "hybrid-aquatic:block/giant_clam_closed",
"y": 45
},
{
"model": "hybrid-aquatic:block/giant_clam_closed",
"y": 90
},
{
"model": "hybrid-aquatic:block/giant_clam_closed",
"y": 135
}
],
"state=dead": [
{
"model": "hybrid-aquatic:block/giant_clam_dead"
},
{
"model": "hybrid-aquatic:block/giant_clam_dead",
"y": 45
},
{
"model": "hybrid-aquatic:block/giant_clam_dead",
"y": 90
},
{
"model": "hybrid-aquatic:block/giant_clam_dead",
"y": 135
}
]
"state=closed": {
"model": "hybrid-aquatic:block/giant_clam_closed"
},
"state=dead": {
"model": "hybrid-aquatic:block/giant_clam_dead"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"credit": "Made with Blockbench",
"texture_size": [32, 32],
"textures": {
"0": "hybrid-aquatic:block/giant_clam",
"2": "hybrid-aquatic:block/giant_clam",
"particle": "hybrid-aquatic:block/giant_clam_dead"
},
"elements": [
Expand All @@ -10,64 +11,64 @@
"to": [14, 8, 8],
"rotation": {"angle": 0, "axis": "x", "origin": [8, 0, 8]},
"faces": {
"north": {"uv": [1, 4, 4, 6], "texture": "#0"},
"east": {"uv": [0, 4, 1, 6], "texture": "#0"},
"south": {"uv": [5, 4, 8, 6], "texture": "#0"},
"west": {"uv": [4, 4, 5, 6], "texture": "#0"},
"up": {"uv": [4, 4, 1, 3], "texture": "#0"},
"down": {"uv": [7, 3, 4, 4], "texture": "#0"}
"north": {"uv": [0, 0, 6, 4], "texture": "#2"},
"east": {"uv": [0, 10, 2, 14], "texture": "#2"},
"south": {"uv": [0, 4, 6, 8], "texture": "#2"},
"west": {"uv": [2, 10, 4, 14], "texture": "#2"},
"up": {"uv": [12, 2, 6, 0], "texture": "#2"},
"down": {"uv": [12, 2, 6, 4], "texture": "#2"}
}
},
{
"from": [2, 0, 8],
"to": [14, 8, 12],
"rotation": {"angle": 0, "axis": "x", "origin": [8, 0, 8]},
"faces": {
"north": {"uv": [1, 1, 4, 3], "texture": "#0"},
"east": {"uv": [0, 1, 1, 3], "texture": "#0"},
"south": {"uv": [5, 1, 8, 3], "texture": "#0"},
"west": {"uv": [4, 1, 5, 3], "texture": "#0"},
"up": {"uv": [4, 1, 1, 0], "texture": "#0"},
"down": {"uv": [7, 0, 4, 1], "texture": "#0"}
"north": {"uv": [0, 4, 6, 8], "texture": "#2"},
"east": {"uv": [2, 10, 4, 14], "texture": "#2"},
"south": {"uv": [0, 0, 6, 4], "texture": "#2"},
"west": {"uv": [0, 10, 2, 14], "texture": "#2"},
"up": {"uv": [12, 6, 6, 4], "texture": "#2"},
"down": {"uv": [12, 6, 6, 8], "texture": "#2"}
}
},
{
"from": [4, 1.5, 6.5],
"to": [7, 5.5, 9.5],
"rotation": {"angle": 10, "axis": "z", "origin": [5.5, 3.5, 6.5]},
"from": [9, 0, 6.5],
"to": [12, 4, 9.5],
"rotation": {"angle": 0, "axis": "y", "origin": [10.5, 2, 8]},
"faces": {
"north": {"uv": [0.75, 7.75, 1.5, 8.75], "texture": "#0"},
"east": {"uv": [0, 7.75, 0.75, 8.75], "texture": "#0"},
"south": {"uv": [2.25, 7.75, 3, 8.75], "texture": "#0"},
"west": {"uv": [1.5, 7.75, 2.25, 8.75], "texture": "#0"},
"up": {"uv": [1.5, 7.75, 0.75, 7], "texture": "#0"},
"down": {"uv": [2.25, 7, 1.5, 7.75], "texture": "#0"}
"north": {"uv": [4, 10, 5.5, 12], "texture": "#2"},
"east": {"uv": [4, 10, 5.5, 12], "texture": "#2"},
"south": {"uv": [4, 10, 5.5, 12], "texture": "#2"},
"west": {"uv": [4, 10, 5.5, 12], "texture": "#2"},
"up": {"uv": [7, 11.5, 5.5, 10], "texture": "#2"},
"down": {"uv": [8.5, 10, 7, 11.5], "texture": "#2"}
}
},
{
"from": [9, 1.5, 6.5],
"to": [12, 5.5, 9.5],
"rotation": {"angle": -10, "axis": "z", "origin": [10.5, 3.5, 6.5]},
"from": [4, 0, 6.5],
"to": [7, 4, 9.5],
"rotation": {"angle": 0, "axis": "y", "origin": [5.5, 2, 8]},
"faces": {
"north": {"uv": [1.5, 7.75, 0.75, 8.75], "texture": "#0"},
"east": {"uv": [2.25, 7.75, 1.5, 8.75], "texture": "#0"},
"south": {"uv": [3, 7.75, 2.25, 8.75], "texture": "#0"},
"west": {"uv": [0.75, 7.75, 0, 8.75], "texture": "#0"},
"up": {"uv": [0.75, 7.75, 1.5, 7], "texture": "#0"},
"down": {"uv": [1.5, 7, 2.25, 7.75], "texture": "#0"}
"north": {"uv": [4, 10, 5.5, 12], "texture": "#2"},
"east": {"uv": [4, 10, 5.5, 12], "texture": "#2"},
"south": {"uv": [4, 10, 5.5, 12], "texture": "#2"},
"west": {"uv": [4, 10, 5.5, 12], "texture": "#2"},
"up": {"uv": [7, 11.5, 5.5, 10], "texture": "#2"},
"down": {"uv": [8.5, 10, 7, 11.5], "texture": "#2"}
}
},
{
"from": [3, 4.75, 6],
"to": [13, 4.75, 10],
"rotation": {"angle": 0, "axis": "y", "origin": [8, -1.25, 8]},
"from": [2.5, 3.5, 6],
"to": [13.5, 3.5, 10],
"rotation": {"angle": 0, "axis": "y", "origin": [8.5, 3.5, 8]},
"faces": {
"north": {"uv": [1, 7, 3.5, 7], "texture": "#0"},
"east": {"uv": [0, 7, 1, 7], "texture": "#0"},
"south": {"uv": [4.5, 7, 7, 7], "texture": "#0"},
"west": {"uv": [3.5, 7, 4.5, 7], "texture": "#0"},
"up": {"uv": [3.5, 7, 1, 6], "texture": "#0"},
"down": {"uv": [6, 6, 3.5, 7], "texture": "#0"}
"north": {"uv": [0, 0, 5.5, 0], "texture": "#2"},
"east": {"uv": [0, 0, 2, 0], "texture": "#2"},
"south": {"uv": [0, 0, 5.5, 0], "texture": "#2"},
"west": {"uv": [0, 0, 2, 0], "texture": "#2"},
"up": {"uv": [5.5, 10, 0, 8], "texture": "#2"},
"down": {"uv": [5.5, 8, 0, 10], "texture": "#2"}
}
}
]
Expand Down
Loading

0 comments on commit 31d7d23

Please sign in to comment.