Jump to content

[1.19.2] Strange Duplicate id value error for spawning custom Entity


StarDuster01

Recommended Posts

Hi all,

When I try and spawn my custom entity GhastKing nothing happens in game but the console throws this error 

Failed to handle packet net.minecraft.network.protocol.game.ServerboundUseItemOnPacket@ac2e660, suppressing error
java.lang.IllegalArgumentException: Duplicate id value for 16!

I've tried manually assigning an ID number on registration among other things. See below my GhastKingEntity.java class and my ModEntityTypes.java class

 

All help and advice is appreciated, thanks in advance.


 

package com.stardust.mymod.entity.custom;

import java.util.EnumSet;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.util.Mth;
import java.util.Random;
import net.minecraft.util.RandomSource;
import net.minecraft.world.Difficulty;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.EntityDimensions;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.FlyingMob;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.entity.Pose;
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.ai.control.MoveControl;
import net.minecraft.world.entity.ai.goal.Goal;
import net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal;
import net.minecraft.world.entity.monster.Enemy;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.LargeFireball;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull;
import software.bernie.geckolib3.core.IAnimatable;
import software.bernie.geckolib3.core.manager.AnimationData;
import software.bernie.geckolib3.core.manager.AnimationFactory;

public class GhastKingEntity extends FlyingMob implements Enemy, IAnimatable {

private static EntityDataAccessor<Boolean> DATA_IS_CHARGINGG = SynchedEntityData.defineId(GhastKingEntity.class, EntityDataSerializers.BOOLEAN);


private int explosionPower = 1;

public GhastKingEntity(EntityType<? extends GhastKingEntity> entityType, Level world) {
super(entityType, world);
this.xpReward = 5;
this.moveControl = new GhastKingEntity.GhastKingEntityMoveControl(this);
this.getAttribute(Attributes.MAX_HEALTH);
this.getAttribute(Attributes.ATTACK_DAMAGE);
this.getAttribute(Attributes.ATTACK_SPEED);
this.getAttribute(Attributes.FLYING_SPEED);
this.getAttribute(Attributes.FOLLOW_RANGE);
this.entityData.define(DATA_IS_CHARGINGG, false);
}

public static AttributeSupplier.Builder createAttributes() {
return Mob.createMobAttributes().add(Attributes.MAX_HEALTH, 20.0D).add(Attributes.FOLLOW_RANGE, 5.0D).add(Attributes.ATTACK_DAMAGE, 3.0D).add(Attributes.ATTACK_SPEED, 4.0D).add(Attributes.FLYING_SPEED, 1.0D);


}




protected void registerGoals() {
this.goalSelector.addGoal(5, new GhastKingEntity.RandomFloatAroundGoal(this));
this.goalSelector.addGoal(7, new GhastKingEntity.GhastKingEntityLookGoal(this));
this.goalSelector.addGoal(7, new GhastKingEntity.GhastKingEntityShootFireballGoal(this));
this.targetSelector.addGoal(1, new NearestAttackableTargetGoal<>(this, Player.class, 10, true, false, (p_32755_) -> {
return Math.abs(p_32755_.getY() - this.getY()) <= 4.0D;
}));
}

public boolean isCharging() {
return this.entityData.get(DATA_IS_CHARGINGG);
}

public void setCharging(boolean charging) {
this.entityData.set(DATA_IS_CHARGINGG, charging);
}

public int getExplosionPower() {
return this.explosionPower;
}

protected boolean shouldDespawnInPeaceful() {
return true;
}

private static boolean isReflectedFireball(DamageSource damageSource) {
return damageSource.getDirectEntity() instanceof LargeFireball && damageSource.getEntity() instanceof Player;
}

public boolean isInvulnerableTo(@NotNull DamageSource damageSource) {
return !isReflectedFireball(damageSource) && super.isInvulnerableTo(damageSource);
}

public boolean hurt(DamageSource damageSource, float p_32731_) {
if (isReflectedFireball(damageSource)) {
super.hurt(damageSource, 1000.0F);
return true;
} else {
return !this.isInvulnerableTo(damageSource) && super.hurt(damageSource, p_32731_);
}
}


@Override
protected void defineSynchedData() {
super.defineSynchedData();

this.entityData.define(DATA_IS_CHARGINGG, false);
}

public SoundSource getSoundSource() {
return SoundSource.HOSTILE;
}

protected SoundEvent getAmbientSound() {
return SoundEvents.GHAST_AMBIENT;
}

protected SoundEvent getHurtSound(DamageSource damageSource) {
return SoundEvents.GHAST_HURT;
}

protected SoundEvent getDeathSound() {
return SoundEvents.GHAST_DEATH;
}

protected float getSoundVolume() {
return 5.0F;
}

public static boolean checkGhastKingEntitySpawnRules(EntityType<GhastKingEntity> p_218985_, LevelAccessor p_218986_, MobSpawnType p_218987_, BlockPos p_218988_, RandomSource p_218989_) {
return p_218986_.getDifficulty() != Difficulty.PEACEFUL && p_218989_.nextInt(20) == 0 && checkMobSpawnRules(p_218985_, p_218986_, p_218987_, p_218988_, p_218989_);
}

public int getMaxSpawnClusterSize() {
return 1;
}

public void addAdditionalSaveData(CompoundTag compoundTag) {
super.addAdditionalSaveData(compoundTag);
compoundTag.putByte("ExplosionPower", (byte)this.explosionPower);
}

public void readAdditionalSaveData(CompoundTag compoundTag) {
super.readAdditionalSaveData(compoundTag);
if (compoundTag.contains("ExplosionPower", 99)) {
this.explosionPower = compoundTag.getByte("ExplosionPower");
}

}

protected float getStandingEyeHeight(Pose p_32741_, EntityDimensions p_32742_) {
return 2.6F;
}

@Override
public void registerControllers(AnimationData data) {
}

@Override
public AnimationFactory getFactory() {
return null;
}

static class GhastKingEntityLookGoal extends Goal {
private final GhastKingEntity GhastKingEntity;

public GhastKingEntityLookGoal(GhastKingEntity ghastKingEntity) {
this.GhastKingEntity = ghastKingEntity;
this.setFlags(EnumSet.of(Goal.Flag.LOOK));
}

public boolean canUse() {
return true;
}

public boolean requiresUpdateEveryTick() {
return true;
}

public void tick() {
if (this.GhastKingEntity.getTarget() == null) {
Vec3 vec3 = this.GhastKingEntity.getDeltaMovement();
this.GhastKingEntity.setYRot(-((float)Mth.atan2(vec3.x, vec3.z)) * (180F / (float)Math.PI));
this.GhastKingEntity.yBodyRot = this.GhastKingEntity.getYRot();
} else {
LivingEntity livingentity = this.GhastKingEntity.getTarget();
double d0 = 64.0D;
if (livingentity.distanceToSqr(this.GhastKingEntity) < 4096.0D) {
double d1 = livingentity.getX() - this.GhastKingEntity.getX();
double d2 = livingentity.getZ() - this.GhastKingEntity.getZ();
this.GhastKingEntity.setYRot(-((float)Mth.atan2(d1, d2)) * (180F / (float)Math.PI));
this.GhastKingEntity.yBodyRot = this.GhastKingEntity.getYRot();
}
}

}
}

static class GhastKingEntityMoveControl extends MoveControl {
private final GhastKingEntity GhastKingEntity;
private int floatDuration;

public GhastKingEntityMoveControl(GhastKingEntity ghastKingEntity) {
super(ghastKingEntity);
this.GhastKingEntity = ghastKingEntity;
}

public void tick() {
if (this.operation == MoveControl.Operation.MOVE_TO) {
if (this.floatDuration-- <= 0) {
this.floatDuration += this.GhastKingEntity.getRandom().nextInt(5) + 2;
Vec3 vec3 = new Vec3(this.wantedX - this.GhastKingEntity.getX(), this.wantedY - this.GhastKingEntity.getY(), this.wantedZ - this.GhastKingEntity.getZ());
double d0 = vec3.length();
vec3 = vec3.normalize();
if (this.canReach(vec3, Mth.ceil(d0))) {
this.GhastKingEntity.setDeltaMovement(this.GhastKingEntity.getDeltaMovement().add(vec3.scale(0.1D)));
} else {
this.operation = MoveControl.Operation.WAIT;
}
}

}
}

private boolean canReach(Vec3 p_32771_, int p_32772_) {
AABB aabb = this.GhastKingEntity.getBoundingBox();

for(int i = 1; i < p_32772_; ++i) {
aabb = aabb.move(p_32771_);
if (!this.GhastKingEntity.level.noCollision(this.GhastKingEntity, aabb)) {
return false;
}
}

return true;
}
}

static class GhastKingEntityShootFireballGoal extends Goal {
private final GhastKingEntity GhastKingEntity;
public int chargeTime;

public GhastKingEntityShootFireballGoal(GhastKingEntity p_32776_) {
this.GhastKingEntity = p_32776_;
}

public boolean canUse() {
return this.GhastKingEntity.getTarget() != null;
}

public void start() {
this.chargeTime = 0;
}

public void stop() {
this.GhastKingEntity.setCharging(false);
}

public boolean requiresUpdateEveryTick() {
return true;
}

public void tick() {
LivingEntity livingentity = this.GhastKingEntity.getTarget();
if (livingentity != null) {
double d0 = 64.0D;
if (livingentity.distanceToSqr(this.GhastKingEntity) < 4096.0D && this.GhastKingEntity.hasLineOfSight(livingentity)) {
Level level = this.GhastKingEntity.level;
++this.chargeTime;
if (this.chargeTime == 10 && !this.GhastKingEntity.isSilent()) {
level.levelEvent((Player)null, 1015, this.GhastKingEntity.blockPosition(), 0);
}

if (this.chargeTime == 20) {
double d1 = 4.0D;
Vec3 vec3 = this.GhastKingEntity.getViewVector(1.0F);
double d2 = livingentity.getX() - (this.GhastKingEntity.getX() + vec3.x * 4.0D);
double d3 = livingentity.getY(0.5D) - (0.5D + this.GhastKingEntity.getY(0.5D));
double d4 = livingentity.getZ() - (this.GhastKingEntity.getZ() + vec3.z * 4.0D);
if (!this.GhastKingEntity.isSilent()) {
level.levelEvent((Player)null, 1016, this.GhastKingEntity.blockPosition(), 0);
}

LargeFireball largefireball = new LargeFireball(level, this.GhastKingEntity, d2, d3, d4, this.GhastKingEntity.getExplosionPower());
largefireball.setPos(this.GhastKingEntity.getX() + vec3.x * 4.0D, this.GhastKingEntity.getY(0.5D) + 0.5D, largefireball.getZ() + vec3.z * 4.0D);
level.addFreshEntity(largefireball);
this.chargeTime = -40;
}
} else if (this.chargeTime > 0) {
--this.chargeTime;
}

this.GhastKingEntity.setCharging(this.chargeTime > 10);
}
}
}

static class RandomFloatAroundGoal extends Goal {
private final GhastKingEntity GhastKingEntity;

public RandomFloatAroundGoal(GhastKingEntity p_32783_) {
this.GhastKingEntity = p_32783_;
this.setFlags(EnumSet.of(Goal.Flag.MOVE));
}

public boolean canUse() {
MoveControl movecontrol = this.GhastKingEntity.getMoveControl();
if (!movecontrol.hasWanted()) {
return true;
} else {
double d0 = movecontrol.getWantedX() - this.GhastKingEntity.getX();
double d1 = movecontrol.getWantedY() - this.GhastKingEntity.getY();
double d2 = movecontrol.getWantedZ() - this.GhastKingEntity.getZ();
double d3 = d0 * d0 + d1 * d1 + d2 * d2;
return d3 < 1.0D || d3 > 3600.0D;
}
}

public boolean canContinueToUse() {
return false;
}

public void start() {
RandomSource randomsource = this.GhastKingEntity.getRandom();
double d0 = this.GhastKingEntity.getX() + (double)((randomsource.nextFloat() * 2.0F - 1.0F) * 16.0F);
double d1 = this.GhastKingEntity.getY() + (double)((randomsource.nextFloat() * 2.0F - 1.0F) * 16.0F);
double d2 = this.GhastKingEntity.getZ() + (double)((randomsource.nextFloat() * 2.0F - 1.0F) * 16.0F);
this.GhastKingEntity.getMoveControl().setWantedPosition(d0, d1, d2, 1.0D);
}
}
}

 

////////////////////////////////////////////////////////////////////////

 

package com.stardust.mymod.entity;

import com.stardust.mymod.Main;
import com.stardust.mymod.entity.custom.GhastKingEntity;
import com.stardust.mymod.items.TexEntity;
import com.stardust.mymod.items.TexEntityRenderer;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.client.renderer.entity.ThrownItemRenderer;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MobCategory;
import net.minecraft.world.entity.MobType;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;

public class ModEntityTypes {
public static final DeferredRegister<EntityType<?>> ENTITIES = DeferredRegister.create(ForgeRegistries.ENTITY_TYPES, Main.MODID);

public static final int TEX_ENTITY_ID = 743;
public static final int GHAST_KING_ID = 229;

public static final RegistryObject<EntityType<TexEntity>> TEX_ENTITY = ENTITIES.register("tex_entity",
() -> EntityType.Builder.<TexEntity>of(TexEntity::new, MobCategory.MISC)
.sized(0.25F, 0.25F)
.setTrackingRange(4)
.setUpdateInterval(10)
.build(Integer.toString(TEX_ENTITY_ID)));
public static final RegistryObject<EntityType<GhastKingEntity>> GHAST_KING = ENTITIES.register("ghast_king", () -> EntityType.Builder.of(GhastKingEntity::new, MobCategory.MONSTER)
.sized(1.0F, 1.0F) // Change these values based on the size of your GhastKingEntity
.setTrackingRange(8)
.setUpdateInterval(3)
.setShouldReceiveVelocityUpdates(true)
.build(Integer.toString(GHAST_KING_ID))
);







}

 

Edited by StarDuster01
Link to comment
Share on other sites

  • StarDuster01 changed the title to [1.19.2] Strange Duplicate id value error for spawning custom Entity
  • 2 weeks later...

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

    • I have the problem that when I have flares or blocks to build in my offhand, they seem to be assigned an NBT tag, so I can't stack them with other flares or blocks.  
    • Thank you that was this mod indeed, it tried to spawn a structure at spawn but since It was already generated he was not able to and so crashed the server lol. I was looking for mod during the pregen and added it just before the ram issue, thank you
    • I’m trying to make a mod that lets me put beacon beams through barrels for a mod pack I’m making but I don’t know what code to put and where to make this happen   (Forge 1.20.1)  
    • ---- Minecraft Crash Report ---- // My bad. Time: 2024-07-17 11:17:18 Description: Unexpected error java.lang.NullPointerException: Unexpected error     at com.google.common.collect.Iterators$6.transform(Iterators.java:829)     at com.google.common.collect.TransformedIterator.next(TransformedIterator.java:52)     at net.minecraft.class_2370.remap(class_2370.java:744)     at net.minecraft.class_2370.unmap(class_2370.java:875)     at net.fabricmc.fabric.impl.registry.sync.RegistrySyncManager.unmap(RegistrySyncManager.java:368)     at net.minecraft.class_310.handler$bma000$fabric-registry-sync-v0$disconnectAfter(class_310.java:11691)     at net.minecraft.class_310.method_18096(class_310.java:2269)     at net.minecraft.class_8673.method_10839(class_8673.java:319)     at net.minecraft.class_2535.method_10768(class_2535.java:673)     at net.minecraft.class_636.method_2927(class_636.java:290)     at net.minecraft.class_310.method_1574(class_310.java:1908)     at net.minecraft.class_310.method_1523(class_310.java:1246)     at net.minecraft.class_310.method_1514(class_310.java:882)     at net.minecraft.client.main.Main.main(Main.java:256)     at net.fabricmc.loader.impl.game.minecraft.MinecraftGameProvider.launch(MinecraftGameProvider.java:470)     at net.fabricmc.loader.impl.launch.knot.Knot.launch(Knot.java:74)     at net.fabricmc.loader.impl.launch.knot.KnotClient.main(KnotClient.java:23) A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Thread: Render thread Stacktrace:     at com.google.common.collect.Iterators$6.transform(Iterators.java:829)     at com.google.common.collect.TransformedIterator.next(TransformedIterator.java:52)     at net.minecraft.class_2370.remap(class_2370.java:744)     at net.minecraft.class_2370.unmap(class_2370.java:875)     at net.fabricmc.fabric.impl.registry.sync.RegistrySyncManager.unmap(RegistrySyncManager.java:368)     at net.minecraft.class_310.handler$bma000$fabric-registry-sync-v0$disconnectAfter(class_310.java:11691)     at net.minecraft.class_310.method_18096(class_310.java:2269)     at net.minecraft.class_8673.method_10839(class_8673.java:319)     at net.minecraft.class_2535.method_10768(class_2535.java:673)     at net.minecraft.class_636.method_2927(class_636.java:290) -- Uptime -- Details:     JVM uptime: 111.259s     Wall uptime: 70.335s     High-res time: 44.634s     Client ticks: 508 ticks / 25.400s Stacktrace:     at net.minecraft.class_310.method_1587(class_310.java:2501)     at net.minecraft.class_310.method_54580(class_310.java:949)     at net.minecraft.class_310.method_1514(class_310.java:905)     at net.minecraft.client.main.Main.main(Main.java:256)     at net.fabricmc.loader.impl.game.minecraft.MinecraftGameProvider.launch(MinecraftGameProvider.java:470)     at net.fabricmc.loader.impl.launch.knot.Knot.launch(Knot.java:74)     at net.fabricmc.loader.impl.launch.knot.KnotClient.main(KnotClient.java:23) -- Last reload -- Details:     Reload number: 1     Reload reason: initial     Finished: Yes     Packs: vanilla, fabric, accessories, advanced-xray-fabric, appleskin, armoroftheages, auditory, balm-fabric, beautify, betterf3, betterthirdperson, biolith, bobby, bosses_of_mass_destruction, caffeineconfig, cardinal-components, cardinal-components-base, cardinal-components-block, cardinal-components-chunk, cardinal-components-entity, cardinal-components-item, cardinal-components-level, cardinal-components-scoreboard, cardinal-components-world, carryon, chipped, chunky, cinderscapes, cinderscapes-client, cinderscapes-common, cinderscapes-worldgen, cloth-config, comforts, conditional-mixin, cool_elytra, cratedelight, creativecore, creeperoverhaul, cristellib, croptopia, dramaticdoors, duckling, eatinganimationid, elytratrims, entity_texture_features, epherolib, explorerscompass, fabric-api, fabric-api-base, fabric-api-lookup-api-v1, fabric-biome-api-v1, fabric-block-api-v1, fabric-block-view-api-v2, fabric-blockrenderlayer-v1, fabric-client-tags-api-v1, fabric-command-api-v1, fabric-command-api-v2, fabric-commands-v0, fabric-content-registries-v0, fabric-convention-tags-v1, fabric-convention-tags-v2, fabric-crash-report-info-v1, fabric-data-attachment-api-v1, fabric-data-generation-api-v1, fabric-dimensions-v1, fabric-entity-events-v1, fabric-events-interaction-v0, fabric-game-rule-api-v1, fabric-item-api-v1, fabric-item-group-api-v1, fabric-key-binding-api-v1, fabric-keybindings-v0, fabric-language-kotlin, fabric-lifecycle-events-v1, fabric-loot-api-v2, fabric-loot-api-v3, fabric-message-api-v1, fabric-model-loading-api-v1, fabric-networking-api-v1, fabric-object-builder-api-v1, fabric-particles-v1, fabric-recipe-api-v1, fabric-registry-sync-v0, fabric-renderer-api-v1, fabric-renderer-indigo, fabric-renderer-registries-v1, fabric-rendering-data-attachment-v1, fabric-rendering-fluids-v1, fabric-rendering-v0, fabric-rendering-v1, fabric-resource-conditions-api-v1, fabric-resource-loader-v0, fabric-screen-api-v1, fabric-screen-handler-api-v1, fabric-sound-api-v1, fabric-transfer-api-v1, fabric-transitive-access-wideners-v1, fabricloader, forf, freecam, friendsandfoes, geocluster, glassential, glore, grassoverhaul, horizontal_glass_panes, infinity-cave, iris, jade, jamlib, jankson, libgui, mavapi, mavm, medieval_buildings, mes, midnightlib, mns, more_armor_trims, mostructures, mr_dungeons_andtavernsdeserttempleoverhaul, mr_dungeons_andtavernsendcastlestandalone, mr_dungeons_andtavernsjungletempleoverhaul, mr_dungeons_andtavernsnetherfortressoverhaul, mr_dungeons_andtavernsoceanmonumentoverhaul, mr_dungeons_andtavernswoodlandmansionoverhaul, mss, mvs, natures_spirit, necronomicon, new_slab_variants, nicer-skies, noisium, notenoughanimations, polymer-core, polymer-resource-pack, resourcefulconfig, simple_backpack, sodium, sodium-extra, sound_physics_remastered, spectrelib, status-effect-bars, stendhal, sulfurpotassiummod, terraform-biome-remapper-api-v1, terraform-shapes-api-v1, terraform-surfaces-api-v1, terraform-wood-api-v1, the_bumblezone, time_on_display, toggleableitemframes, toomanypaintings, travelersbackpack, trimeffects, universal-graves, utility_belt, variantbarrels, variantbeehives, variantbookshelves, variantcomposters, variantsandventures, visuality, waterframes, waxablecoral, waystones, xaerominimap, xaeroworldmap, yet_another_config_lib_v3, zoomify, minecraft:supporteatinganimation, file/Stay_True_1.21.zip, file/Better Cats v2.0 1.21.zip, file/Better Horses v2.0 1.21.zip, file/Torrezx-Bad_omen.zip, file/Torrezx-Sculk_power.zip, file/Torrezx-Warden_Power.zip, file/Torrezx-Heavy_core_tools.zip, file/waystones_1.21.zip  
    • Maybe an issue with spawnstructures_forge
  • Topics

×
×
  • Create New...

Important Information

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