Jump to content

Recommended Posts

Posted

For some reason, whenever I kill the custom entity I made, no items drop and this is error occurs:

 

 

[10:31:45] [server thread/ERROR]: Couldn't load loot table tetracraft:entities/terrakon from file:/C:/Users/novag/MEGA/Minecraft/1.9.4/classes/production/1.9.4_main/assets/tetracraft/loot_tables/entities/terrakon.json
com.google.gson.JsonParseException: Loot Table "tetracraft:entities/terrakon" Missing `name` entry for pool #0
   at net.minecraftforge.common.ForgeHooks.readPoolName(ForgeHooks.java:1094) ~[ForgeHooks.class:?]
   at net.minecraft.world.storage.loot.LootPool$Serializer.deserialize(LootPool.java:152) ~[LootPool$Serializer.class:?]
   at net.minecraft.world.storage.loot.LootPool$Serializer.deserialize(LootPool.java:147) ~[LootPool$Serializer.class:?]
   at com.google.gson.TreeTypeAdapter.read(TreeTypeAdapter.java:58) ~[TreeTypeAdapter.class:?]
   at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:40) ~[TypeAdapterRuntimeTypeWrapper.class:?]
   at com.google.gson.internal.bind.ArrayTypeAdapter.read(ArrayTypeAdapter.java:72) ~[ArrayTypeAdapter.class:?]
   at com.google.gson.Gson.fromJson(Gson.java:803) ~[Gson.class:?]
   at com.google.gson.Gson.fromJson(Gson.java:868) ~[Gson.class:?]
   at com.google.gson.Gson$1.deserialize(Gson.java:126) ~[Gson$1.class:?]
   at net.minecraft.util.JsonUtils.deserializeClass(JsonUtils.java:378) ~[JsonUtils.class:?]
   at net.minecraft.util.JsonUtils.deserializeClass(JsonUtils.java:400) ~[JsonUtils.class:?]
   at net.minecraft.world.storage.loot.LootTable$Serializer.deserialize(LootTable.java:209) ~[LootTable$Serializer.class:?]
   at net.minecraft.world.storage.loot.LootTable$Serializer.deserialize(LootTable.java:204) ~[LootTable$Serializer.class:?]
   at com.google.gson.TreeTypeAdapter.read(TreeTypeAdapter.java:58) ~[TreeTypeAdapter.class:?]
   at com.google.gson.Gson.fromJson(Gson.java:803) ~[Gson.class:?]
   at com.google.gson.Gson.fromJson(Gson.java:768) ~[Gson.class:?]
   at com.google.gson.Gson.fromJson(Gson.java:717) ~[Gson.class:?]
   at com.google.gson.Gson.fromJson(Gson.java:689) ~[Gson.class:?]
   at net.minecraftforge.common.ForgeHooks.loadLootTable(ForgeHooks.java:1018) ~[ForgeHooks.class:?]
   at net.minecraft.world.storage.loot.LootTableManager$Loader.loadBuiltinLootTable(LootTableManager.java:148) [LootTableManager$Loader.class:?]
   at net.minecraft.world.storage.loot.LootTableManager$Loader.load(LootTableManager.java:71) [LootTableManager$Loader.class:?]
   at net.minecraft.world.storage.loot.LootTableManager$Loader.load(LootTableManager.java:52) [LootTableManager$Loader.class:?]
   at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3524) [guava-17.0.jar:?]
   at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2317) [guava-17.0.jar:?]
   at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2280) [guava-17.0.jar:?]
   at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2195) [guava-17.0.jar:?]
   at com.google.common.cache.LocalCache.get(LocalCache.java:3934) [guava-17.0.jar:?]
   at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3938) [guava-17.0.jar:?]
   at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4821) [guava-17.0.jar:?]
   at com.google.common.cache.LocalCache$LocalLoadingCache.getUnchecked(LocalCache.java:4827) [guava-17.0.jar:?]
   at net.minecraft.world.storage.loot.LootTableManager.getLootTableFromLocation(LootTableManager.java:39) [LootTableManager.class:?]
   at net.minecraft.entity.EntityLiving.dropLoot(EntityLiving.java:589) [EntityLiving.class:?]
   at net.minecraft.entity.EntityLivingBase.onDeath(EntityLivingBase.java:1164) [EntityLivingBase.class:?]
   at net.minecraft.entity.passive.EntityTameable.onDeath(EntityTameable.java:279) [EntityTameable.class:?]
   at net.minecraft.entity.EntityLivingBase.attackEntityFrom(EntityLivingBase.java:1056) [EntityLivingBase.class:?]
   at net.minecraft.entity.passive.EntityAnimal.attackEntityFrom(EntityAnimal.java:80) [EntityAnimal.class:?]
   at com.novaviper.tetracraft.common.entity.EntityTerrakon.attackEntityFrom(EntityTerrakon.java:171) [EntityTerrakon.class:?]
   at net.minecraft.entity.projectile.EntityArrow.onHit(EntityArrow.java:380) [EntityArrow.class:?]
   at net.minecraft.entity.projectile.EntityArrow.onUpdate(EntityArrow.java:280) [EntityArrow.class:?]
   at net.minecraft.entity.projectile.EntityTippedArrow.onUpdate(EntityTippedArrow.java:87) [EntityTippedArrow.class:?]
   at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2095) [World.class:?]
   at net.minecraft.world.WorldServer.updateEntityWithOptionalForce(WorldServer.java:872) [WorldServer.class:?]
   at net.minecraft.world.World.updateEntity(World.java:2061) [World.class:?]
   at net.minecraft.world.World.updateEntities(World.java:1881) [World.class:?]
   at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:644) [WorldServer.class:?]
   at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:781) [MinecraftServer.class:?]
   at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:685) [MinecraftServer.class:?]
   at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:155) [integratedServer.class:?]
   at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:534) [MinecraftServer.class:?]
   at java.lang.Thread.run(Thread.java:745) [?:1.8.0_91]

 

 

 

The Lootable was working before I upgraded to 1.9.4. My code is here:

 

Entity

 

package com.novaviper.tetracraft.common.entity;
import com.google.common.base.Predicate;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityAgeable;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.*;
import net.minecraft.entity.passive.EntityAnimal;
import net.minecraft.entity.passive.EntityCow;
import net.minecraft.entity.passive.EntityRabbit;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.init.Items;
import net.minecraft.init.SoundEvents;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.Item;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemStack;
import net.minecraft.util.*;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.World;
import com.novaviper.cryolib.common.helper.ChatHelper;
import com.novaviper.tetracraft.common.init.ModItems;
import com.novaviper.tetracraft.common.init.ModLootTables;
import com.novaviper.tetracraft.common.util.ItemUtils;
import com.novaviper.cryolib.lib.Constants;
import com.novaviper.tetracraft.common.init.ModSoundEvents;

import java.util.UUID;

/**
* @author NovaViper
* @date 7/10/2016
* @purpose Main Entity class for the Terrakon
*/
public class EntityTerrakon extends EntityModRideableTameable {

   public EntityTerrakon(World worldIn) {
      super(worldIn);
      this.setSize(1f, 1.5f);
      this.setTamed(false);
   }

   @Override
   protected void initEntityAI() {
      this.tasks.addTask(1, new EntityAISwimming(this));
      this.tasks.addTask(2, this.aiSit = new EntityAISit(this));
      this.tasks.addTask(3, new EntityAILeapAtTarget(this, 0.4F));
      this.tasks.addTask(4, new EntityAIAttackMelee(this, 1.0D, true));
      this.tasks.addTask(5, new EntityAIFollowOwner(this, 1.0D, 10.0F, 2.0F));
      this.tasks.addTask(6, new EntityAIMate(this, 1.0D));
      this.tasks.addTask(7, new EntityAIWander(this, 1.0D));
      this.tasks.addTask(9, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
      this.tasks.addTask(9, new EntityAILookIdle(this));
      this.targetTasks.addTask(1, new EntityAIOwnerHurtByTarget(this));
      this.targetTasks.addTask(2, new EntityAIOwnerHurtTarget(this));
      this.targetTasks.addTask(3, new EntityAIHurtByTarget(this, true, new Class[0]));
      this.targetTasks.addTask(4, new EntityAITargetNonTamed(this, EntityAnimal.class, false, new Predicate<Entity>()
      {
         public boolean apply(Entity entity)
         {
            return entity instanceof EntityCow || entity instanceof EntityRabbit;
         }
      }));
      //this.targetTasks.addTask(5, new EntityAINearestAttackableTarget(this, EntitySkeleton.class, false));
   }

   @Override
   protected void applyEntityAttributes() {
      super.applyEntityAttributes();
      this.updateEntityAttributes();
   }

   @Override
   public void updateEntityAttributes() {
      this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.40000001192092896D);
      if (this.isTamed()) {
         if (!this.isChild()) {
            this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(50.0D);
            this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(6.0D);
         } else {
            this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(10.0D);
            this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(1.0D);
         }

      } else {
         if (!this.isChild()) {
            this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(40.0D);
            this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(6.0D);
         } else {
            this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(10.0D);
            this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(1.0D);
         }
      }
   }

   @Override
   protected SoundEvent getStepSound() {
      return SoundEvents.ENTITY_WOLF_STEP;
   }

   @Override
   protected SoundEvent getFallSound() {
      return SoundEvents.ENTITY_GENERIC_SMALL_FALL;
   }

   @Override
   protected SoundEvent getGallopSound() {
      return SoundEvents.ENTITY_HORSE_GALLOP;
   }

   @Override
   protected SoundEvent getHurtSound() {
      return ModSoundEvents.terrakonHurt;
   }

   @Override
   protected SoundEvent getDeathSound() {
      return ModSoundEvents.terrakonDeath;
   }

   @Override
   protected SoundEvent getAmbientSound() {
      return isAngry() ? ModSoundEvents.terrakonGrowl : rand.nextInt(3) == 0
            ? isTamed() && getHealth() <= Constants.LOW_HP ? ModSoundEvents.terrakonWhine
            : ModSoundEvents.terrakonPanting : ModSoundEvents.terrakonBark;
   }

   /**
    * Returns the volume for the sounds this mob makes.
    */
   @Override
   public float getSoundVolume() {
      return 2F;
   }

   /**
    * Gets the pitch of living sounds in living entities.
    */
   @Override
   public float getPitch() {
      if (!isChild()) {
         return super.getSoundPitch();
      } else {
         return super.getSoundPitch() * 1;
      }
   }


   /**
    * Called when the entity is attacked.
    */
   @Override
   public boolean attackEntityFrom(DamageSource source, float amount) {
      if (this.isEntityInvulnerable(source)) {
         return false;
      } else {
         Entity entity = source.getEntity();

         if (this.aiSit != null) {
            this.aiSit.setSitting(false);
         }

         if (entity != null && !(entity instanceof EntityPlayer) && !(entity instanceof EntityArrow)) {
            amount = (amount + 1.0F) / 2.0F;
         }

         return super.attackEntityFrom(source, amount);
      }
   }

   public boolean attackEntityAsMob(Entity entityIn) {
      boolean flag = entityIn.attackEntityFrom(DamageSource.causeMobDamage(this), (float) ((int) this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue()));

      if (flag) {
         this.applyEnchantments(this, entityIn);
         this.updateEntityAttributes();
      }

      return flag;
   }

   public void setTamed(boolean tamed) {
      super.setTamed(tamed);
      this.updateEntityAttributes();
   }

   /**
    * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig.
    */
   @Override
   public boolean processInteract(EntityPlayer player, EnumHand hand, ItemStack stack) {
      if (this.isTamed()) {
         if (stack != null) {
            if (stack.getItem() instanceof ItemFood) {
               ItemFood itemfood = null;
               if (getHealthRelative() < 1) {
                  itemfood = (ItemFood) ItemUtils.consumeEquipped(player, EntityEquipmentSlot.MAINHAND, this.populateEatableFoods());
                  if (itemfood != null) {
                     float volume = getSoundVolume() * 1.0f;
                     float pitch = getPitch();
                     BlockPos pos = this.getPosition();
                     worldObj.playSound(player, pos.getX(), pos.getY(), pos.getZ(), SoundEvents.ENTITY_GENERIC_EAT, SoundCategory.NEUTRAL, volume, pitch);
                     this.heal(itemfood.getHealAmount(stack));
                  }
                  return true;
               }
            } else if (ItemUtils.hasEquipped(player, EntityEquipmentSlot.MAINHAND, Items.SHEARS) && this.canInteract(player)) {
               if (isServer()) {
                  unTame();
                  this.setSaddled(false);
               }
               return true;
            }
            else if (ItemUtils.hasEquipped(player, EntityEquipmentSlot.MAINHAND, Items.SADDLE) && !this.isSaddled() && isServer()) {
               if(this.canInteract(player)) {
                  if (!this.isChild()) {
                     this.setSaddled(true);
                     this.playSound(ModSoundEvents.Saddle, 0.5F, 1.0F);
                     ItemUtils.consumeEquipped(player, EntityEquipmentSlot.MAINHAND, Items.SADDLE);
                  } else {
                     TextComponentTranslation text = ChatHelper.getChatComponentTranslation("interaction.tetracraft.entity.cannotBeRidden");
                     this.tooYoungForInteract(this, player, text);
                     return true;
                  }
               }else{
                  this.doNotOwnMessage(this, player);
               }
            }
            else if (ItemUtils.consumeEquipped(player, EntityEquipmentSlot.MAINHAND, Items.DYE) && this.canInteract(player)) {
               EnumDyeColor enumdyecolor = EnumDyeColor.byDyeDamage(stack.getMetadata());
               if (enumdyecolor != this.getCollarColor()) {
                  this.setCollarColor(enumdyecolor);
                  return true;
               }
            }
            /*else if (stack.getItem() == Items.stick && canInteract(player))
            {
               if (isServer()) {
                  player.openGui(TetraCraft.instance, CommonProxy.PetPack, this.worldObj, this.getEntityId(), MathHelper.floor_double(this.posY), MathHelper.floor_double(this.posZ));
                  this.worldObj.playSoundEffect(this.posX, this.posY + 0.5D, this.posZ, "random.chestopen", 0.5F, this.worldObj.rand.nextFloat() * 0.1F + 0.9F);
                  return true;
               }
            }*/
         }
         if (canInteract(player) && isServer() && !this.isBreedingItem(stack)) {
            this.aiSit.setSitting(!this.isSitting());
            this.isJumping = false;
            this.navigator.clearPathEntity();
            this.setAttackTarget((EntityLivingBase)null);
         }

         if(this.isSaddled() && !player.onGround){
            if(this.canInteract(player)) {
               this.makePlayerRide(player);
            }else{
               this.doNotOwnMessage(this, player);
            }
            return true;
         }
      } else if (ItemUtils.consumeEquipped(player, EntityEquipmentSlot.MAINHAND, Items.BONE) && !this.isAngry()) {
         if (isServer()) {
            tamedFor(player, this.rand.nextInt(3) == 0);
         }
         return true;
      }
      return super.processInteract(player, hand, stack);
   }

   /**
    * Checks if the parameter is an item which this animal can be fed to breed it (wheat, carrots or seeds depending on
    * the animal type)
    */
   @Override
   public boolean isBreedingItem(ItemStack stack) {
      return (stack == null ? false : stack.getItem() == ModItems.breedingBone);
   }

   @Override
   public Item[] populateEatableFoods() {
      super.populateEatableFoods();
      Item[] food = {Items.BEEF, Items.CHICKEN, Items.PORKCHOP, Items.MUTTON, Items.RABBIT, Items.FISH,
            Items.COOKED_BEEF, Items.COOKED_CHICKEN, Items.COOKED_PORKCHOP, Items.COOKED_MUTTON, Items.COOKED_RABBIT, Items.COOKED_FISH};

      return food;
   }

   @Override
   protected ResourceLocation getLootTable() {
      return ModLootTables.LootTableTerrakon;
   }

   /**
    * Returns true if the mob is currently able to mate with the specified mob.
    */

   @Override
   public boolean canMateWith(EntityAnimal otherAnimal) {
      if (otherAnimal == this) {
         return false;
      } else if (!this.isTamed()) {
         return false;
      } else if (!(otherAnimal instanceof EntityTerrakon)) {
         return false;
      } else {
         EntityTerrakon entityTerrakon = (EntityTerrakon) otherAnimal;
         return !entityTerrakon.isTamed() ? false : (entityTerrakon.isSitting() ? false
               : this.getGender() == entityTerrakon.getGender() ? false
               : this.isInLove() && entityTerrakon.isInLove());
      }
   }

   @Override
   public EntityTerrakon createChild(EntityAgeable ageable) {
      EntityTerrakon entityTerrakon = new EntityTerrakon(this.worldObj);
      UUID uuid = this.getOwnerId();

      if (uuid != null) {
         entityTerrakon.setOwnerId(uuid);
         entityTerrakon.setTamed(true);
      }

      return entityTerrakon;
   }

}

 

 

Register

/** * Register a {@link LootTable} with the specified ID.
*
* @param id The ID of the LootTable without the modID
* @return The ID of the LootTable
*/
public static ResourceLocation registerLootTable(String modid, String id, String location) {
    return LootTableList.register(new ResourceLocation(modid, location + "/" + id));
}

 

 

LootTable Loading Class

package com.novaviper.tetracraft.common.init;

import net.minecraft.util.ResourceLocation;
import net.minecraft.world.storage.loot.LootTable;
import com.novaviper.cryolib.lib.Registers;
import com.novaviper.tetracraft.lib.ModReference;

/**
* @author NovaViper
* @date 7/10/2016
* @purpose Defines and registers this mod's {@link LootTable}s.
*/
public class ModLootTables {
   public static final ResourceLocation LootTableTerrakon = registerLootTable("terrakon", "entities");

   private static ResourceLocation registerLootTable(String entityName, String id){
      return Registers.registerLootTable(ModReference.MOD_ID, entityName, id);
   }
}

r]

 

 

 

LootTable JSON

{
  "pools": [
    {
      "rolls": 1,
      "entries": [
        {
          "type": "item",
          "name": "minecraft:slime_ball",
          "weight": 1,
          "functions": [
            {
              "function": "set_count",
              "count": {
                "min": 0,
                "max": 2
              }
            },
            {
              "function": "looting_enchant",
              "count": {
                "min": 0,
                "max": 1
              }
            }
          ]
        }
      ]
    }
  ]
}

 

Main Developer and Owner of Zero Quest

Visit the Wiki for more information

If I helped anyone, please give me a applaud and a thank you!

Posted

Your LootPool needs a name entry.

 

I did put a name entry, I copied the slime JSON from the source code.. and it still didn't work

Main Developer and Owner of Zero Quest

Visit the Wiki for more information

If I helped anyone, please give me a applaud and a thank you!

Posted

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.