Skip to content

Commit

Permalink
New feature featureBreakingRestriction
Browse files Browse the repository at this point in the history
- Refactor cache solution
- Refactor renderer util
  • Loading branch information
Hendrix-Shen committed Aug 25, 2022
1 parent a83a3b2 commit b8a4ff5
Show file tree
Hide file tree
Showing 22 changed files with 731 additions and 224 deletions.
10 changes: 10 additions & 0 deletions src/main/java/top/hendrixshen/tweakmyclient/TweakMyClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
import top.hendrixshen.tweakmyclient.config.ConfigHandler;
import top.hendrixshen.tweakmyclient.config.Configs;
import top.hendrixshen.tweakmyclient.event.RenderHandler;
import top.hendrixshen.tweakmyclient.util.render.CustomBlockHitBoxRenderer;
//#if MC >= 11600
import top.hendrixshen.tweakmyclient.util.render.OpenWaterHelperRenderer;
//#endif
import top.hendrixshen.tweakmyclient.util.render.RestrictionBoxRenderer;

public class TweakMyClient implements ClientModInitializer {
private static final Logger logger = LogManager.getLogger(TweakMyClientReference.getModId());
Expand Down Expand Up @@ -43,6 +48,11 @@ public void onInitializeClient() {
ConfigHandler.register(configHandler);
Configs.initCallbacks(configHandler.configManager);
RenderEventHandler.getInstance().registerWorldLastRenderer(RenderHandler.getInstance());
RenderHandler.getInstance().registerWorldLastRenderer(CustomBlockHitBoxRenderer.getInstance());
//#if MC >= 11600
RenderHandler.getInstance().registerWorldLastRenderer(OpenWaterHelperRenderer.getInstance());
//#endif
RenderHandler.getInstance().registerWorldLastRenderer(RestrictionBoxRenderer.getInstance());

logger.info("[{}]: Mod initialized - Version: {} ({})", TweakMyClientReference.getModName(), TweakMyClientReference.getModVersion(), TweakMyClientReference.getModVersionType());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package top.hendrixshen.tweakmyclient.config;

import top.hendrixshen.magiclib.config.ConfigManager;
import top.hendrixshen.tweakmyclient.helper.ListCache;
import top.hendrixshen.tweakmyclient.helper.Cache;
import top.hendrixshen.tweakmyclient.util.StringUtil;

public class ConfigHandler extends top.hendrixshen.magiclib.config.ConfigHandler {
Expand All @@ -12,8 +12,6 @@ public ConfigHandler(String modId, ConfigManager configManager, int configVersio
@Override
public void load() {
super.load();
ListCache.itemAutoDropBlackList = StringUtil.getItemStackSets(Configs.listAutoDropBlackList);
ListCache.itemAutoDropWhiteList = StringUtil.getItemStackSets(Configs.listAutoDropWhiteList);
ListCache.itemGlowingBlacklist = StringUtil.getItemStackSets(Configs.listItemGlowingBlacklist);
Cache.getInstance().rebuildAllCache();
}
}
19 changes: 19 additions & 0 deletions src/main/java/top/hendrixshen/tweakmyclient/config/Configs.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,15 @@ public class Configs {
@Config(category = ConfigCategory.LIST)
public static ArrayList<String> listAutoDropWhiteList = Lists.newArrayList("minecraft:stone", "minecraft:dirt", "minecraft:cobblestone", "minecraft:gravel", "minecraft:rotten_flesh");

@Config(category = ConfigCategory.LIST)
public static ArrayList<String> listBreakingRestrictionBoxBlacklist = Lists.newArrayList("-1 -1 -1 1 1 1");

@Config(category = ConfigCategory.LIST)
public static BreakingRestrictionBoxType listBreakingRestrictionBoxType = BreakingRestrictionBoxType.WHITELIST;

@Config(category = ConfigCategory.LIST)
public static ArrayList<String> listBreakingRestrictionBoxWhitelist = Lists.newArrayList("-1 -1 -1 1 1 1");

@Config(category = ConfigCategory.LIST)
public static ArrayList<String> listCustomWindowTitle = Lists.newArrayList("Minecraft {mc_version} with TweakMyClient {tmc_version} | Player {mc_username} | FPS: {mc_fps}");

Expand All @@ -170,6 +179,12 @@ public class Configs {
@Config(category = ConfigCategory.COLOR)
public static Color4f colorBlockHitBoxOverlayFill = Color4f.fromColor(StringUtils.getColor("#2CFFFF10", 0));

@Config(category = ConfigCategory.COLOR)
public static Color4f colorBreakingRestrictionBoxBlacklistMode = Color4f.fromColor(StringUtils.getColor("#7FFF0000", 0));

@Config(category = ConfigCategory.COLOR)
public static Color4f colorBreakingRestrictionBoxWhitelistMode = Color4f.fromColor(StringUtils.getColor("#7F00FF00", 0));

@Config(category = ConfigCategory.COLOR)
public static Color4f colorGuiStart = Color4f.fromColor(StringUtils.getColor("#C00F0F0F", 0));

Expand Down Expand Up @@ -205,6 +220,10 @@ public class Configs {
@Config(category = ConfigCategory.FEATURE)
public static boolean featureAutoRespawn = false;

@Hotkey()
@Config(category = ConfigCategory.FEATURE)
public static boolean featureBreakingRestrictionBox = false;

@Hotkey()
@Config(category = ConfigCategory.FEATURE)
public static boolean featureCustomBlockHitBoxOverlayFill = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
package top.hendrixshen.tweakmyclient.event;

import com.google.common.collect.Lists;
//#if MC >= 11500
import com.mojang.blaze3d.vertex.PoseStack;
//#endif
//#if MC > 11600
import com.mojang.math.Matrix4f;
//#endif
import fi.dy.masa.malilib.interfaces.IRenderer;
import net.minecraft.client.Minecraft;
import top.hendrixshen.tweakmyclient.TweakMyClient;
import top.hendrixshen.tweakmyclient.config.Configs;
import top.hendrixshen.tweakmyclient.util.render.OverlayRenderer;

import java.util.List;

public class RenderHandler implements IRenderer {
private static final RenderHandler INSTANCE = new RenderHandler();
private final Minecraft minecraft;

public RenderHandler() {
this.minecraft = TweakMyClient.getMinecraftClient();
}
private final List<top.hendrixshen.tweakmyclient.util.render.IRenderer> worldLastRenderer = Lists.newArrayList();

public static RenderHandler getInstance() {
return INSTANCE;
}

public void registerWorldLastRenderer(top.hendrixshen.tweakmyclient.util.render.IRenderer renderer) {
if (this.worldLastRenderer.contains(renderer)) {
TweakMyClient.getLogger().warn("Renderer {} has been registered!", renderer);
return;
}
this.worldLastRenderer.add(renderer);
}

@Override
//#if MC >= 11700
public void onRenderWorldLast(PoseStack poseStack, Matrix4f matrix4f) {
Expand All @@ -32,13 +36,10 @@ public void onRenderWorldLast(PoseStack poseStack, Matrix4f matrix4f) {
//#else
//$$ public void onRenderWorldLast(float partialTicks) {
//#endif
//#if MC >= 11600
if (Configs.featureOpenWaterHelper) {
OverlayRenderer.getInstance().renderOpenWater(minecraft);
}
//#endif
if (Configs.featureCustomBlockHitBoxOverlayFill || Configs.featureCustomBlockHitBoxOverlayOutline) {
OverlayRenderer.getInstance().renderBlockOverlay(minecraft);
for (top.hendrixshen.tweakmyclient.util.render.IRenderer renderer : this.worldLastRenderer) {
if (renderer.shouldRender()) {
renderer.render();
}
}
}
}
120 changes: 120 additions & 0 deletions src/main/java/top/hendrixshen/tweakmyclient/helper/AreaBox.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package top.hendrixshen.tweakmyclient.helper;

import fi.dy.masa.malilib.util.IntBoundingBox;
import net.minecraft.core.BlockPos;
import org.jetbrains.annotations.NotNull;

public class AreaBox {
private final int minX;
private final int minY;
private final int minZ;
private final int maxX;
private final int maxY;
private final int maxZ;

public AreaBox(int x1, int y1, int z1, int x2, int y2, int z2) {
this.minX = Math.min(x1, x2);
this.minY = Math.min(y1, y2);
this.minZ = Math.min(z1, z2);
this.maxX = Math.max(x1, x2);
this.maxY = Math.max(y1, y2);
this.maxZ = Math.max(z1, z2);
}

public AreaBox(@NotNull BlockPos blockPos1, @NotNull BlockPos blockPos2) {
this(blockPos1.getX(), blockPos1.getY(), blockPos1.getZ(), blockPos2.getX(), blockPos2.getY(), blockPos2.getZ());
}

public int getMinX() {
return this.minX;
}

public int getMinY() {
return this.minY;
}

public int getMinZ() {
return this.minZ;
}

public int getMaxX() {
return this.maxX;
}

public int getMaxY() {
return this.maxY;
}

public int getMaxZ() {
return this.maxZ;
}

public boolean contains(int x, int y, int z) {
return x >= this.minX && x <= this.maxX && y >= this.minY && y <= this.maxY && z >= this.minZ && z <= this.maxZ;
}

public boolean contains(@NotNull BlockPos blockPos) {
return this.contains(blockPos.getX(), blockPos.getY(), blockPos.getZ());
}

public boolean intersects(@NotNull AreaBox areaBox) {
return this.maxX >= areaBox.minX
&& this.minX <= areaBox.maxX
&& this.maxZ >= areaBox.minZ
&& this.minZ <= areaBox.maxZ
&& this.maxY >= areaBox.minY
&& this.minY <= areaBox.maxY;
}

public int getXSize() {
return this.maxX - this.minX;
}

public int getYSize() {
return this.maxY - this.minY;
}

public int getZSize() {
return this.maxZ - this.minZ;
}

@Override
public int hashCode() {
int prime = 31;
int result = 1;
result = prime * result + this.maxX;
result = prime * result + this.maxY;
result = prime * result + this.maxZ;
result = prime * result + this.minX;
result = prime * result + this.minY;
return prime * result + this.minZ;
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
} else if (obj instanceof AreaBox) {
AreaBox areaBox = (AreaBox) obj;
if (areaBox.minX != this.minX) {
return false;
} else if (areaBox.minY != this.minY) {
return false;
} else if (areaBox.minZ != this.minZ) {
return false;
} else if (areaBox.maxX != this.maxX) {
return false;
} else if (areaBox.maxY != this.maxY) {
return false;
} else {
return areaBox.maxZ == this.maxZ;
}
}
return false;
}

@Override
public String toString() {
return "AreaBox[" + this.minX + ", " + this.minY + ", " + this.minZ + "] -> [" + this.maxX + ", " + this.maxY + ", " + this.maxZ + "]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public String getStringValue() {

@Override
public String getDisplayName() {
return StringUtil.tr(String.format("label.autoDropListType.%s", this.name));
return StringUtil.tr(String.format("label.misc.%s", this.name));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package top.hendrixshen.tweakmyclient.helper;

import top.hendrixshen.tweakmyclient.util.StringUtil;

public enum BreakingRestrictionBoxType implements ConfigOptionListEntryApi {
BLACKLIST("blackList"),
WHITELIST("whiteList");

private final String name;

BreakingRestrictionBoxType(String name) {
this.name = name;
}

@Override
public String getStringValue() {
return this.name;
}

@Override
public String getDisplayName() {
return StringUtil.tr(String.format("label.misc.%s", this.name));
}

@Override
public ConfigOptionListEntryApi cycle(boolean forward) {
return ConfigOptionListEntryHelper.cycle(forward, this.ordinal(), BreakingRestrictionBoxType.values());
}

@Override
public ConfigOptionListEntryApi fromString(String value) {
return ConfigOptionListEntryHelper.fromString(value, BreakingRestrictionBoxType.WHITELIST, BreakingRestrictionBoxType.values());
}

@Override
public String getName() {
return this.name;
}
}
Loading

0 comments on commit b8a4ff5

Please sign in to comment.