Skip to content
This repository was archived by the owner on Apr 22, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import net.minecraft.world.level.Level;
import software.bernie.geckolib.animatable.GeoEntity;

public abstract class DumbAnimal extends Animal implements GeoEntity, DumbEntity {
public abstract class DumbAnimal extends Animal implements DumbEntity {
@SuppressWarnings("unchecked")
protected DumbAnimal(EntityType<? extends Entity> pEntityType, Level pLevel) {
super((EntityType<? extends Animal>) pEntityType, pLevel);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.dumbcode.projectnublar.core.mobs;

import software.bernie.geckolib.core.animatable.GeoAnimatable;

public interface DumbEntity extends GeoAnimatable {
public interface DumbEntity {
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@
import net.dumbcode.projectnublar.core.mobs.DumbEntity;
import net.dumbcode.projectnublar.core.mobs.DumbMobs;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.*;
import net.minecraft.world.entity.animal.Animal;
import net.minecraft.world.entity.boss.enderdragon.EnderDragon;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand All @@ -19,37 +24,46 @@
import software.bernie.geckolib.renderer.GeoEntityRenderer;
import software.bernie.geckolib.util.GeckoLibUtil;

public class DinosaurEntity extends DumbAnimal {
protected AnimatableInstanceCache animationCache = GeckoLibUtil.createInstanceCache(this);
import java.util.List;

public abstract class DinosaurEntity extends DumbAnimal {

public static final EntityDataAccessor<Integer> AGE = SynchedEntityData.defineId(DinosaurEntity.class, EntityDataSerializers.INT);

public DinosaurEntity(EntityType<? extends Entity> pEntityType, Level pLevel) {
super(pEntityType, pLevel);
}

public static class Renderer extends GeoEntityRenderer<DumbAnimal> {
public Renderer(DumbMobs.@NotNull Mobs mob, EntityRendererProvider.Context renderManager) {
super(renderManager, mob.getModel());
}
// we're getting the value and then adding to it the amount of sub parts
// so the ID of the entity is the x, and after this code runs it will be x + partsSize + 1
// but since we're getting and then adding, we should add 1 to the main entity id ourselves
this.setId(ENTITY_COUNTER.getAndAdd(getHitboxParts().size() + 1) + 1);
}

@Override
public @Nullable AgeableMob getBreedOffspring(@NotNull ServerLevel serverLevel, @NotNull AgeableMob ageableMob) {
return ageableMob;
protected void defineSynchedData() {
super.defineSynchedData();

// This is our ECS
this.getEntityData().define(AGE, 1);
}

@Override
public AnimatableInstanceCache getAnimatableInstanceCache() {
return animationCache;
public void setId(int pId) {
super.setId(pId);
List<DinosaurEntityPart> parts = getHitboxParts();
for(int i = 0; i < parts.size(); i++) {
parts.get(i).setId(pId + i + 1);
}
}

@Override
public void registerControllers(AnimatableManager.@NotNull ControllerRegistrar controllers) {
controllers.add(new AnimationController<>(this, "Head", 5, this::headAnimationController));
public @Nullable AgeableMob getBreedOffspring(@NotNull ServerLevel serverLevel, @NotNull AgeableMob ageableMob) {
return ageableMob;
}

private PlayState headAnimationController(AnimationState<DinosaurEntity> entity) {
// if entity is attacking, play specific animation by using
// event.setAndContinue(animation)
return PlayState.STOP;
// this method should always return same objects, but the holder can be different.
public abstract List<DinosaurEntityPart> getHitboxParts();

public boolean hurt(DinosaurEntityPart part, DamageSource source, float amount) {
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package net.dumbcode.projectnublar.core.mobs.elements;

import net.dumbcode.projectnublar.core.mobs.DumbEntity;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityDimensions;
import net.minecraft.world.entity.Pose;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.entity.PartEntity;
import org.jetbrains.annotations.NotNull;
import software.bernie.geckolib.animatable.GeoEntity;
import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache;
import software.bernie.geckolib.util.GeckoLibUtil;

import javax.annotation.Nullable;

public abstract class DinosaurEntityPart extends PartEntity<DinosaurEntity> implements DumbEntity, GeoEntity {
public final DinosaurEntity parentMob;
public final String name;
private final EntityDimensions size;
protected AnimatableInstanceCache animationCache = GeckoLibUtil.createInstanceCache(this);
public DinosaurEntityPart(DinosaurEntity parent, String name, float width, float height) {
super(parent);
this.size = EntityDimensions.scalable(width, height);
this.name = name;
this.parentMob = parent;
}

@Override
protected void defineSynchedData() {}

@Override
protected void readAdditionalSaveData(CompoundTag compoundTag) {}

@Override
protected void addAdditionalSaveData(CompoundTag compoundTag) {}
@Override
public boolean isPickable() {
return true;
}

@Nullable
public ItemStack getPickResult() {
return this.parentMob.getPickResult();
}

@Override
public boolean hurt(@NotNull DamageSource source, float amount) {
return !this.isInvulnerableTo(source) && this.parentMob.hurt(this, source, amount);
}

@Override
public boolean is(Entity pEntity) {
return this == pEntity || this.parentMob == pEntity;
}

@Override
public Packet<ClientGamePacketListener> getAddEntityPacket() {
throw new UnsupportedOperationException();
}

@Override
public EntityDimensions getDimensions(Pose pPose) {
return this.size;
}

@Override
public boolean shouldBeSaved() {
return false;
}

@Override
public AnimatableInstanceCache getAnimatableInstanceCache() {
return animationCache;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.ai.attributes.Attribute;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
Expand Down Expand Up @@ -53,6 +54,7 @@ public class Registrar {
public static final DeferredRegister<EntityType<?>> ENTITY_TYPES = DeferredRegister.create(ForgeRegistries.ENTITY_TYPES, MOD_ID);
public static final DeferredRegister<BlockEntityType<?>> BLOCK_ENTITY_TYPES = DeferredRegister.create(ForgeRegistries.BLOCK_ENTITY_TYPES, MOD_ID);
public static final DeferredRegister<CreativeModeTab> CREATIVE_MODE_TABS = DeferredRegister.create(Registries.CREATIVE_MODE_TAB, MOD_ID);
public static final DeferredRegister<Attribute> ATTRIBUTES = DeferredRegister.create(Registries.ATTRIBUTE, MOD_ID);

public static void register(@NotNull IEventBus bus) {
BLOCKS.register(bus);
Expand Down