Skip to content

Commit

Permalink
Fix portal not transferring to the right dimension when using StAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
thecatcore committed Mar 31, 2024
1 parent 1e36afa commit d721e9b
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 64 deletions.
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
package io.github.betterthanupdates.shockahpi.mixin.client;

import java.io.File;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.llamalad7.mixinextras.sugar.Share;
import com.llamalad7.mixinextras.sugar.ref.LocalRef;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import shockahpi.DimensionBase;

import net.minecraft.world.WorldManager;
import net.minecraft.world.chunk.ChunkIO;
import net.minecraft.world.dimension.Dimension;
import net.minecraft.world.dimension.DimensionData;
Expand All @@ -43,6 +36,6 @@ private boolean getChuckIOCondition(Object obj, Operation<Boolean> original,
at = @At(value = "INVOKE", target = "Ljava/io/File;<init>(Ljava/io/File;Ljava/lang/String;)V"))
private String getChunkIOFileName(String child,
@Share("dimensionBase") LocalRef<DimensionBase> dimensionBase) {
return "DIM " + dimensionBase.get().number;
return dimensionBase.get() != null ? "DIM " + dimensionBase.get().number : child;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void getChunkIO(Dimension paramxa, CallbackInfoReturnable<ChunkIO> cir) {
File localFile1 = this.getParentFolder();
DimensionBase localDimensionBase = DimensionBase.getDimByProvider(paramxa.getClass());

if (localDimensionBase.number != 0) {
if (localDimensionBase != null && localDimensionBase.number != 0) {
File localFile2 = new File(localFile1, "DIM" + localDimensionBase.number);
localFile2.mkdirs();
cir.setReturnValue(new WorldChunkLoader(localFile2));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
package io.github.betterthanupdates.shockahpi.mixin.client;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import playerapi.PlayerAPI;
import shockahpi.PlayerBaseSAPI;

import net.minecraft.block.PortalBlock;
import net.minecraft.client.entity.player.AbstractClientPlayerEntity;
import net.minecraft.entity.Entity;
import net.minecraft.world.World;

import io.github.betterthanupdates.shockahpi.block.ShockAhPIPortalBlock;

Expand All @@ -20,12 +12,4 @@ public abstract class PortalBlockMixin implements ShockAhPIPortalBlock {
public int getDimNumber() {
return -1;
}

@Inject(method = "onEntityCollision", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;method_1388()V", shift = At.Shift.BEFORE))
public void onEntityCollision(World world, int i, int j, int k, Entity entity, CallbackInfo ci) {
if (entity instanceof AbstractClientPlayerEntity) {
AbstractClientPlayerEntity entityplayersp = (AbstractClientPlayerEntity) entity;
PlayerAPI.getPlayerBase(entityplayersp, PlayerBaseSAPI.class).portal = this.getDimNumber();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,71 +1,43 @@
package io.github.betterthanupdates.shockahpi.mixin.client;

import com.llamalad7.mixinextras.sugar.Local;
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.ModifyArg;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import shockahpi.DimensionBase;
import shockahpi.Loc;
import shockahpi.SAPI;

import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.minecraft.world.WorldProperties;
import net.minecraft.world.dimension.Dimension;

@Mixin(World.class)
public abstract class WorldMixin implements BlockView {
@Shadow
public WorldProperties properties;

@Redirect(method = "<init>(Lnet/minecraft/world/dimension/DimensionData;Ljava/lang/String;JLnet/minecraft/world/dimension/Dimension;)V",
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/dimension/Dimension;getByID(I)Lnet/minecraft/world/dimension/Dimension;", ordinal = 0))
private Dimension sapi$ctr1(int i) {
DimensionBase localDimensionBase = DimensionBase.getDimByNumber(i);
return localDimensionBase.getWorldProvider();
}

@Redirect(method = "<init>(Lnet/minecraft/world/dimension/DimensionData;Ljava/lang/String;JLnet/minecraft/world/dimension/Dimension;)V",
@ModifyArg(method = "<init>(Lnet/minecraft/world/dimension/DimensionData;Ljava/lang/String;JLnet/minecraft/world/dimension/Dimension;)V",
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/dimension/Dimension;getByID(I)Lnet/minecraft/world/dimension/Dimension;", ordinal = 1))
private Dimension sapi$ctr2(int i) {
private int sapi$fixDimensionId(int i) {
if (this.properties != null) {
i = this.properties.getDimensionId();
}

DimensionBase localDimensionBase = DimensionBase.getDimByNumber(i);
return localDimensionBase.getWorldProvider();
}

int cachedI, cachedJ, cachedK;

@Inject(method = "setBlockWithMetadata", at = @At("HEAD"))
private void sapi$setBlockWithMetadata(int i, int j, int k, int l, int i1, CallbackInfoReturnable<Boolean> cir) {
this.cachedI = i;
this.cachedJ = j;
this.cachedK = k;
return i;
}

@ModifyArg(method = "setBlockWithMetadata",
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/chunk/Chunk;setBlockWithMetadata(IIIII)Z"), index = 3)
private int sapi$setBlockWithMetadata$1(int i) {
return SAPI.interceptBlockSet((World) (Object) this, new Loc(this.cachedI, this.cachedJ, this.cachedK), i);
}

int cachedI2, cachedJ2, cachedK2;

@Inject(method = "setBlockInChunk", at = @At("HEAD"))
private void sapi$setBlockInChunk(int i, int j, int k, int l, CallbackInfoReturnable<Boolean> cir) {
this.cachedI2 = i;
this.cachedJ2 = j;
this.cachedK2 = k;
private int sapi$setBlockWithMetadata$1(int i, @Local(ordinal = 0, argsOnly = true) int x, @Local(ordinal = 1, argsOnly = true) int y,
@Local(ordinal = 2, argsOnly = true) int z) {
return SAPI.interceptBlockSet((World) (Object) this, new Loc(x, y, z), i);
}

@ModifyArg(method = "setBlockInChunk",
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/chunk/Chunk;method_860(IIII)Z"), index = 3)
private int sapi$setBlockInChunk$1(int i) {
return SAPI.interceptBlockSet((World) (Object) this, new Loc(this.cachedI2, this.cachedJ2, this.cachedK2), i);
private int sapi$setBlockInChunk$1(int i, @Local(ordinal = 0, argsOnly = true) int x, @Local(ordinal = 1, argsOnly = true) int y,
@Local(ordinal = 2, argsOnly = true) int z) {
return SAPI.interceptBlockSet((World) (Object) this, new Loc(x, y, z), i);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.github.betterthanupdates.shockahpi.mixin.client.nostation;

import io.github.betterthanupdates.shockahpi.block.ShockAhPIPortalBlock;
import net.minecraft.block.PortalBlock;
import net.minecraft.client.entity.player.AbstractClientPlayerEntity;
import net.minecraft.entity.Entity;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import playerapi.PlayerAPI;
import shockahpi.PlayerBaseSAPI;

@Mixin(PortalBlock.class)
public abstract class PortalBlockMixin implements ShockAhPIPortalBlock {

@Inject(method = "onEntityCollision", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;method_1388()V", shift = At.Shift.BEFORE))
public void onEntityCollision(World world, int i, int j, int k, Entity entity, CallbackInfo ci) {
if (entity instanceof AbstractClientPlayerEntity) {
AbstractClientPlayerEntity entityplayersp = (AbstractClientPlayerEntity) entity;
PlayerAPI.getPlayerBase(entityplayersp, PlayerBaseSAPI.class).portal = this.getDimNumber();
}
}
}
5 changes: 4 additions & 1 deletion apron/src/main/resources/shockahpi.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@
"nostation.AchievementsScreenMixin"
],
"plugin": "io.github.betterthanupdates.apron.ApronMixinPlugin",
"parent": "apron.parent.mixins.json"
"parent": "apron.parent.mixins.json",
"mixins": [
"nostation.PortalBlockMixin"
]
}

0 comments on commit d721e9b

Please sign in to comment.