Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix fireballs that stay immobile on world/chunk reload #105

Merged
merged 3 commits into from
Sep 10, 2022
Merged
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 @@ -35,6 +35,7 @@ public class LoadingConfig {
public boolean fixPotionEffectRender;
public boolean fixPotionRenderOffset;
public boolean fixPotionLimit;
public boolean fixImmobileFireballs;
public boolean fixPerspectiveCamera;
public boolean fixHopperVoidingItems;
public boolean fixHugeChatKick;
Expand Down Expand Up @@ -164,6 +165,12 @@ public LoadingConfig(File file) {
.getBoolean();
fixPotionLimit = config.get("fixes", "fixPotionLimit", true, "Fix potions >= 128")
.getBoolean();
fixImmobileFireballs = config.get(
"fixes",
"fixImmobileFireballs",
true,
"Fix the bug that makes fireballs stop moving when chunk unloads")
.getBoolean();
fixPerspectiveCamera = config.get(
"fixes",
"fixPerspectiveCamera",
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/mitchej123/hodgepodge/mixins/Mixins.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public enum Mixins {
Side.CLIENT,
() -> Hodgepodge.config.fixPotionEffectRender,
TargetedMod.VANILLA),
FIX_IMMOBILE_FIREBALLS(
"minecraft.MixinEntityFireball", () -> Hodgepodge.config.fixImmobileFireballs, TargetedMod.VANILLA),
CHUNK_COORDINATES_HASHCODE(
"minecraft.MixinChunkCoordinates",
() -> Hodgepodge.config.speedupChunkCoordinatesHashCode,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.mitchej123.hodgepodge.mixins.minecraft;

import net.minecraft.entity.Entity;
import net.minecraft.entity.projectile.EntityFireball;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(EntityFireball.class)
public abstract class MixinEntityFireball extends Entity {

@Shadow
public double accelerationX;

@Shadow
public double accelerationY;

@Shadow
public double accelerationZ;

@Inject(method = "writeEntityToNBT", at = @At("TAIL"))
public void hodgepodge$writeFireballAcceleration(NBTTagCompound p_70014_1_, CallbackInfo ci) {
p_70014_1_.setTag(
"acceleration", this.newDoubleNBTList(this.accelerationX, this.accelerationY, this.accelerationZ));
}

@Inject(method = "readEntityFromNBT", at = @At(value = "TAIL"))
public void hodgepodge$readFireballAcceleration(NBTTagCompound p_70037_1_, CallbackInfo ci) {
if (p_70037_1_.hasKey("acceleration", 9)) {
NBTTagList nbttaglist = p_70037_1_.getTagList("acceleration", 6);
this.accelerationX = nbttaglist.func_150309_d(0);
this.accelerationY = nbttaglist.func_150309_d(1);
this.accelerationZ = nbttaglist.func_150309_d(2);
} else {
this.setDead();
}
}

/*Forced to have constructor*/
public MixinEntityFireball(World p_i1582_1_) {
super(p_i1582_1_);
}
}