Jump to content

Recommended Posts

Posted

SOLVED

----------

Problem: I had a block where when you bump into it, it takes you inside of it, I added a new dimension for this but couldn't figure out how to generate the interior only once in the dimension.

 

Solution: In whatever your teleporting method is, either an item, colliding with block, etc... whereever you change the player's dimension is where you need to do the generation. Just use entity.getEntityWorld() to get the world, AFTER you change dimensions, then you will have the "dimension's world". Then use that world to do all of the structure creation.

 

Posted

I'm not sure if worlds have nbt but you could generate the structure once with an IWorldGenerator and then create a tag that says the structure has been built so it doesn't keep rebuilding it. Then again I've never really messed around with a chunk provider so I have no idea if this is possible.

The proud(ish) developer of Ancients

Posted

Don't think it would work. I added a dummy variable to hold whether or not it's been built and based on that add the block.

 

private boolean built = false;

 

if(built == false)

{

  addblockstuffhere

  built = true;

}

Posted

Oh, yes, sorry. Forgot to include that in last post ??? It doesn't work, it just doesn't add anything, but... I did another test, I had a counter variable, that increased every time that method was called and was printed out. When I first entered my dimension it was being increased without stopping until a certain point.. then it only increased as a moved towards un-generates terrain.

Posted

If it's easier, I could also just have it generate a cube of air and then build the structure inside. But I also couldn't get that working, as I keep getting index out of bound errors.

Posted

If it's easier, I could also just have it generate a cube of air and then build the structure inside. But I also couldn't get that working, as I keep getting index out of bound errors.

Post your current code.

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

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

Posted

Here..

 

    public void func_180520_a(int p_180520_1_, int p_180520_2_, ChunkPrimer primer)

    {

        for(int x = 0; x < 100; x++)

        {

            for(int z = 0; z < 100; z++)

            {

                primer.setBlockState(x, 100, z, Blocks.air.getDefaultState());

            }

        }

 

        primer.setBlockState(0, 100, 0, Blocks.end_stone.getDefaultState());

    }

 

Posted

Here..

 

    public void func_180520_a(int p_180520_1_, int p_180520_2_, ChunkPrimer primer)

    {

        for(int x = 0; x < 100; x++)

        {

            for(int z = 0; z < 100; z++)

            {

                primer.setBlockState(x, 100, z, Blocks.air.getDefaultState());

            }

        }

 

        primer.setBlockState(0, 100, 0, Blocks.end_stone.getDefaultState());

    }

1. You should post the full code, not just a method.

2. Post the crash report together.

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

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

Posted

Generating a cube of air and my structure inside forever was just a quick though, I would prefer the OP answered instead.

 

ChunkProvider

 

 

public class MYCHUNKPROVIDER implements IChunkProvider

{

    private Random endRNG;

    private NoiseGeneratorOctaves noiseGen1;

    private NoiseGeneratorOctaves noiseGen2;

    private NoiseGeneratorOctaves noiseGen3;

    public NoiseGeneratorOctaves noiseGen4;

    public NoiseGeneratorOctaves noiseGen5;

    private World endWorld;

    private double[] densities;

    /** The biomes that are used to generate the chunk */

    private BiomeGenBase[] biomesForGeneration;

    double[] noiseData1;

    double[] noiseData2;

    double[] noiseData3;

    double[] noiseData4;

    double[] noiseData5;

    private static final String __OBFID = "CL_00000397";

 

    public MYCHUNKPROVIDER(World worldIn, long p_i2007_2_)

    {

        this.endWorld = worldIn;

        this.endRNG = new Random(p_i2007_2_);

        this.noiseGen1 = new NoiseGeneratorOctaves(this.endRNG, 16);

        this.noiseGen2 = new NoiseGeneratorOctaves(this.endRNG, 16);

        this.noiseGen3 = new NoiseGeneratorOctaves(this.endRNG, 8);

        this.noiseGen4 = new NoiseGeneratorOctaves(this.endRNG, 10);

        this.noiseGen5 = new NoiseGeneratorOctaves(this.endRNG, 16);

 

        NoiseGenerator[] noiseGens = {noiseGen1, noiseGen2, noiseGen3, noiseGen4, noiseGen5};

        noiseGens = TerrainGen.getModdedNoiseGenerators(worldIn, this.endRNG, noiseGens);

        this.noiseGen1 = (NoiseGeneratorOctaves)noiseGens[0];

        this.noiseGen2 = (NoiseGeneratorOctaves)noiseGens[1];

        this.noiseGen3 = (NoiseGeneratorOctaves)noiseGens[2];

        this.noiseGen4 = (NoiseGeneratorOctaves)noiseGens[3];

        this.noiseGen5 = (NoiseGeneratorOctaves)noiseGens[4];

    }

 

 

    public void func_180520_a(int p_180520_1_, int p_180520_2_, ChunkPrimer primer)

    {

        for(int x = 0; x < 100; x++)

        {

            for(int z = 0; z < 100; z++)

            {

                primer.setBlockState(x, 100, z, Blocks.air.getDefaultState());

            }

        }

 

        primer.setBlockState(0, 100, 0, Blocks.end_stone.getDefaultState());

    }

 

    public void func_180519_a(ChunkPrimer primer)

    {

 

    }

 

    private int chunkX=0, chunkZ=0;

    /**

    * Will return back a chunk, if it doesn't exist and its not a MP client it will generates all the blocks for the

    * specified chunk from the map seed and chunk seed

    */

    public Chunk provideChunk(int x, int z)

    {

        chunkX = x; chunkZ = z;

        this.endRNG.setSeed((long)x * 341873128712L + (long)z * 132897987541L);

        ChunkPrimer chunkprimer = new ChunkPrimer();

        this.biomesForGeneration = this.endWorld.getWorldChunkManager().loadBlockGeneratorData(this.biomesForGeneration, x * 16, z * 16, 16, 16);

        this.func_180520_a(x, z, chunkprimer);

        this.func_180519_a(chunkprimer);

        Chunk chunk = new Chunk(this.endWorld, chunkprimer, x, z);

        byte[] abyte = chunk.getBiomeArray();

 

        for (int k = 0; k < abyte.length; ++k)

        {

            abyte[k] = (byte)this.biomesForGeneration[k].biomeID;

        }

 

        chunk.generateSkylightMap();

        return chunk;

    }

 

    /**

    * generates a subset of the level's terrain data. Takes 7 arguments: the [empty] noise array, the position, and the

    * size.

    */

    private double[] initializeNoiseField(double[] p_73187_1_, int p_73187_2_, int p_73187_3_, int p_73187_4_, int p_73187_5_, int p_73187_6_, int p_73187_7_)

    {

        ChunkProviderEvent.InitNoiseField event = new ChunkProviderEvent.InitNoiseField(this, p_73187_1_, p_73187_2_, p_73187_3_, p_73187_4_, p_73187_5_, p_73187_6_, p_73187_7_);

        MinecraftForge.EVENT_BUS.post(event);

        if (event.getResult() == Result.DENY) return event.noisefield;

 

        if (p_73187_1_ == null)

        {

            p_73187_1_ = new double[p_73187_5_ * p_73187_6_ * p_73187_7_];

        }

 

        double d0 = 684.412D;

        double d1 = 684.412D;

        this.noiseData4 = this.noiseGen4.generateNoiseOctaves(this.noiseData4, p_73187_2_, p_73187_4_, p_73187_5_, p_73187_7_, 1.121D, 1.121D, 0.5D);

        this.noiseData5 = this.noiseGen5.generateNoiseOctaves(this.noiseData5, p_73187_2_, p_73187_4_, p_73187_5_, p_73187_7_, 200.0D, 200.0D, 0.5D);

        d0 *= 2.0D;

        this.noiseData1 = this.noiseGen3.generateNoiseOctaves(this.noiseData1, p_73187_2_, p_73187_3_, p_73187_4_, p_73187_5_, p_73187_6_, p_73187_7_, d0 / 80.0D, d1 / 160.0D, d0 / 80.0D);

        this.noiseData2 = this.noiseGen1.generateNoiseOctaves(this.noiseData2, p_73187_2_, p_73187_3_, p_73187_4_, p_73187_5_, p_73187_6_, p_73187_7_, d0, d1, d0);

        this.noiseData3 = this.noiseGen2.generateNoiseOctaves(this.noiseData3, p_73187_2_, p_73187_3_, p_73187_4_, p_73187_5_, p_73187_6_, p_73187_7_, d0, d1, d0);

        int k1 = 0;

 

        for (int l1 = 0; l1 < p_73187_5_; ++l1)

        {

            for (int i2 = 0; i2 < p_73187_7_; ++i2)

            {

                float f = (float)(l1 + p_73187_2_) / 1.0F;

                float f1 = (float)(i2 + p_73187_4_) / 1.0F;

                float f2 = 100.0F - MathHelper.sqrt_float(f * f + f1 * f1) * 8.0F;

 

                if (f2 > 80.0F)

                {

                    f2 = 80.0F;

                }

 

                if (f2 < -100.0F)

                {

                    f2 = -100.0F;

                }

 

                for (int j2 = 0; j2 < p_73187_6_; ++j2)

                {

                    double d2 = 0.0D;

                    double d3 = this.noiseData2[k1] / 512.0D;

                    double d4 = this.noiseData3[k1] / 512.0D;

                    double d5 = (this.noiseData1[k1] / 10.0D + 1.0D) / 2.0D;

 

                    if (d5 < 0.0D)

                    {

                        d2 = d3;

                    }

                    else if (d5 > 1.0D)

                    {

                        d2 = d4;

                    }

                    else

                    {

                        d2 = d3 + (d4 - d3) * d5;

                    }

 

                    d2 -= 8.0D;

                    d2 += (double)f2;

                    byte b0 = 2;

                    double d6;

 

                    if (j2 > p_73187_6_ / 2 - b0)

                    {

                        d6 = (double)((float)(j2 - (p_73187_6_ / 2 - b0)) / 64.0F);

                        d6 = MathHelper.clamp_double(d6, 0.0D, 1.0D);

                        d2 = d2 * (1.0D - d6) + -3000.0D * d6;

                    }

 

                    b0 = 8;

 

                    if (j2 < b0)

                    {

                        d6 = (double)((float)(b0 - j2) / ((float)b0 - 1.0F));

                        d2 = d2 * (1.0D - d6) + -30.0D * d6;

                    }

 

                    p_73187_1_[k1] = d2;

                    ++k1;

                }

            }

        }

 

        return p_73187_1_;

    }

 

    /**

    * Checks to see if a chunk exists at x, z

    */

    public boolean chunkExists(int x, int z)

    {

        return true;

    }

 

    /**

    * Populates chunk with ores etc etc

    */

    public void populate(IChunkProvider provider, int p_73153_2_, int p_73153_3_)

    {

        BlockFalling.fallInstantly = true;

 

        MinecraftForge.EVENT_BUS.post(new PopulateChunkEvent.Pre(provider, endWorld, endWorld.rand, p_73153_2_, p_73153_3_, false));

 

        BlockPos blockpos = new BlockPos(p_73153_2_ * 16, 0, p_73153_3_ * 16);

        this.endWorld.getBiomeGenForCoords(blockpos.add(16, 0, 16)).decorate(this.endWorld, this.endWorld.rand, blockpos);

 

        MinecraftForge.EVENT_BUS.post(new PopulateChunkEvent.Post(provider, endWorld, endWorld.rand, p_73153_2_, p_73153_3_, false));

        BlockFalling.fallInstantly = false;

    }

 

    public boolean func_177460_a(IChunkProvider p_177460_1_, Chunk p_177460_2_, int p_177460_3_, int p_177460_4_)

    {

        return false;

    }

 

    /**

    * Two modes of operation: if passed true, save all Chunks in one go.  If passed false, save up to two chunks.

    * Return true if all chunks have been saved.

    */

    public boolean saveChunks(boolean p_73151_1_, IProgressUpdate p_73151_2_)

    {

        return true;

    }

 

    /**

    * Save extra data not associated with any Chunk.  Not saved during autosave, only during world unload.  Currently

    * unimplemented.

    */

    public void saveExtraData() {}

 

    /**

    * Unloads chunks that are marked to be unloaded. This is not guaranteed to unload every such chunk.

    */

    public boolean unloadQueuedChunks()

    {

        return false;

    }

 

    /**

    * Returns if the IChunkProvider supports saving.

    */

    public boolean canSave()

    {

        return true;

    }

 

    /**

    * Converts the instance data to a readable string.

    */

    public String makeString()

    {

        return "RandomLevelSource";

    }

 

    public List func_177458_a(EnumCreatureType p_177458_1_, BlockPos p_177458_2_)

    {

        return this.endWorld.getBiomeGenForCoords(p_177458_2_).getSpawnableList(p_177458_1_);

    }

 

    public BlockPos getStrongholdGen(World worldIn, String p_180513_2_, BlockPos p_180513_3_)

    {

        return null;

    }

 

    public int getLoadedChunkCount()

    {

        return 0;

    }

 

    public void recreateStructures(Chunk p_180514_1_, int p_180514_2_, int p_180514_3_) {}

 

    public Chunk provideChunk(BlockPos blockPosIn)

    {

        return this.provideChunk(blockPosIn.getX() >> 4, blockPosIn.getZ() >> 4);

    }

}

 

 

Posted

1. First remove this line:

private static final String __OBFID = "CL_00000397";

It is minecraft deobfuscation id, which is totally useless and unrelated with modding.

(+ Do not copy-paste code if you cant fully understand the code..)

2. Please rephrase your issue, I cant understand what is your problem.

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

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

Posted

Here..

 

    public void func_180520_a(int p_180520_1_, int p_180520_2_, ChunkPrimer primer)

    {

        for(int x = 0; x < 100; x++)

        {

            for(int z = 0; z < 100; z++)

            {

                primer.setBlockState(x, 100, z, Blocks.air.getDefaultState());

            }

        }

 

        primer.setBlockState(0, 100, 0, Blocks.end_stone.getDefaultState());

    }

1. You should post the full code, not just a method.

2. Post the crash report together.

 

 

All I need, is an empty dimension, with one structure generated inside, that way when teleported there (working), I am teleported into that structure.

Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • So me and a couple of friends are playing with a shitpost mod pack and one of the mods in the pack is corail tombstone and for some reason there is a problem with it, where on death to fire the player will get kicked out of the server and the tombstone will not spawn basically deleting an entire inventory, it doesn't matter what type of fire it is, whether it's from vanilla fire/lava, or from modded fire like ice&fire/lycanites and it's common enough to where everyone on the server has experienced at least once or twice and it doesn't give any crash log. a solution to this would be much appreciated thank you!
    • 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.