NoLag: Add blocks and item specific render filtering

This commit is contained in:
noil 2021-12-24 22:04:28 -05:00
parent f0b454938e
commit 8f19f6b29f
1 changed files with 77 additions and 3 deletions

View File

@ -1,10 +1,14 @@
package me.rigamortis.seppuku.impl.module.render;
import me.rigamortis.seppuku.Seppuku;
import me.rigamortis.seppuku.api.event.EventStageable;
import me.rigamortis.seppuku.api.event.gui.hud.EventUIValueChanged;
import me.rigamortis.seppuku.api.event.gui.hud.modulelist.EventUIListValueChanged;
import me.rigamortis.seppuku.api.event.network.EventReceivePacket;
import me.rigamortis.seppuku.api.event.render.*;
import me.rigamortis.seppuku.api.event.world.EventAddEntity;
import me.rigamortis.seppuku.api.event.world.EventLightUpdate;
import me.rigamortis.seppuku.api.event.world.EventLoadWorld;
import me.rigamortis.seppuku.api.event.world.EventSpawnParticle;
import me.rigamortis.seppuku.api.module.Module;
import me.rigamortis.seppuku.api.value.Value;
@ -20,6 +24,8 @@ import net.minecraft.entity.item.EntityTNTPrimed;
import net.minecraft.entity.projectile.EntityWitherSkull;
import net.minecraft.init.Blocks;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.network.play.server.*;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntitySign;
@ -30,19 +36,29 @@ import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import team.stiff.pomelo.impl.annotated.handler.annotation.Listener;
import java.util.ArrayList;
import java.util.List;
/**
* Author Seth
* 4/11/2019 @ 3:48 AM.
*/
public final class NoLagModule extends Module {
public final Value<Boolean> blocks = new Value<Boolean>("Blocks", new String[]{"NoLagBlocks", "Block", "b"}, "Manual override for block renders", false);
public final Value<Boolean> blocksAll = new Value<Boolean>("BlocksAll", new String[]{"NoLagBlocksAll", "AllBlocks", "ba"}, "Disables the rendering of all blocks", false);
public final Value<List<Block>> blocksList = new Value<List<Block>>("BlocksList", new String[]{"NoLagBlocksList", "BlockIds", "blockid"}, "Blocks to disable rendering");
public final Value<Boolean> items = new Value<Boolean>("Items", new String[]{"Item", "i"}, "Manual override for dropped item renders", false);
public final Value<Boolean> itemsAll = new Value<Boolean>("ItemsAll", new String[]{"AllItems", "ia"}, "Disables the rendering of all items", false);
public final Value<Boolean> itemsItemBlocks = new Value<Boolean>("ItemsItemBlocks", new String[]{"AllItemBlocks", "itemblocks"}, "Disables the rendering of dropped item-block stacks", false);
public final Value<List<Item>> itemsList = new Value<List<Item>>("ItemsList", new String[]{"ItemIds", "itemid"}, "Items to disable rendering");
public final Value<Boolean> light = new Value<Boolean>("Light", new String[]{"Lit", "l"}, "Choose to enable the lighting lag fix. Disables lighting updates", false);
public final Value<Boolean> signs = new Value<Boolean>("Signs", new String[]{"Sign", "si"}, "Choose to enable the sign lag fix. Disables the rendering of sign text", false);
public final Value<Boolean> sounds = new Value<Boolean>("Sounds", new String[]{"Sound", "s"}, "Choose to enable the sound lag fix. Disable entity swap-item/equip sound", true);
public final Value<Boolean> fluids = new Value<Boolean>("Fluids", new String[]{"Fluid", "f", "Liquids", "liq", "Water", "Lava"}, "Disables the rendering of all fluids", false);
public final Value<Boolean> pistons = new Value<Boolean>("Pistons", new String[]{"Piston", "p"}, "Choose to enable the piston lag fix. Disables pistons from rendering", false);
public final Value<Boolean> slimes = new Value<Boolean>("Slimes", new String[]{"Slime", "sl"}, "Choose to enable the slime lag fix. Disables slimes from spawning", false);
public final Value<Boolean> items = new Value<Boolean>("Items", new String[]{"Item", "i"}, "Disables the rendering of items", false);
public final Value<Boolean> particles = new Value<Boolean>("Particles", new String[]{"Part", "par"}, "Disables the spawning of all particles", true);
public final Value<Boolean> particlesPackets = new Value<Boolean>("ParticlesPackets", new String[]{"PartPacket", "parpac"}, "Disables particle packets and effect packets", false);
public final Value<Boolean> particlesEntityPackets = new Value<Boolean>("ParticlesEntityPackets", new String[]{"PartEntPacket", "parentpac"}, "Disables entity effect packets (usually particles)", false);
@ -63,6 +79,9 @@ public final class NoLagModule extends Module {
public NoLagModule() {
super("NoLag", new String[]{"AntiLag", "NoRender"}, "Fixes malicious lag exploits and bugs that cause lag", "NONE", -1, ModuleType.RENDER);
this.blocksList.setValue(new ArrayList<>());
this.itemsList.setValue(new ArrayList<>());
}
@Listener
@ -141,6 +160,18 @@ public final class NoLagModule extends Module {
final BlockPos pos = event.getPos();
final Block block = Minecraft.getMinecraft().world.getBlockState(pos).getBlock();
if (block != Blocks.AIR) {
if (this.blocks.getValue()) {
if (this.blocksAll.getValue()) {
event.setCanceled(true);
} else {
this.blocksList.getValue().forEach(listBlock -> {
if (Block.getIdFromBlock(block) == Block.getIdFromBlock(listBlock)) {
event.setCanceled(true);
}
});
}
}
if (this.fluids.getValue()) {
if (block instanceof BlockLiquid) {
event.setCanceled(true);
@ -209,8 +240,25 @@ public final class NoLagModule extends Module {
public void onRenderEntity(EventRenderEntity event) {
if (event.getEntity() != null) {
if (this.items.getValue()) {
if (event.getEntity() instanceof EntityItem)
event.setCanceled(true);
if (event.getEntity() instanceof EntityItem) {
if (this.itemsAll.getValue()) {
event.setCanceled(true);
} else {
final EntityItem entityItem = (EntityItem) event.getEntity();
if (this.itemsItemBlocks.getValue()) {
if (entityItem.getItem().getItem() instanceof ItemBlock) {
event.setCanceled(true);
}
}
this.itemsList.getValue().forEach(item -> {
if (Item.getIdFromItem(item) == Item.getIdFromItem(entityItem.getItem().getItem())) {
event.setCanceled(true);
}
});
}
}
}
if (this.withers.getValue()) {
@ -309,4 +357,30 @@ public final class NoLagModule extends Module {
}
}
}
@Listener
public void onWorldLoad(EventLoadWorld event) {
if (event.getWorld() == null)
return;
if (this.blocksList.getValue().isEmpty())
this.blocksList.getValue().add(Block.getBlockFromName("stone"));
if (this.itemsList.getValue().isEmpty())
this.itemsList.getValue().add(Item.getByNameOrId("stick"));
}
@Listener
public void onValueChanged(EventUIValueChanged event) {
if (event.getValue().getAlias()[0].toLowerCase().startsWith("nolagblocks")) {
Minecraft.getMinecraft().renderGlobal.loadRenderers();
}
}
@Listener
public void onListValueChanged(EventUIListValueChanged event) {
if (event.getValue().getAlias()[0].equalsIgnoreCase("nolagblockslist")) {
Minecraft.getMinecraft().renderGlobal.loadRenderers();
}
}
}