Jump to content

net.minecraft.client.renderer.RenderBlocks#getBlockIconFromSideAndMetadata in 1.10.2?


Recommended Posts

Posted

im trying to port this bit of code to 1.10.2 (from 1.7.10)

                            IIcon icon = renderer.getBlockIconFromSideAndMetadata(block, 1, meta);
                            double tu0 = (double)icon.getMinUV();
                            double tu1 = (double)icon.getMaxU();
                            double tv0 = (double)icon.getMinV();
                            double tv1 = (double)icon.getMaxV();

 

Posted

What is your overall goal? What feature is this code a part of? We need some more context than a snippet of code.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted (edited)
3 minutes ago, diesieben07 said:

That code alone does precisely nothing.

yes i know its because its part of bigger thing

4 minutes ago, Choonster said:

What is your overall goal? What feature is this code a part of? We need some more context than a snippet of code.

im using this to then be able to use tessalator to render some stuff

Edited by lukas2005
Posted
2 minutes ago, lukas2005 said:

im using this to then be able to use tessalator to render some stuff

 

What "stuff"? You're being very vague, which makes it hard to help you.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted
Just now, Choonster said:

 

What "stuff"? You're being very vague, which makes it hard to help you.

i just use this little snippet for rendering an i need to know what is repacment for IIcon and RenderBlocks

Posted
Just now, lukas2005 said:

i just use this little snippet for rendering an i need to know what is repacment for IIcon and RenderBlocks

 

But what are you trying to render? Where are you rendering it?

 

IIcon and RenderBlocks were replaced by the baked model system, but it's hard to tell you what you need to do when we don't actually know what you're trying to do.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

i am trying to make terrain smoother rather than just blocks and i need to know the size of textures for tesselator

 

whole render method: (1.7.10)

 

public static boolean renderChunk(int pass, int cx, int cy, int cz, IBlockAccess cache, RenderBlocks renderer) {
        if(!ModConfig.MOD_ENABLED) {
            return false;
        } else if(pass != 0) {
            return false;
        } else {
            Tessellator tess = Tessellator.getInstance();
            int[] dims = new int[]{16, 16, 16};
            int[] c = new int[]{cx, cy, cz};
            int[] x = new int[3];
            int[] r = new int[]{1, dims[0] + 3, (dims[0] + 3) * (dims[1] + 3)};
            float[] grid = new float[8];
            float[][] buffer = new float[r[2] * 2][3];
            int bufno = 1;

            for(x[2] = 0; x[2] < dims[2] + 1; r[2] = -r[2]) {
                int m = 1 + (dims[0] + 3) * (1 + bufno * (dims[1] + 3));

                for(x[1] = 0; x[1] < dims[1] + 1; m += 2) {
                    for(x[0] = 0; x[0] < dims[0] + 1; ++m) {
                        int mask = 0;
                        int g = 0;

                        for(int k = 0; k < 2; ++k) {
                            for(int j = 0; j < 2; ++j) {
                                for(int i = 0; i < 2; ++g) {
                                    float p = getBlockDensity(c[0] + x[0] + i, c[1] + x[1] + j, c[2] + x[2] + k, cache);
                                    grid[g] = p;
                                    mask |= p > 0.0F?1 << g:0;
                                    ++i;
                                }
                            }
                        }

                        if(mask != 0 && mask != 255) {
                            Block block = Blocks.AIR;
                            int meta = 0;

                            label368:
                            for(int k = -1; k < 2; ++k) {
                                for(int j = -1; j < 2; ++j) {
                                    for(int i = -1; i < 2; ++i) {
                                        IBlockState bs = cache.getBlockState(new BlockPos(c[0] + x[0] + i, c[1] + x[1] + k, c[2] + x[2] + j));
                                        Block b = bs.getBlock();
                                        if(Main.shouldSmooth(b) && block != Blocks.SNOW_LAYER && block != Blocks.GRASS) {
                                            block = b;
                                            meta = b.getMetaFromState(bs);
                                            if(b == Blocks.SNOW_LAYER || b == Blocks.GRASS) {
                                                break label368;
                                            }
                                        }
                                    }
                                }
                            }

                            int[] br = new int[]{c[0] + x[0], c[1] + x[1] + 1, c[2] + x[2]};

                            label594:
                            for(int k = -1; k < 2; ++k) {
                                for(int j = -2; j < 3; ++j) {
                                    for(int i = -1; i < 2; ++i) {
                                        IBlockState bs = cache.getBlockState(new BlockPos(c[0] + x[0] + i, c[1] + x[1] + k, c[2] + x[2] + j));
                                        Block b = bs.getBlock();
                                        if(!b.isOpaqueCube(bs)) {
                                            br[0] = c[0] + x[0] + i;
                                            br[1] = c[1] + x[1] + k;
                                            br[2] = c[2] + x[2] + j;
                                            break label594;
                                        }
                                    }
                                }
                            }

                            IIcon icon = renderer.getBlockIconFromSideAndMetadata(block, 1, meta);
                            double tu0 = (double)icon.getMinUV();
                            double tu1 = (double)icon.getMaxU();
                            double tv0 = (double)icon.getMinV();
                            double tv1 = (double)icon.getMaxV();
                            int edgemask = edge_table[mask];
                            int ecount = 0;
                            float[] v = new float[]{0.0F, 0.0F, 0.0F};

                            for(int i = 0; i < 12; ++i) {
                                if((edgemask & 1 << i) != 0) {
                                    ++ecount;
                                    int e0 = cube_edges[i << 1];
                                    int e1 = cube_edges[(i << 1) + 1];
                                    float g0 = grid[e0];
                                    float g1 = grid[e1];
                                    float t = g0 - g1;
                                    if(Math.abs(t) > 0.0F) {
                                        t = g0 / t;
                                        int j = 0;

                                        for(int k = 1; j < 3; k <<= 1) {
                                            int a = e0 & k;
                                            int b = e1 & k;
                                            if(a != b) {
                                                v[j] += a != 0?1.0F - t:t;
                                            } else {
                                                v[j] += a != 0?1.0F:0.0F;
                                            }

                                            ++j;
                                        }
                                    }
                                }
                            }

                            float s = 1.0F / (float)ecount;

                            for(int i = 0; i < 3; ++i) {
                                v[i] = (float)(c[i] + x[i]) + s * v[i];
                            }

                            int tx = x[0] == 16?0:x[0];
                            int ty = x[1] == 16?0:x[1];
                            int tz = x[2] == 16?0:x[2];
                            long i1 = (long)(tx * 3129871) ^ (long)tz * 116129781L ^ (long)ty;
                            i1 = i1 * i1 * 42317861L + i1 * 11L;
                            v[0] = (float)((double)v[0] - ((double)((float)(i1 >> 16 & 15L) / 15.0F) - 0.5D) * 0.2D);
                            v[1] = (float)((double)v[1] - ((double)((float)(i1 >> 20 & 15L) / 15.0F) - 1.0D) * 0.2D);
                            v[2] = (float)((double)v[2] - ((double)((float)(i1 >> 24 & 15L) / 15.0F) - 0.5D) * 0.2D);
                            buffer[m] = v;

                            for(int i = 0; i < 3; ++i) {
                                if((edgemask & 1 << i) != 0) {
                                    int iu = (i + 1) % 3;
                                    int iv = (i + 2) % 3;
                                    if(x[iu] != 0 && x[iv] != 0) {
                                        int du = r[iu];
                                        int dv = r[iv];
                                        //tess.setBrightness(block.getMixedBrightnessForBlock(Minecraft.getMinecraft().theWorld, br[0], br[1], br[2]));
                                        //tess.setColorOpaque_I(block.colorMultiplier(cache, c[0] + x[0], c[1] + x[1], c[2] + x[2])); dont know what to do with these too
                                        float[] v0 = buffer[m];
                                        float[] v1 = buffer[m - du];
                                        float[] v2 = buffer[m - du - dv];
                                        float[] v3 = buffer[m - dv];
                                        if((mask & 1) != 0) {
                                            tess.addVertexWithUV((double)v0[0], (double)v0[1], (double)v0[2], tu0, tv1);
                                            tess.addVertexWithUV((double)v1[0], (double)v1[1], (double)v1[2], tu1, tv1);
                                            tess.addVertexWithUV((double)v2[0], (double)v2[1], (double)v2[2], tu1, tv0);
                                            tess.addVertexWithUV((double)v3[0], (double)v3[1], (double)v3[2], tu0, tv0);
                                        } else {
                                            tess.addVertexWithUV((double)v0[0], (double)v0[1], (double)v0[2], tu0, tv1);
                                            tess.addVertexWithUV((double)v3[0], (double)v3[1], (double)v3[2], tu1, tv1);
                                            tess.addVertexWithUV((double)v2[0], (double)v2[1], (double)v2[2], tu1, tv0);
                                            tess.addVertexWithUV((double)v1[0], (double)v1[1], (double)v1[2], tu0, tv0);
                                        }
                                    }
                                }
                            }
                        }

                        ++x[0];
                    }

                    ++x[1];
                }

                ++x[2];
                bufno ^= 1;
            }

            return true;
        }
    }

    static {
        int k = 0;

        for(int i = 0; i < 8; ++i) {
            for(int j = 1; j <= 4; j <<= 1) {
                int p = i ^ j;
                if(i <= p) {
                    cube_edges[k++] = i;
                    cube_edges[k++] = p;
                }
            }
        }

        for(int i = 0; i < 256; ++i) {
            int em = 0;

            for(int j = 0; j < 24; j += 2) {
                boolean a = (i & 1 << cube_edges[j]) != 0;
                boolean b = (i & 1 << cube_edges[j + 1]) != 0;
                em |= a != b?1 << (j >> 1):0;
            }

            edge_table[i] = em;
        }

    }

 

Posted

The main problem you'll run into is that blocks no longer have textures, they now have models. An IBakedModel can have any number of BakedQuads, each of which belongs to an EnumFacing (or null) and has a texture.

 

You can use IBakedModel#getQuads to get the BakedQuads for an optional IBlockState and optional EnumFacing. You'll need to work out what to do if the model has either zero or more than one BakedQuads for EnumFacing.UP (probably blacklist that state from being smoothed).

 

Look at BlockRendererDispatcher#renderBlock to see how it gets the actual state from the in-world state, the model from the actual state and the extended state from the actual state before rendering the model.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted
3 minutes ago, Choonster said:

The main problem you'll run into is that blocks no longer have textures, they now have models. An IBakedModel can have any number of BakedQuads, each of which belongs to an EnumFacing (or null) and has a texture.

 

You can use IBakedModel#getQuads to get the BakedQuads for an optional IBlockState and optional EnumFacing. You'll need to work out what to do if the model has either zero or more than one BakedQuads for EnumFacing.UP (probably blacklist that state from being smoothed).

 

Look at BlockRendererDispatcher#renderBlock to see how it gets the actual state from the in-world state, the model from the actual state and the extended state from the actual state before rendering the model.

how do i get the IBakedModel from block?

Posted
2 minutes ago, lukas2005 said:

how do i get the IBakedModel from block?

 

As I said, look at BlockRendererDispatcher#renderBlock.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted (edited)
2 minutes ago, Choonster said:

 

As I said, look at BlockRendererDispatcher#renderBlock.

well it uses non-static method getModelForState then how do i get BlockRendererDispatcher instance?EDIT ok i got it Minecraft.getMinecraft().getBlockRendererDispatcher()

Edited by lukas2005
Posted
Just now, lukas2005 said:

well it uses non-static method getModelForState

 

Yes, you should use it too. Use Minecraft#getBlockRendererDispatcher to get the BlockRenderDispatcher instance.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted
4 minutes ago, lukas2005 said:

now in IBakedModel#getQuads teres a strange long at the and called rand what shlou it be? random long?

 

That's a "random" number derived from the BlockPos, use MathHelper.getPositionRandom to calculate it.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted (edited)

ok i have the quads list now what do i do with a quad?]

 

EDIT: i got an object called TextureAtlasSprite from a quad and it seems to have almost same functions as the old IIcon object wich is great

Edited by lukas2005
Posted
1 minute ago, lukas2005 said:

ok i have the quads list now what do i do with a quad?

 

Get its texture with BakedQuad#getSprite. This is a TextureAtlasSprite, a sprite on the block/item texture atlas (like IIcon).

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

ok i now have my sizes but there is one more thing what are these?

tess.setBrightness(block.getMixedBrightnessForBlock(Minecraft.getMinecraft().theWorld, br[0], br[1], br[2]));

tess.setColorOpaque_I(block.colorMultiplier(cache, c[0] + x[0], c[1] + x[1], c[2] + x[2]));

Posted
19 minutes ago, lukas2005 said:

ok i now have my sizes but there is one more thing what are these?

tess.setBrightness(block.getMixedBrightnessForBlock(Minecraft.getMinecraft().theWorld, br[0], br[1], br[2]));

tess.setColorOpaque_I(block.colorMultiplier(cache, c[0] + x[0], c[1] + x[1], c[2] + x[2]));

 

I can't really help you with rendering specifics like this, all I can suggest is looking at ForgeBlockModelRenderer#renderModelFlat/ForgeBlockModelRenderer#renderModelSmooth (called by BlockModelRenderer#renderModel) to see how they render block models.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

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

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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