Skip to content

Commit

Permalink
Add handling for dumb vanilla particle change, remove extra texture, …
Browse files Browse the repository at this point in the history
…fix missing hat
  • Loading branch information
fonnymunkey committed Oct 2, 2024
1 parent 858c377 commit de88714
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 30 deletions.
12 changes: 11 additions & 1 deletion src/main/java/fonnymunkey/simplehats/client/hat/HatLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
import net.minecraft.entity.passive.VillagerEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.particle.EntityEffectParticleEffect;
import net.minecraft.particle.ParticleEffect;
import net.minecraft.particle.ParticleType;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.util.math.RotationAxis;

public class HatLayer<T extends LivingEntity, M extends EntityModel<T> & ModelWithHead> extends FeatureRenderer<T, M> {
Expand Down Expand Up @@ -72,7 +76,13 @@ private void render(ItemStack itemStack, MatrixStack poseStack, VertexConsumerPr
case TRAILING_FEET -> livingEntity.getY()+0.25;
case TRAILING_FULL -> livingEntity.getRandomBodyY();
};
livingEntity.getWorld().addParticle(particleSettings.getParticleType(), livingEntity.getX() + livingEntity.getRandom().nextFloat() - 0.5, y, livingEntity.getZ() + livingEntity.getRandom().nextFloat() - 0.5, d0, d1,d2);
ParticleType<?> particleType = particleSettings.getParticleType();
if(particleType instanceof ParticleEffect particleEffect) {
livingEntity.getWorld().addParticle(particleEffect, livingEntity.getX() + livingEntity.getRandom().nextFloat() - 0.5, y, livingEntity.getZ() + livingEntity.getRandom().nextFloat() - 0.5, d0, d1,d2);
}
else if(particleType == ParticleTypes.ENTITY_EFFECT) {
livingEntity.getWorld().addParticle(EntityEffectParticleEffect.create(ParticleTypes.ENTITY_EFFECT, livingEntity.getRandom().nextFloat(), livingEntity.getRandom().nextFloat(), livingEntity.getRandom().nextFloat()), livingEntity.getX() + livingEntity.getRandom().nextFloat() - 0.5, y, livingEntity.getZ() + livingEntity.getRandom().nextFloat() - 0.5, d0, d1,d2);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class ModRegistry {
public static final HatItem HATSPECIAL = Registry.register(Registries.ITEM, Identifier.of(SimpleHats.modId, "special"), new HatItem(new HatEntry("special", Rarity.EPIC, 0)));

public static void registerHats() {
ModRegistry.hatList.add(HATSPECIAL);
for(HatEntry entry : HatJson.getHatList()) {
HatItem hat = entry.getHatDyeSettings().getUseDye() ? new HatItemDyeable(entry) : new HatItem(entry);
hat = Registry.register(Registries.ITEM, Identifier.of(SimpleHats.modId, entry.getHatName()), hat);
Expand Down
13 changes: 4 additions & 9 deletions src/main/java/fonnymunkey/simplehats/util/HatEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

import com.google.gson.annotations.SerializedName;
import fonnymunkey.simplehats.SimpleHats;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.particle.SimpleParticleType;
import net.minecraft.particle.*;
import net.minecraft.registry.Registries;
import net.minecraft.util.Identifier;
import net.minecraft.util.Rarity;
Expand Down Expand Up @@ -132,7 +131,7 @@ public static class HatParticleSettings {
@SerializedName("movement")
private HatParticleMovement particleMovement;

private transient SimpleParticleType particleTypeParsed = ParticleTypes.HEART;
private transient ParticleType<?> particleTypeParsed = ParticleTypes.HEART;

public HatParticleSettings(boolean useParticle, String particleTypeString, float particleFrequency, HatParticleMovement particleMovement) {
this.useParticle = useParticle;
Expand All @@ -144,7 +143,7 @@ public HatParticleSettings(boolean useParticle, String particleTypeString, float

public boolean getUseParticles() { return this.useParticle; }

public SimpleParticleType getParticleType() { return this.particleTypeParsed; }
public ParticleType<?> getParticleType() { return this.particleTypeParsed; }

public float getParticleFrequency() { return this.particleFrequency; }

Expand All @@ -158,11 +157,7 @@ public void validateParticleSettings() {
}

private void parseParticleString() {
var particleType = Registries.PARTICLE_TYPE.get(Identifier.tryParse(this.particleTypeString));

if (particleType instanceof SimpleParticleType simpleParticleType) {
this.particleTypeParsed = simpleParticleType;
}
this.particleTypeParsed = Registries.PARTICLE_TYPE.get(Identifier.tryParse(this.particleTypeString));

if(this.particleTypeParsed == null) {
SimpleHats.logger.log(Level.ERROR, "Particle type \"" + this.particleTypeString + "\" failed to parse, setting default.");
Expand Down
Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

0 comments on commit de88714

Please sign in to comment.