Jump to content

Recommended Posts

Posted

Hi everyone,

I'm currently making a tech-mod and I'm locked at a point where i'd need some help.

I'd like to know how could I make a tree generates, and when I break the logs, I could get the rubber from my mod.

Thanks for the help ! Tongue

EDIT: I'm in 1.9.4

R-EDIT: I think i will change this topic to be my new mod help topic :P

Posted

Pheno I know this is kind of an random question. And keep in mind im not trying to make you do this. But im always looking for a partner to make a mod with. I know its a bit random but im trying to find a conpanion. And as for your rubber drop. It should be what he said. Thanks. And if you would like to make a mod togther Email me. Again not making you but my email is [email protected]

Are You Feeling it now Mr.Krabs?

 

GitHub

https://github.com/nuclearelectricity/Nuclear-Electricity

Posted

But actually, I can't find any tutorial to code a type of tree that would generate in the overworld in 1.9.4

Do you know how to do it ?

Thanks :)

 

The vanilla trees are placed in worldgen by various classes (WorldGenTrees (oak by default), WorldGenBirchTree, WorldGenSavannaTree etc) which all extend WorldGenAbstractTree, which extends WorldGenerator already.

 

You can take a shortcut, and call WorldGenTrees with the constructor of

boolean notify, int minHeight, IBlockState logBlock, IBlockState leafBlock, boolean haveVines

. (Notify should be "true", otherwise clients won't see the tree) It will create a normal oak-structured tree for you, with the specified blocks already. This is of course unless you want your tree to have a custom appearance (Like Thaumcraft's or Forestry's trees, for example). For that, you would have to lookup said WorldGen____ classes and see how they use the WorldGenAbstractTree methods.

 

To actually implement the actual worldgen, I would advice you to create a class that implements IWorldGenerator, and then register it in the

init phase

with

GameRegistry.registerWorldGenerator(new NameOfWorldGenClass(), weight);

where

weight

is an integer that states in what approximate order it falls into during worldgen, where low numbers usually go first, high numbers gets placed last.

I have an IWorldGenerator that places several different vanilla trees, you can view it here:

https://github.com/Matryoshika/Underworld/blob/master/src/main/java/se/Matryoshika/Underworld/WorldGen/Dirty/DirtyTreeGen.java

You cannot simply copy paste though (Not saying I thought you would, just that you cannot) because it is used in wordgen that uses a different WorldProvider & BiomeProvider entirely. Ignore the code that references those.

 

I'd advice you to use the

generate

method to get a blockpos first, using World#getTopSolidOrLiquidBlock(pos) where pos only uses the x & z blockpos gained from the method's chunkX & chunkZ coords.

Then, see if the tree can spawn with a boolean method (If the blockpos gained contains grass/dirt (hardcoded check into the WorldGenTree classes, if there's not grass/dirt, it doesnt spawn)). Then, you call your actual generateTree method, that places the tree at the pos#up() coord.

Also previously known as eAndPi.

"Pi, is there a station coming up where we can board your train of thought?" -Kronnn

Published Mods: Underworld

Handy links: Vic_'s Forge events Own WIP Tutorials.

Posted

Aight Big thanks to both of you !

But now i've got another problem :/

I did an ore generation for my ore (allium).

All is running correctly, but when I make a new world to see if the ore generates, it crashes ;-;.

Here's the report :[embed=425,349]WARNING: coremods are present:

  IC2core (industrialcraft-2-2.5.63-ex19-dev.jar)

Contact their authors BEFORE contacting forge

 

// I just don't know what went wrong :(

 

Time: 28/08/16 12:33

Description: Exception in server tick loop

 

java.lang.NullPointerException: Exception in server tick loop

at init.worldgen.WorldGen.runGenerator(WorldGen.java:59)

at init.worldgen.WorldGen.generate(WorldGen.java:34)

at net.minecraftforge.fml.common.registry.GameRegistry.generateWorld(GameRegistry.java:113)

at net.minecraft.world.chunk.Chunk.populateChunk(Chunk.java:1075)

at net.minecraft.world.chunk.Chunk.populateChunk(Chunk.java:1057)

at net.minecraft.world.gen.ChunkProviderServer.provideChunk(ChunkProviderServer.java:163)

at net.minecraft.server.MinecraftServer.initialWorldChunkLoad(MinecraftServer.java:335)

at net.minecraft.server.integrated.IntegratedServer.loadAllWorlds(IntegratedServer.java:106)

at net.minecraft.server.integrated.IntegratedServer.startServer(IntegratedServer.java:123)

at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:494)

at java.lang.Thread.run(Unknown Source)

 

 

A detailed walkthrough of the error, its code path and all known details is as follows:

---------------------------------------------------------------------------------------

 

-- System Details --

Details:

Minecraft Version: 1.9.4

Operating System: Windows 8.1 (amd64) version 6.3

Java Version: 1.8.0_31, Oracle Corporation

Java VM Version: Java HotSpot 64-Bit Server VM (mixed mode), Oracle Corporation

Memory: 712922584 bytes (679 MB) / 1056309248 bytes (1007 MB) up to 1056309248 bytes (1007 MB)

JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M

IntCache: cache: 1, tcache: 1, allocated: 12, tallocated: 94

FML: MCP 9.28 Powered by Forge 12.17.0.2051 5 mods loaded, 5 mods active

States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored

UCHIJAA mcp{9.19} [Minecraft Coder Pack] (minecraft.jar)

UCHIJAA FML{8.0.99.99} [Forge Mod Loader] (forgeSrc-1.9.4-12.17.0.2051.jar)

UCHIJAA Forge{12.17.0.2051} [Minecraft Forge] (forgeSrc-1.9.4-12.17.0.2051.jar)

UCHIJAA advancedic2{0.1-alpha} [Advanced IC2] (bin)

UCHIJAA IC2{2.5.63-ex19} [industrialCraft 2] (industrialcraft-2-2.5.63-ex19-dev.jar)

Loaded coremods (and transformers):

IC2core (industrialcraft-2-2.5.63-ex19-dev.jar)

 

GL info: ~~ERROR~~ RuntimeException: No OpenGL context found in the current thread.

Profiler Position: N/A (disabled)

Player Count: 0 / 8; []

Type: Integrated Server (map_client.txt)

Is Modded: Definitely; Client brand changed to 'fml,forge'

[12:33:18] [Client thread/INFO] [sTDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:649]: #@!@# Game crashed! Crash report saved to: #@!@# .\crash-reports\crash-2016-08-28_12.33.16-server.txt

[12:33:18] [Client Shutdown Thread/INFO]: Stopping server

[12:33:18] [Client Shutdown Thread/INFO]: Saving players

[12:33:18] [Client Shutdown Thread/INFO]: Saving worlds

AL lib: (EE) alc_cleanup: 1 device not closed

Java HotSpot 64-Bit Server VM warning: Using incremental CMS is deprecated and will likely be removed in a future release[/embed]

Posted

[3:06:11 PM] Adam: ...

[3:06:26 PM] Adam: Wtf

[3:07:17 PM] Adam: Dude you gotta trust me I'm not going to do anything. Teamviewer was so we could see each others screens

[3:07:26 PM] Adam: ill give you my username and password

[3:07:36 PM] Adam: 948 955 252

[3:07:41 PM] Adam: 13js1s

Im sorry guys but i have no other way of contacting him hes scared of me doing something to his computer

There are things called PM's and I assume he emailed you.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted

Post the all OreGeneration Code and please use spoilers for things like crash reports and code tags for code.

 

Aight, here's the oregen code WITH SPOILER :

 

That's the WorldGenMineable.java

 

 

package init.worldgen;

 

import java.util.Random;

 

import com.google.common.base.Predicate;

 

import net.minecraft.block.state.IBlockState;

import net.minecraft.block.state.pattern.BlockMatcher;

import net.minecraft.init.Blocks;

import net.minecraft.util.math.BlockPos;

import net.minecraft.util.math.MathHelper;

import net.minecraft.world.World;

import net.minecraft.world.gen.feature.WorldGenerator;

 

public class WorldGenMineable extends WorldGenerator

{

    private final IBlockState oreBlock;

    /** The number of blocks to generate. */

    private final int numberOfBlocks;

    private final Predicate<IBlockState> predicate;

 

    public WorldGenMineable(IBlockState alliumore, int blockCount)

    {

        this(alliumore, blockCount, BlockMatcher.forBlock(Blocks.STONE));

    }

 

    public WorldGenMineable(IBlockState state, int blockCount, Predicate<IBlockState> p_i45631_3_)

    {

        this.oreBlock = state;

        this.numberOfBlocks = blockCount;

        this.predicate = p_i45631_3_;

    }

 

public boolean generate(World worldIn, Random rand, BlockPos position)

    {

        float f = rand.nextFloat() * (float)Math.PI;

        double d0 = (double)((float)(position.getX() + 8) + MathHelper.sin(f) * (float)this.numberOfBlocks / 8.0F);

        double d1 = (double)((float)(position.getX() + 8) - MathHelper.sin(f) * (float)this.numberOfBlocks / 8.0F);

        double d2 = (double)((float)(position.getZ() + 8) + MathHelper.cos(f) * (float)this.numberOfBlocks / 8.0F);

        double d3 = (double)((float)(position.getZ() + 8) - MathHelper.cos(f) * (float)this.numberOfBlocks / 8.0F);

        double d4 = (double)(position.getY() + rand.nextInt(3) - 2);

        double d5 = (double)(position.getY() + rand.nextInt(3) - 2);

 

        for (int i = 0; i < this.numberOfBlocks; ++i)

        {

            float f1 = (float)i / (float)this.numberOfBlocks;

            double d6 = d0 + (d1 - d0) * (double)f1;

            double d7 = d4 + (d5 - d4) * (double)f1;

            double d8 = d2 + (d3 - d2) * (double)f1;

            double d9 = rand.nextDouble() * (double)this.numberOfBlocks / 16.0D;

            double d10 = (double)(MathHelper.sin((float)Math.PI * f1) + 1.0F) * d9 + 1.0D;

            double d11 = (double)(MathHelper.sin((float)Math.PI * f1) + 1.0F) * d9 + 1.0D;

            int j = MathHelper.floor_double(d6 - d10 / 2.0D);

            int k = MathHelper.floor_double(d7 - d11 / 2.0D);

            int l = MathHelper.floor_double(d8 - d10 / 2.0D);

            int i1 = MathHelper.floor_double(d6 + d10 / 2.0D);

            int j1 = MathHelper.floor_double(d7 + d11 / 2.0D);

            int k1 = MathHelper.floor_double(d8 + d10 / 2.0D);

 

            for (int l1 = j; l1 <= i1; ++l1)

            {

                double d12 = ((double)l1 + 0.5D - d6) / (d10 / 2.0D);

 

                if (d12 * d12 < 1.0D)

                {

                    for (int i2 = k; i2 <= j1; ++i2)

                    {

                        double d13 = ((double)i2 + 0.5D - d7) / (d11 / 2.0D);

 

                        if (d12 * d12 + d13 * d13 < 1.0D)

                        {

                            for (int j2 = l; j2 <= k1; ++j2)

                            {

                                double d14 = ((double)j2 + 0.5D - d8) / (d10 / 2.0D);

 

                                if (d12 * d12 + d13 * d13 + d14 * d14 < 1.0D)

                                {

                                    BlockPos blockpos = new BlockPos(l1, i2, j2);

 

                                    IBlockState state = worldIn.getBlockState(blockpos);

                                    if (state.getBlock().isReplaceableOreGen(state, worldIn, blockpos, this.predicate))

                                    {

                                        worldIn.setBlockState(blockpos, this.oreBlock, 2);

                                    }

                                }

                            }

                        }

                    }

                }

            }

        }

 

        return true;

    }

}

 

 

And that's the world gen

 

 

 

package init.worldgen;

 

import java.util.Random;

 

import com.google.common.base.Predicate;

 

import net.minecraft.util.math.BlockPos;

import net.minecraft.world.World;

import net.minecraft.world.chunk.IChunkGenerator;

import net.minecraft.world.chunk.IChunkProvider;

import net.minecraft.world.gen.feature.WorldGenerator;

import net.minecraftforge.fml.common.IWorldGenerator;

import phenolphtaleine.advancedic2.Reference.aIC2Blocks;

 

public class WorldGen implements IWorldGenerator

{

 

//OverWorldOres

private WorldGenerator ALLIUMORE;

 

public WorldGen()

{

 

}

 

@Override

public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator,

IChunkProvider chunkProvider)

{

switch(world.provider.getDimension())

{

case 0: //OverWorld

 

this.runGenerator(this.ALLIUMORE, world, random, chunkX, chunkZ, 40, 0, 40);

 

break;

 

case -1: //Nether

 

break;

   

case 1:  //EndWorld

 

break;

}

}

 

private void runGenerator(WorldGenerator generator, World world, Random random, int chunkX, int chunkZ, int chanceToSpawn, int minHeight, int maxHeight)

{

if(minHeight < 0 || maxHeight >256 || minHeight > maxHeight)

throw new IllegalArgumentException("Minimum or Max height out of bounds");

 

int heightDiff = maxHeight = minHeight +1;

for(int i = 0; i < chanceToSpawn; i++)

{

int x = chunkX * 16 + random.nextInt(16);

int y = minHeight + random.nextInt(heightDiff);

int z = chunkZ * 16 + random.nextInt(16);

generator.generate(world, random, new BlockPos(x, y, z));

}

}

 

 

}

 

 

 

Here we go

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

    • 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() ); } }  
    • Do you use features of inventory profiles next (ipnext) or is there a change without it?
    • Remove rubidium - you are already using embeddium, which is a fork of rubidium
  • Topics

×
×
  • Create New...

Important Information

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