Skip to content

Commit

Permalink
Port ShockAhPI mixins
Browse files Browse the repository at this point in the history
  • Loading branch information
thecatcore committed Jan 2, 2025
1 parent e51b941 commit 538226e
Show file tree
Hide file tree
Showing 15 changed files with 102 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* @author ShockAh
* Methods implemented in {@link net.minecraft.block.PortalBlock PortalBlock} by ShockAhPI
* Methods implemented in {@link net.minecraft.block.NetherPortalBlock PortalBlock} by ShockAhPI
*/
public interface ShockAhPIPortalBlock {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.betterthanupdates.shockahpi.client.gui.screen;

import net.minecraft.stat.achievement.Achievement;
import net.minecraft.achievement.Achievement;

public interface ShockAhPIAchievementsScreen {
boolean isVisibleAchievement(Achievement achievement, int deep);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package io.github.betterthanupdates.shockahpi.mixin.client;

import java.lang.reflect.Array;

import net.minecraft.client.gui.screen.achievement.AchievementsScreen;
import fr.catcore.cursedmixinextensions.annotations.Public;
import org.spongepowered.asm.mixin.Mixin;

import net.minecraft.client.gui.screen.menu.AchievementsScreen;

@Mixin(AchievementsScreen.class)
public class AchievementsScreenMixin {
@Public
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import shockahpi.SAPI;

import net.minecraft.entity.block.ChestBlockEntity;
import net.minecraft.block.entity.ChestBlockEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraft.world.feature.DungeonFeature;
import net.minecraft.world.feature.Feature;

import net.minecraft.world.gen.feature.DungeonFeature;
import net.minecraft.world.gen.feature.Feature;
import com.llamalad7.mixinextras.sugar.Local;

@Mixin(DungeonFeature.class)
Expand All @@ -23,13 +21,13 @@ public abstract class DungeonFeatureMixin extends Feature {
* @author SAPI
* @reason
*/
@Inject(method = "generate", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/world/World;getBlockEntity(III)Lnet/minecraft/entity/BlockEntity;", ordinal = 0, shift = At.Shift.BY, by = 2))
@Inject(method = "generate", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/world/World;method_1777(III)Lnet/minecraft/block/entity/BlockEntity;", ordinal = 0, shift = At.Shift.BY, by = 2))
public void generate(World world, Random random, int i, int j, int k, CallbackInfoReturnable<Boolean> cir, @Local ChestBlockEntity chestBlockEntity) {
for (int i6 = 0; i6 < Math.min(19, SAPI.dungeonGetAmountOfGuaranteed()); ++i6) {
ItemStack stack = SAPI.dungeonGetGuaranteed(i6).getStack();

if (stack != null) {
chestBlockEntity.setInventoryItem(random.nextInt(chestBlockEntity.getInventorySize()), stack);
chestBlockEntity.setStack(random.nextInt(chestBlockEntity.size()), stack);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
package io.github.betterthanupdates.shockahpi.mixin.client;

import com.llamalad7.mixinextras.injector.ModifyReturnValue;
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.CallbackInfoReturnable;
import shockahpi.SAPI;

import net.minecraft.client.ClientInteractionManager;
import net.minecraft.MultiplayerInteractionManager;
import net.minecraft.client.InteractionManager;
import net.minecraft.client.Minecraft;
import net.minecraft.client.MultiplayerClientInteractionManager;

@Mixin(MultiplayerClientInteractionManager.class)
public class MultiplayerClientInteractionManagerMixin extends ClientInteractionManager {
@Mixin(MultiplayerInteractionManager.class)
public class MultiplayerClientInteractionManagerMixin extends InteractionManager {
public MultiplayerClientInteractionManagerMixin(Minecraft minecraft) {
super(minecraft);
}

@Inject(method = "getBlockReachDistance", at = @At("RETURN"), cancellable = true)
public void shockahpi$getBlockReachDistance(CallbackInfoReturnable<Float> cir) {
if (cir.getReturnValue() == 4.0F) cir.setReturnValue(SAPI.reachGet());
@ModifyReturnValue(method = "method_1715", at = @At("RETURN"))
public float shockahpi$getBlockReachDistance(float reach) {
if (reach == 4.0F) return SAPI.reachGet();

return reach;
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
package io.github.betterthanupdates.shockahpi.mixin.client;

import net.minecraft.client.entity.player.AbstractClientPlayerEntity;
import net.minecraft.block.NetherPortalBlock;
import net.minecraft.entity.Entity;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;

import net.minecraft.block.PortalBlock;

import io.github.betterthanupdates.shockahpi.block.ShockAhPIPortalBlock;
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)
@Mixin(NetherPortalBlock.class)
public abstract class PortalBlockMixin implements ShockAhPIPortalBlock {
@Override
public int getDimNumber() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package io.github.betterthanupdates.shockahpi.mixin.client;

import com.llamalad7.mixinextras.injector.ModifyReturnValue;
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.CallbackInfoReturnable;
import shockahpi.Loc;
import shockahpi.SAPI;

import net.minecraft.client.ClientInteractionManager;
import net.minecraft.SingleplayerInteractionManager;
import net.minecraft.client.InteractionManager;
import net.minecraft.client.Minecraft;
import net.minecraft.client.SingleplayerInteractionManager;

@Mixin(SingleplayerInteractionManager.class)
public abstract class SinglePlayerInteractionManagerMixin extends ClientInteractionManager {
public abstract class SinglePlayerInteractionManagerMixin extends InteractionManager {
public SinglePlayerInteractionManagerMixin(Minecraft client) {
super(client);
}
Expand All @@ -21,23 +21,25 @@ public SinglePlayerInteractionManagerMixin(Minecraft client) {
* @author ShockAh
* @reason Implement ShockAhPI function
*/
@Inject(method = "getBlockReachDistance", cancellable = true, at = @At("RETURN"))
public void shockahpi$getBlockReachDistance(CallbackInfoReturnable<Float> cir) {
if (cir.getReturnValue() == 4.0F) cir.setReturnValue(SAPI.reachGet());
@ModifyReturnValue(method = "method_1715", at = @At("RETURN"))
public float shockahpi$getBlockReachDistance(float reach) {
if (reach == 4.0F) return SAPI.reachGet();

return reach;
}

/**
* @author ShockAh
* @reason Implement ShockAhPI function
*/
@Inject(method = "breakBlock", cancellable = true, at = @At(value = "INVOKE", shift = At.Shift.BEFORE,
@Inject(method = "method_1716", cancellable = true, at = @At(value = "INVOKE", shift = At.Shift.BEFORE,
target = "Lnet/minecraft/block/Block;afterBreak(Lnet/minecraft/world/World;Lnet/minecraft/entity/player/PlayerEntity;IIII)V")
)
public void shockahpi$breakBlock_beforeAfterBreak(int x, int y, int z, int par4, CallbackInfoReturnable<Boolean> cir) {
int blockId = this.client.world.getBlockId(x, y, z);
int meta = this.client.world.getBlockMeta(x, y, z);
int blockId = this.minecraft.world.getBlockId(x, y, z);
int meta = this.minecraft.world.getBlockMeta(x, y, z);

if (SAPI.interceptHarvest(this.client.world, this.client.player, new Loc(x, y, z), blockId, meta)) {
if (SAPI.interceptHarvest(this.minecraft.world, this.minecraft.player, new Loc(x, y, z), blockId, meta)) {
cir.setReturnValue(true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.Material;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.AxeItem;
Expand All @@ -31,16 +31,16 @@
@ChangeSuperClass(Tool.class)
public abstract class ToolItemMixin extends Item {
@Shadow
public float field_2713;
public float miningSpeed;

@Shadow
public int field_2714;
public int damage;

@Shadow
protected ToolMaterial toolMaterial;

@Shadow
private Block[] effectiveBlocksBase;
private Block[] effectiveOnBlocks;

public ToolItemMixin(int i) {
super(i);
Expand All @@ -51,9 +51,9 @@ public ToolItemMixin(int i) {

@ReplaceConstructor
public void ctr(int itemID, int damage, ToolMaterial material, Block[] blocks) {
this.Tool$ctr(false, null, itemID, material.getDurability(), (float)(damage + material.getAttackDamage()), getToolPower(material), material.getMiningSpeed());
this.field_2713 = Float.NaN;
this.field_2714 = Integer.MIN_VALUE;
this.Tool$ctr(false, null, itemID, material.getDurability(), (float)(damage + material.getAttackDamage()), getToolPower(material), material.getMiningSpeedMultiplier());
this.miningSpeed = Float.NaN;
this.damage = Integer.MIN_VALUE;

this.toolMaterial = material;
((Tool)(Object)this).toolBase = this.getToolBase();
Expand Down Expand Up @@ -101,7 +101,7 @@ public boolean canHarvest(Block block) {
return false;
}

if (block.material == Material.STONE || block.material == Material.ICE) {
if (block.material == Material.STONE || block.material == Material.field_997) {
return true;
}

Expand All @@ -113,15 +113,15 @@ public boolean canHarvest(Block block) {
return false;
}

if (block.material == Material.WOOD || block.material == Material.LEAVES || block.material == Material.PLANT || block.material == Material.CACTUS || block.material == Material.PUMPKIN) {
if (block.material == Material.WOOD || block.material == Material.LEAVES || block.material == Material.field_988 || block.material == Material.field_1000 || block.material == Material.PUMPKIN) {
return true;
}
} else if (((Object)this) instanceof ShovelItem) {
if (((Tool)(Object)this).id <= 369) {
return false;
}

if (block.material == Material.ORGANIC || block.material == Material.DIRT || block.material == Material.SAND || block.material == Material.SNOW || block.material == Material.SNOW_BLOCK || block.material == Material.CLAY) {
if (block.material == Material.SOLID_ORGANIC || block.material == Material.SOIL || block.material == Material.SAND || block.material == Material.field_998 || block.material == Material.field_999 || block.material == Material.CLAY) {
return true;
}
}
Expand Down Expand Up @@ -160,17 +160,17 @@ private boolean isBlockOnList(int blockID) {
* @reason check tool speed
*/
@Overwrite
public float getStrengthOnBlock(ItemStack stack, Block block) {
if (this.effectiveBlocksBase != null) {
for (Block value : this.effectiveBlocksBase) {
public float getMiningSpeedMultiplier(ItemStack stack, Block block) {
if (this.effectiveOnBlocks != null) {
for (Block value : this.effectiveOnBlocks) {
if (value == block) {
return this.getToolSpeed();
}
}

return 1.0F;
} else {
return super.getStrengthOnBlock(stack, block);
return super.getMiningSpeedMultiplier(stack, block);
}
}

Expand All @@ -181,14 +181,14 @@ public float getStrengthOnBlock(ItemStack stack, Block block) {
@Overwrite
public int getAttackDamage(Entity entity) {
int i = super.getAttackDamage(entity);
return this.field_2714 != Integer.MIN_VALUE && (double)i == Math.floor((double)((Tool)(Object)this).baseDamage) ? this.field_2714 : i;
return this.damage != Integer.MIN_VALUE && (double)i == Math.floor((double)((Tool)(Object)this).baseDamage) ? this.damage : i;
}

@ShadowSuper("getToolSpeed")
public abstract float Tool$getToolSpeed();

protected float getToolSpeed() {
return Float.isNaN(this.field_2713) ? this.Tool$getToolSpeed() : this.field_2713;
return Float.isNaN(this.miningSpeed) ? this.Tool$getToolSpeed() : this.miningSpeed;
}

/**
Expand All @@ -215,7 +215,7 @@ public boolean postMine(ItemStack arg, int i, int j, int k, int l, LivingEntity
*/
@Environment(EnvType.CLIENT)
@Overwrite
public boolean isRendered3d() {
return super.isRendered3d();
public boolean isHandheld() {
return super.isHandheld();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public abstract class WorldMixin implements BlockView {
public WorldProperties properties;

@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))
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/dimension/Dimension;method_1767(I)Lnet/minecraft/world/dimension/Dimension;", ordinal = 1))
private int sapi$fixDimensionId(int i) {
if (this.properties != null) {
i = this.properties.getDimensionId();
Expand All @@ -27,15 +27,15 @@ public abstract class WorldMixin implements BlockView {
return i;
}

@ModifyArg(method = "setBlockWithMetadata",
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/chunk/Chunk;setBlockWithMetadata(IIIII)Z"), index = 3)
@ModifyArg(method = "method_154",
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/chunk/Chunk;setBlock(IIIII)Z"), index = 3)
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)
@ModifyArg(method = "method_200",
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/chunk/Chunk;setBlockId(IIII)Z"), index = 3)
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);
Expand Down
Loading

0 comments on commit 538226e

Please sign in to comment.