package net.mattias.oceancritteria.entity; import…
- User
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
package net.mattias.oceancritteria.entity;
import net.mattias.oceancritteria.OceanCritteria; import net.mattias.oceancritteria.entity.custom.PenguinEntity; import net.mattias.oceancritteria.entity.custom.projectile.IceArrow; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.MobCategory; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.RegistryObject;
public class ModEntities { public static final DeferredRegister<EntityType<?>> ENTITY_TYPES = DeferredRegister.create(ForgeRegistries.ENTITY_TYPES, OceanCritteria.MOD_ID);
public static final RegistryObject<EntityType<PenguinEntity>> PENGUIN =
ENTITY_TYPES.register("penguin", () -> EntityType.Builder.of(PenguinEntity::new, MobCategory.CREATURE)
.sized(1f, 1f).build("penguin"));
public static final RegistryObject<EntityType<?>> ICE_ARROW =
ENTITY_TYPES.register("penguin", () -> EntityType.Builder.of(IceArrow::new, MobCategory.MISC)
.sized(1f, 1f).build("penguin"));
public static void register(IEventBus eventBus) {
ENTITY_TYPES.register(eventBus);
}
}
Please make the ModEntities work
also
I tried making this class
package net.mattias.oceancritteria.entity.custom.projectile;
import net.mattias.oceancritteria.item.ModItems; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.projectile.AbstractArrow; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level;
public class IceArrow extends AbstractArrow { private final Item referenceitem; public IceArrow(EntityType<? extends AbstractArrow> type, Level level) { super(type, level); this.referenceitem = ModItems.ICE_ARROW.get(); }
public IceArrow(LivingEntity shooter, Level level, Item referenceitem) {
super(type, shooter, level);
this.referenceitem = referenceitem;
}
@Override
protected ItemStack getPickupItem() {
return new ItemStack(this.referenceitem);
}
}
Do you already have it in package net.mattias.oceancritteria.item.custom;
import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.effect.MobEffects; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.projectile.AbstractArrow; import net.minecraft.world.entity.projectile.Arrow; import net.minecraft.world.item.ArrowItem; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.enchantment.EnchantmentHelper; import net.minecraft.world.item.enchantment.Enchantments; import net.minecraft.world.level.Level; import net.minecraft.world.phys.EntityHitResult;
public class IceArrowItem extends ArrowItem { public final float damage;
public IceArrowItem(Properties properties, float damage) {
super(properties);
this.damage = damage;
}
@Override
public AbstractArrow createArrow(Level level, ItemStack stack, LivingEntity shooter) {
IceArrow arrow = new IceArrow(level, shooter);
arrow.setEffectsFromItem(stack);
return arrow;
}
@Override
public boolean isInfinite(ItemStack stack, ItemStack bow, Player player) {
int infinityLevel = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.INFINITY_ARROWS, bow);
return infinityLevel > 0 && this.getClass() == ArrowItem.class;
}
public static class IceArrow extends Arrow {
public IceArrow(Level level, LivingEntity shooter) {
super(level, shooter);
}
@Override
protected void onHitEntity(EntityHitResult pResult) {
super.onHitEntity(pResult);
Entity target = pResult.getEntity();
if (target instanceof LivingEntity livingTarget) {
int currentFreezeTicks = livingTarget.getTicksFrozen();
int newFreezeTicks = Math.min(currentFreezeTicks + 40, 140);
livingTarget.setTicksFrozen(newFreezeTicks);
livingTarget.addEffect(new MobEffectInstance(
MobEffects.MOVEMENT_SLOWDOWN,
60,
1,
false,
false
));
}
}
}
}
Thanks for providing all the relevant code! Let's fix everything so that:
ModEntities class correctly registers your custom entities.IceArrow projectile class compiles and works with Forge 1.20.1.IceArrowItem properly creates and uses the external IceArrow projectile.You're mixing two versions of IceArrow:
IceArrowItem (nested class)net.mattias.oceancritteria.entity.custom.projectile.IceArrow)This causes confusion and compilation errors.
Also, in ModEntities, you're trying to register an entity called "penguin" twice — once for penguin, once for ice arrow — which is incorrect.
IceArrow out of IceArrowItemWe'll use the standalone version of IceArrow in entity.custom.projectile.
IceArrow.javapackage net.mattias.oceancritteria.entity.custom.projectile;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.projectile.AbstractArrow;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
public class IceArrow extends AbstractArrow {
public IceArrow(EntityType<? extends AbstractArrow> type, Level level) {
super(type, level);
}
public IceArrow(Level level, LivingEntity shooter) {
super(level, shooter);
}
public IceArrow(Level level, double x, double y, double z) {
super(level, x, y, z);
}
@Override
protected ItemStack getPickupItem() {
// Return the actual item this arrow should drop as
return getDefaultPickupItem();
}
public static ItemStack getDefaultPickupItem() {
// You must define this somewhere or use a registry object
return new ItemStack(net.mattias.oceancritteria.item.ModItems.ICE_ARROW.get());
}
}
ModEntities.javaMake sure both the penguin and ice arrow are registered under unique names.
ModEntities.javapackage net.mattias.oceancritteria.entity;
import net.mattias.oceancritteria.OceanCritteria;
import net.mattias.oceancritteria.entity.custom.PenguinEntity;
import net.mattias.oceancritteria.entity.custom.projectile.IceArrow;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MobCategory;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;
public class ModEntities {
public static final DeferredRegister<EntityType<?>> ENTITY_TYPES =
DeferredRegister.create(ForgeRegistries.ENTITY_TYPES, OceanCritteria.MOD_ID);
public static final RegistryObject<EntityType<PenguinEntity>> PENGUIN =
ENTITY_TYPES.register("penguin", () -> EntityType.Builder.of(PenguinEntity::new, MobCategory.CREATURE)
.sized(1f, 1f).build("penguin"));
public static final RegistryObject<EntityType<IceArrow>> ICE_ARROW =
ENTITY_TYPES.register("ice_arrow", () -> EntityType.Builder.<IceArrow>of(IceArrow::new, MobCategory.MISC)
.sized(0.5f, 0.5f) // Adjust size if needed
.build("ice_arrow"));
public static void register(IEventBus eventBus) {
ENTITY_TYPES.register(eventBus);
}
}
IceArrowItem.javaUse the external IceArrow from the entity.custom.projectile package.
IceArrowItem.javapackage net.mattias.oceancritteria.item.custom;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.AbstractArrow;
import net.minecraft.world.item.ArrowItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.EntityHitResult;
import net.mattias.oceancritteria.entity.custom.projectile.IceArrow;
public class IceArrowItem extends ArrowItem {
public final float damage;
public IceArrowItem(Properties properties, float damage) {
super(properties);
this.damage = damage;
}
@Override
public AbstractArrow createArrow(Level level, ItemStack stack, LivingEntity shooter) {
IceArrow arrow = new IceArrow(level, shooter);
arrow.setBaseDamage(this.damage);
arrow.setEffectsFromItem(stack);
return arrow;
}
@Override
public boolean isInfinite(ItemStack stack, ItemStack bow, Player player) {
int infinityLevel = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.INFINITY_ARROWS, bow);
return infinityLevel > 0 && this.getClass() == ArrowItem.class;
}
}
ModItems.ICE_ARROW is registered and available.ModEntities.register(eventBus) is called during mod construction.EntityType<IceArrow> is passed into the constructor of IceArrowItem.IceArrow#onHitEntity(EntityHitResult result).Would you like me to generate a complete example of how to register the item and entity together, or help you test spawning the arrow?