Skip to content

Commit

Permalink
Entities and renderers (281 left!)
Browse files Browse the repository at this point in the history
  • Loading branch information
Electro593 committed Jan 29, 2025
1 parent 7e6849f commit 673185b
Show file tree
Hide file tree
Showing 21 changed files with 110 additions and 167 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void registerCategories(CategoryRegistry registry) {

@Override
public void registerDisplays(DisplayRegistry registry) {
registry.registerFiller(AnvilCrushingRecipe.class, AnvilCrushingDisplay::new);
registry.registerRecipeFiller(AnvilCrushingRecipe.class, SpectrumRecipeTypes.ANVIL_CRUSHING, AnvilCrushingDisplay::new);
registry.registerRecipeFiller(PedestalRecipe.class, SpectrumRecipeTypes.PEDESTAL, PedestalCraftingDisplay::new);
registry.registerRecipeFiller(FusionShrineRecipe.class, SpectrumRecipeTypes.FUSION_SHRINE, FusionShrineDisplay::new);
registry.registerRecipeFiller(EnchanterRecipe.class, SpectrumRecipeTypes.ENCHANTER, EnchanterEnchantingDisplay::new);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public class SpectrumEntityTypes {
public static final EntityType<LightSpearEntity> LIGHT_SPEAR = register("light_spear", EntityType.Builder.<LightSpearEntity>create(LightSpearEntity::new, SpawnGroup.MISC).disableSaving().makeFireImmune().dimensions(0.75F, 0.75F).maxTrackingRange(4).trackingTickInterval(20));
public static final EntityType<LightMineEntity> LIGHT_MINE = register("light_mine", EntityType.Builder.<LightMineEntity>create(LightMineEntity::new, SpawnGroup.MISC).disableSaving().makeFireImmune().dimensions(0.75F, 0.75F).maxTrackingRange(4).trackingTickInterval(20));
public static final EntityType<MonstrosityEntity> MONSTROSITY = register("monstrosity", EntityType.Builder.create(MonstrosityEntity::new, SpawnGroup.MISC).makeFireImmune().spawnableFarFromPlayer().dimensions(6.0F, 6.0F).maxTrackingRange(10));
public static final EntityType<PreservationTurretEntity> PRESERVATION_TURRET = register("preservation_turret", EntityType.Builder.create(PreservationTurretEntity::new, SpawnGroup.MONSTER).makeFireImmune().spawnableFarFromPlayer().dimensions(1.0F, 1.0F).maxTrackingRange(10));
public static final EntityType<PreservationTurretEntity> PRESERVATION_TURRET = register("preservation_turret", EntityType.Builder.create(PreservationTurretEntity::new, SpawnGroup.MONSTER).makeFireImmune().spawnableFarFromPlayer().dimensions(1.0F, 1.0F).vehicleAttachment().maxTrackingRange(10));
public static final EntityType<LizardEntity> LIZARD = register("lizard", EntityType.Builder.create(LizardEntity::new, SpawnGroup.MONSTER).dimensions(1.0F, 0.7F).maxTrackingRange(10));
public static final EntityType<KindlingEntity> KINDLING = register("kindling", EntityType.Builder.create(KindlingEntity::new, SpawnGroup.CREATURE).dimensions(1.0F, 1.0F).maxTrackingRange(10).makeFireImmune());
public static final EntityType<KindlingEntity> KINDLING = register("kindling", EntityType.Builder.create(KindlingEntity::new, SpawnGroup.CREATURE).dimensions(1.0F, 1.0F).passengerAttachments(0.5F).maxTrackingRange(10).makeFireImmune());
public static final EntityType<KindlingCoughEntity> KINDLING_COUGH = register("kindling_cough", EntityType.Builder.<KindlingCoughEntity>create(KindlingCoughEntity::new, SpawnGroup.MISC).dimensions(0.25F, 0.25F).maxTrackingRange(4).trackingTickInterval(10).makeFireImmune());
public static final EntityType<EraserEntity> ERASER = register("eraser", EntityType.Builder.create(EraserEntity::new, SpawnGroup.MONSTER).dimensions(0.3F, 0.3F).maxTrackingRange(10));
public static final EntityType<ItemProjectileEntity> ITEM_PROJECTILE = register("item_projectile", EntityType.Builder.<ItemProjectileEntity>create(ItemProjectileEntity::new, SpawnGroup.MISC).dimensions(0.25F, 0.25F).maxTrackingRange(6).trackingTickInterval(20));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,44 +122,41 @@ private void spawnParticles(int amount) {
protected void onEntityHit(EntityHitResult entityHitResult) {
super.onEntityHit(entityHitResult);

Entity entity = entityHitResult.getEntity();
Entity target = entityHitResult.getEntity();

if (EntityColorProcessorRegistry.colorEntity(entity, getInkColor().getDyeColor())) {
entity.getWorld().playSoundFromEntity(null, entity, SoundEvents.ITEM_DYE_USE, SoundCategory.PLAYERS, 1.0F, 1.0F);
if (EntityColorProcessorRegistry.colorEntity(target, getInkColor().getDyeColor())) {
target.getWorld().playSoundFromEntity(null, target, SoundEvents.ITEM_DYE_USE, SoundCategory.PLAYERS, 1.0F, 1.0F);
}

float velocity = (float) this.getVelocity().length();
int damage = MathHelper.ceil(MathHelper.clamp((double) velocity * DAMAGE_PER_POTENCY * SPELL_POTENCY, 0.0D, 2.147483647E9D));

Entity entity2 = this.getOwner();
Entity owner = this.getOwner();
DamageSource damageSource;
if (entity2 == null) {
if (owner == null) {
damageSource = SpectrumDamageTypes.inkProjectile(this, this);
} else {
damageSource = SpectrumDamageTypes.inkProjectile(this, entity2);
if (entity2 instanceof LivingEntity) {
((LivingEntity) entity2).onAttacking(entity);
damageSource = SpectrumDamageTypes.inkProjectile(this, owner);
if (owner instanceof LivingEntity livingOwner) {
livingOwner.onAttacking(target);
}
}

if (entity.damage(damageSource, (float) damage)) {
if (entity instanceof LivingEntity livingEntity) {
if (target.damage(damageSource, (float) damage)) {
if (target instanceof LivingEntity livingTarget) {

if (!this.getWorld().isClient() && entity2 instanceof LivingEntity) {
EnchantmentHelper.onUserDamaged(livingEntity, entity2);
EnchantmentHelper.onTargetDamaged((LivingEntity) entity2, livingEntity);
if (this.getWorld() instanceof ServerWorld serverWorld) {
EnchantmentHelper.onTargetDamaged(serverWorld, target, damageSource, null);
}

this.onHit(livingEntity);
this.onHit(livingTarget);

if (livingEntity != entity2 && livingEntity instanceof PlayerEntity && entity2 instanceof ServerPlayerEntity && !this.isSilent()) {
((ServerPlayerEntity) entity2).networkHandler.sendPacket(new GameStateChangeS2CPacket(GameStateChangeS2CPacket.PROJECTILE_HIT_PLAYER, 0.0F));
if (target != owner && target instanceof PlayerEntity && owner instanceof ServerPlayerEntity ownerPlayer && !this.isSilent()) {
ownerPlayer.networkHandler.sendPacket(new GameStateChangeS2CPacket(GameStateChangeS2CPacket.PROJECTILE_HIT_PLAYER, 0.0F));
}

if (!this.getWorld().isClient() && entity2 instanceof ServerPlayerEntity serverPlayerEntity) {
if (!entity.isAlive()) {
SpectrumAdvancementCriteria.KILLED_BY_INK_PROJECTILE.trigger(serverPlayerEntity, List.of(entity));
}
if (owner instanceof ServerPlayerEntity ownerPlayer && !target.isAlive()) {
SpectrumAdvancementCriteria.KILLED_BY_INK_PROJECTILE.trigger(ownerPlayer, List.of(target));
}
}

Expand Down Expand Up @@ -221,23 +218,17 @@ protected void onHit(LivingEntity target) {
if (colorOrdinal != -1) {
//InkColor.all().get(colorOrdinal);


Entity entity = target; //this.getEffectCause();

if(this.getInkColor() == InkColors.ORANGE)
{
if(this.getInkColor() == InkColors.ORANGE) {
entity.setOnFireFor(2);
}
else
{
} else {
// TODO: this is a dummy effect
Vec3d vec3d = this.getVelocity().multiply(1.0D, 0.0D, 1.0D).normalize().multiply((double) 3 * 0.6D);
if (vec3d.lengthSquared() > 0.0D) {
entity.addVelocity(vec3d.x, 0.1D, vec3d.z);
}
}



affectEntitiesInRange(this.getOwner());

Expand Down Expand Up @@ -288,7 +279,7 @@ public void affectEntitiesInRange(Entity attacker) {
entity.getWorld().playSoundFromEntity(null, entity, SoundEvents.ITEM_DYE_USE, SoundCategory.PLAYERS, 1.0F, 1.0F);
}

if (!entity.isImmuneToExplosion()) {
if (!entity.isImmuneToExplosion(null)) {
double w = Math.sqrt(entity.squaredDistanceTo(vec3d)) / (double) q;
if (w <= 1.0D) {
double x = entity.getX() - posX;
Expand All @@ -300,17 +291,19 @@ public void affectEntitiesInRange(Entity attacker) {
y /= aa;
z /= aa;
double ab = Explosion.getExposure(vec3d, entity);
double ac = (1.0D - w) * ab;
double velocity = (1.0D - w) * ab;

//float damage = (float) ((int) ((ac * ac + ac) / 2.0D * (double) q + 1.0D));
//entity.damage(SpectrumDamageSources.inkProjectile(this, attacker), damage);

double ad = ac;
if (entity instanceof LivingEntity livingEntity) {
ad = ProtectionEnchantment.transformExplosionKnockback(livingEntity, ac);
int i = SpectrumEnchantmentHelper.getEquipmentLevel(getWorld().getRegistryManager(), Enchantments.BLAST_PROTECTION, livingEntity);
if (i > 0) {
velocity *= MathHelper.clamp(1.0 - (double)i * 0.15, 0.0, 1.0);
}
}

entity.setVelocity(entity.getVelocity().add(x * ad, y * ad, z * ad));
entity.setVelocity(entity.getVelocity().add(x * velocity, y * velocity, z * velocity));
}
}
}
Expand Down
68 changes: 12 additions & 56 deletions src/main/java/de/dafuqs/spectrum/entity/entity/KindlingEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@

public class KindlingEntity extends AbstractHorseEntity implements RangedAttackMob, Angerable, Shearable {

private static final UUID HORSE_ARMOR_BONUS_ID = UUID.fromString("f55b70e7-db42-4384-8843-6e9c843336af");

protected static final TrackedData<KindlingVariant> VARIANT = DataTracker.registerData(KindlingEntity.class, SpectrumTrackedDataHandlerRegistry.KINDLING_VARIANT);
protected static final Ingredient FOOD = Ingredient.fromTag(SpectrumItemTags.KINDLING_FOOD);

Expand Down Expand Up @@ -154,23 +152,15 @@ public void setKindlingVariant(KindlingVariant variant) {
this.dataTracker.set(VARIANT, variant);
}

@Override
public double getMountedHeightOffset() {
return super.getMountedHeightOffset() - 0.25;
}

@Override
public void writeCustomDataToNbt(NbtCompound nbt) {
super.writeCustomDataToNbt(nbt);
this.writeAngerToNbt(nbt);
nbt.putString("variant", SpectrumRegistries.KINDLING_VARIANT.getId(this.getKindlingVariant()).toString());
Optional.ofNullable(SpectrumRegistries.KINDLING_VARIANT.getId(this.getKindlingVariant())).ifPresent(id ->
nbt.putString("variant", id.toString()));
nbt.putInt("chillTime", getChillTime());
nbt.putInt("eepyTime", getEepyTime());
nbt.putBoolean("playing", isPlaying());

if (!this.items.getStack(1).isEmpty()) {
nbt.put("ArmorItem", this.items.getStack(1).writeNbt(new NbtCompound()));
}
}

@Override
Expand All @@ -186,13 +176,13 @@ public void readCustomDataFromNbt(NbtCompound nbt) {
setPlaying(nbt.getBoolean("playing"));

if (nbt.contains("ArmorItem", 10)) {
ItemStack itemStack = ItemStack.fromNbt(nbt.getCompound("ArmorItem"));
ItemStack itemStack = ItemStack.fromNbt(this.getRegistryManager(), nbt.getCompound("ArmorItem")).orElse(ItemStack.EMPTY);
if (!itemStack.isEmpty() && this.isHorseArmor(itemStack)) {
this.items.setStack(1, itemStack);
}
}

this.updateSaddle();
this.updateSaddledFlag();
}

@Override
Expand All @@ -210,46 +200,18 @@ public PassiveEntity createChild(ServerWorld world, PassiveEntity entity) {
return baby;
}

public ItemStack getArmorType() {
return this.getEquippedStack(EquipmentSlot.CHEST);
}

private void equipArmor(ItemStack stack) {
this.equipStack(EquipmentSlot.CHEST, stack);
this.setEquipmentDropChance(EquipmentSlot.CHEST, 0.0F);
}

protected void updateSaddle() {
if (!this.getWorld().isClient) {
super.updateSaddle();
this.setArmorTypeFromStack(this.items.getStack(1));
this.setEquipmentDropChance(EquipmentSlot.CHEST, 0.0F);
}
}

private void setArmorTypeFromStack(ItemStack stack) {
this.equipArmor(stack);
if (!this.getWorld().isClient) {
this.getAttributeInstance(EntityAttributes.GENERIC_ARMOR).removeModifier(HORSE_ARMOR_BONUS_ID);
if (this.isHorseArmor(stack)) {
int armorBonus = ((AnimalArmorItem) stack.getItem()).getBonus();
if (armorBonus != 0) {
this.getAttributeInstance(EntityAttributes.GENERIC_ARMOR).addTemporaryModifier(new EntityAttributeModifier(HORSE_ARMOR_BONUS_ID, "Horse armor bonus", armorBonus, EntityAttributeModifier.Operation.ADD_VALUE));
}
}
}
}

@Override
public void onInventoryChanged(Inventory sender) {
ItemStack itemStack = this.getArmorType();
ItemStack itemStack = this.getBodyArmor();
super.onInventoryChanged(sender);
ItemStack itemStack2 = this.getArmorType();
ItemStack itemStack2 = this.getBodyArmor();
if (this.age > 20 && this.isHorseArmor(itemStack2) && itemStack != itemStack2) {
this.playSound(SoundEvents.ENTITY_HORSE_ARMOR, 0.5F, 1.0F);
}
}

public boolean hasArmorSlot() {
@Override
public boolean canUseSlot(EquipmentSlot slot) {
return true;
}

Expand Down Expand Up @@ -700,7 +662,7 @@ public void takeRevenge(UUID target) {
}

@Override
public void attack(LivingEntity target, float pullProgress) {
public void shootAt(LivingEntity target, float pullProgress) {
this.coughAt(target);
}

Expand All @@ -714,11 +676,6 @@ public boolean canBreedWith(AnimalEntity other) {
return other != this && other instanceof KindlingEntity otherKindling && this.canBreed() && otherKindling.canBreed();
}

@Override
public EntityView method_48926() {
return this.getWorld();
}

protected class CoughRevengeGoal extends RevengeGoal {

public CoughRevengeGoal(KindlingEntity kindling) {
Expand Down Expand Up @@ -795,9 +752,8 @@ public boolean shouldContinue() {
}

@Override
protected void attack(LivingEntity target, double squaredDistance) {
double d = this.getSquaredMaxAttackDistance(target);
if (squaredDistance <= d && this.getCooldown() <= 0) {
protected void attack(LivingEntity target) {
if (this.canAttack(target)) {
this.resetCooldown();
this.mob.swingHand(Hand.MAIN_HAND);
this.mob.tryAttack(target);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.google.common.collect.*;
import de.dafuqs.spectrum.*;
import de.dafuqs.spectrum.entity.*;
import de.dafuqs.spectrum.helpers.*;
import net.minecraft.component.type.*;
import net.minecraft.entity.*;
import net.minecraft.entity.data.*;
import net.minecraft.entity.effect.*;
Expand Down Expand Up @@ -50,7 +52,7 @@ public void setEffects(List<StatusEffectInstance> effects) {
if (this.effects.isEmpty()) {
setColor(16777215);
} else {
setColor(PotionUtil.getColor(this.effects));
setColor(PotionContentsComponent.getColor(this.effects));
}
}

Expand All @@ -71,19 +73,15 @@ protected void writeCustomDataToNbt(NbtCompound nbt) {
nbt.putInt("Color", this.getColor());
}
if (!this.effects.isEmpty()) {
NbtList nbtList = new NbtList();
for (StatusEffectInstance statusEffectInstance : this.effects) {
nbtList.add(statusEffectInstance.writeNbt(new NbtCompound()));
}
nbt.put("CustomPotionEffects", nbtList);
CodecHelper.writeNbt(nbt, "CustomPotionEffects", StatusEffectInstance.CODEC.listOf(), this.effects.stream().toList());
}
}

@Override
protected void readCustomDataFromNbt(NbtCompound nbt) {
super.readCustomDataFromNbt(nbt);

this.setEffects(PotionUtil.getCustomPotionEffects(nbt));
this.setEffects(CodecHelper.fromNbt(StatusEffectInstance.CODEC.listOf(), nbt.get("CustomPotionEffects"), List.of()));

if (nbt.contains("Color", NbtElement.NUMBER_TYPE)) {
this.setColor(nbt.getInt("Color"));
Expand All @@ -92,7 +90,7 @@ protected void readCustomDataFromNbt(NbtCompound nbt) {
if (this.effects.isEmpty()) {
this.dataTracker.set(COLOR, NO_POTION_COLOR);
} else {
this.dataTracker.set(COLOR, PotionUtil.getColor(this.effects));
this.dataTracker.set(COLOR, PotionContentsComponent.getColor(this.effects));
}
}
}
Expand All @@ -119,10 +117,7 @@ public void tick() {
private void spawnParticles() {
if (!this.effects.isEmpty()) {
int color = this.getColor();
double d = (double) (color >> 16 & 255) / 255.0;
double e = (double) (color >> 8 & 255) / 255.0;
double f = (double) (color & 255) / 255.0;
this.getWorld().addParticle(ParticleTypes.ENTITY_EFFECT, this.getParticleX(0.5), this.getRandomBodyY(), this.getParticleZ(0.5), d, e, f);
this.getWorld().addParticle(EntityEffectParticleEffect.create(ParticleTypes.ENTITY_EFFECT, color), this.getParticleX(0.5), this.getRandomBodyY(), this.getParticleZ(0.5), 0.0, 0.0, 0.0);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public Identifier getTexture() {
}

static {
SPRITES = Identifier.of[4];
SPRITES = new Identifier[4];
SPRITES[0] = SpectrumCommon.locate("textures/entity/projectile/light_shard_0.png");
SPRITES[1] = SpectrumCommon.locate("textures/entity/projectile/light_shard_1.png");
SPRITES[2] = SpectrumCommon.locate("textures/entity/projectile/light_shard_2.png");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected void onBlockHit(BlockHitResult blockHitResult) {
if (entity instanceof PlayerEntity player) {
Predicate<BlockState> minablePredicate = state -> {
int miningLevel = this.toolStack.getItem() instanceof ToolItem toolItem ? toolItem.getMaterial().getMiningLevel() : 1;
int efficiency = EnchantmentHelper.getLevel(Enchantments.EFFICIENCY, this.toolStack);
int efficiency = SpectrumEnchantmentHelper.getLevel(getWorld().getRegistryManager(), Enchantments.EFFICIENCY, this.toolStack);
return state.getBlock().getHardness() <= miningLevel + efficiency;
};
AoEHelper.breakBlocksAround(player, this.toolStack, blockHitResult.getBlockPos(), MINING_RANGE, minablePredicate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void tick() {
}
}

public MoltenFishingBobberEntity(PlayerEntity thrower, World world, int luckBonus, float waitTimeReductionTicks, int exuberanceLevel, int bigCatchLevel, int serendipityReelLevel, boolean inventoryInsertion) {
public MoltenFishingBobberEntity(PlayerEntity thrower, World world, int luckBonus, int waitTimeReductionTicks, int exuberanceLevel, int bigCatchLevel, int serendipityReelLevel, boolean inventoryInsertion) {
super(SpectrumEntityTypes.MOLTEN_FISHING_BOBBER, thrower, world, luckBonus, waitTimeReductionTicks, exuberanceLevel, bigCatchLevel, serendipityReelLevel, inventoryInsertion, true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public void tick() {

if (this.hasInvincibilityTicks()) {
for (int j = 0; j < 3; ++j) {
this.getWorld().addParticle(ParticleTypes.ENTITY_EFFECT, this.getX() + this.random.nextGaussian(), this.getY() + (double) (this.random.nextFloat() * 3.3F), this.getZ() + this.random.nextGaussian(), 0.7, 0.7, 0.7);
this.getWorld().addParticle(EntityEffectParticleEffect.create(ParticleTypes.ENTITY_EFFECT, 0.7f, 0.7f, 0.7f), this.getX() + this.random.nextGaussian(), this.getY() + (double) (this.random.nextFloat() * 3.3F), this.getZ() + this.random.nextGaussian(), 0.0, 0.0, 0.0);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,11 @@ private void tickOpenProgress() {
}

@Override
public double getHeightOffset() {
EntityType<?> vehicleType = this.getVehicle().getType();
return vehicleType != EntityType.BOAT && vehicleType != EntityType.MINECART ? super.getHeightOffset() : 0.1875 - this.getVehicle().getMountedHeightOffset();
public Vec3d getVehicleAttachmentPos(Entity vehicle) {
if (vehicle.getType() != EntityType.BOAT && vehicle.getType() != EntityType.MINECART)
return super.getVehicleAttachmentPos(vehicle);
var ridingPos = vehicle.getPassengerRidingPos(this);
return new Vec3d(ridingPos.x, 0.1875 - ridingPos.y, ridingPos.z);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public LivingEntity.FallSounds getFallSounds() {
}

@Override
public boolean canBeLeashedBy(PlayerEntity player) {
public boolean canBeLeashed() {
return false;
}

Expand Down
Loading

0 comments on commit 673185b

Please sign in to comment.