Speed up forge event registration (#64)

Co-authored-by: Alexdoru <[email protected]>
This commit is contained in:
boubou19andAlexdoru authored and GitHub committed 2025-07-18 22:22:10 +00:00
1 parent 5b551eb8ec
commit 39f86c8b0c
9 files changed
+271 -234

No files matched your search

@@ -11,6 +11,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
@@ -40,36 +41,12 @@ public abstract class BlockDesign extends BlockMetadata implements IMultipassBlo
designSystem = system;
}
public static int getMetadata(int plank1, int plank2, int design) {
return plank1 + (plank2 << 9) + (design << 18);
public void registerHandler() {
MinecraftForge.EVENT_BUS.register(new EventHandler());
}
@SubscribeEvent
public void onClick(PlayerInteractEvent event) {
if (event.action != PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) {
return;
}
World world = event.entityPlayer.worldObj;
EntityPlayer player = event.entityPlayer;
int x = event.x;
int y = event.y;
int z = event.z;
if (!(world.getBlock(x, y, z) instanceof BlockDesign blockDesign)) {
return;
}
ItemStack item = player.getHeldItem();
if (item == null || !(item.getItem() instanceof IToolHammer)
|| !((IToolHammer) item.getItem()).isActive(item)) {
return;
}
DesignBlock carpentryBlock = blockDesign.getCarpentryBlock(world, x, y, z);
TileEntityMetadata tile = (TileEntityMetadata) world.getTileEntity(x, y, z);
carpentryBlock.rotate(event.face, item, player, world, x, y, z);
int meta = carpentryBlock.getBlockMetadata(blockDesign.getDesignSystem());
tile.setTileMetadata(meta, true);
public static int getMetadata(int plank1, int plank2, int design) {
return plank1 + (plank2 << 9) + (design << 18);
}
public abstract ItemStack getCreativeStack(IDesign design);
@@ -160,4 +137,35 @@ public abstract class BlockDesign extends BlockMetadata implements IMultipassBlo
public int getNumberOfPasses() {
return 2;
}
public static class EventHandler {
@SubscribeEvent
public void onClick(PlayerInteractEvent event) {
if (event.action != PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) {
return;
}
World world = event.entityPlayer.worldObj;
EntityPlayer player = event.entityPlayer;
int x = event.x;
int y = event.y;
int z = event.z;
if (!(world.getBlock(x, y, z) instanceof BlockDesign blockDesign)) {
return;
}
ItemStack item = player.getHeldItem();
if (item == null || !(item.getItem() instanceof IToolHammer)
|| !((IToolHammer) item.getItem()).isActive(item)) {
return;
}
DesignBlock carpentryBlock = blockDesign.getCarpentryBlock(world, x, y, z);
TileEntityMetadata tile = (TileEntityMetadata) world.getTileEntity(x, y, z);
carpentryBlock.rotate(event.face, item, player, world, x, y, z);
int meta = carpentryBlock.getBlockMetadata(blockDesign.getDesignSystem());
tile.setTileMetadata(meta, true);
}
}
}