Skip to content

Commit

Permalink
add nullity particle as workaround for artemis missile tick calls
Browse files Browse the repository at this point in the history
  • Loading branch information
LocusAzzurro committed Jan 20, 2022
1 parent f6a1e11 commit f55c7df
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.minecraft.particles.BasicParticleType;
import net.minecraft.particles.IParticleData;
import net.minecraft.particles.ParticleType;
import net.minecraft.particles.ParticleTypes;
import net.minecraft.util.IndirectEntityDamageSource;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.EntityRayTraceResult;
Expand Down Expand Up @@ -111,8 +112,7 @@ public void tick() {
}
//todo make low speed particle rendering

//todo use AT for better compatibility
this.projectileTick();
super.tick();

if (this.getTarget() != null)
{
Expand Down Expand Up @@ -206,6 +206,10 @@ protected boolean shouldBurn(){
return false;
}

protected IParticleData getTrailParticle() {
return ParticleRegistry.nullity.get();
}

@Override
public boolean isPickable(){
return true;
Expand All @@ -217,11 +221,6 @@ public void addAdditionalSaveData(CompoundNBT nbt) {
nbt.putUUID("Target", this.targetUUID);
}
nbt.putInt("Fuel", this.fuel);

// inherited
if (this.leftOwner) {
nbt.putBoolean("LeftOwner", true);
}
}

@Override
Expand All @@ -230,9 +229,6 @@ public void readAdditionalSaveData(CompoundNBT nbt) {
this.targetUUID = nbt.getUUID("Owner");
}
this.fuel = nbt.getInt("Fuel");

// inherited
this.leftOwner = nbt.getBoolean("LeftOwner");
}

@Override
Expand All @@ -245,87 +241,4 @@ public IPacket<?> getAddEntityPacket() {
return NetworkHooks.getEntitySpawningPacket(this);
}

// START INHERITED TICK CALL -> this#tick -> DamagingProjectileEntity#tick -> ProjectileEntity#tick -> Entity#tick -> Entity#baseTick
// This whole chain and related methods needed to be inherited to modify particle behavior.

private boolean leftOwner;

// DamagingProjectileEntity#tick
private void projectileTick(){
Entity entity = this.getOwner();
if (this.level.isClientSide || (entity == null || !entity.removed) && this.level.hasChunkAt(this.blockPosition())) {

// START ProjectileEntity#tick
if (!this.leftOwner) {
this.leftOwner = this.checkLeftOwner();
}
// START Entity#tick
if (!this.level.isClientSide) {
this.setSharedFlag(6, this.isGlowing());
}

this.baseTick();

// END Entity#tick

// END ProjectileEntity#tick
/*
// removed burn check
if (this.shouldBurn()) {
this.setSecondsOnFire(1);
}
*/

RayTraceResult raytraceresult = ProjectileHelper.getHitResult(this, this::canHitEntity);
if (raytraceresult.getType() != RayTraceResult.Type.MISS && !net.minecraftforge.event.ForgeEventFactory.onProjectileImpact(this, raytraceresult)) {
this.onHit(raytraceresult);
}

this.checkInsideBlocks();
Vector3d vector3d = this.getDeltaMovement();
double d0 = this.getX() + vector3d.x;
double d1 = this.getY() + vector3d.y;
double d2 = this.getZ() + vector3d.z;
ProjectileHelper.rotateTowardsMovement(this, 0.2F);
float f = this.getInertia();


// removed bubble particle
/*
if (this.isInWater()) {
for(int i = 0; i < 4; ++i) {
float f1 = 0.25F;
this.level.addParticle(ParticleTypes.BUBBLE, d0 - vector3d.x * 0.25D, d1 - vector3d.y * 0.25D, d2 - vector3d.z * 0.25D, vector3d.x, vector3d.y, vector3d.z);
}
f = 0.8F;
} */

this.setDeltaMovement(vector3d.add(this.xPower, this.yPower, this.zPower).scale((double)f));
//this.level.addParticle(this.getTrailParticle(), d0, d1 + 0.5D, d2, 0.0D, 0.0D, 0.0D); // particle disabled
this.setPos(d0, d1, d2);
} else {
this.remove();
}
}

private boolean checkLeftOwner() {
Entity entity = this.getOwner();
if (entity != null) {
for(Entity entity1 : this.level.getEntities(this, this.getBoundingBox().expandTowards(this.getDeltaMovement()).inflate(1.0D), (p_234613_0_) -> {
return !p_234613_0_.isSpectator() && p_234613_0_.isPickable();
})) {
if (entity1.getRootVehicle() == entity.getRootVehicle()) {
return false;
}
}
}

return true;
}

// END INHERITED TICK CALL

}
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
package org.mineplugin.locusazzurro.icaruswings.event;

import net.minecraft.client.Minecraft;
import net.minecraft.client.particle.IParticleFactory;
import net.minecraft.client.particle.ParticleManager;
import net.minecraft.particles.ParticleType;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.ParticleFactoryRegisterEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import org.mineplugin.locusazzurro.icaruswings.particles.GoldenSparkleParticle;
import org.mineplugin.locusazzurro.icaruswings.particles.*;
import org.mineplugin.locusazzurro.icaruswings.registry.ParticleRegistry;
import org.mineplugin.locusazzurro.icaruswings.particles.PlasmaTrailParticle;

@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
public class ClientParticleFactoryHandler {

@SubscribeEvent
public static void onParticleFactoryRegister(ParticleFactoryRegisterEvent event){
ParticleManager particleEngine = Minecraft.getInstance().particleEngine;
particleEngine.register(ParticleRegistry.nullity.get(), NullityParticle.Factory::new);
particleEngine.register(ParticleRegistry.plasmaTrail.get(), PlasmaTrailParticle.Factory::new);
particleEngine.register(ParticleRegistry.goldenSparkle.get(), GoldenSparkleParticle.Factory::new);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.mineplugin.locusazzurro.icaruswings.particles;

import net.minecraft.client.particle.*;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.particles.BasicParticleType;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

import javax.annotation.Nullable;

/*
Particle used to get around classes/methods that require a particle without making a complicated workaround
*/
public class NullityParticle extends SpriteTexturedParticle {

public NullityParticle(ClientWorld world, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed) {
super(world, x, y, z, xSpeed, ySpeed, zSpeed);
this.setSize(0.00f, 0.00f);
this.xd = 0;
this.yd = 0;
this.zd = 0;
this.lifetime = 0;
this.hasPhysics = false;
}

@Override
public void tick(){
this.remove();
}

@Override
public IParticleRenderType getRenderType() {
return IParticleRenderType.NO_RENDER;
}

@OnlyIn(Dist.CLIENT)
public static class Factory implements IParticleFactory<BasicParticleType> {

private final IAnimatedSprite sprites;

public Factory(IAnimatedSprite sprite) {
this.sprites = sprite;
}

@Nullable
@Override
public Particle createParticle(BasicParticleType dataIn, ClientWorld worldIn, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed) {
NullityParticle particle = new NullityParticle(worldIn, x, y, z, xSpeed, ySpeed, zSpeed);
particle.pickSprite(sprites);
return particle;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ public class ParticleRegistry {

public static DeferredRegister<ParticleType<?>> PARTICLES = DeferredRegister.create(ForgeRegistries.PARTICLE_TYPES, ModData.MOD_ID);

public static RegistryObject<BasicParticleType> nullity = PARTICLES.register("nullity",
() -> new BasicParticleType(true));
public static RegistryObject<BasicParticleType> plasmaTrail = PARTICLES.register("plasma_trail",
() -> new BasicParticleType(true));
public static RegistryObject<BasicParticleType> goldenSparkle = PARTICLES.register("golden_sparkle",
() -> new BasicParticleType(true));



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"textures": [
"locusazzurro_icaruswings:nullity"
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f55c7df

Please sign in to comment.