Skip to content

Commit

Permalink
Merge pull request #501 from jchung01/vanilla-tweaks
Browse files Browse the repository at this point in the history
Improve confetti creepers tweak, fix some client-side things being loaded on server
  • Loading branch information
ACGaming authored Jul 1, 2024
2 parents b30aed8 + 5497e96 commit c04a5f7
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ public class UTLoadingPlugin implements IFMLLoadingPlugin, IEarlyMixinLoader
put("mixins.tweaks.performance.pathfinding.json", () -> UTConfigTweaks.PERFORMANCE.utPathfindingChunkCacheFixToggle);
put("mixins.tweaks.performance.prefixcheck.json", () -> UTConfigTweaks.PERFORMANCE.utPrefixCheckToggle);
put("mixins.tweaks.performance.redstone.json", () -> UTConfigTweaks.PERFORMANCE.utRedstoneLightingToggle);
put("mixins.tweaks.performance.texturemapcheck.json", () -> UTConfigTweaks.PERFORMANCE.utTextureMapCheckToggle);
put("mixins.tweaks.world.chunks.gen.json", () -> UTConfigTweaks.WORLD.CHUNK_GEN_LIMIT.utChunkGenLimitToggle);
put("mixins.tweaks.world.loading.server.json", () -> UTConfigTweaks.PERFORMANCE.utWorldLoadingToggle);
put("mixins.tweaks.world.sealevel.json", () -> UTConfigTweaks.WORLD.utSeaLevel != 63);
Expand Down Expand Up @@ -214,6 +213,7 @@ public class UTLoadingPlugin implements IFMLLoadingPlugin, IEarlyMixinLoader
put("mixins.tweaks.performance.missingmodel.json", () -> UTConfigTweaks.PERFORMANCE.utDisableFancyMissingModelToggle);
put("mixins.tweaks.performance.mobspawnerrender.json", () -> UTConfigTweaks.PERFORMANCE.utDisableMobSpawnerRendering);
put("mixins.tweaks.performance.resourcemanager.json", () -> UTConfigTweaks.PERFORMANCE.utCheckAnimatedModelsToggle);
put("mixins.tweaks.performance.texturemapcheck.json", () -> UTConfigTweaks.PERFORMANCE.utTextureMapCheckToggle);
put("mixins.tweaks.world.loading.client.json", () -> UTConfigTweaks.PERFORMANCE.utWorldLoadingToggle);
put("mixins.tweaks.world.voidfog.json", () -> UTConfigTweaks.WORLD.VOID_FOG.utVoidFogToggle);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
package mod.acgaming.universaltweaks.tweaks.entities.spawning.creeper.confetti.mixin;

import java.util.List;
import java.util.Random;

import com.google.common.collect.Lists;
import net.minecraft.client.Minecraft;
import net.minecraft.client.particle.ParticleFirework;
import net.minecraft.client.particle.ParticleManager;
import mod.acgaming.universaltweaks.UniversalTweaks;
import mod.acgaming.universaltweaks.config.UTConfigGeneral;
import mod.acgaming.universaltweaks.config.UTConfigTweaks;
import mod.acgaming.universaltweaks.util.UTRandomUtil;
import net.minecraft.entity.monster.EntityCreeper;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.item.ItemDye;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.datasync.DataParameter;
import net.minecraft.network.datasync.DataSerializers;
import net.minecraft.network.datasync.EntityDataManager;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.Explosion;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import mod.acgaming.universaltweaks.UniversalTweaks;
import mod.acgaming.universaltweaks.config.UTConfigGeneral;
import mod.acgaming.universaltweaks.config.UTConfigTweaks;
import mod.acgaming.universaltweaks.util.UTRandomUtil;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

// Courtesy of SR2610
// Courtesy of SR2610, jchung01
@Mixin(EntityCreeper.class)
public abstract class UTCreeperConfettiMixin extends EntityMob
{
@SuppressWarnings("WrongEntityDataParameterClass")
@Unique
private static final DataParameter<Boolean> ut$CONFETTI = EntityDataManager.createKey(EntityCreeper.class, DataSerializers.BOOLEAN);

protected UTCreeperConfettiMixin(World worldIn)
{
super(worldIn);
Expand All @@ -41,33 +40,57 @@ protected UTCreeperConfettiMixin(World worldIn)
@Shadow
public abstract boolean getPowered();

@Inject(method = "explode", at = @At("HEAD"), cancellable = true)
public void utCreeperConfetti(CallbackInfo ci)
@Shadow
protected abstract void spawnLingeringCloud();

/**
* Register confetti DataParameter.
* @author jchung01
*/
@Inject(method = "entityInit", at = @At(value = "TAIL"))
private void utRegisterConfetti(CallbackInfo ci)
{
this.dataManager.register(ut$CONFETTI, Boolean.FALSE);
}

/**
* Determine on spawn if this creeper should explode into confetti.
* @author jchung01
*/
@Inject(method = "<init>", at = @At(value = "TAIL"))
private void utInitConfetti(World worldIn, CallbackInfo ci)
{
if (this.world.isRemote) return;
double chargedChance = UTConfigTweaks.ENTITIES.CREEPER_CONFETTI.utCreeperConfettiChance;
if (chargedChance <= 0.0D || !UTRandomUtil.chance(chargedChance, new Random(this.getUniqueID().getMostSignificantBits() & Long.MAX_VALUE))) return;
if (chargedChance > 0.0D && UTRandomUtil.chance(chargedChance, this.rand))
{
this.dataManager.set(ut$CONFETTI, Boolean.TRUE);
}
}

@Inject(method = "explode", at = @At("HEAD"), cancellable = true)
private void utDoConfetti(CallbackInfo ci)
{
if (!this.dataManager.get(ut$CONFETTI)) return;
if (UTConfigGeneral.DEBUG.utDebugToggle) UniversalTweaks.LOGGER.debug("UTCreeperConfetti ::: Explode");
if (this.world.isRemote) spawnParticles(this.getEntityWorld(), this.getPosition(), this.getPowered());
if (this.world.isRemote)
{
BlockPos pos = this.getPosition();
boolean powered = this.getPowered();
this.world.makeFireworks(pos.getX(), pos.getY() + (powered ? 2.5F : 0.5F), pos.getZ(), 0, 0, 0, ut$generateTag(powered));
}
else
{
this.dead = true;
this.setDead();
this.spawnLingeringCloud();
this.damagePlayers(((EntityCreeper) (Object) this));
this.ut$damagePlayers(((EntityCreeper) (Object) this));
}
ci.cancel();
}

@Unique
@SideOnly(Side.CLIENT)
public void spawnParticles(World world, BlockPos pos, boolean powered)
{
ParticleManager particleManager = Minecraft.getMinecraft().effectRenderer;
particleManager.addEffect(new ParticleFirework.Starter(world, pos.getX(), pos.getY() + (powered ? 2.5F : 0.5F), pos.getZ(), 0, 0, 0, particleManager, generateTag(powered)));
}

@Unique
public NBTTagCompound generateTag(boolean powered)
private NBTTagCompound ut$generateTag(boolean powered)
{
NBTTagCompound fireworkTag = new NBTTagCompound();
NBTTagCompound fireworkItemTag = new NBTTagCompound();
Expand All @@ -88,13 +111,10 @@ public NBTTagCompound generateTag(boolean powered)
}

@Unique
public void damagePlayers(EntityCreeper creeper)
private void ut$damagePlayers(EntityCreeper creeper)
{
float explosionStrength = (float) (creeper.getPowered() ? UTConfigTweaks.ENTITIES.CREEPER_CONFETTI.utCreeperConfettiDamage * 2 : UTConfigTweaks.ENTITIES.CREEPER_CONFETTI.utCreeperConfettiDamage);
Explosion explosion = new Explosion(creeper.getEntityWorld(), creeper, creeper.posX, creeper.posY, creeper.posZ, 3.0F * explosionStrength, false, false);
explosion.doExplosionA();
}

@Shadow
protected abstract void spawnLingeringCloud();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"refmap": "universaltweaks.refmap.json",
"minVersion": "0.8",
"compatibilityLevel": "JAVA_8",
"mixins": ["UTTextureMapCheckMixin"]
"client": ["UTTextureMapCheckMixin"]
}

0 comments on commit c04a5f7

Please sign in to comment.