Jump to content

[Solved][1.6.x] TESR with transparency depth issue


Recommended Posts

Posted

Hey all, I've got an issue with a custom tile entity special renderer that I searched long and hard for a solution for, but wasn't able to find.

 

The tile entity is suppose to be a completely transparent, collision-free block that renders a highly animated magic circle at its location.  The animation would have had an enormous number of frames if I had just done it as a texture with an mcmeta file, so I decided to split it into sections and have the tessellator handle the rotation animations for me.

[spoiler=textures (warning, large)]

IOShSBk.png

qIGgeVV.png

 

 

One section rotates clockwise, while the other rotates counter-clockwise.  They share a common center point, with a slight y-offset to prevent z-fighting.

 

Now... my problem is this.  When placed in an open space, the entity functions perfectly.  However, when placed near other, opaque blocks... well...

 

YAMQnbz.png

 

The textures are rendered around the middle of the block level that the tile entity is on, so I know that they're supposed to be showing over the blocks below them, and the same issue happens when I reverse the setup and stick the tile entity below a level of blocks.  For some reason, the blocks are being rendered on top of my texture, despite being below it.  Furthermore, the effect is inconsistent...  If I move within a block or so y-distance to the tile entity, the problem goes away (at least, until I move again).

 

[spoiler=Here's my render code:]

package narhiril.homblocks.client;

import org.lwjgl.opengl.GL11;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import narhiril.homblocks.common.HomBlocks;
import narhiril.homblocks.common.blocks.BlockAthiCircle;
import narhiril.homblocks.common.tileentity.TileEntityAthiCircle;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraft.util.MathHelper;
import net.minecraft.util.ResourceLocation;

public class TileEntityCircleRenderer extends TileEntitySpecialRenderer{
  
    private float rotationAngle = 0.01F;
    private float holdRotationAngle = 0.01F;
    private static double minu = 0.0D;
    private static double minv = 0.0D;
    private static double maxu = 1.0D;
    private static double maxv = 1.0D;
    private static final ResourceLocation rl1 = new ResourceLocation("homblocks:textures/blocks/athiPortalCircleInner.png");
    private static final ResourceLocation rl2 = new ResourceLocation("homblocks:textures/blocks/athiPortalCircleOuter.png");
    
      
@Override
public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float f) {

	Minecraft.getMinecraft().renderEngine.bindTexture(rl1);
        x-= 0.5D;
        z-= 0.5D;
	float size = 5.0F; // in blocks
	float height = 0.7F; // in blocks
	double cx = x;
	double cz = z;
	double tempX = 0D;
	double tempZ = 0D;	
	double rotatedX = 0D;
	double rotatedZ = 0D;
	double cornerX = x;
	double cornerZ = z;

	rotationAngle = rotationAngle + 0.01F;
	if (rotationAngle >= 360.0F)
	{
		rotationAngle = 0.0F;
	}
	holdRotationAngle = rotationAngle;

	double sinRot = Math.sin(rotationAngle);
	double cosRot = Math.cos(rotationAngle);

	Tessellator tessellator = Tessellator.instance;
        GL11.glPushMatrix();
        GL11.glTranslated(x+(size/2)-0.5, y+0.1, z+(size/2)-0.5);
        GL11.glDisable(GL11.GL_LIGHTING);
	GL11.glDisable(GL11.GL_CULL_FACE);
	GL11.glEnable(GL11.GL_BLEND);

    //first ring
    
    tessellator.startDrawingQuads();
    
    //rotation for corner 1
    cornerX = x-size;
    cornerZ = z-size;
    tempX = cornerX - cx;
    tempZ = cornerZ - cz;
    rotatedX = tempX*cosRot - tempZ*sinRot;
    rotatedZ = tempX*sinRot + tempZ*cosRot;
    cornerX = rotatedX + cx;
    cornerZ = rotatedZ + cz;
    
    tessellator.addVertexWithUV(cornerX, y+height, cornerZ, minu, minv);

    //rotation for corner 2
    cornerX = x-size;
    cornerZ = z+size;
    tempX = cornerX - cx;
    tempZ = cornerZ - cz;
    rotatedX = tempX*cosRot - tempZ*sinRot;
    rotatedZ = tempX*sinRot + tempZ*cosRot;
    cornerX = rotatedX + cx;
    cornerZ = rotatedZ + cz;
    
    tessellator.addVertexWithUV(cornerX, y+height, cornerZ, minu, maxv);
    

    //rotation for corner 3
    cornerX = x+size;
    cornerZ = z+size;
    tempX = cornerX - cx;
    tempZ = cornerZ - cz;
    rotatedX = tempX*cosRot - tempZ*sinRot;
    rotatedZ = tempX*sinRot + tempZ*cosRot;
    cornerX = rotatedX + cx;
    cornerZ = rotatedZ + cz;
    
    tessellator.addVertexWithUV(cornerX, y+height, cornerZ, maxu, maxv);

    //rotation for corner 4
    cornerX = x+size;
    cornerZ = z-size;
    tempX = cornerX - cx;
    tempZ = cornerZ - cz;
    rotatedX = tempX*cosRot - tempZ*sinRot;
    rotatedZ = tempX*sinRot + tempZ*cosRot;
    cornerX = rotatedX + cx;
    cornerZ = rotatedZ + cz;
    
    tessellator.addVertexWithUV(cornerX, y+height, cornerZ, maxu , minv);

    tessellator.draw();


    //second ring
    
    rotationAngle = 360-rotationAngle; //retrograde spin

    Minecraft.getMinecraft().renderEngine.bindTexture(rl2);
    sinRot = Math.sin(rotationAngle);
    cosRot = Math.cos(rotationAngle);
    size = 5.0F;
    height = 0.6F;

    
    
    tessellator.startDrawingQuads();
    
    //rotation for corner 1
    cornerX = x-size;
    cornerZ = z-size;
    tempX = cornerX - cx;
    tempZ = cornerZ - cz;
    rotatedX = tempX*cosRot - tempZ*sinRot;
    rotatedZ = tempX*sinRot + tempZ*cosRot;
    cornerX = rotatedX + cx;
    cornerZ = rotatedZ + cz;
    
    tessellator.addVertexWithUV(cornerX, y+height, cornerZ, minu, minv);

    //rotation for corner 2
    cornerX = x-size;
    cornerZ = z+size;
    tempX = cornerX - cx;
    tempZ = cornerZ - cz;
    rotatedX = tempX*cosRot - tempZ*sinRot;
    rotatedZ = tempX*sinRot + tempZ*cosRot;
    cornerX = rotatedX + cx;
    cornerZ = rotatedZ + cz;
    
    tessellator.addVertexWithUV(cornerX, y+height, cornerZ, minu, maxv);
    

    //rotation for corner 3
    cornerX = x+size;
    cornerZ = z+size;
    tempX = cornerX - cx;
    tempZ = cornerZ - cz;
    rotatedX = tempX*cosRot - tempZ*sinRot;
    rotatedZ = tempX*sinRot + tempZ*cosRot;
    cornerX = rotatedX + cx;
    cornerZ = rotatedZ + cz;
    
    tessellator.addVertexWithUV(cornerX, y+height, cornerZ, maxu, maxv);

    //rotation for corner 4
    cornerX = x+size;
    cornerZ = z-size;
    tempX = cornerX - cx;
    tempZ = cornerZ - cz;
    rotatedX = tempX*cosRot - tempZ*sinRot;
    rotatedZ = tempX*sinRot + tempZ*cosRot;
    cornerX = rotatedX + cx;
    cornerZ = rotatedZ + cz;
    
    tessellator.addVertexWithUV(cornerX, y+height, cornerZ, maxu , minv);
    
    tessellator.draw();
    
    rotationAngle = holdRotationAngle;

    GL11.glEnable(GL11.GL_CULL_FACE);
    GL11.glEnable(GL11.GL_LIGHTING);
    GL11.glPopMatrix();

}


}

 

 

 

I was under the impression that tile entities were rendered last, after both block render passes.  So... why is this happening, and what can I do to fix it?

 

Thanks a bunch in advance.

Posted

I think 1.6.x is too outdated..

You would not be able to get supported with the version.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Posted

My hands are kind of tied on that one.  This is a custom job for a server that's running on 1.6.4.

 

Nevertheless, I think the code is similar enough to 1.7.x that someone might be able to help me.

Posted

Hi

 

It doesn't matter whether your section is rendered first or last, the depth culling should take care of it. It seems pretty obvious to me that the ring is rendering below the blocks, I think there must be something wrong with your y-position.

 

I think it is here

tessellator.addVertexWithUV(cornerX, y+height, cornerZ, minu, minv);

 

You have already translated by y so you shouldn't have y in there.

 

-TGG

 

Posted

First of all, let me get over being starstruck for a moment since I learned how to do my first renderer based on your tutorials, TGG.

 

I went ahead and removed that height factor and upped the translation to +0.5 (rather than +0.1.  Also tried +1.5 with no improvement).  Unfortunately, my problem still persists.

 

[spoiler=From the side, to show height (curiously, it renders properly when I'm this close to it)]

HfLx7dT.png

 

 

 

[spoiler=The same circle, from above]

R5nxsLm.png

 

 

 

I tried using a texture without an alpha channel and turning GL_BLEND off, still happens.  I even tried turning off the rotation while I try to sort this out, but still no luck.  I'm still assuming the issue is with the renderer and not something else like the block or the tile entity, but here's the code for those just in case.  I'm completely baffled.

 

[spoiler= Block]



public class BlockAthiCircle extends BlockContainer {

public static Icon blockIconCopy;
public static Icon blockIconSecondary;
    public static String secondaryTexture = "homblocks:athiPortalCircleOuter";

    public BlockAthiCircle(int par1, String unlocalizedName) {
        super(par1, Material.iron);
        this.setUnlocalizedName(unlocalizedName);
        this.setHardness(2.0F);
        this.setResistance(6.0F);
        this.setTextureName("homblocks:athiPortalCircleInner");
        this.setBlockBounds(0,0,0,1,1,1);
        
    }

    @Override
    public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4)
    {
        return null;
    }

    
    public boolean isOpaqueCube()
    {
        return false;
    }

    
    @Override
    public boolean shouldSideBeRendered(IBlockAccess iblockaccess, int i, int j, int k, int l)
    {
    	return false;
    }
    
    public boolean renderAsNormalBlock()
    {
        return false;
    }
    public void registerIcons(IconRegister iconRegister)
    {
    	         blockIcon = iconRegister.registerIcon("homblocks:multitexture");
    	         blockIconCopy = iconRegister.registerIcon(this.textureName);
    	         blockIconSecondary = iconRegister.registerIcon(this.secondaryTexture);
    	
    }

    @Override
    public TileEntity createNewTileEntity(World world) {
        return new TileEntityAthiCircle();
    }
}


 

 

 

[spoiler= TileEntity]


public class TileEntityAthiCircle extends TileEntity{


    @Override
    @SideOnly(Side.CLIENT)
    public double getMaxRenderDistanceSquared()
    {
        return 4096.0D;
    }
}
[/spoiler]

Posted

Aaaaand I'm an idiot.  I completely misread your suggestion as "remove the +height" rather than "remove the y entirely."

 

Thanks TGG, that fixed it.  Everything works now.  ^_^

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • It is 1.12.2 - I have no idea if there is a 1.12 pack
    • Okay, but does the modpack works with 1.12 or just with 1.12.2, because I need the Forge client specifically for Minecraft 1.12, not 1.12.2
    • Version 1.19 - Forge 41.0.63 I want to create a wolf entity that I can ride, so far it seems to be working, but the problem is that when I get on the wolf, I can’t control it. I then discovered that the issue is that the server doesn’t detect that I’m riding the wolf, so I’m struggling with synchronization. However, it seems to not be working properly. As I understand it, the server receives the packet but doesn’t register it correctly. I’m a bit new to Java, and I’ll try to provide all the relevant code and prints *The comments and prints are translated by chatgpt since they were originally in Spanish* Thank you very much in advance No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. MountableWolfEntity package com.vals.valscraft.entity; import com.vals.valscraft.network.MountSyncPacket; import com.vals.valscraft.network.NetworkHandler; import net.minecraft.client.Minecraft; import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.network.syncher.EntityDataSerializers; import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.ai.attributes.AttributeSupplier; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.animal.Wolf; import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.Entity; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.level.Level; import net.minecraft.world.phys.Vec3; import net.minecraftforge.event.TickEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.network.PacketDistributor; public class MountableWolfEntity extends Wolf { private boolean hasSaddle; private static final EntityDataAccessor<Byte> DATA_ID_FLAGS = SynchedEntityData.defineId(MountableWolfEntity.class, EntityDataSerializers.BYTE); public MountableWolfEntity(EntityType<? extends Wolf> type, Level level) { super(type, level); this.hasSaddle = false; } @Override protected void defineSynchedData() { super.defineSynchedData(); this.entityData.define(DATA_ID_FLAGS, (byte)0); } public static AttributeSupplier.Builder createAttributes() { return Wolf.createAttributes() .add(Attributes.MAX_HEALTH, 20.0) .add(Attributes.MOVEMENT_SPEED, 0.3); } @Override public InteractionResult mobInteract(Player player, InteractionHand hand) { ItemStack itemstack = player.getItemInHand(hand); if (itemstack.getItem() == Items.SADDLE && !this.hasSaddle()) { if (!player.isCreative()) { itemstack.shrink(1); } this.setSaddle(true); return InteractionResult.SUCCESS; } else if (!level.isClientSide && this.hasSaddle()) { player.startRiding(this); MountSyncPacket packet = new MountSyncPacket(true); // 'true' means the player is mounted NetworkHandler.CHANNEL.sendToServer(packet); // Ensure the server handles the packet return InteractionResult.SUCCESS; } return InteractionResult.PASS; } @Override public void travel(Vec3 travelVector) { if (this.isVehicle() && this.getControllingPassenger() instanceof Player) { System.out.println("The wolf has a passenger."); System.out.println("The passenger is a player."); Player player = (Player) this.getControllingPassenger(); // Ensure the player is the controller this.setYRot(player.getYRot()); this.yRotO = this.getYRot(); this.setXRot(player.getXRot() * 0.5F); this.setRot(this.getYRot(), this.getXRot()); this.yBodyRot = this.getYRot(); this.yHeadRot = this.yBodyRot; float forward = player.zza; float strafe = player.xxa; if (forward <= 0.0F) { forward *= 0.25F; } this.flyingSpeed = this.getSpeed() * 0.1F; this.setSpeed((float) this.getAttributeValue(Attributes.MOVEMENT_SPEED) * 1.5F); this.setDeltaMovement(new Vec3(strafe, travelVector.y, forward).scale(this.getSpeed())); this.calculateEntityAnimation(this, false); } else { // The wolf does not have a passenger or the passenger is not a player System.out.println("No player is mounted, or the passenger is not a player."); super.travel(travelVector); } } public boolean hasSaddle() { return this.hasSaddle; } public void setSaddle(boolean hasSaddle) { this.hasSaddle = hasSaddle; } @Override protected void dropEquipment() { super.dropEquipment(); if (this.hasSaddle()) { this.spawnAtLocation(Items.SADDLE); this.setSaddle(false); } } @SubscribeEvent public static void onServerTick(TickEvent.ServerTickEvent event) { if (event.phase == TickEvent.Phase.START) { MinecraftServer server = net.minecraftforge.server.ServerLifecycleHooks.getCurrentServer(); if (server != null) { for (ServerPlayer player : server.getPlayerList().getPlayers()) { if (player.isPassenger() && player.getVehicle() instanceof MountableWolfEntity) { MountableWolfEntity wolf = (MountableWolfEntity) player.getVehicle(); System.out.println("Tick: " + player.getName().getString() + " is correctly mounted on " + wolf); } } } } } private boolean lastMountedState = false; @Override public void tick() { super.tick(); if (!this.level.isClientSide) { // Only on the server boolean isMounted = this.isVehicle() && this.getControllingPassenger() instanceof Player; // Only print if the state changed if (isMounted != lastMountedState) { if (isMounted) { Player player = (Player) this.getControllingPassenger(); // Verify the passenger is a player System.out.println("Server: Player " + player.getName().getString() + " is now mounted."); } else { System.out.println("Server: The wolf no longer has a passenger."); } lastMountedState = isMounted; } } } @Override public void addPassenger(Entity passenger) { super.addPassenger(passenger); if (passenger instanceof Player) { Player player = (Player) passenger; if (!this.level.isClientSide && player instanceof ServerPlayer) { // Send the packet to the server to indicate the player is mounted NetworkHandler.CHANNEL.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new MountSyncPacket(true)); } } } @Override public void removePassenger(Entity passenger) { super.removePassenger(passenger); if (passenger instanceof Player) { Player player = (Player) passenger; if (!this.level.isClientSide && player instanceof ServerPlayer) { // Send the packet to the server to indicate the player is no longer mounted NetworkHandler.CHANNEL.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new MountSyncPacket(false)); } } } @Override public boolean isControlledByLocalInstance() { Entity entity = this.getControllingPassenger(); return entity instanceof Player; } @Override public void positionRider(Entity passenger) { if (this.hasPassenger(passenger)) { double xOffset = Math.cos(Math.toRadians(this.getYRot() + 90)) * 0.4; double zOffset = Math.sin(Math.toRadians(this.getYRot() + 90)) * 0.4; passenger.setPos(this.getX() + xOffset, this.getY() + this.getPassengersRidingOffset() + passenger.getMyRidingOffset(), this.getZ() + zOffset); } } } MountSyncPacket package com.vals.valscraft.network; import com.vals.valscraft.entity.MountableWolfEntity; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; public class MountSyncPacket { private final boolean isMounted; public MountSyncPacket(boolean isMounted) { this.isMounted = isMounted; } public void encode(FriendlyByteBuf buffer) { buffer.writeBoolean(isMounted); } public static MountSyncPacket decode(FriendlyByteBuf buffer) { return new MountSyncPacket(buffer.readBoolean()); } public void handle(NetworkEvent.Context context) { context.enqueueWork(() -> { ServerPlayer player = context.getSender(); // Get the player from the context if (player != null) { // Verifies if the player has dismounted if (!isMounted) { Entity vehicle = player.getVehicle(); if (vehicle instanceof MountableWolfEntity wolf) { // Logic to remove the player as a passenger wolf.removePassenger(player); System.out.println("Server: Player " + player.getName().getString() + " is no longer mounted."); } } } }); context.setPacketHandled(true); // Marks the packet as handled } } networkHandler package com.vals.valscraft.network; import com.vals.valscraft.valscraft; import net.minecraft.resources.ResourceLocation; import net.minecraftforge.network.NetworkRegistry; import net.minecraftforge.network.simple.SimpleChannel; import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; public class NetworkHandler { private static final String PROTOCOL_VERSION = "1"; public static final SimpleChannel CHANNEL = NetworkRegistry.newSimpleChannel( new ResourceLocation(valscraft.MODID, "main"), () -> PROTOCOL_VERSION, PROTOCOL_VERSION::equals, PROTOCOL_VERSION::equals ); public static void init() { int packetId = 0; // Register the mount synchronization packet CHANNEL.registerMessage( packetId++, MountSyncPacket.class, MountSyncPacket::encode, MountSyncPacket::decode, (msg, context) -> msg.handle(context.get()) // Get the context with context.get() ); } }  
  • Topics

×
×
  • Create New...

Important Information

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