Jump to content

Recommended Posts

Posted

Hi.

 

I'm having trouble getting my items to show up on the custom creative tab that i made.

 

The items can be spawned by /give command.

And all textures are correct.

Even my custom creative tab shows, but its empty..

 

I create my custom tab in my main mod file:

public static final KaktusTab kaktusmodcreativetab = new KaktusTab("KaktusModTab");

 

My KaktusTab.java:

 

package kaktus.mods.kaktusmod;

import kaktus.mods.kaktusmod.items.kaktusItems;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;

public class KaktusTab extends CreativeTabs{

public KaktusTab(String label) {
	super(label);
	this.setBackgroundImageName("kaktusmod.png");
}

@Override
public Item getTabIconItem() {
	return kaktusItems.turtleShellHelmet;
}

}

 

And my createitems routine:

 

turtleShellChestplate = new TurtleshellArmor("turtleshellchestplate", turtleArmorMaterial, 1, 1).setCreativeTab(KaktusMod.kaktusmodcreativetab);

 

I have also tried this in my custom armor class constructor:

 

this.setCreativeTab(KaktusMod.kaktusmodcreativetab);

 

So anyone knows what im doing wrong?

Not all things in the world are red, there are round objects too!

Posted

Here is my main mod file:

 

package kaktus.mods.kaktusmod;

import kaktus.mods.kaktusmod.entities.passive.EntityTurtle;

import kaktus.mods.kaktusmod.proxy.CommonProxy;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.item.Item;
import net.minecraft.item.ItemArmor.ArmorMaterial;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.Mod.Instance;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.registry.EntityRegistry;
import net.minecraftforge.fml.common.registry.LanguageRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.common.util.EnumHelper;

@Mod(modid = Config.MODID, name = Config.MODNAME, version = Config.VERSION, acceptedMinecraftVersions = "[1.8]", dependencies = "required-after:Forge@[11.14.3.1450,)")
public class KaktusMod {
@SidedProxy(clientSide = "kaktus.mods.kaktusmod.proxy.ClientProxy", serverSide = "kaktus.mods.kaktusmod.proxy.ServerProxy")
public static CommonProxy proxy;

@Mod.Instance(Config.MODID)
public static KaktusMod instance;

public static final KaktusTab kaktusmodcreativetab = new KaktusTab("KaktusModTab");

@EventHandler
public void preinit(FMLPreInitializationEvent event) {
	proxy.preInit(event);
}

@EventHandler
public void init(FMLInitializationEvent event) {
	proxy.init(event);
}

@EventHandler
public void postInit(FMLPostInitializationEvent event) {
	proxy.postInit(event);
}

}

Not all things in the world are red, there are round objects too!

Posted

In my commonproxy.java:

 

public void preInit(FMLPreInitializationEvent event) {

	kaktusItems.createItems();

 

and then in my kaktusItems.java file:

 

package kaktus.mods.kaktusmod.items;

import kaktus.mods.kaktusmod.Config;
import kaktus.mods.kaktusmod.KaktusMod;
import kaktus.mods.kaktusmod.items.armor.TurtleshellArmor;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemArmor.ArmorMaterial;
import net.minecraftforge.common.util.EnumHelper;
import net.minecraftforge.fml.common.registry.GameRegistry;

public class kaktusItems {

public static Item turtleShellHelmet;
public static Item turtleShellChestplate;
public static Item turtleShellLeggings;
public static Item turtleShellBoots;

public static ArmorMaterial turtleArmorMaterial = EnumHelper.addArmorMaterial(
		"turtleArmorMaterial",
		Config.MODID + ":turtleArmorMaterial", 
		1000, 
		new int[] {3, 8, 6, 3},
		30);


public static void createItems(){
	turtleShellHelmet = new TurtleshellArmor("turtleshellhelmet", turtleArmorMaterial, 1, 0);
	turtleShellChestplate = new TurtleshellArmor("turtleshellchestplate", turtleArmorMaterial, 1, 1).setCreativeTab(KaktusMod.kaktusmodcreativetab);
	turtleShellLeggings = new TurtleshellArmor("turtleshellleggings", turtleArmorMaterial, 2, 2).setCreativeTab(KaktusMod.kaktusmodcreativetab);
	turtleShellBoots = new TurtleshellArmor("turtleshellboots", turtleArmorMaterial, 1, 3).setCreativeTab(KaktusMod.kaktusmodcreativetab);

	registerItems();

}

public static void registerItems(){
	GameRegistry.registerItem(turtleShellHelmet, turtleShellHelmet.getUnlocalizedName().substring(5));
	GameRegistry.registerItem(turtleShellChestplate, turtleShellChestplate.getUnlocalizedName().substring(5));
	GameRegistry.registerItem(turtleShellLeggings, turtleShellLeggings.getUnlocalizedName().substring(5));
	GameRegistry.registerItem(turtleShellBoots, turtleShellBoots.getUnlocalizedName().substring(5));		
}

public static void registerRenders(){
	registerRender(turtleShellHelmet);
	registerRender(turtleShellChestplate);
	registerRender(turtleShellLeggings);
	registerRender(turtleShellBoots);
}

public static void registerRender(Item item){
	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(
			item, 0, new ModelResourceLocation(
					Config.MODID + ":" + item.getUnlocalizedName().substring(5), "inventory"));
}

}

 

Anf then finally my armor class:

 

package kaktus.mods.kaktusmod.items.armor;

import java.util.List;

import kaktus.mods.kaktusmod.Config;
import kaktus.mods.kaktusmod.KaktusMod;
import kaktus.mods.kaktusmod.items.kaktusItems;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.DamageSource;
import net.minecraft.world.World;
import net.minecraftforge.common.ISpecialArmor;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class TurtleshellArmor extends ItemArmor implements ISpecialArmor {

public static final Enchantment[] helmetTurtleEnchantments = { Enchantment.thorns };
public static final int[] helmetTurtleEnchantmentLevels = { 3 };
public static final PotionEffect[] helmetTurtleEffects = { new PotionEffect(Potion.waterBreathing.id, 200, 0) };

public TurtleshellArmor(String unlocalizedName, ArmorMaterial material, int renderIndex, int armorType) {
	super(material, renderIndex, armorType);

	this.setUnlocalizedName(unlocalizedName);
	//this.setCreativeTab(KaktusMod.kaktusmodcreativetab);
	this.maxStackSize = 1;
}

@Override
public void onCreated(ItemStack itemStack, World worldIn, EntityPlayer player) {
	if (itemStack.getDisplayName().equals("turtleshellhelmet")) {
		for (int i = 0; i < helmetTurtleEnchantments.length; i++) {
			itemStack.addEnchantment(helmetTurtleEnchantments[i], helmetTurtleEnchantmentLevels[i]);
		}
	}
}

@Override
@SideOnly(Side.CLIENT)
public void getSubItems(Item itemIn, CreativeTabs tab, List subItems) {
	ItemStack itemStack = new ItemStack(itemIn, 1, 0);

	if (itemIn.equals(kaktusItems.turtleShellHelmet)) {
		for (int i = 0; i < helmetTurtleEnchantments.length; i++) {
			itemStack.addEnchantment(helmetTurtleEnchantments[i], helmetTurtleEnchantmentLevels[i]);
		}
	}
}

@Override
public void onArmorTick(World world, EntityPlayer player, ItemStack itemStack) {
	if (itemStack.getItem().equals(kaktusItems.turtleShellHelmet)) {
			this.effectPlayer(player, Potion.waterBreathing, 0);
	}
	if (this.isWearingFullSet(player, kaktusItems.turtleShellHelmet, kaktusItems.turtleShellChestplate, kaktusItems.turtleShellLeggings, kaktusItems.turtleShellBoots)) {
		this.effectPlayer(player, Potion.regeneration, 1);
	}
}

private void effectPlayer(EntityPlayer player, Potion potion, int amplifier) {
	//Always effect for 8 seconds, then refresh
	if (player.getActivePotionEffect(potion) == null || player.getActivePotionEffect(potion).getDuration() <= 1)
		player.addPotionEffect(new PotionEffect(potion.id, 159, amplifier, true, true));
}

private boolean isWearingFullSet(EntityPlayer player, Item helmet, Item chestplate, Item leggings, Item boots) {
	return player.inventory.armorItemInSlot(3) != null && player.inventory.armorItemInSlot(3).getItem() == helmet
			&& player.inventory.armorItemInSlot(2) != null && player.inventory.armorItemInSlot(2).getItem() == chestplate
			&& player.inventory.armorItemInSlot(1) != null && player.inventory.armorItemInSlot(1).getItem() == leggings
			&& player.inventory.armorItemInSlot(0) != null && player.inventory.armorItemInSlot(0).getItem() == boots;
}

@Override
public ArmorProperties getProperties(EntityLivingBase player, ItemStack armor, DamageSource source, double damage,
		int slot) {
	// TODO Auto-generated method stub
	return null;
}

@Override
public int getArmorDisplay(EntityPlayer player, ItemStack armor, int slot) {
	// TODO Auto-generated method stub
	return 0;
}

@Override
public void damageArmor(EntityLivingBase entity, ItemStack stack, DamageSource source, int damage, int slot) {
	// TODO Auto-generated method stub

}

}

 

 

And then in my kaktusItems.java:

 


Not all things in the world are red, there are round objects too!

Posted

my clientproxy:

 

package kaktus.mods.kaktusmod.proxy;

import kaktus.mods.kaktusmod.Config;
import kaktus.mods.kaktusmod.KaktusMod;
import kaktus.mods.kaktusmod.entities.passive.EntityTurtle;
import kaktus.mods.kaktusmod.entities.renderer.RenderTurtle;
import kaktus.mods.kaktusmod.items.kaktusItems;
import kaktus.mods.kaktusmod.entities.kaktusMobs;
import kaktus.mods.kaktusmod.models.ModelTurtle;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraftforge.fml.client.registry.RenderingRegistry;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)
public class ClientProxy extends CommonProxy {

@Override
public void preInit(FMLPreInitializationEvent event) {
	super.preInit(event);

	kaktusItems.createItems();
}

@Override
public void init(FMLInitializationEvent event) {
	super.init(event);

	kaktusItems.registerRenders();

	kaktusMobs.init();

}

@Override
public void postInit(FMLPostInitializationEvent event) {
	super.postInit(event);
}
}

Not all things in the world are red, there are round objects too!

Posted

Because ive tried to move the createitems call all over the place hoping to find that it would work in one place.

 

This merely the latest snapshot of my debugging.

Not all things in the world are red, there are round objects too!

Posted
Then whatever you are doing you are not registering your Items.

 

Then this must not be true, becaus i can /give my player the items, and i can wear them.

Even the potion effect of the helmet works.

Not all things in the world are red, there are round objects too!

Posted

I have now tried with

setCreativeTab(CreativeTabs.tabCombat);

 

With the same result, nothing.

 

Im setting up a github now if you want a better overlook.

Not all things in the world are red, there are round objects too!

Posted

Hm, maybe I can help. Going to look now in your repository, if I can find something I'll create a comment there.

 

And how its messed up? Well...

Example of my private (and free) Bitbucket repository:

 

gradle/wrapper

src/main

.gitignore

CONTRIBUTING.md

README.md

build.gradle

build.propeties

gradlew

gradlew.bat

 

Do you see the difference? (not just more files)

Bektor

Developer of Primeval Forest.

Posted

Hm, maybe I can help. Going to look now in your repository, if I can find something I'll create a comment there.

 

And how its messed up? Well...

Example of my private (and free) Bitbucket repository:

 

gradle/wrapper

src/main

.gitignore

CONTRIBUTING.md

README.md

build.gradle

build.propeties

gradlew

gradlew.bat

 

Do you see the difference? (not just more files)

Bektor

 

Ahh now I see, I created the repository one level to deep.  :P

 

(And thanks b.t.w. to offer your help  :) )

Not all things in the world are red, there are round objects too!

Posted

Yep. I'm now installing your Forge version, could take a while.

And I would recommend you to correct your class names:

 

Java:

  • Class names: first letter capitalized, example: Test
  • package names: first letter small, example: test
  • variable names: first letter small, example: test

Just a small information for the future, ;) because I saw one class which was different named. xD

 

Bektor

 

EDIT:

hm, it seems to be that your Forge is a bit out of date: In your main class you are using Forge 1.8-11.14.3.1450, newest recommend build is 1.8-11.14.4.1563. ;)

 

EDIT 2:

hm, for me there are no items, they just don't appear in the Game... going to track down the problem now

 

EDIT 3:

thats weird, how can the CreativeTab has access to an item which is never used... which does not appear in the game for me...

Developer of Primeval Forest.

Posted

I've updated the repo with your suggestions (Thanks b.t.w.)

 

Now I'm trying to figure out how I update Forge ith my current setup.

 

Updated forge to the latest recommended, still same error though, or rather, no error but strange behaviour ^^

Not all things in the world are red, there are round objects too!

Posted

Added this ti my armor class to se if it would crash. ( To se if this was actually run )

 

Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("MineCraft DIE!"));
	this.setCreativeTab(KaktusMod.kaktusmodcreativetab);
	Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("MineCraft DIE End."));

 

And sure enough, it crashed.

 

Fatal errors were detected during the transition from PREINITIALIZATION to INITIALIZATION. Loading cannot continue

 

So am I right assuming that without these chat message the code will be runned? And therefor should set the item to the creative tab? (But it doesnt)

Not all things in the world are red, there are round objects too!

Posted

Hm, for me it the items don't want to appear ingame in any CreativeTab, but the CreativeTab is using the helmet for the icon, so they should be loaded.

But I wasn't able to find out why they don't appear in the CreativeTab...

 

Oh and when you rename the class, you have to rename the file itself, too. ;)

<classname>.java
public class <classname>

So replace the <classname> with your classname and then both should be the same, the filename and the class name, except for the .java ending of the filename ;)

(besides that, I'm wondering if there are BB codes like [icode][/icode] here on the forum)

 

Bektor

 

Developer of Primeval Forest.

Posted

That was my problem, that the items wont show up in creative tab, but they are accessible by "/give player kaktusmod:turtleshelhelmet" for example.

 

Then the item will show up in the inventory and you can throw it to the ground, pick it up again. Wear it, and the potion effect will start etc. It behaves like a normal item. But refuses to be in the creative tab.

 

Which class are you refering to?

 

I thought i renamed all classes and files.

Not all things in the world are red, there are round objects too!

Posted

What is your experience in the debugger? What breakpoints did you set, and what variable values did you see that you can't explain?

 

The debugger is your friend (at least it's a tool). Don't come here until you have either a log file from crash or a narrative from using the debugger.

 

You'll be amazed how many bugs you crack on your own steam once you invoke the debugger, and we will be so much more productive when you can share its info after you get stuck again.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Posted

What is your experience in the debugger? What breakpoints did you set, and what variable values did you see that you can't explain?

 

The debugger dont show me anything useful, maybe I'm not using it as effectively as I could.

 

But I made a brekpoint on the setCreativeTab call in my item.

 

Followed (stepped) thru it and saw that the setCreativeTab function was run, and my item was passed along. (Not much of a function the setCreativeTab)

 

Then all went along.

 

There is no errors or anything.

Not all things in the world are red, there are round objects too!

Posted
Well, duh. Using the debug mode doesn't change how your program runs.
That was just an answer to him that there is no crash.

 

I did find the error though: This if statement will never ever evaluate to true, hence you do not produce any sub-items to be listed in the creative tab.

 

This actually evaluate to true, and the debugger share my beliefe becaus if i set a brekpoint inside it, the debugger kicks in and breaks at the breakpoint  ;)

http://image.baver.se/img/tce47wH

Not all things in the world are red, there are round objects too!

Posted

Yeah, I misread. The method still does not produce any sub-items. It creates an ItemStack, adds some enchantments to it and then forgets about it.

 

Ahh there it was.

 

I wonder what I was thinking..

 

But thank you for kickstarting my brain.

Not all things in the world are red, there are round objects too!

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.