Jump to content

[1.14.4] Fluid system: can't use custom texture and texture loading bugs


Recommended Posts

Posted (edited)

I found two issues with the new fluid system:

 

1) I can't assign any texture to it which does not belong to a registered block or item: that means I have to register a block/item that uses my _flow texture and another one that uses my _still texture in order to apply custom textures to the fluid

 

2) Sometimes, if I quit the game right in front of a custom fluid and then reload the game and world, it will show the missing texture for an instant

Edited by Alex Sim
Posted

You can use TextureStitchEvent.pre to add your textures, instead of creating a block or item.  This may or may not also affect issue two.  (I've not seen any texture problems, so far)

 

That said, gigaherz has made further changes to the Fluid API that will remove the need for the manual texture stitching entirely.  Keep an eye on Forge PR #6110 for details there.

  • Thanks 1
Posted (edited)
5 hours ago, Ommina said:

You can use TextureStitchEvent.pre to add your textures, instead of creating a block or item.  This may or may not also affect issue two.  (I've not seen any texture problems, so far)

 

That said, gigaherz has made further changes to the Fluid API that will remove the need for the manual texture stitching entirely.  Keep an eye on Forge PR #6110 for details there.

Thank you, do you happen to know how I add player interaction to the fluid? (eg: swimming, damage etc.)

Edited by Alex Sim
Posted
9 hours ago, Alex Sim said:

Thank you, do you happen to know how I add player interaction to the fluid? (eg: swimming, damage etc.)

 

Much of that kind of behaviour (sounds when jumping into/out of, entity push, drowning, fall damage negation, likely others), is enabled simply by adding the fluid to vanilla's water.json tag.  Likewise, burning can be enabled by adding to the lava.json tag.

 

But, I've not done much research into if this enables too much (spawning freshwater fish into a mod's brine, for example).

Posted (edited)
5 hours ago, Ommina said:

 

Much of that kind of behaviour (sounds when jumping into/out of, entity push, drowning, fall damage negation, likely others), is enabled simply by adding the fluid to vanilla's water.json tag.  Likewise, burning can be enabled by adding to the lava.json tag.

 

But, I've not done much research into if this enables too much (spawning freshwater fish into a mod's brine, for example).

I tried to make something similar to what @jabelar does here (this was from 1.12) but it seems to only work for other entities, not the player;

 

Here's my code so far, it's in Kotlin BTW:

 

//This variable uses a small reflection delegate I made
var Entity.submergedHeightKt : Double by ReflectField("field_211517_W")

@SubscribeEvent(priority = EventPriority.NORMAL, receiveCanceled = true)
fun onPlayerTickEvent(event: PlayerTickEvent) = event.player.takeIf {event.phase === TickEvent.Phase.START && it.world.isRemote}?.apply {
    handleFluidAccelerationKt(Glacia.Blocks.PLASMA)
}

@SubscribeEvent(priority=EventPriority.NORMAL, receiveCanceled=true)
fun onWorldTickEvent(event: TickEvent.WorldTickEvent) = (event.world as? ServerWorld)?.takeIf {event.phase !== TickEvent.Phase.END}?.entities?.forEach { entity ->
    entity.handleFluidAccelerationKt(Glacia.Blocks.PLASMA)
}

fun Entity.handleFluidAccelerationKt(block: Block): Boolean {
    val axisAlignedBB = boundingBox.shrink(0.001)
    val i = MathHelper.floor(axisAlignedBB.minX)
    val j = MathHelper.ceil(axisAlignedBB.maxX)
    val k = MathHelper.floor(axisAlignedBB.minY)
    val l = MathHelper.ceil(axisAlignedBB.maxY)
    val i1 = MathHelper.floor(axisAlignedBB.minZ)
    val j1 = MathHelper.ceil(axisAlignedBB.maxZ)

	if (!world.isAreaLoaded(i, k, i1, j, l, j1)) return false
    else {
        var d0 = 0.0
        val flag = this.isPushedByWater
        var flag1 = false
        var vec3d = Vec3d.ZERO
        var k1 = 0

        BlockPos.PooledMutableBlockPos.retain().use {mutableBlockPos ->
            for (l1 in i until j) {
                for (i2 in k until l) {
                    for (j2 in i1 until j1) {
                        mutableBlockPos.setPos(l1, i2, j2)
                        val fluidState = this.world.getFluidState(mutableBlockPos)
                        if (fluidState.blockState.block === block) {
                            val d1 = (i2.toFloat() + fluidState.func_215679_a(this.world, mutableBlockPos)).toDouble()
                            if (d1 >= axisAlignedBB.minY) {
                                flag1 = true
                                d0 = Math.max(d1 - axisAlignedBB.minY, d0)
                                if (flag) {
                                    var vec3d1 = fluidState.getFlow(this.world, mutableBlockPos)
                                    if (d0 < 0.4) {
                                        vec3d1 = vec3d1.scale(d0)
                                    }

                                    vec3d = vec3d.add(vec3d1)
                                    ++k1
                                }
                            }
                        }
                    }
                }
            }
        }

        if (vec3d.length() > 0.0) {
            if (k1 > 0) vec3d = vec3d.scale(1.0 / k1.toDouble())
            if (this !is PlayerEntity) vec3d = vec3d.normalize()
            motion = motion.add(vec3d.scale(0.014))
        }

        submergedHeightKt = d0
        return flag1
    }
}

 

Edited by Alex Sim
Posted
1 hour ago, diesieben07 said:

Not relevant to the topic at hand, but I just want to say that this is very cool.

Props for actually using Kotlin as a fully featured language instead of just a "fancy Java".

Thanks, here is the class if you're curious or want to use it

Posted
On 9/7/2019 at 12:12 PM, Alex Sim said:

Thank you, do you happen to know how I add player interaction to the fluid? (eg: swimming, damage etc.)

Override the onEntityCollision in your fluid's block to affect players/entities inside the fluid.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.