Skip to content

Commit

Permalink
Fix block place lag
Browse files Browse the repository at this point in the history
  • Loading branch information
vaxerski committed Sep 12, 2021
1 parent 1b9d6c2 commit 9015e8d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,6 @@ hs_err_pid*
# End of https://www.gitignore.io/api/java,eclipse,forgegradle,intellij+all
/build/
/.gradle/

# vs
.vscode/
11 changes: 11 additions & 0 deletions src/main/java/me/vaxry/harakiri/Harakiri.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import me.vaxry.harakiri.impl.manager.*;
import me.vaxry.harakiri.impl.module.config.ReloadConfigsModule;
import me.vaxry.harakiri.impl.module.render.CustomFontModule;
import me.vaxry.harakiri.impl.module.render.XrayModule;
import net.minecraft.client.Minecraft;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.ITextComponent;
Expand Down Expand Up @@ -43,6 +44,9 @@ public final class Harakiri {

private Logger logger;

// For fast access to XRay (block lag)
private XrayModule xrayModule = null;

//private String prevTitle;

private EventManager eventManager;
Expand Down Expand Up @@ -142,6 +146,9 @@ public void init() {
// Create the font renderer
fontRendererExtd = new FontRendererExtd(Minecraft.getMinecraft().gameSettings, new ResourceLocation("harakirimod", "textures/ascii.png"), Minecraft.getMinecraft().renderEngine, true);

// Get the XRay Module
this.xrayModule = (XrayModule)this.moduleManager.find(XrayModule.class);

// Add runtime hook to listen for shutdown to save configs
Runtime.getRuntime().addShutdownHook(new Thread("Harakiri SH") {
@Override
Expand Down Expand Up @@ -420,6 +427,10 @@ public void initPlexusEffect(PlexusComponent plx) {
this.plexusEffect = new PlexusEffect(plx);
}

public XrayModule getXRayModule() {
return this.xrayModule;
}

public static Harakiri get(){
return INSTANCE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
import me.vaxry.harakiri.Harakiri;
import me.vaxry.harakiri.framework.event.render.EventRenderBlockSide;
import me.vaxry.harakiri.framework.event.world.EventAddCollisionBox;
import me.vaxry.harakiri.framework.event.world.EventGetBlockLayer;
import me.vaxry.harakiri.impl.module.render.XrayModule;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
Expand All @@ -25,22 +24,25 @@
public class MixinBlock {
@Inject(at = @At("HEAD"), method = "shouldSideBeRendered", cancellable = true)
private void onShouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side, CallbackInfoReturnable<Boolean> cir) {
final EventRenderBlockSide event = new EventRenderBlockSide((Block) (Object) this);
Harakiri.get().getEventManager().dispatchEvent(event);
if (event.isCanceled()) {
cir.cancel();
cir.setReturnValue(event.isRenderable());
// prevent horrible block place lag
if(Harakiri.get().getXRayModule().isEnabled()) {
final EventRenderBlockSide event = new EventRenderBlockSide((Block) (Object) this);
Harakiri.get().getEventManager().dispatchEvent(event);
if (event.isCanceled()) {
cir.cancel();
cir.setReturnValue(event.isRenderable());
}
}
}

@Inject(at = @At("HEAD"), method = "getRenderLayer", cancellable = true)
/*@Inject(at = @At("HEAD"), method = "getRenderLayer", cancellable = true)
private void onGetRenderLayer(CallbackInfoReturnable<BlockRenderLayer> cir) {
final EventGetBlockLayer event = new EventGetBlockLayer((Block) (Object) this);
Harakiri.get().getEventManager().dispatchEvent(event);
if (event.isCanceled()) {
cir.cancel();
}
}
}*/


@Inject(at = @At("HEAD"), method = "addCollisionBoxToList(Lnet/minecraft/block/state/IBlockState;Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/math/AxisAlignedBB;Ljava/util/List;Lnet/minecraft/entity/Entity;Z)V", cancellable = true)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package me.vaxry.harakiri.framework.mixin.gui;

import jdk.nashorn.internal.codegen.CompilerConstants;
import me.vaxry.harakiri.Harakiri;
import me.vaxry.harakiri.framework.event.gui.EventRenderTooltip;
import me.vaxry.harakiri.impl.module.render.GuiPlusModule;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.item.ItemStack;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
Expand Down

0 comments on commit 9015e8d

Please sign in to comment.