mirror of
https://github.com/GTNewHorizons/StructureLib.git
synced 2026-11-12 00:07:27 +00:00
Simple Cleanups (#61)
Cleans up the code a tiny bit, moving comments around, removing some `@SuppressWarnings` and some unused code, and using modern Java features. These changes should require no modifications to any outside mods. --------- Co-authored-by: Glease <4586901+Glease@users.noreply.github.com>
This commit is contained in:
1 parent
287e8317c9
commit
2c5fa02a9e
20 files changed
+746
-153
No files matched your search
@@ -346,9 +346,7 @@ public class ClientProxy extends CommonProxy {
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof HintParticleInfo)) return false;
|
||||
|
||||
HintParticleInfo that = (HintParticleInfo) o;
|
||||
if (!(o instanceof HintParticleInfo that)) return false;
|
||||
|
||||
return x == that.x && y == that.y && z == that.z;
|
||||
}
|
||||
@@ -397,8 +395,6 @@ public class ClientProxy extends CommonProxy {
|
||||
double worldY = y + 0.25;
|
||||
double worldZ = z + 0.25;
|
||||
|
||||
// this rendering code is independently written by glee8e on July 10th, 2023
|
||||
// and is released as part of StructureLib under LGPL terms, just like everything else in this project
|
||||
// cube is a very special model. its facings can be rendered correctly by viewer distance without using
|
||||
// surface normals and view vector
|
||||
// here we do a 2 pass render.
|
||||
|
||||
@@ -112,7 +112,6 @@ public class GuiEditRegistryConfig extends GuiScreen {
|
||||
/**
|
||||
* Adds the buttons (and other controls) to the screen in question.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void initGui() {
|
||||
Keyboard.enableRepeatEvents(true);
|
||||
@@ -185,8 +184,7 @@ public class GuiEditRegistryConfig extends GuiScreen {
|
||||
*/
|
||||
@Override
|
||||
public void onGuiClosed() {
|
||||
if (this.configID != null && this.parentScreen instanceof GuiConfig) {
|
||||
GuiConfig parentGuiConfig = (GuiConfig) this.parentScreen;
|
||||
if (this.configID != null && this.parentScreen instanceof GuiConfig parentGuiConfig) {
|
||||
parentGuiConfig.needsRefresh = true;
|
||||
parentGuiConfig.initGui();
|
||||
}
|
||||
@@ -319,21 +317,16 @@ public class GuiEditRegistryConfig extends GuiScreen {
|
||||
for (EntriesList list : lists) {
|
||||
list.drawScreenPost(mouseX, mouseY, partialTicks);
|
||||
}
|
||||
if (this.undoHoverChecker.checkHover(mouseX, mouseY)) this.drawToolTip(
|
||||
if (this.undoHoverChecker.checkHover(mouseX, mouseY)) this.func_146283_a(
|
||||
this.mc.fontRenderer.listFormattedStringToWidth(I18n.format("fml.configgui.tooltip.undoAll"), 300),
|
||||
mouseX,
|
||||
mouseY);
|
||||
if (this.resetHoverChecker.checkHover(mouseX, mouseY)) this.drawToolTip(
|
||||
if (this.resetHoverChecker.checkHover(mouseX, mouseY)) this.func_146283_a(
|
||||
this.mc.fontRenderer.listFormattedStringToWidth(I18n.format("fml.configgui.tooltip.resetAll"), 300),
|
||||
mouseX,
|
||||
mouseY);
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void drawToolTip(List stringList, int x, int y) {
|
||||
this.func_146283_a(stringList, x, y);
|
||||
}
|
||||
|
||||
private class EntriesList extends GuiListExtended {
|
||||
|
||||
final String heading;
|
||||
@@ -571,13 +564,13 @@ public class GuiEditRegistryConfig extends GuiScreen {
|
||||
void drawToolTip(int mouseX, int mouseY) {
|
||||
// ensure checkHover() is always called, or the hover threshold might fail under certain corner cases
|
||||
if (hoverCheckerText.checkHover(mouseX, mouseY)) {
|
||||
GuiEditRegistryConfig.this.drawToolTip(
|
||||
GuiEditRegistryConfig.this.func_146283_a(
|
||||
mc.fontRenderer.listFormattedStringToWidth(tooltip, entriesList.getListWidth()),
|
||||
mouseX,
|
||||
mouseY);
|
||||
}
|
||||
if (hoverCheckerBtnDrag.checkHover(mouseX, mouseY) && !isDragging) {
|
||||
GuiEditRegistryConfig.this.drawToolTip(
|
||||
GuiEditRegistryConfig.this.func_146283_a(
|
||||
mc.fontRenderer.listFormattedStringToWidth(
|
||||
I18n.format("structurelib.configgui.drag.tooltip"),
|
||||
entriesList.getListWidth()),
|
||||
|
||||
@@ -75,7 +75,6 @@ public class SortedRegistry<V> implements Iterable<V> {
|
||||
}
|
||||
|
||||
static void cleanup(MinecraftServer server) {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<EntityPlayerMP> players = server.getConfigurationManager().playerEntityList;
|
||||
Set<UUID> onlinePlayerIDs = players.stream().map(EntityPlayerMP::getUniqueID).collect(Collectors.toSet());
|
||||
int removed = 0;
|
||||
|
||||
+1
-2
@@ -70,8 +70,7 @@ public class ConstructableUtility {
|
||||
|
||||
if (constructable == null) return false;
|
||||
|
||||
if (aPlayer instanceof EntityPlayerMP) {
|
||||
EntityPlayerMP playerMP = (EntityPlayerMP) aPlayer;
|
||||
if (aPlayer instanceof EntityPlayerMP playerMP) {
|
||||
// server side and sneaking (already checked above)
|
||||
// do construct
|
||||
if (aPlayer.capabilities.isCreativeMode) {
|
||||
|
||||
@@ -65,10 +65,9 @@ public class BlockHint extends Block {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void getSubBlocks(Item aItem, CreativeTabs par2CreativeTabs, List aList) {
|
||||
public void getSubBlocks(Item item, CreativeTabs tab, List<ItemStack> list) {
|
||||
for (int i = 0; i <= 15; i++) {
|
||||
aList.add(new ItemStack(aItem, 1, i));
|
||||
list.add(new ItemStack(item, 1, i));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -45,9 +45,7 @@ public class CommandConfigureChannels extends CommandBase {
|
||||
public void processCommand(ICommandSender sender, String[] args) {
|
||||
if (args.length == 0) throw new WrongUsageException(getCommandUsage(sender));
|
||||
|
||||
if (!(sender instanceof EntityPlayerMP)) throw new WrongUsageException("must be a player");
|
||||
|
||||
EntityPlayerMP player = (EntityPlayerMP) sender;
|
||||
if (!(sender instanceof EntityPlayerMP player)) throw new WrongUsageException("must be a player");
|
||||
|
||||
ItemStack heldItem = player.getHeldItem();
|
||||
if (heldItem == null || !(heldItem.getItem() instanceof ItemConstructableTrigger)) {
|
||||
|
||||
@@ -39,9 +39,7 @@ public class CommandRegistryDebug extends CommandBase {
|
||||
public void processCommand(ICommandSender sender, String[] args) {
|
||||
if (args.length != 1) throw new WrongUsageException(getCommandUsage(sender));
|
||||
|
||||
if (!(sender instanceof EntityPlayerMP)) throw new WrongUsageException("must be a player");
|
||||
|
||||
EntityPlayerMP player = (EntityPlayerMP) sender;
|
||||
if (!(sender instanceof EntityPlayerMP player)) throw new WrongUsageException("must be a player");
|
||||
|
||||
SortedRegistry<?> registry = SortedRegistry.getRegistry(args[0]);
|
||||
if (registry == null) throw new WrongUsageException("registry not found");
|
||||
|
||||
@@ -21,10 +21,9 @@ public class ItemBlockHint extends ItemBlock {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void addInformation(ItemStack aStack, EntityPlayer aPlayer, List aList, boolean aF3_H) {
|
||||
aList.add(translateToLocal("structurelib.blockhint.desc.0")); // Helps while building
|
||||
switch (aStack.getItemDamage()) {
|
||||
public void addInformation(ItemStack stack, EntityPlayer player, List<String> tooltip, boolean adv) {
|
||||
tooltip.add(translateToLocal("structurelib.blockhint.desc.0")); // Helps while building
|
||||
switch (stack.getItemDamage()) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
@@ -37,35 +36,36 @@ public class ItemBlockHint extends ItemBlock {
|
||||
case 9:
|
||||
case 10:
|
||||
case 11:
|
||||
aList.add(
|
||||
// Placeholder for a certain group.
|
||||
tooltip.add(
|
||||
EnumChatFormatting.AQUA.toString() + EnumChatFormatting.BOLD
|
||||
+ translateToLocal("structurelib.blockhint.desc.1")); // Placeholder for a certain
|
||||
// group.
|
||||
+ translateToLocal("structurelib.blockhint.desc.1"));
|
||||
break;
|
||||
case 12:
|
||||
aList.add(
|
||||
// General placeholder.
|
||||
tooltip.add(
|
||||
EnumChatFormatting.AQUA.toString() + EnumChatFormatting.BOLD
|
||||
+ translateToLocal("structurelib.blockhint.desc.2")); // General placeholder.
|
||||
+ translateToLocal("structurelib.blockhint.desc.2"));
|
||||
break;
|
||||
case 13:
|
||||
aList.add(
|
||||
// Make sure it contains Air material.
|
||||
tooltip.add(
|
||||
EnumChatFormatting.AQUA.toString() + EnumChatFormatting.BOLD
|
||||
+ translateToLocal("structurelib.blockhint.desc.3")); // Make sure it contains Air
|
||||
// material.
|
||||
+ translateToLocal("structurelib.blockhint.desc.3"));
|
||||
break;
|
||||
case 14:
|
||||
aList.add(
|
||||
// Make sure it does not contain Air material.
|
||||
tooltip.add(
|
||||
EnumChatFormatting.AQUA.toString() + EnumChatFormatting.BOLD
|
||||
+ translateToLocal("structurelib.blockhint.desc.4")); // Make sure it does not contain
|
||||
// Air material.
|
||||
+ translateToLocal("structurelib.blockhint.desc.4"));
|
||||
break;
|
||||
case 15:
|
||||
aList.add(EnumChatFormatting.BLUE + translateToLocal("structurelib.blockhint.desc.5")); // ERROR, what
|
||||
// did u expect?
|
||||
// ERROR, what did u expect?
|
||||
tooltip.add(EnumChatFormatting.BLUE + translateToLocal("structurelib.blockhint.desc.5"));
|
||||
break;
|
||||
default: // WTF?
|
||||
aList.add("Damn son where did you get that!?");
|
||||
aList.add(EnumChatFormatting.BLUE + "From outer space... I guess...");
|
||||
tooltip.add("Damn son where did you get that!?");
|
||||
tooltip.add(EnumChatFormatting.BLUE + "From outer space... I guess...");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,31 +45,30 @@ public class ItemConstructableTrigger extends Item {
|
||||
return ConstructableUtility.handle(stack, player, world, x, y, z, side);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void addInformation(ItemStack aStack, EntityPlayer ep, List aList, boolean boo) {
|
||||
public void addInformation(ItemStack stack, EntityPlayer player, List<String> tooltip, boolean adv) {
|
||||
if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
|
||||
aList.add(
|
||||
tooltip.add(
|
||||
translateToLocalFormatted(
|
||||
"item.structurelib.constructableTrigger.desc.lshift.0",
|
||||
ChannelDataAccessor.countChannelData(aStack)));
|
||||
ChannelDataAccessor.iterateChannelData(aStack).map(e -> e.getKey() + ": " + e.getValue())
|
||||
.forEach(aList::add);
|
||||
ChannelDataAccessor.countChannelData(stack)));
|
||||
ChannelDataAccessor.iterateChannelData(stack).map(e -> e.getKey() + ": " + e.getValue())
|
||||
.forEach(tooltip::add);
|
||||
} else {
|
||||
aList.add(translateToLocal("item.structurelib.constructableTrigger.desc.0")); // Triggers Constructable
|
||||
// Interface
|
||||
aList.add(BLUE + translateToLocal("item.structurelib.constructableTrigger.desc.1")); // Shows multiblock
|
||||
// construction
|
||||
// details,
|
||||
aList.add(BLUE + translateToLocal("item.structurelib.constructableTrigger.desc.2")); // just Use on a
|
||||
// multiblock
|
||||
// controller.
|
||||
aList.add(BLUE + translateToLocal("item.structurelib.constructableTrigger.desc.3")); // (Sneak Use in
|
||||
// creative to build)
|
||||
aList.add(BLUE + translateToLocal("item.structurelib.constructableTrigger.desc.4")); // Quantity affects
|
||||
// tier/mode/type
|
||||
if (ChannelDataAccessor.hasSubChannel(aStack))
|
||||
aList.add(translateToLocal("item.structurelib.constructableTrigger.desc.5"));
|
||||
// Tooltip text:
|
||||
// Triggers Constructable Interface
|
||||
// Shows multiblock construction details,
|
||||
// just Use on a multiblock controller.
|
||||
// (Sneak Use in creative to build)
|
||||
// Quantity affects tier/mode/type
|
||||
|
||||
tooltip.add(translateToLocal("item.structurelib.constructableTrigger.desc.0"));
|
||||
tooltip.add(BLUE + translateToLocal("item.structurelib.constructableTrigger.desc.1"));
|
||||
tooltip.add(BLUE + translateToLocal("item.structurelib.constructableTrigger.desc.2"));
|
||||
tooltip.add(BLUE + translateToLocal("item.structurelib.constructableTrigger.desc.3"));
|
||||
tooltip.add(BLUE + translateToLocal("item.structurelib.constructableTrigger.desc.4"));
|
||||
if (ChannelDataAccessor.hasSubChannel(stack))
|
||||
tooltip.add(translateToLocal("item.structurelib.constructableTrigger.desc.5"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -34,15 +34,14 @@ public class ItemFrontRotationTool extends Item {
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addInformation(ItemStack p_77624_1_, EntityPlayer p_77624_2_, List<String> aList, boolean p_77624_4_) {
|
||||
aList.add(translateToLocal("item.structurelib.frontRotationTool.desc.0")); // Triggers Front Rotation Interface
|
||||
aList.add(EnumChatFormatting.BLUE + translateToLocal("item.structurelib.frontRotationTool.desc.1")); // Rotates
|
||||
// only the
|
||||
// front
|
||||
// panel,
|
||||
aList.add(EnumChatFormatting.BLUE + translateToLocal("item.structurelib.frontRotationTool.desc.2")); // which
|
||||
// allows
|
||||
// structure
|
||||
// rotation.
|
||||
public void addInformation(ItemStack stack, EntityPlayer player, List<String> tooltip, boolean adv) {
|
||||
// Tooltip Text:
|
||||
// Triggers Front Rotation Interface
|
||||
// Rotates only the front panel,
|
||||
// which allows structure rotation.
|
||||
|
||||
tooltip.add(translateToLocal("item.structurelib.frontRotationTool.desc.0"));
|
||||
tooltip.add(EnumChatFormatting.BLUE + translateToLocal("item.structurelib.frontRotationTool.desc.1"));
|
||||
tooltip.add(EnumChatFormatting.BLUE + translateToLocal("item.structurelib.frontRotationTool.desc.2"));
|
||||
}
|
||||
}
|
||||
@@ -14,9 +14,7 @@ class ChatThrottleKey {
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof NoExplicitChannel)) return false;
|
||||
|
||||
NoExplicitChannel that = (NoExplicitChannel) o;
|
||||
if (!(o instanceof NoExplicitChannel that)) return false;
|
||||
|
||||
return subchannel.equals(that.subchannel);
|
||||
}
|
||||
|
||||
@@ -344,8 +344,7 @@ public class StructureUtility {
|
||||
new ChatComponentTranslation("structurelib.autoplace.missing_block", stack.func_151000_E()));
|
||||
return PlaceResult.REJECT;
|
||||
}
|
||||
if (block instanceof ICustomBlockSetting) {
|
||||
ICustomBlockSetting blockCustom = (ICustomBlockSetting) block;
|
||||
if (block instanceof ICustomBlockSetting blockCustom) {
|
||||
blockCustom.setBlock(world, x, y, z, meta);
|
||||
} else if (!stack.copy()
|
||||
.tryPlaceItemIntoWorld(actor, world, x, y, z, ForgeDirection.UP.ordinal(), 0.5f, 0.5f, 0.5f)) {
|
||||
@@ -638,7 +637,7 @@ public class StructureUtility {
|
||||
* given tier, then player will be allowed to use multiple kinds of blocks, but their tier is guaranteed to be the
|
||||
* same.
|
||||
* <p>
|
||||
* <h3>WARNING</h3> <b>You SHOULD NOT return notSet from your tierExtractor.</b> If you do so, we will have this
|
||||
* <h4>WARNING</h4> <b>You SHOULD NOT return notSet from your tierExtractor.</b> If you do so, we will have this
|
||||
* chain of events:
|
||||
* <ul>
|
||||
* <li>at check start, tier is reset to notSet
|
||||
@@ -651,7 +650,7 @@ public class StructureUtility {
|
||||
* doing its business
|
||||
* <li>Player enjoy a (probably) hilariously shaped multi and (probably) reduced build cost.
|
||||
* </ul>
|
||||
* <h3>Example Implementation</h3>
|
||||
* <h4>Example Implementation</h4>
|
||||
* <p>
|
||||
* Assume you have 16 tier, each map to one particular block's 16 different meta. You will usually want something
|
||||
* like this
|
||||
@@ -770,8 +769,7 @@ public class StructureUtility {
|
||||
public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
Pair<Block, Integer> hint = getHint(trigger);
|
||||
if (hint == null) return false;
|
||||
if (hint.getKey() instanceof ICustomBlockSetting) {
|
||||
ICustomBlockSetting block = (ICustomBlockSetting) hint.getKey();
|
||||
if (hint.getKey() instanceof ICustomBlockSetting block) {
|
||||
block.setBlock(world, x, y, z, hint.getValue());
|
||||
} else {
|
||||
world.setBlock(x, y, z, hint.getKey(), hint.getValue(), 2);
|
||||
@@ -2811,7 +2809,7 @@ public class StructureUtility {
|
||||
if (keyExtractor == null || map == null) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
return defer(keyExtractorCheck.andThen(map::get), keyExtractor.<IStructureElement<T>>andThen(map::get));
|
||||
return defer(keyExtractorCheck.andThen(map::get), keyExtractor.andThen(map::get));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,17 +1,3 @@
|
||||
/**
|
||||
* Copyright (c) 2022, glee8e This file is part of StructureLib.
|
||||
* <p>
|
||||
* StructureLib is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General
|
||||
* Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any
|
||||
* later version.
|
||||
* <p>
|
||||
* StructureLib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
* <p>
|
||||
* You should have received a copy of the GNU Lesser General Public License along with Foobar; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package com.gtnewhorizon.structurelib.util;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
package com.gtnewhorizon.structurelib.util;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class ItemStackArrayIterable implements Iterable<ItemStack> {
|
||||
|
||||
private final ItemStack[] stacks;
|
||||
|
||||
public ItemStackArrayIterable(ItemStack[] stacks) {
|
||||
this.stacks = stacks;
|
||||
}
|
||||
|
||||
public ItemStack[] getStacks() {
|
||||
return stacks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<ItemStack> iterator() {
|
||||
return new Iterator<ItemStack>() {
|
||||
|
||||
private int ptr = 0;
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return ptr < stacks.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack next() {
|
||||
return stacks[ptr++];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
stacks[ptr - 1] = null;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,6 @@ public class MiscUtils {
|
||||
|
||||
private MiscUtils() {}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Set<String> getTagKeys(NBTTagCompound tag) {
|
||||
return tag.func_150296_c();
|
||||
}
|
||||
|
||||
@@ -141,8 +141,7 @@ public class Vec3Impl implements Comparable<Vec3Impl> {
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
} else if (o instanceof Vec3Impl) {
|
||||
Vec3Impl vec3i = (Vec3Impl) o;
|
||||
} else if (o instanceof Vec3Impl vec3i) {
|
||||
return val0 == vec3i.val0 && val1 == vec3i.val1 && val2 == vec3i.val2;
|
||||
}
|
||||
return false;
|
||||
|
||||
Reference in new issue
Block a user