Skip to content

Commit

Permalink
fix cv powered wand recharge pedestal not updating in MP (#370)
Browse files Browse the repository at this point in the history
* fix cv powered wand recharge pedestal not updating

Signed-off-by: Glease <4586901+Glease@users.noreply.github.com>

* workaround refmap issue

Signed-off-by: Glease <4586901+Glease@users.noreply.github.com>

---------

Signed-off-by: Glease <4586901+Glease@users.noreply.github.com>
Co-authored-by: Martin Robertz <dream-master@gmx.net>
  • Loading branch information
Glease and Dream-Master authored May 22, 2024
1 parent 14b9c58 commit 3bec1dd
Showing 1 changed file with 62 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

import java.util.ArrayList;

import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChunkCoordinates;

import org.objectweb.asm.Opcodes;
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.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

Expand All @@ -19,34 +20,80 @@
import thaumcraft.api.aspects.AspectList;
import thaumcraft.api.visnet.TileVisNode;
import thaumcraft.api.visnet.VisNetHandler;
import thaumcraft.common.items.baubles.ItemAmuletVis;
import thaumcraft.common.items.wands.ItemWandCasting;
import thaumcraft.common.tiles.TileWandPedestal;

@Mixin(value = TileWandPedestal.class)
public class MixinTileWandPedestal extends TileThaumcraft {
public abstract class MixinTileWandPedestal extends TileThaumcraft implements ISidedInventory {

private int hodgepodge$ticksSinceLastSync = 0;
private boolean hodgepodge$needSync;

@Shadow(remap = false)
ArrayList<ChunkCoordinates> nodes = null;

@Redirect(
@Shadow(remap = false)
public boolean draining;

@Shadow(remap = false)
private boolean somethingChanged;

@Inject(
method = "updateEntity",
at = @At(
remap = false,
target = "Lthaumcraft/common/items/wands/ItemWandCasting;getAspectsWithRoom(Lnet/minecraft/item/ItemStack;)Lthaumcraft/api/aspects/AspectList;",
value = "INVOKE"),
method = "Lthaumcraft/common/tiles/TileWandPedestal;updateEntity()V",
value = "FIELD",
target = "Lthaumcraft/common/tiles/TileWandPedestal;draining:Z",
opcode = Opcodes.PUTFIELD,
ordinal = 0,
shift = At.Shift.AFTER,
by = 1),
require = 1)
private AspectList hodgepodge$getAspectsWithRoomReplacement(ItemWandCasting wand, ItemStack wandstack) {
AspectList as = wand.getAspectsWithRoom(wandstack);
if (as != null && as.size() > 0) {
for (Aspect aspect : as.getAspects()) {
// Pedestal operates every 5 ticks
int drained = VisNetHandler.drainVis(this.worldObj, this.xCoord, this.yCoord, this.zCoord, aspect, 25);
if (drained > 0) {
wand.addRealVis(wandstack, aspect, drained, true);
private void hodgepodge$rechargeViaCV(CallbackInfo ci) {
// no null check because vanilla does it
ItemStack stack = getStackInSlot(0);

if (stack.getItem() instanceof ItemWandCasting wand) {
AspectList as = wand.getAspectsWithRoom(stack);
if (as != null && as.size() > 0) {
for (Aspect aspect : as.getAspects()) {
// Pedestal operates every 5 ticks
int drained = VisNetHandler
.drainVis(this.worldObj, this.xCoord, this.yCoord, this.zCoord, aspect, 25);
if (drained > 0) {
wand.addRealVis(stack, aspect, drained, true);
draining = true;
somethingChanged = true;
hodgepodge$needSync = true;
}
}
}
} else if (stack.getItem() instanceof ItemAmuletVis amulet) {
AspectList as = amulet.getAspectsWithRoom(stack);
if (as != null && as.size() > 0) {
for (Aspect aspect : as.getAspects()) {
// Pedestal operates every 5 ticks
int drained = VisNetHandler
.drainVis(this.worldObj, this.xCoord, this.yCoord, this.zCoord, aspect, 25);
if (drained > 0) {
amulet.addRealVis(stack, aspect, drained, true);
draining = true;
somethingChanged = true;
hodgepodge$needSync = true;
}
}
}
}
return as;
}

@Inject(method = "updateEntity", at = @At("TAIL"))
private void hodgepodge$onTickEnd(CallbackInfo ci) {
if (!worldObj.isRemote && hodgepodge$needSync && hodgepodge$ticksSinceLastSync++ > 5) {
hodgepodge$ticksSinceLastSync = 0;
hodgepodge$needSync = false;
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
}

@Inject(
Expand Down

0 comments on commit 3bec1dd

Please sign in to comment.