Skip to content

Commit

Permalink
multiplayer bug bash (bump to 1.0.5)
Browse files Browse the repository at this point in the history
  • Loading branch information
strubium committed Dec 29, 2024
1 parent b7c984e commit 927c0bf
Show file tree
Hide file tree
Showing 21 changed files with 126 additions and 105 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ org.gradle.caching = true
org.gradle.daemon = true

modname=TheOneSmeagle
version=1.12-1.0.4
version=1.12-1.0.5
curse_type=release
projectId=245211
github_project=strubium/TheOneSmeagle
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/mcjty/theoneprobe/ClientForgeEventHandlers.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class ClientForgeEventHandlers {
@SubscribeEvent
public void onGuiOpen(GuiOpenEvent event) {
if (ignoreNextGuiClose) {
GuiScreen current = Tools.mc.currentScreen;
GuiScreen current = ClientTools.mc.currentScreen;
if (event.getGui() == null && (current instanceof GuiConfig || current instanceof GuiNote)) {
ignoreNextGuiClose = false;
// We don't want our gui to be closed for a new 'null' gui
Expand Down Expand Up @@ -63,7 +63,7 @@ public void renderGameOverlayEvent(RenderGameOverlayEvent.Pre event) {
break;
case PROBE_NEEDED:
case PROBE_NEEDEDHARD:
if (ModItems.hasAProbeSomewhere(Tools.mc.player)) {
if (ModItems.hasAProbeSomewhere(ClientTools.mc.player)) {
OverlayRenderer.renderHUD(getModeForPlayer(), event.getPartialTicks());
}
break;
Expand All @@ -72,7 +72,7 @@ public void renderGameOverlayEvent(RenderGameOverlayEvent.Pre event) {
}

private ProbeMode getModeForPlayer() {
EntityPlayerSP player = Tools.mc.player;
EntityPlayerSP player = ClientTools.mc.player;
if (Config.extendedInMain) {
if (hasItemInMainHand(ModItems.probe)) {
return ProbeMode.EXTENDED;
Expand All @@ -82,15 +82,15 @@ private ProbeMode getModeForPlayer() {
}

private boolean hasItemInEitherHand(Item item) {
ItemStack mainHeldItem = Tools.mc.player.getHeldItem(EnumHand.MAIN_HAND);
ItemStack offHeldItem = Tools.mc.player.getHeldItem(EnumHand.OFF_HAND);
ItemStack mainHeldItem = ClientTools.mc.player.getHeldItem(EnumHand.MAIN_HAND);
ItemStack offHeldItem = ClientTools.mc.player.getHeldItem(EnumHand.OFF_HAND);
return (mainHeldItem != null && mainHeldItem.getItem() == item) ||
(offHeldItem != null && offHeldItem.getItem() == item);
}


private boolean hasItemInMainHand(Item item) {
ItemStack mainHeldItem = Tools.mc.player.getHeldItem(EnumHand.MAIN_HAND);
ItemStack mainHeldItem = ClientTools.mc.player.getHeldItem(EnumHand.MAIN_HAND);
return mainHeldItem != null && mainHeldItem.getItem() == item;
}
}
14 changes: 14 additions & 0 deletions src/main/java/mcjty/theoneprobe/ClientTools.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package mcjty.theoneprobe;

import net.minecraft.client.Minecraft;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)
public class ClientTools {

/**
* Constant for {@link Minecraft#getMinecraft()}
*/
public static final Minecraft mc = Minecraft.getMinecraft();
}
7 changes: 1 addition & 6 deletions src/main/java/mcjty/theoneprobe/Tools.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ public class Tools {

private final static Map<String, String> modNamesForIds = new HashMap<>();

/**
* Constant for {@link Minecraft#getMinecraft()}
*/
public static final Minecraft mc = Minecraft.getMinecraft();

private static void init() {
Map<String, ModContainer> modMap = Loader.instance().getIndexedModList();
for (Map.Entry<String, ModContainer> modEntry : modMap.entrySet()) {
Expand Down Expand Up @@ -99,7 +94,7 @@ public static boolean show(ProbeMode mode, IProbeConfig.ConfigMode cfg) {
* @return The screen width in pixels.
*/
public static int getScreenWidth() {
ScaledResolution resolution = new ScaledResolution(Tools.mc);
ScaledResolution resolution = new ScaledResolution(ClientTools.mc);
return resolution.getScaledWidth();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package mcjty.theoneprobe.apiimpl.client;

import mcjty.theoneprobe.ClientTools;
import mcjty.theoneprobe.Tools;
import mcjty.theoneprobe.api.IEntityStyle;
import mcjty.theoneprobe.rendering.RenderHelper;
Expand All @@ -18,7 +19,7 @@
public class ElementEntityRender {

public static void renderPlayer(String entityName, Integer playerID, IEntityStyle style, int x, int y) {
Entity entity = Tools.mc.world.getEntityByID(playerID);
Entity entity = ClientTools.mc.world.getEntityByID(playerID);
if (entity != null) {
renderEntity(style, x, y, entity);
}
Expand All @@ -28,12 +29,12 @@ public static void render(String entityName, NBTTagCompound entityNBT, IEntitySt
if (entityName != null && !entityName.isEmpty()) {
Entity entity = null;
if (entityNBT != null) {
entity = EntityList.createEntityFromNBT(entityNBT, Tools.mc.world);
entity = EntityList.createEntityFromNBT(entityNBT, ClientTools.mc.world);
} else {
String fixed = fixEntityId(entityName);
EntityEntry value = ForgeRegistries.ENTITIES.getValue(new ResourceLocation(fixed));
if (value != null) {
entity = value.newInstance(Tools.mc.world);
entity = value.newInstance(ClientTools.mc.world);
}
}
if (entity != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package mcjty.theoneprobe.apiimpl.client;

import mcjty.theoneprobe.ClientTools;
import mcjty.theoneprobe.Tools;
import mcjty.theoneprobe.rendering.RenderHelper;
import net.minecraft.client.renderer.GlStateManager;
Expand All @@ -20,11 +21,11 @@ public static void render(ResourceLocation icon, int x, int y, int w, int h, int
}

if (u == -1) {
TextureAtlasSprite sprite = Tools.mc.getTextureMapBlocks().getAtlasSprite(icon.toString());
Tools.mc.getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
TextureAtlasSprite sprite = ClientTools.mc.getTextureMapBlocks().getAtlasSprite(icon.toString());
ClientTools.mc.getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
RenderHelper.drawTexturedModalRect(x, y, sprite, w, h);
} else {
Tools.mc.getTextureManager().bindTexture(icon);
ClientTools.mc.getTextureManager().bindTexture(icon);
RenderHelper.drawTexturedModalRect(x, y, u, v, w, h, txtw, txth);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package mcjty.theoneprobe.apiimpl.client;

import mcjty.theoneprobe.ClientTools;
import mcjty.theoneprobe.Tools;
import mcjty.theoneprobe.api.IItemStyle;
import mcjty.theoneprobe.rendering.RenderHelper;
Expand All @@ -13,7 +14,7 @@
public class ElementItemStackRender {

public static void render(ItemStack itemStack, IItemStyle style, int x, int y) {
RenderItem itemRender = Tools.mc.getRenderItem();
RenderItem itemRender = ClientTools.mc.getRenderItem();
if (!itemStack.isEmpty()) {
int size = itemStack.getCount();
String amount;
Expand All @@ -29,9 +30,9 @@ public static void render(ItemStack itemStack, IItemStyle style, int x, int y) {
amount = size / 1000000000 + "g";
}

if (!RenderHelper.renderItemStack(Tools.mc, itemRender, itemStack, x + (style.getWidth() - 18) / 2, y + (style.getHeight() - 18) / 2, amount)) {
if (!RenderHelper.renderItemStack(ClientTools.mc, itemRender, itemStack, x + (style.getWidth() - 18) / 2, y + (style.getHeight() - 18) / 2, amount)) {
// There was a crash rendering this item
RenderHelper.renderText(Tools.mc, x, y, TextFormatting.RED + "{*theoneprobe.probe.error_indicator*} " + itemStack.getDisplayName());
RenderHelper.renderText(ClientTools.mc, x, y, TextFormatting.RED + "{*theoneprobe.probe.error_indicator*} " + itemStack.getDisplayName());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package mcjty.theoneprobe.apiimpl.client;

import mcjty.theoneprobe.ClientTools;
import mcjty.theoneprobe.Tools;
import mcjty.theoneprobe.api.IProgressStyle;
import mcjty.theoneprobe.apiimpl.elements.ElementProgress;
Expand Down Expand Up @@ -34,7 +35,7 @@ public static void render(IProgressStyle style, long current, long max, int x, i
}

if (style.isShowText()) {
RenderHelper.renderText(Tools.mc, x + 3, y + 2, style.getPrefix() + ElementProgress.format(current, style.getNumberFormat(), style.getSuffix()));
RenderHelper.renderText(ClientTools.mc, x + 3, y + 2, style.getPrefix() + ElementProgress.format(current, style.getNumberFormat(), style.getSuffix()));
}
}

Expand Down Expand Up @@ -77,11 +78,11 @@ private static void drawGradientBar(int startX, int startY, int endX, int endY,

private static void renderLifeBar(long current, int x, int y, int w, int h) {
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
Tools.mc.getTextureManager().bindTexture(ICONS);
ClientTools.mc.getTextureManager().bindTexture(ICONS);
if (current * 4 >= w) {
// Shortened view
RenderHelper.drawTexturedModalRect(x, y, 52, 0, 9, 9);
RenderHelper.renderText(Tools.mc, x + 12, y, TextFormatting.WHITE + String.valueOf((current / 2)));
RenderHelper.renderText(ClientTools.mc, x + 12, y, TextFormatting.WHITE + String.valueOf((current / 2)));
} else {
for (int i = 0; i < current / 2; i++) {
RenderHelper.drawTexturedModalRect(x, y, 52, 0, 9, 9);
Expand All @@ -95,11 +96,11 @@ private static void renderLifeBar(long current, int x, int y, int w, int h) {

private static void renderArmorBar(long current, int x, int y, int w, int h) {
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
Tools.mc.getTextureManager().bindTexture(ICONS);
ClientTools.mc.getTextureManager().bindTexture(ICONS);
if (current * 4 >= w) {
// Shortened view
RenderHelper.drawTexturedModalRect(x, y, 43, 9, 9, 9);
RenderHelper.renderText(Tools.mc, x + 12, y, TextFormatting.WHITE + String.valueOf((current / 2)));
RenderHelper.renderText(ClientTools.mc, x + 12, y, TextFormatting.WHITE + String.valueOf((current / 2)));
} else {
for (int i = 0; i < current / 2; i++) {
RenderHelper.drawTexturedModalRect(x, y, 43, 9, 9, 9);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package mcjty.theoneprobe.apiimpl.client;

import mcjty.theoneprobe.ClientTools;
import mcjty.theoneprobe.Tools;
import mcjty.theoneprobe.api.IProgressStyle;
import mcjty.theoneprobe.apiimpl.elements.ElementProgress;
Expand Down Expand Up @@ -41,17 +42,17 @@ public static void render(IProgressStyle style, long current, long max, int x, i
}

if (style.isShowText()) {
RenderHelper.renderText(Tools.mc, x + 3, y + 2, style.getPrefix() + ElementProgress.format(current, style.getNumberFormat(), style.getSuffix()));
RenderHelper.renderText(ClientTools.mc, x + 3, y + 2, style.getPrefix() + ElementProgress.format(current, style.getNumberFormat(), style.getSuffix()));
}
}

private static void renderLifeBar(long current, int x, int y, int w, int h) {
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
Tools.mc.getTextureManager().bindTexture(ICONS);
ClientTools.mc.getTextureManager().bindTexture(ICONS);
if (current * 4 >= w) {
// Shortened view
RenderHelper.drawTexturedModalRect(x, y, 52, 0, 9, 9);
RenderHelper.renderText(Tools.mc, x + 12, y, TextFormatting.WHITE + String.valueOf((current / 2)));
RenderHelper.renderText(ClientTools.mc, x + 12, y, TextFormatting.WHITE + String.valueOf((current / 2)));
} else {
for (int i = 0; i < current / 2; i++) {
RenderHelper.drawTexturedModalRect(x, y, 52, 0, 9, 9);
Expand All @@ -65,11 +66,11 @@ private static void renderLifeBar(long current, int x, int y, int w, int h) {

private static void renderArmorBar(long current, int x, int y, int w, int h) {
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
Tools.mc.getTextureManager().bindTexture(ICONS);
ClientTools.mc.getTextureManager().bindTexture(ICONS);
if (current * 4 >= w) {
// Shortened view
RenderHelper.drawTexturedModalRect(x, y, 43, 9, 9, 9);
RenderHelper.renderText(Tools.mc, x + 12, y, TextFormatting.WHITE + String.valueOf((current / 2)));
RenderHelper.renderText(ClientTools.mc, x + 12, y, TextFormatting.WHITE + String.valueOf((current / 2)));
} else {
for (int i = 0; i < current / 2; i++) {
RenderHelper.drawTexturedModalRect(x, y, 43, 9, 9, 9);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package mcjty.theoneprobe.apiimpl.client;

import mcjty.theoneprobe.ClientTools;
import mcjty.theoneprobe.Tools;
import mcjty.theoneprobe.api.TextStyleClass;
import mcjty.theoneprobe.config.Config;
Expand All @@ -19,7 +20,7 @@
public class ElementTextRender {

public static void render(String text, int x, int y) {
RenderHelper.renderText(Tools.mc, x, y, stylifyString(text));
RenderHelper.renderText(ClientTools.mc, x, y, stylifyString(text));
}

private static String stylifyString(String text) {
Expand Down Expand Up @@ -64,6 +65,6 @@ private static String stylifyString(String text) {
}

public static int getWidth(String text) {
return Tools.mc.fontRenderer.getStringWidth(stylifyString(text));
return ClientTools.mc.fontRenderer.getStringWidth(stylifyString(text));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mcjty.theoneprobe.apiimpl.providers;

import mcjty.lib.api.power.IBigPower;
import mcjty.theoneprobe.ClientTools;
import mcjty.theoneprobe.TheOneProbe;
import mcjty.theoneprobe.Tools;
import mcjty.theoneprobe.api.*;
Expand Down Expand Up @@ -348,7 +349,7 @@ public static void showStandardBlockInfo(IProbeConfig config, ProbeMode mode, IP

if (Config.getBlockNameMaxWidth() != 0) {
// Calculate available width for text
FontRenderer fontRenderer = Tools.mc.fontRenderer;
FontRenderer fontRenderer = ClientTools.mc.fontRenderer;
int screenWidth = Tools.getScreenWidth();
int availableWidth = (int) (screenWidth * Config.getBlockNameMaxWidth());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
import mcjty.theoneprobe.items.ModItems;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemTool;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.translation.I18n;
import net.minecraft.world.World;

import java.util.HashMap;
Expand All @@ -27,7 +27,6 @@ public class HarvestInfoTools {

private static final ResourceLocation ICONS = new ResourceLocation(TheOneProbe.MODID, "textures/gui/icons.png");


private static final HashMap<String, ItemStack> testTools = new HashMap<>();
static {
testTools.put("theoneprobe.probe.shovel", new ItemStack(Items.WOODEN_SHOVEL));
Expand All @@ -45,12 +44,12 @@ static void showHarvestLevel(IProbeInfo probeInfo, IBlockState blockState, Block
if (harvestLevel < 0 || harvestLevel >= Config.getHarvestLevels().length) {
harvestName = Integer.toString(harvestLevel);
} else {
// Use I18n to translate the harvest level
harvestName = I18n.format(Config.getHarvestLevels()[harvestLevel]);
// Use server-side translation
harvestName = I18n.translateToLocal(Config.getHarvestLevels()[harvestLevel]);
}

// Add text information to the probe with translated tool and level
probeInfo.text(LABEL + I18n.format("theoneprobe.probe.tool_indicator") + " " + INFO + I18n.format(harvestTool) + " (" + I18n.format("theoneprobe.probe.level_indicator") + " " + harvestName + ")");
// Add text information to the probe
probeInfo.text(LABEL + I18n.translateToLocal("theoneprobe.probe.tool_indicator") + " " + INFO + I18n.translateToLocal(harvestTool) + " (" + I18n.translateToLocal("theoneprobe.probe.level_indicator") + " " + harvestName + ")");
}
}

Expand All @@ -61,9 +60,9 @@ static void showCanBeHarvested(IProbeInfo probeInfo, World world, BlockPos pos,

boolean harvestable = block.canHarvestBlock(world, pos, player) && world.getBlockState(pos).getBlockHardness(world, pos) >= 0;
if (harvestable) {
probeInfo.text(OK + I18n.format("theoneprobe.probe.harvestable_indicator"));
probeInfo.text(OK + I18n.translateToLocal("theoneprobe.probe.harvestable_indicator"));
} else {
probeInfo.text(WARNING + I18n.format("theoneprobe.probe.not_harvestable_indicator"));
probeInfo.text(WARNING + I18n.translateToLocal("theoneprobe.probe.not_harvestable_indicator"));
}
}

Expand All @@ -83,8 +82,8 @@ static void showHarvestInfo(IProbeInfo probeInfo, World world, BlockPos pos, Blo
if (testTool != null && testTool.getItem() instanceof ItemTool) {
ItemTool toolItem = (ItemTool) testTool.getItem();
if (testTool.getDestroySpeed(blockState) >= toolItem.toolMaterial.getEfficiency()) {
// Use lang key for tool name
harvestTool = I18n.format(testToolEntry.getKey());
// Use server-side translation
harvestTool = I18n.translateToLocal(testToolEntry.getKey());
break;
}
}
Expand All @@ -97,9 +96,9 @@ static void showHarvestInfo(IProbeInfo probeInfo, World world, BlockPos pos, Blo
if (harvestLevel < 0) {
// If harvest level is out of bounds, set the name manually
} else if (harvestLevel >= Config.getHarvestLevels().length) {
harvestName = I18n.format(Config.getHarvestLevels()[Config.getHarvestLevels().length - 1]);
harvestName = I18n.translateToLocal(Config.getHarvestLevels()[Config.getHarvestLevels().length - 1]);
} else {
harvestName = I18n.format(Config.getHarvestLevels()[harvestLevel]);
harvestName = I18n.translateToLocal(Config.getHarvestLevels()[harvestLevel]);
}
}

Expand All @@ -112,14 +111,14 @@ static void showHarvestInfo(IProbeInfo probeInfo, World world, BlockPos pos, Blo
IProbeInfo horizontal = probeInfo.horizontal(alignment);
if (harvestable) {
horizontal.icon(ICONS, 0, offs, dim, dim, iconStyle)
.text(OK + ((harvestTool != null) ? harvestTool : I18n.format("theoneprobe.probe.notool_indicator")));
.text(OK + ((harvestTool != null) ? harvestTool : "{*theoneprobe.probe.notool_indicator*}"));
} else {
if (harvestName == null || harvestName.isEmpty()) {
horizontal.icon(ICONS, 16, offs, dim, dim, iconStyle)
.text(WARNING + ((harvestTool != null) ? harvestTool : I18n.format("theoneprobe.probe.notool_indicator")));
.text(WARNING + ((harvestTool != null) ? harvestTool : "{*theoneprobe.probe.notool_indicator*}"));
} else {
horizontal.icon(ICONS, 16, offs, dim, dim, iconStyle)
.text(WARNING + ((harvestTool != null) ? harvestTool : I18n.format("theoneprobe.probe.notool_indicator")) + " (" + I18n.format("theoneprobe.probe.level_indicator") + " " + harvestName + ")");
.text(WARNING + ((harvestTool != null) ? harvestTool : I18n.translateToLocal("theoneprobe.probe.notool_indicator")) + " (" + I18n.translateToLocal("theoneprobe.probe.level_indicator") + " " + harvestName + ")");
}
}
}
Expand Down
Loading

0 comments on commit 927c0bf

Please sign in to comment.