Jump to content

Recommended Posts

Posted

I am working on my project, but I need to use coremode instead of mod.I can't find any tutorials for 1.7.2

Can somebody help me with setup Eclipse and basics of core mods?

Posted

I'm sorry but from what you have said just there... It sounds like core mods are way out of your league. Do you know how to use ASM?

We all stuff up sometimes... But I seem to be at the bottom of that pot.

Posted

What code do you need to add, where do you need to add it, and why do you need to add it?

 

Are you absolutely certain there is no way around a coremod?

Posted

I know that I need to use ASD, but it's my forst contact with coremods and ASM.

To my project I must made own village that will be a bit similar to vanilla, but my own villagecolection need to be add in finishSetup() method and world(...)

Posted

This might still be relevant. Specifically,

VillagerRegistry#registerVillageCreationHandler

.

 

If that is not what you had in mind, there are hooks for adding your own structures to worldgen as well - I don't know them, specifically, but you should definitely not have to tamper with vanilla classes.

Posted

I don't want to add own building yet.But create own village.

Here is what i need to add to World.class

 

public VillageCollection villageCollectionObj;

 

in finishSetup():

        VillageCollection villagecollection = (VillageCollection)this.mapStorage.loadData(VillageCollection.class, "villages");

 

        if (villagecollection == null)

        {

            this.villageCollectionObj = new VillageCollection(this);

            this.mapStorage.setData("villages", this.villageCollectionObj);

        }

        else

        {

            this.villageCollectionObj = villagecollection;

            this.villageCollectionObj.func_82566_a(this);

        }

 

and in world(ISaveHandler p_i45369_1_, String p_i45369_2_, WorldSettings p_i45369_3_, WorldProvider p_i45369_4_, Profiler p_i45369_5_):

        VillageCollection villagecollection = (VillageCollection)this.perWorldStorage.loadData(VillageCollection.class, "villages");

 

        if (villagecollection == null)

        {

            this.villageCollectionObj = new VillageCollection(this);

            this.perWorldStorage.setData("villages", this.villageCollectionObj);

        }

        else

        {

            this.villageCollectionObj = villagecollection;

            this.villageCollectionObj.func_82566_a(this);

        }

 

 

of course all the needed names will be changed

Posted

Please use [ code ] tags for short snippets of code, and gists for larger amounts :)

 

Do you want your village to coexist with other villages? Do you want to use the vanilla buildings in your village?

 

If you would please be a bit more specific about what you need - not just "I need to add this code", but rather "I want this and this result", I think we can find a way around your needs without having to rely on coremods.

 

Also, I believe the general sentiment is, if you don't know how to make a coremod, you shouldn't be making one.

 

There are plenty of resources both on this forum - and on the web - on how to go about making coremods in the general sense. If you can't tailor those guides and instructions to suit your specific needs, you probably should really be looking into how to achieve what you want to do without making a coremod.

 

In fact, you should probably always be very sure you need a coremod before you choose to make one.

 

Your current need sounds like it can be managed without a coremod, so let's approach it from that angle to begin with, shall we?

 

Note: If you end up making a coremod, and you are having specific issues that to your knowledge should work, yet do not seem to, you are more than welcome to ask for advice, here.

 

I don't think anyone will be willing to take you from Goth to Boss on coremods without very serious justification and commitment on your end.

Posted

To brighten the problem:

I don't want buildings.

Code writen higher is needed to make my village setting and anihilating, by checking the door number.

Without that code my village can't appear.

Maybe there is some way to make village collection without editing world.class or using asm, but so far it's only way known to me.

 

Posted

You don't want buildings? What do you want, then?

 

You want your villages (which consists of what?) to appear and disappear based on door numbers? ... But without buildings, there are no doors (probably).

 

What is the village collection supposed to represent, and what will it do?

Posted

Village can be material (structures) and nomaterial(village centred in some point

calculated from doors).My village will apear after generating my own building on world. When it will generate, door will create village and to make that village I need to add that method and villagecollection class.

Sorry for problems with explaining, but english isn't my native language.

Posted

I am absolutely new with events too.

Something I have wrong.

In my load method      MinecraftForge.EVENT_BUS.register(new BetterWorldHandler());

And method in my handler 

 

@SubscribeEvent
public void someEventMethod(WorldEvent event) 
{		
BetterVillageCollection villagecollection = (BetterVillageCollection)this.mapStorage.loadData(BetterVillageCollection.class, "bettervillages");
        
        if (villagecollection == null)
        {
            this.villageCollectionObj = new BetterVillageCollection(world);
            this.mapStorage.setData("bettervillages", this.villageCollectionObj);
        }
        else
        {
            this.villageCollectionObj = villagecollection;
            this.villageCollectionObj.func_82566_a(world);
        }
}

 

And error from Console

 

[13:13:52] [server thread/ERROR]: Encountered an unexpected exception
net.minecraft.util.ReportedException: Exception getting block type in world
at net.minecraft.world.World.<init>(World.java:316) ~[World.class:?]
at net.minecraft.world.WorldServer.<init>(WorldServer.java:103) ~[WorldServer.class:?]
at net.minecraft.server.integrated.IntegratedServer.loadAllWorlds(IntegratedServer.java:63) ~[integratedServer.class:?]
at net.minecraft.server.integrated.IntegratedServer.startServer(IntegratedServer.java:96) ~[integratedServer.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:442) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:742) [MinecraftServer$2.class:?]
Caused by: java.lang.NullPointerException
at BetterWorld.BetterWorldHandler.someEventMethod(BetterWorldHandler.java:18) ~[betterWorldHandler.class:?]
at cpw.mods.fml.common.eventhandler.ASMEventHandler_4_BetterWorldHandler_someEventMethod_WorldEvent.invoke(.dynamic) ~[?:?]
at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:51) ~[ASMEventHandler.class:?]
at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:122) ~[EventBus.class:?]
at net.minecraft.world.chunk.Chunk.onChunkLoad(Chunk.java:1014) ~[Chunk.class:?]
at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:149) ~[ChunkProviderServer.class:?]
at net.minecraft.world.gen.ChunkProviderServer.provideChunk(ChunkProviderServer.java:163) ~[ChunkProviderServer.class:?]
at net.minecraft.world.World.getChunkFromChunkCoords(World.java:487) ~[World.class:?]
at net.minecraft.world.World.getBlock(World.java:392) ~[World.class:?]
at net.minecraft.world.World.isAirBlock(World.java:415) ~[World.class:?]
at net.minecraft.world.World.getTopBlock(World.java:376) ~[World.class:?]
at net.minecraft.world.WorldProvider.canCoordinateBeSpawn(WorldProvider.java:97) ~[WorldProvider.class:?]
at net.minecraft.world.WorldServer.createSpawnPosition(WorldServer.java:806) ~[WorldServer.class:?]
at net.minecraft.world.WorldServer.initialize(WorldServer.java:770) ~[WorldServer.class:?]
at net.minecraft.world.World.<init>(World.java:301) ~[World.class:?]

 

 

 

Posted

So what I need to do to make my  villageCollectionObj in  world server???

 

EntityPlayer player = mc.thePlayer;

        WorldServer worldServer = DimensionManager.getWorld(player.dimension);

        if(worldServer == null){

            return null;

        }

        BetterVillageCollection vlgc = worldServer.villageCollectionObj;

        BetterVillage closestVillage = vlgc.findNearestVillage(

                MathHelper.floor_double(player.posX),

                MathHelper.floor_double(player.posY),

                MathHelper.floor_double(player.posZ), 50);

Posted

Stil doesn't work.

Handler class:

public static BetterVillageCollection villageCollectionObj;

@SubscribeEvent
public void someEventMethod(WorldEvent event) 
{	
	BetterVillageCollection villagecollection = (BetterVillageCollection)event.world.mapStorage.loadData(BetterVillageCollection.class, "bettervillages");	

        if (villagecollection == null)
        {
            this.villageCollectionObj = new BetterVillageCollection(event.world);
            event.world.mapStorage.setData("bettervillages", this.villageCollectionObj);
        }
        else
        {
            this.villageCollectionObj = villagecollection;
            this.villageCollectionObj.func_82566_a(event.world);
        }
}

And code for my mod.

     
BetterWorldHandler handler = new BetterWorldHandler();

        BetterVillageCollection vlgc = handler.villageCollectionObj;
        BetterVillage closestVillage = vlgc.findNearestVillage(
                MathHelper.floor_double(player.posX),
                MathHelper.floor_double(player.posY),
                MathHelper.floor_double(player.posZ), 50);
[/cpde]

Posted

It's terrible.I only need to load and set data from world.

Now my code looks like:

public static BetterVillageCollection get(World world)
{
	BetterVillageCollection data = (BetterVillageCollection)world.loadItemData(BetterVillageCollection.class, IDENTIFIER);

	if (data == null)
	{
		data = new BetterVillageCollection(world);
		world.setItemData(IDENTIFIER, data);
	}
        else
        {
            data.func_82566_a(world);
        }

	return data;
}

[code]
        BetterWorldHandler handler = new BetterWorldHandler();

        BetterVillageCollection vlgc = handler.get(worldServer);
        BetterVillage closestVillage = vlgc.findNearestVillage(
                MathHelper.floor_double(player.posX),
                MathHelper.floor_double(player.posY),
                MathHelper.floor_double(player.posZ), 50);

[/code]

Posted

I use bottom code with findNearestVillage() to search village and get from it informations.When I use normall village the code works and in my GUI disply e.g. number of villagers.My code for village is the same, because I need to be sure that village creates.

If the code is the same with necesary changes ,the code for loading and saving data is incorrect.

  • 2 weeks later...
Posted

My village code is the same.

I am not sure is the code working, but it should, because it's the same as vanilla.

I want to make more usefull villages and I don't want to edit base files.

Why should I send Packets if I my mod is for single player?

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.