Skip to content

Commit

Permalink
Port Mod compat mixins
Browse files Browse the repository at this point in the history
  • Loading branch information
thecatcore committed Jan 2, 2025
1 parent 538226e commit b1fed98
Show file tree
Hide file tree
Showing 24 changed files with 345 additions and 351 deletions.
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
package io.github.betterthanupdates.apron.compat;

import java.lang.invoke.LambdaMetafactory;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.IntFunction;
import java.util.function.Supplier;
import java.util.function.ToDoubleFunction;

import net.mine_diver.infsprites.render.TextureManager;
import net.mine_diver.infsprites.util.Util;
import net.mine_diver.infsprites.util.compatibility.ForgePatcher;
import org.lwjgl.opengl.GL11;
import overrideapi.utils.Reflection;

import net.minecraft.client.render.Tessellator;

Expand Down Expand Up @@ -72,9 +66,9 @@ public static Tessellator getWorldTessellator(int terrainId) {
} else {
Tessellator tessellator = (Tessellator)get(terrainId).get();
if (ACTIVE_WORLD_TESSELLATORS.add(terrainId)) {
tessellator.start();
tessellator.startQuads();
Tessellator vanillaTessellator = (Tessellator)VANILLA_TESSELLATOR.get();
tessellator.setOffset(
tessellator.translate(
X_OFFSET_GETTER.applyAsDouble(vanillaTessellator),
Y_OFFSET_GETTER.applyAsDouble(vanillaTessellator),
Z_OFFSET_GETTER.applyAsDouble(vanillaTessellator)
Expand All @@ -88,7 +82,7 @@ public static Tessellator getWorldTessellator(int terrainId) {
public static void drawActiveWorldTessellators() {
ACTIVE_WORLD_TESSELLATORS.forEach(terrainId -> {
GL11.glBindTexture(3553, TextureManager.getTerrain(terrainId));
((Tessellator)tessellators[terrainId].get()).tessellate();
((Tessellator)tessellators[terrainId].get()).draw();
});
ACTIVE_WORLD_TESSELLATORS.clear();
GL11.glBindTexture(3553, TextureManager.getTerrain(0));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package io.github.betterthanupdates.apron.compat.betterthanwolves;

import net.minecraft.block.Block;
import net.minecraft.client.render.block.BlockRenderer;
import net.minecraft.client.render.block.BlockRenderManager;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;

public interface BTWFireBlock {
void OnBlockDestroyedByFire(World world, int i, int j, int k);
boolean RenderFire(BlockRenderer renderBlocks, BlockView iBlockAccess, int i, int j, int k, Block block);
boolean RenderFire(BlockRenderManager renderBlocks, BlockView iBlockAccess, int i, int j, int k, Block block);
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,27 @@
@Mixin(ArrowEntity.class)
public abstract class ArrowEntityMixin extends Entity {
@Shadow
private int inBlock;
private int field_1580;

@Shadow
private int blockX;
private int field_1577;

@Shadow
private int blockY;
private int field_1578;

@Shadow
private int blockZ;
private int field_1579;

public ArrowEntityMixin(World arg) {
super(arg);
}

@Inject(method = "tick", at = @At(value = "FIELD", target = "Lnet/minecraft/entity/projectile/ArrowEntity;shake:I", ordinal = 2, shift = At.Shift.AFTER))
@Inject(method = "tick", at = @At(value = "FIELD", target = "Lnet/minecraft/entity/projectile/ArrowEntity;field_1575:I", ordinal = 2, shift = At.Shift.AFTER))
private void btw$tick(CallbackInfo ci) {
if (this.inBlock == mod_FCBetterThanWolves.fcBlockDetector.id) {
mod_FCBetterThanWolves.fcBlockDetector.onEntityCollision(this.world, this.blockX, this.blockY, this.blockZ, this);
} else if (this.inBlock == mod_FCBetterThanWolves.fcVase.id) {
((FCBlockVase)mod_FCBetterThanWolves.fcVase).BreakVase(this.world, this.blockX, this.blockY, this.blockZ);
if (this.field_1580 == mod_FCBetterThanWolves.fcBlockDetector.id) {
mod_FCBetterThanWolves.fcBlockDetector.onEntityCollision(this.world, this.field_1577, this.field_1578, this.field_1579, this);
} else if (this.field_1580 == mod_FCBetterThanWolves.fcVase.id) {
((FCBlockVase)mod_FCBetterThanWolves.fcVase).BreakVase(this.world, this.field_1577, this.field_1578, this.field_1579);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import net.minecraft.FCUtilsMisc;
import net.minecraft.block.Block;
import net.minecraft.world.World;
import net.minecraft.world.feature.BirchTreeFeature;
import net.minecraft.world.gen.feature.BirchTreeFeature;

@Mixin(BirchTreeFeature.class)
public class BirchTreeFeatureMixin {
Expand All @@ -35,7 +35,7 @@ public boolean generate(World world, Random random, int i, int j, int k) {
for(int l2 = k - byte0; l2 <= k + byte0 && flag; ++l2) {
if (i1 >= 0 && i1 < 128) {
int j3 = world.getBlockId(i2, i1, l2);
if (!world.isAir(i2, i1, l2) && j3 != Block.LEAVES.id) {
if (!world.method_234(i2, i1, l2) && j3 != Block.LEAVES.id) {
flag = false;
}
} else {
Expand All @@ -49,9 +49,9 @@ public boolean generate(World world, Random random, int i, int j, int k) {
return false;
} else {
int j1 = world.getBlockId(i, j - 1, k);
if ((j1 == Block.GRASS.id || j1 == Block.DIRT.id || FCUtilsMisc.CanPlantGrowOnBlock(world, i, j - 1, k, Block.SAPLING)) && j < 128 - l - 1) {
if (j1 == Block.GRASS.id) {
world.setBlockInChunk(i, j - 1, k, Block.DIRT.id);
if ((j1 == Block.GRASS_BLOCK.id || j1 == Block.DIRT.id || FCUtilsMisc.CanPlantGrowOnBlock(world, i, j - 1, k, Block.SAPLING)) && j < 128 - l - 1) {
if (j1 == Block.GRASS_BLOCK.id) {
world.method_200(i, j - 1, k, Block.DIRT.id);
}

for(int k1 = j - 3 + l; k1 <= j + l; ++k1) {
Expand All @@ -64,17 +64,17 @@ public boolean generate(World world, Random random, int i, int j, int k) {
for(int i4 = k - i3; i4 <= k + i3; ++i4) {
int j4 = i4 - k;
if ((Math.abs(l3) != i3 || Math.abs(j4) != i3 || random.nextInt(2) != 0 && j2 != 0)
&& !Block.FULL_OPAQUE[world.getBlockId(k3, k1, i4)]) {
world.setBlockWithMetadata(k3, k1, i4, Block.LEAVES.id, 2);
&& !Block.BLOCKS_OPAQUE[world.getBlockId(k3, k1, i4)]) {
world.method_154(k3, k1, i4, Block.LEAVES.id, 2);
}
}
}
}

for(int l1 = 0; l1 < l; ++l1) {
int k2 = world.getBlockId(i, j + l1, k);
if (world.isAir(i, j + l1, k) || k2 == Block.LEAVES.id) {
world.setBlockWithMetadata(i, j + l1, k, Block.LOG.id, 2);
if (world.method_234(i, j + l1, k) || k2 == Block.LEAVES.id) {
world.method_154(i, j + l1, k, Block.LOG.id, 2);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.llamalad7.mixinextras.sugar.Local;
import net.minecraft.block.Block;
import net.minecraft.block.CakeBlock;
import net.minecraft.block.material.Material;
import net.minecraft.block.Material;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -24,12 +24,12 @@ protected CakeBlockMixin(int i, Material arg) {
}

@Override
public void onBlockPlaced(World world, int i, int j, int k) {
super.onBlockPlaced(world, i, j, k);
public void onPlaced(World world, int i, int j, int k) {
super.onPlaced(world, i, j, k);
boolean bReceivingRedstone = world.method_263(i, j, k);
if (bReceivingRedstone) {
this.SetRedstoneOn(world, i, j, k, true);
world.playSound((double)i + 0.5, (double)j + 0.5, (double)k + 0.5, "mob.ghast.scream", 1.0F, world.rand.nextFloat() * 0.4F + 0.8F);
world.playSound((double)i + 0.5, (double)j + 0.5, (double)k + 0.5, "mob.ghast.scream", 1.0F, world.field_214.nextFloat() * 0.4F + 0.8F);
}
}

Expand All @@ -43,12 +43,12 @@ public void onBlockPlaced(World world, int i, int j, int k) {
return this.GetEatState(arg, i, j, k);
}

@ModifyVariable(method = "getOutlineShape", at = @At("HEAD"), ordinal = 0)
@ModifyVariable(method = "getBoundingBox", at = @At("HEAD"), ordinal = 0)
private int btw$getOutlineShape(int var5, @Local World arg, @Local(ordinal = 0) int i, @Local(ordinal = 1) int j, @Local(ordinal = 2) int k) {
return this.GetEatState(arg, i, j, k);
}

@ModifyVariable(method = "getTextureForSide(II)I", at = @At("HEAD"), ordinal = 1, argsOnly = true)
@ModifyVariable(method = "getTexture(II)I", at = @At("HEAD"), ordinal = 1, argsOnly = true)
private int btw$getTextureForSide(int value) {
return value & 7;
}
Expand All @@ -58,20 +58,20 @@ public void onBlockPlaced(World world, int i, int j, int k) {
return this.GetEatState(arg, i, j, k) + 1;
}

@Redirect(method = "method_1528", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockMeta(IIII)V"))
@Redirect(method = "method_1528", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;method_215(IIII)V"))
private void btw$method_1528$2(World instance, int j, int k, int l, int i, @Local(ordinal = 3) int var6) {
this.SetEatState(instance, i, j, k, var6);
}

@Inject(method = "onAdjacentBlockUpdate", at = @At("TAIL"))
@Inject(method = "neighborUpdate", at = @At("TAIL"))
private void addBTWCheck(World world, int i, int j, int k, int l, CallbackInfo callbackInfo) {
if (this.canGrow(world, i, j, k)) {
boolean bOn = this.IsRedstoneOn(world, i, j, k);
boolean bReceivingRedstone = world.method_263(i, j, k);
if (bOn != bReceivingRedstone) {
this.SetRedstoneOn(world, i, j, k, bReceivingRedstone);
if (bReceivingRedstone) {
world.playSound((double)i + 0.5, (double)j + 0.5, (double)k + 0.5, "mob.ghast.scream", 1.0F, world.rand.nextFloat() * 0.4F + 0.8F);
world.playSound((double)i + 0.5, (double)j + 0.5, (double)k + 0.5, "mob.ghast.scream", 1.0F, world.field_214.nextFloat() * 0.4F + 0.8F);
}
}
}
Expand All @@ -89,7 +89,7 @@ public void SetRedstoneOn(World world, int i, int j, int k, boolean bOn) {
iMetaData |= 8;
}

world.setBlockMeta(i, j, k, iMetaData);
world.method_215(i, j, k, iMetaData);
}

@Override
Expand All @@ -101,7 +101,7 @@ public int GetEatState(BlockView iBlockAccess, int i, int j, int k) {
public void SetEatState(World world, int i, int j, int k, int state) {
int iMetaData = world.getBlockMeta(i, j, k) & 8;
iMetaData |= state;
world.setBlockMeta(i, j, k, iMetaData);
world.method_215(i, j, k, iMetaData);
}

@Override
Expand Down
Loading

0 comments on commit b1fed98

Please sign in to comment.