Skip to content

Commit

Permalink
add: wrappers for methods with coordinates from BlockBasePressurePlat…
Browse files Browse the repository at this point in the history
…e, BlockBed, BlockBush, BlockButton, BlockCake, BlockCauldron, BlockChest, BlockCrops, BlockDispenser to BlockPos; add: wrappers for methods with coordinates from Item to ItemPos;
  • Loading branch information
MJaroslav committed Feb 14, 2024
1 parent 4aa6e8b commit 03b647d
Show file tree
Hide file tree
Showing 10 changed files with 395 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.github.mjaroslav.mjutils.asm.mixin.accessors;

import net.minecraft.block.BlockBasePressurePlate;
import net.minecraft.world.World;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;

@Mixin(BlockBasePressurePlate.class)
public interface AccessorBlockBasePressurePlate {
@Invoker("func_150065_e")
int getRedstonePowerByCollidedEntities(@NotNull World world, int x, int y, int z);

@Invoker("func_150062_a")
void updateAndPlayEffects(@NotNull World world, int x, int y, int z, int meta);

@Invoker("func_150064_a_")
void notifyBlocksOfNeighborChange(@NotNull World world, int x, int y, int z);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.github.mjaroslav.mjutils.asm.mixin.accessors;

import net.minecraft.block.BlockBush;
import net.minecraft.world.World;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;

@Mixin(BlockBush.class)
public interface AccessorBlockBush {
@Invoker("checkAndDropBlock")
void checkAndDropBlock(@NotNull World world, int x, int y, int z);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.github.mjaroslav.mjutils.asm.mixin.accessors;

import net.minecraft.block.BlockButton;
import net.minecraft.world.World;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;

@Mixin(BlockButton.class)
public interface AccessorBlockButton {
@Invoker("func_150045_e")
int getRotatedMetaByNeighbors(@NotNull World world, int x, int y, int z);

@Invoker("func_150044_m")
boolean checkAndDropBlock(@NotNull World world, int x, int y, int z);

@Invoker("func_150046_n")
void updateAndPlayEffects(@NotNull World world, int x, int y, int z);

@Invoker("func_150042_a")
void notifyBlocksOfNeighborChange(@NotNull World world, int x, int y, int z, int meta);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.github.mjaroslav.mjutils.asm.mixin.accessors;

import net.minecraft.block.BlockCake;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;

@Mixin(BlockCake.class)
public interface AccessorBlockCake {
@Invoker("func_150036_b")
void eatCake(@NotNull World world, int x, int y, int z, @NotNull EntityPlayer eater);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.github.mjaroslav.mjutils.asm.mixin.accessors;

import net.minecraft.block.BlockChest;
import net.minecraft.inventory.IInventory;
import net.minecraft.world.World;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;

@Mixin(BlockChest.class)
public interface AccessorBlockChest {
@Invoker("func_149954_e")
void rotateAndConnect(@NotNull World world, int x, int y, int z);

@Invoker("func_149952_n")
boolean isSameBlockAround(@NotNull World world, int x, int y, int z);

@Invoker("func_149951_m")
@Nullable IInventory getInventory(@NotNull World world, int x, int y, int z);

@Invoker("func_149953_o")
static boolean isOcelotSittingOnChest(@NotNull World world, int x, int y, int z) {
throw new AssertionError();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.github.mjaroslav.mjutils.asm.mixin.accessors;

import net.minecraft.block.BlockCrops;
import net.minecraft.world.World;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;

@Mixin(BlockCrops.class)
public interface AccessorBlockCrops {
@Invoker("func_149864_n")
float calculateGrowthChance(@NotNull World world, int x, int y, int z);

@Invoker("func_149863_m")
void tryGrowth(@NotNull World world, int x, int y, int z);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.github.mjaroslav.mjutils.asm.mixin.accessors;

import net.minecraft.block.BlockDispenser;
import net.minecraft.world.World;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;

@Mixin(BlockDispenser.class)
public interface AccessorBlockDispenser {
@Invoker("func_149941_e")
void updateAndPlayEffects(@NotNull World world, int x, int y, int z);
}
251 changes: 211 additions & 40 deletions src/main/java/io/github/mjaroslav/mjutils/pos/BlockPos.java

Large diffs are not rendered by default.

55 changes: 54 additions & 1 deletion src/main/java/io/github/mjaroslav/mjutils/pos/ItemPos.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,61 @@
package io.github.mjaroslav.mjutils.pos;

import io.github.mjaroslav.sharedjava.tuple.Triplet;
import lombok.experimental.UtilityClass;
import net.minecraft.block.Block;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import org.jetbrains.annotations.NotNull;

@UtilityClass
public class ItemPos {
// TODO: WIP
//region Item
//-------------------------
public boolean onItemUse(@NotNull Item owner, @NotNull ItemStack stack, @NotNull EntityPlayer user,
@NotNull World world,
@NotNull Triplet<? extends Number, ? extends Number, ? extends Number> pos,
@NotNull ForgeDirection side,
@NotNull Triplet<? extends Number, ? extends Number, ? extends Number> hitPos) {
return owner.onItemUse(stack, user, world, pos.getX().intValue(), pos.getY().intValue(), pos.getZ().intValue(),
side.ordinal(), hitPos.getX().floatValue(), hitPos.getY().floatValue(), hitPos.getZ().floatValue());
}

public boolean onBlockDestroyed(@NotNull Item owner, @NotNull ItemStack stack, @NotNull World world,
@NotNull Block block,
@NotNull Triplet<? extends Number, ? extends Number, ? extends Number> pos,
@NotNull EntityLivingBase initiator) {
return owner.onBlockDestroyed(stack, world, block, pos.getX().intValue(), pos.getY().intValue(),
pos.getZ().intValue(), initiator);
}

public boolean onItemUseFirst(@NotNull Item owner, @NotNull ItemStack stack, @NotNull EntityPlayer user,
@NotNull World world,
@NotNull Triplet<? extends Number, ? extends Number, ? extends Number> pos,
@NotNull ForgeDirection side,
@NotNull Triplet<? extends Number, ? extends Number, ? extends Number> hitPos) {
return owner.onItemUseFirst(stack, user, world, pos.getX().intValue(), pos.getY().intValue(),
pos.getZ().intValue(), side.ordinal(), hitPos.getX().floatValue(), hitPos.getY().floatValue(),
hitPos.getZ().floatValue());
}

public boolean onBlockStartBreak(@NotNull Item owner, @NotNull ItemStack stack,
@NotNull Triplet<? extends Number, ? extends Number, ? extends Number> pos,
@NotNull EntityPlayer breaker) {
return owner.onBlockStartBreak(stack, pos.getX().intValue(), pos.getY().intValue(), pos.getZ().intValue(),
breaker);
}

public boolean doesSneakBypassUse(@NotNull Item owner, @NotNull World world,
@NotNull Triplet<? extends Number, ? extends Number, ? extends Number> pos,
@NotNull EntityPlayer user) {
return owner.doesSneakBypassUse(world, pos.getX().intValue(), pos.getY().intValue(), pos.getZ().intValue(),
user);
}
//-------------------------
//endregion

}
7 changes: 7 additions & 0 deletions src/main/resources/mixin.mjutils.accessors.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
},
"mixins": [
"AccessorBlock",
"AccessorBlockBasePressurePlate",
"AccessorBlockBush",
"AccessorBlockButton",
"AccessorBlockCake",
"AccessorBlockChest",
"AccessorBlockCrops",
"AccessorBlockDispenser",
"AccessorEntityPigZombie",
"AccessorEnumHolder",
"AccessorExplosion",
Expand Down

0 comments on commit 03b647d

Please sign in to comment.