Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small Cleanup #518

Merged
merged 9 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ developmentEnvironmentUserName = Developer

# Enables using modern Java syntax (up to version 17) via Jabel, while still targeting JVM 8.
# See https://github.com/bsideup/jabel for details on how this works.
enableModernJavaSyntax = false
enableModernJavaSyntax = true

# Enables injecting missing generics into the decompiled source code for a better coding experience.
# Turns most publicly visible List, Map, etc. into proper List<E>, Map<K, V> types.
enableGenericInjection = false
enableGenericInjection = true

# Generate a class with a String field for the mod version named as defined below.
# If generateGradleTokenClass is empty or not missing, no such class will be generated.
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/codechicken/nei/BookmarkPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -1294,8 +1294,7 @@ public void draw(int x, int y) {
RenderHelper.enableGUIStandardItemLighting();
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
GL11.glDisable(GL11.GL_DEPTH_TEST);
@SuppressWarnings("unchecked")
List<Slot> slots = (List<Slot>) this.gui.slotcontainer.inventorySlots;
List<Slot> slots = this.gui.slotcontainer.inventorySlots;

for (Slot slot : slots) {
if (slot != null && slot.getStack() != null) {
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/codechicken/nei/ClientHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ public static void loadHandlerOrdering() {

try (BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()))) {
NEIClientConfig.logger.info("Loading handler ordering from file {}", file);
CSVParser csvParser = CSVFormat.EXCEL.withCommentMarker('#').parse(reader);
CSVParser csvParser = CSVFormat.EXCEL.builder().setCommentMarker('#').build().parse(reader);
for (CSVRecord record : csvParser) {
final String handlerId = record.get(0);

Expand Down Expand Up @@ -410,9 +410,10 @@ public void drawScreen(int par1, int par2, float par3) {
}
};

@SuppressWarnings("serial")
CustomModLoadingErrorDisplayException e = new CustomModLoadingErrorDisplayException() {

private static final long serialVersionUID = -5593387489666663375L;

@Override
public void initGui(GuiErrorScreen errorScreen, FontRenderer fontRenderer) {
Minecraft.getMinecraft().displayGuiScreen(errorGui);
Expand Down
1 change: 0 additions & 1 deletion src/main/java/codechicken/nei/ContainerPotionCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ public void onContainerClosed(EntityPlayer player) {
if (!player.worldObj.isRemote) InventoryUtils.dropOnClose(player, potionInv);
}

@SuppressWarnings("unchecked")
@Override
public void handleServerPacket(PacketCustom packet) {
ItemStack potion = potionInv.getStackInSlot(0);
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/codechicken/nei/GuiExtendedCreativeInv.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ public boolean hideItemPanelSlot(GuiContainer gui, int x, int y, int w, int h) {
}

@Override
protected void handleMouseClick(Slot p_146984_1_, int p_146984_2_, int p_146984_3_, int p_146984_4_) {
protected void handleMouseClick(Slot slotIn, int slotId, int clickedButton, int clickType) {

// Hack for armor slots, because they are outside the container
if (p_146984_1_ != null && p_146984_4_ == 4 && p_146984_1_.xDisplayPosition < 0) {
p_146984_4_ = 0;
if (slotIn != null && clickType == 4 && slotIn.xDisplayPosition < 0) {
clickType = 0;
}

super.handleMouseClick(p_146984_1_, p_146984_2_, p_146984_3_, p_146984_4_);
super.handleMouseClick(slotIn, slotId, clickedButton, clickType);
}
}
1 change: 0 additions & 1 deletion src/main/java/codechicken/nei/ItemList.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ private void damageSearch(Item item, List<ItemStack> permutations) {

private String getTooltip(ItemStack stack) {
try {
@SuppressWarnings("unchecked")
final List<String> namelist = stack.getTooltip(Minecraft.getMinecraft().thePlayer, false);
final StringJoiner sb = new StringJoiner("\n");

Expand Down
11 changes: 6 additions & 5 deletions src/main/java/codechicken/nei/ItemMobSpawner.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public boolean onItemUse(ItemStack itemstack, EntityPlayer entityplayer, World w
}

@Override
public void addInformation(ItemStack itemstack, EntityPlayer par2EntityPlayer, List list, boolean par4) {
public void addInformation(ItemStack itemstack, EntityPlayer par2EntityPlayer, List<String> list, boolean par4) {
setDefaultTag(itemstack);
int meta = itemstack.getItemDamage();
if (meta == 0) {
Expand Down Expand Up @@ -106,9 +106,10 @@ private void setDefaultTag(ItemStack itemstack) {
public static void loadSpawners(World world) {
if (loaded) return;
loaded = true;
HashMap<Class<Entity>, String> classToStringMapping = (HashMap<Class<Entity>, String>) EntityList.classToStringMapping;
HashMap<Class<Entity>, Integer> classToIDMapping = (HashMap<Class<Entity>, Integer>) EntityList.classToIDMapping;
for (Class<Entity> eclass : classToStringMapping.keySet()) {
Map<Class<? extends Entity>, String> classToStringMapping = EntityList.classToStringMapping;
@SuppressWarnings("unchecked")
Map<Class<? extends Entity>, Integer> classToIDMapping = (Map<Class<? extends Entity>, Integer>) EntityList.classToIDMapping;
for (Class<? extends Entity> eclass : classToStringMapping.keySet()) {
if (!EntityLiving.class.isAssignableFrom(eclass)) continue;
try {
EntityLiving entityliving = (EntityLiving) eclass.getConstructor(new Class[] { World.class })
Expand All @@ -131,7 +132,7 @@ public static void loadSpawners(World world) {
}

@Override
public void getSubItems(Item item, CreativeTabs tab, List list) {
public void getSubItems(Item item, CreativeTabs tab, List<ItemStack> list) {
if (!NEIClientConfig.hasSMPCounterPart()) list.add(new ItemStack(item));
else for (int i : IDtoNameMap.keySet()) list.add(new ItemStack(item, 1, i));
}
Expand Down
1 change: 0 additions & 1 deletion src/main/java/codechicken/nei/ItemZoom.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ public void draw(int mx, int my) {
if (key > 0) {
String helpText = NEIClientUtils
.translate("itemzoom.toggle", NEIClientConfig.getKeyName(key, true));
@SuppressWarnings("unchecked")
List<String> lines = fontRenderer.listFormattedStringToWidth(helpText, this.availableAreaWidth);

for (String line : lines) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/codechicken/nei/NEIClientConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ public void run() {

for (Class<?> clazz : classDiscoverer.classes) {
try {
IConfigureNEI config = (IConfigureNEI) clazz.newInstance();
IConfigureNEI config = (IConfigureNEI) clazz.getConstructor().newInstance();
config.loadConfig();
NEIModContainer.plugins.add(config);
logger.debug("Loaded " + clazz.getName());
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/codechicken/nei/NEIServerUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,8 @@ public static ItemStack getSlotContents(EntityPlayer player, int slot, boolean c
else return player.inventory.getStackInSlot(slot);
}

@SuppressWarnings("unchecked")
public static void deleteAllItems(EntityPlayerMP player) {
for (Slot slot : (List<Slot>) player.openContainer.inventorySlots) slot.putStack(null);
for (Slot slot : player.openContainer.inventorySlots) slot.putStack(null);

player.sendContainerAndContentsToPlayer(player.openContainer, player.openContainer.getInventory());
}
Expand Down
1 change: 0 additions & 1 deletion src/main/java/codechicken/nei/SearchTokenParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public static interface ISearchParserProvider {

public ItemFilter getFilter(String searchText);

@SuppressWarnings("unchecked")
public static List<Language> getAllLanguages() {
return new ArrayList<>(Minecraft.getMinecraft().getLanguageManager().getLanguages());
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/codechicken/nei/SpawnerRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public void renderInventoryItem(RenderBlocks render, ItemStack item) {
BossStatus.hasColorModifier = bossHasColorModifier;
}

@SuppressWarnings("incomplete-switch")
@Override
public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
switch (type) {
Expand All @@ -75,6 +74,8 @@ public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
case ENTITY:
renderInventoryItem((RenderBlocks) data[0], item);
break;
default:
break;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/codechicken/nei/ThreadOperationTimer.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

public class ThreadOperationTimer extends Thread {

@SuppressWarnings("serial")
public static class TimeoutException extends RuntimeException {

private static final long serialVersionUID = -8621458005263888185L;
public final Object operation;

public TimeoutException(String msg, Object op) {
Expand Down
1 change: 0 additions & 1 deletion src/main/java/codechicken/nei/api/IOverlayHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public interface IOverlayHandler {
default List<Boolean> presenceOverlay(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex) {
final List<Boolean> itemPresenceSlots = new ArrayList<>();
final List<PositionedStack> ingredients = recipe.getIngredientStacks(recipeIndex);
@SuppressWarnings("unchecked")
final List<ItemStack> invStacks = ((List<Slot>) firstGui.inventorySlots.inventorySlots).stream()
.filter(
s -> s != null && s.getStack() != null
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/codechicken/nei/api/ItemInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public String[] header() {
public String[] dump(Block block, int id, String name) {
final Item item = Item.getItemFromBlock(block);
return new String[] { name, Integer.toString(id), Boolean.toString(item != null),
ItemInfo.itemOwners.get(block), block.getClass().getCanonicalName(),
ItemInfo.itemOwners.get(item), block.getClass().getCanonicalName(),
item != null ? EnumChatFormatting.getTextWithoutFormattingCodes(
GuiContainerManager.itemDisplayNameShort(new ItemStack(item))) : "null" };
}
Expand Down Expand Up @@ -462,7 +462,6 @@ private static void addSpawnEggs() {
addEntityEgg(EntityIronGolem.class, 0xC5C2C1, 0xffe1cc);
}

@SuppressWarnings("unchecked")
private static void addEntityEgg(Class<?> entity, int i, int j) {
int id = (Integer) EntityList.classToIDMapping.get(entity);
EntityList.entityEggs.put(id, new EntityEggInfo(id, i, j));
Expand Down
1 change: 1 addition & 0 deletions src/main/java/codechicken/nei/config/RegistryDumper.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public RegistryDumper(String name) {
super(name);
}

@SuppressWarnings("unchecked")
@Override
public Iterable<String[]> dump(int mode) {
LinkedList<String[]> list = new LinkedList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
*/
@SuppressWarnings("unused")
public class NEIRegisterHandlerInfosEvent extends Event {

public void registerHandlerInfo(HandlerInfo info) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ public static FontRenderer getFontRenderer(ItemStack stack) {
* @param includeHandlers If true tooltip handlers will add to the item tip
* @return A list of Strings representing the text to be displayed on each line of the tool tip.
*/
@SuppressWarnings("unchecked")
public static List<String> itemDisplayNameMultiline(ItemStack stack, GuiContainer gui, boolean includeHandlers) {
List<String> namelist = null;
try {
Expand Down Expand Up @@ -237,7 +236,6 @@ public static String fluidAmountDetails(int amount) {
public static String itemDisplayNameShort(ItemStack itemstack) {

try {
@SuppressWarnings("unchecked")
List<String> namelist = itemstack.getTooltip(Minecraft.getMinecraft().thePlayer, false);

if (!namelist.isEmpty() && !"".equals(namelist.get(0))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/
final class HideousLinkedList<E> extends LinkedList<E> {

private static final long serialVersionUID = -8504433551965776915L;
private final List<E> backing;

HideousLinkedList(List<E> backing) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
import codechicken.nei.PositionedStack;
import codechicken.nei.api.IOverlayHandler;

@SuppressWarnings("rawtypes, unchecked")
public class DefaultOverlayHandler implements IOverlayHandler {

public static Class gtItem;
public static Class<?> gtItem;

static {
try {
Expand Down Expand Up @@ -85,7 +84,6 @@ public void overlayRecipe(GuiContainer gui, IRecipeHandler recipe, int recipeInd
if (quantity != 0) moveIngredients(gui, assignedIngredients, quantity);
}

@SuppressWarnings("unchecked")
private boolean clearIngredients(GuiContainer gui, List<PositionedStack> ingreds) {
for (PositionedStack pstack : ingreds) for (Slot slot : (List<Slot>) gui.inventorySlots.inventorySlots)
if (slot.xDisplayPosition == pstack.relx + offsetx && slot.yDisplayPosition == pstack.rely + offsety) {
Expand All @@ -98,7 +96,6 @@ private boolean clearIngredients(GuiContainer gui, List<PositionedStack> ingreds
return true;
}

@SuppressWarnings("unchecked")
private void moveIngredients(GuiContainer gui, List<IngredientDistribution> assignedIngredients, int quantity) {
for (IngredientDistribution distrib : assignedIngredients) {
if (distrib.slots.length == 0) continue;
Expand Down Expand Up @@ -245,7 +242,6 @@ private List<IngredientDistribution> assignIngredients(List<PositionedStack> ing
return assignedIngredients;
}

@SuppressWarnings("unchecked")
private void findInventoryQuantities(GuiContainer gui, List<DistributedIngred> ingredStacks) {
for (Slot slot : (List<Slot>) gui.inventorySlots.inventorySlots) /* work out how much we have to go round */ {
if (slot.getHasStack() && canMoveFrom(slot, gui)) {
Expand All @@ -272,7 +268,6 @@ public boolean canMoveFrom(Slot slot, GuiContainer gui) {
return slot.inventory instanceof InventoryPlayer;
}

@SuppressWarnings("unchecked")
public Slot[][] mapIngredSlots(GuiContainer gui, List<PositionedStack> ingredients) {
Slot[][] recipeSlotList = new Slot[ingredients.size()][];
for (int i = 0; i < ingredients.size(); i++) /* identify slots */ {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public String getRecipeName() {
return NEIClientUtils.translate("recipe.fuel");
}

@SuppressWarnings("unchecked")
private void loadAllSmelting() {
// Note: Not safe as written for parallelStream
final Map<ItemStack, ItemStack> smeltingRecipes = (Map<ItemStack, ItemStack>) FurnaceRecipes.smelting()
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/codechicken/nei/recipe/GuiOverlayButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.util.stream.Collectors;

import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
import net.minecraftforge.client.event.GuiScreenEvent;
Expand Down Expand Up @@ -223,8 +222,7 @@ public boolean hasOverlay() {

private List<Boolean> presenceOverlay(List<PositionedStack> ingredients) {
final List<Boolean> itemPresenceSlots = new ArrayList<>();
@SuppressWarnings("unchecked")
final List<ItemStack> invStacks = ((List<Slot>) this.firstGui.inventorySlots.inventorySlots).stream()
final List<ItemStack> invStacks = this.firstGui.inventorySlots.inventorySlots.stream()
.filter(
s -> s != null && s.getStack() != null
&& s.getStack().stackSize > 0
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/codechicken/nei/recipe/GuiRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,6 @@ public void close() {
}
}

@SuppressWarnings("unchecked")
public void initGui() {
xSize = 176;
ySize = Math.min(Math.max(height - 68, 166), 370);
Expand Down Expand Up @@ -478,7 +477,6 @@ public void mouseReleased(int mouseX, int mouseY) {
refreshPage();
}

@SuppressWarnings("unchecked")
private void updateOverlayButtons() {
final List<Integer> indices = getRecipeIndices();

Expand Down
5 changes: 2 additions & 3 deletions src/main/java/codechicken/nei/recipe/GuiRecipeTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,9 @@ public static void loadHandlerInfo() {
File handlerFile = NEIClientConfig.handlerFile;
if (!handlerFile.exists()) {
NEIClientConfig.logger.info("Config file doesn't exist, creating");
try {
try (FileOutputStream fileOutputStream = new FileOutputStream(handlerFile.getAbsoluteFile())) {
assert handlerUrl != null;
ReadableByteChannel readableByteChannel = Channels.newChannel(handlerUrl.openStream());
FileOutputStream fileOutputStream = new FileOutputStream(handlerFile.getAbsoluteFile());
FileChannel fileChannel = fileOutputStream.getChannel();
fileChannel.transferFrom(readableByteChannel, 0, Long.MAX_VALUE);
} catch (IOException e) {
Expand All @@ -233,7 +232,7 @@ public static void loadHandlerInfo() {
}
}
try (BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()))) {
CSVParser csvParser = CSVFormat.EXCEL.withFirstRecordAsHeader().parse(reader);
CSVParser csvParser = CSVFormat.EXCEL.builder().setHeader().setSkipHeaderRecord(true).build().parse(reader);
for (CSVRecord record : csvParser) {
final String handler = record.get("handler");
final String modName = record.get("modName");
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/codechicken/nei/recipe/ItemsHistoryHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ public List<String> handleItemTooltip(GuiRecipe<?> gui, ItemStack stack, List<St
}

@Override
public boolean keyTyped(GuiRecipe gui, char keyChar, int keyCode, int recipe) {
public boolean keyTyped(GuiRecipe<?> gui, char keyChar, int keyCode, int recipe) {
return false;
}

@Override
public boolean mouseClicked(GuiRecipe gui, int button, int recipe) {
public boolean mouseClicked(GuiRecipe<?> gui, int button, int recipe) {
return true;
}

Expand Down
7 changes: 3 additions & 4 deletions src/main/java/codechicken/nei/recipe/RecipeCatalysts.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,9 @@ public static void loadCatalystInfo() {
File catalystFile = NEIClientConfig.catalystFile;
if (!catalystFile.exists()) {
NEIClientConfig.logger.info("Config file doesn't exist, creating");
try {
try (FileOutputStream fileOutputStream = new FileOutputStream(catalystFile.getAbsoluteFile())) {
assert handlerUrl != null;
ReadableByteChannel readableByteChannel = Channels.newChannel(handlerUrl.openStream());
FileOutputStream fileOutputStream = new FileOutputStream(catalystFile.getAbsoluteFile());
FileChannel fileChannel = fileOutputStream.getChannel();
fileChannel.transferFrom(readableByteChannel, 0, Long.MAX_VALUE);
} catch (IOException e) {
Expand All @@ -165,7 +164,7 @@ public static void loadCatalystInfo() {
}
}
try (BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()))) {
CSVParser csvParser = CSVFormat.EXCEL.withFirstRecordAsHeader().parse(reader);
CSVParser csvParser = CSVFormat.EXCEL.builder().setHeader().setSkipHeaderRecord(true).build().parse(reader);
for (CSVRecord record : csvParser) {
final String handler = record.get("handler");
final String modId = record.get("modId");
Expand Down Expand Up @@ -194,7 +193,7 @@ public static void loadCatalystInfo() {
try {
// gently handling copy&paste from handlers.csv
Class<?> clazz = Class.forName(handler);
Object object = clazz.newInstance();
Object object = clazz.getConstructor().newInstance();
if (object instanceof IRecipeHandler) {
if (forceClassName) {
forceClassNameList.add(handler);
Expand Down
Loading