-
-
Save Kaupenjoe/5f1061426041610397a478a96e2e314e to your computer and use it in GitHub Desktop.
YT290 - Forge 118 - Entity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
maven { url 'https://dl.cloudsmith.io/public/geckolib3/geckolib/maven/' } | |
implementation fg.deobf('software.bernie.geckolib:geckolib-1.18-forge:3.0.13') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"item.tutorialmod.raccoon_spawn_egg": "Raccoon Spawn Egg", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@SubscribeEvent | |
public static void entityAttributeEvent(EntityAttributeCreationEvent event) { | |
event.put(ModEntityTypes.RACCOON.get(), RaccoonEntity.setAttributes()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static final RegistryObject<Item> RACCOON_SPAWN_EGG = ITEMS.register("raccoon_spawn_egg", | |
() -> new ForgeSpawnEggItem(ModEntityTypes.RACCOON,0x948e8d, 0x3b3635, | |
new Item.Properties().tab(ModCreativeModeTab.TUTORIAL_TAB))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ModEntityTypes.register(eventBus); | |
GeckoLib.initialize(); | |
//clientSetup method | |
EntityRenderers.register(ModEntityTypes.RACCOON.get(), RaccoonRenderer::new); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import net.kaupenjoe.tutorialmod.TutorialMod; | |
import net.kaupenjoe.tutorialmod.entity.custom.RaccoonEntity; | |
import net.minecraft.resources.ResourceLocation; | |
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 ModEntityTypes { | |
public static final DeferredRegister<EntityType<?>> ENTITY_TYPES = | |
DeferredRegister.create(ForgeRegistries.ENTITIES, TutorialMod.MOD_ID); | |
public static final RegistryObject<EntityType<RaccoonEntity>> RACCOON = | |
ENTITY_TYPES.register("raccoon", | |
() -> EntityType.Builder.of(RaccoonEntity::new, MobCategory.CREATURE) | |
.sized(0.8f, 0.6f) | |
.build(new ResourceLocation(TutorialMod.MOD_ID, "raccoon").toString())); | |
public static void register(IEventBus eventBus) { | |
ENTITY_TYPES.register(eventBus); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"parent": "minecraft:item/template_spawn_egg" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import net.minecraft.core.BlockPos; | |
import net.minecraft.server.level.ServerLevel; | |
import net.minecraft.sounds.SoundEvent; | |
import net.minecraft.sounds.SoundEvents; | |
import net.minecraft.world.damagesource.DamageSource; | |
import net.minecraft.world.entity.AgeableMob; | |
import net.minecraft.world.entity.EntityType; | |
import net.minecraft.world.entity.ai.attributes.AttributeSupplier; | |
import net.minecraft.world.entity.ai.attributes.Attributes; | |
import net.minecraft.world.entity.ai.goal.*; | |
import net.minecraft.world.entity.ai.goal.target.HurtByTargetGoal; | |
import net.minecraft.world.entity.animal.Animal; | |
import net.minecraft.world.entity.player.Player; | |
import net.minecraft.world.level.Level; | |
import net.minecraft.world.level.block.state.BlockState; | |
import org.jetbrains.annotations.Nullable; | |
import software.bernie.geckolib3.core.IAnimatable; | |
import software.bernie.geckolib3.core.PlayState; | |
import software.bernie.geckolib3.core.builder.AnimationBuilder; | |
import software.bernie.geckolib3.core.controller.AnimationController; | |
import software.bernie.geckolib3.core.event.predicate.AnimationEvent; | |
import software.bernie.geckolib3.core.manager.AnimationData; | |
import software.bernie.geckolib3.core.manager.AnimationFactory; | |
public class RaccoonEntity extends Animal implements IAnimatable { | |
private AnimationFactory factory = new AnimationFactory(this); | |
public RaccoonEntity(EntityType<? extends Animal> entityType, Level level) { | |
super(entityType, level); | |
} | |
public static AttributeSupplier setAttributes() { | |
return Animal.createMobAttributes() | |
.add(Attributes.MAX_HEALTH, 20.0D) | |
.add(Attributes.ATTACK_DAMAGE, 3.0f) | |
.add(Attributes.ATTACK_SPEED, 2.0f) | |
.add(Attributes.MOVEMENT_SPEED, 0.3f).build(); | |
} | |
protected void registerGoals() { | |
this.goalSelector.addGoal(1, new FloatGoal(this)); | |
this.goalSelector.addGoal(2, new PanicGoal(this, 1.25D)); | |
this.goalSelector.addGoal(3, new LookAtPlayerGoal(this, Player.class, 8.0F)); | |
this.goalSelector.addGoal(4, new WaterAvoidingRandomStrollGoal(this, 1.0D)); | |
this.goalSelector.addGoal(5, new RandomLookAroundGoal(this)); | |
this.targetSelector.addGoal(6, (new HurtByTargetGoal(this)).setAlertOthers()); | |
} | |
@Nullable | |
@Override | |
public AgeableMob getBreedOffspring(ServerLevel p_146743_, AgeableMob p_146744_) { | |
return null; | |
} | |
private <E extends IAnimatable> PlayState predicate(AnimationEvent<E> event) { | |
if (event.isMoving()) { | |
event.getController().setAnimation(new AnimationBuilder().addAnimation("animation.raccoon.walk", true)); | |
return PlayState.CONTINUE; | |
} | |
event.getController().setAnimation(new AnimationBuilder().addAnimation("animation.raccoon.idle", true)); | |
return PlayState.CONTINUE; | |
} | |
@Override | |
public void registerControllers(AnimationData data) { | |
data.addAnimationController(new AnimationController(this, "controller", | |
0, this::predicate)); | |
} | |
@Override | |
public AnimationFactory getFactory() { | |
return this.factory; | |
} | |
protected void playStepSound(BlockPos pos, BlockState blockIn) { | |
this.playSound(SoundEvents.SWEET_BERRY_BUSH_PICK_BERRIES, 0.15F, 1.0F); | |
} | |
protected SoundEvent getAmbientSound() { | |
return SoundEvents.CAT_STRAY_AMBIENT; | |
} | |
protected SoundEvent getHurtSound(DamageSource damageSourceIn) { | |
return SoundEvents.DOLPHIN_HURT; | |
} | |
protected SoundEvent getDeathSound() { | |
return SoundEvents.DOLPHIN_DEATH; | |
} | |
protected float getSoundVolume() { | |
return 0.2F; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import net.kaupenjoe.tutorialmod.TutorialMod; | |
import net.kaupenjoe.tutorialmod.entity.custom.RaccoonEntity; | |
import net.minecraft.resources.ResourceLocation; | |
import software.bernie.geckolib3.model.AnimatedGeoModel; | |
public class RaccoonModel extends AnimatedGeoModel<RaccoonEntity> { | |
@Override | |
public ResourceLocation getModelLocation(RaccoonEntity object) { | |
return new ResourceLocation(TutorialMod.MOD_ID, "geo/raccoon.geo.json"); | |
} | |
@Override | |
public ResourceLocation getTextureLocation(RaccoonEntity object) { | |
return new ResourceLocation(TutorialMod.MOD_ID, "textures/entity/raccoon/raccoon.png"); | |
} | |
@Override | |
public ResourceLocation getAnimationFileLocation(RaccoonEntity animatable) { | |
return new ResourceLocation(TutorialMod.MOD_ID, "animations/raccoon.animation.json"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.mojang.blaze3d.vertex.PoseStack; | |
import com.mojang.blaze3d.vertex.VertexConsumer; | |
import net.kaupenjoe.tutorialmod.TutorialMod; | |
import net.kaupenjoe.tutorialmod.entity.custom.RaccoonEntity; | |
import net.minecraft.client.renderer.MultiBufferSource; | |
import net.minecraft.client.renderer.RenderType; | |
import net.minecraft.client.renderer.entity.EntityRendererProvider; | |
import net.minecraft.resources.ResourceLocation; | |
import software.bernie.geckolib3.model.AnimatedGeoModel; | |
import software.bernie.geckolib3.renderers.geo.GeoEntityRenderer; | |
public class RaccoonRenderer extends GeoEntityRenderer<RaccoonEntity> { | |
public RaccoonRenderer(EntityRendererProvider.Context renderManager) { | |
super(renderManager, new RaccoonModel()); | |
this.shadowRadius = 0.3f; | |
} | |
@Override | |
public ResourceLocation getTextureLocation(RaccoonEntity instance) { | |
return new ResourceLocation(TutorialMod.MOD_ID, "textures/entity/raccoon/raccoon.png"); | |
} | |
@Override | |
public RenderType getRenderType(RaccoonEntity animatable, float partialTicks, PoseStack stack, | |
MultiBufferSource renderTypeBuffer, VertexConsumer vertexBuilder, int packedLightIn, | |
ResourceLocation textureLocation) { | |
stack.scale(0.8F, 0.8F, 0.8F); | |
return super.getRenderType(animatable, partialTicks, stack, renderTypeBuffer, vertexBuilder, packedLightIn, textureLocation); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey Mr. KaupenJoe,
I am sorry, but I failed here with an error.
do you know the reason for this problem ??
my code is correct, but I cannot summon or use spawn_eff to summon the raccoon in the world...
this message will pop up when I try summoning this entity