Code cleanup

Redundent assignments
Wrong comparison of string with MRL
Unneeded reflection
Try with resources
Metallurgy compat deleted (was outcommented) not updated since MC 1.7.10
This commit is contained in:
Tom Elfring committed 2017-08-06 13:38:32 +02:00
1 parent 6bdd00ac49
commit 5dd3dbb8a9
37 files changed
+94 -177

No files matched your search

+3 -7
View File
@@ -233,13 +233,9 @@ public class Pos3D extends Vec3d
double pitchRadians = Math.toRadians(pitch);
double rollRadians = Math.toRadians(roll);
double xPos = x;
double yPos = y;
double zPos = z;
xPos = x * Math.cos(yawRadians) * Math.cos(pitchRadians) + z * (Math.cos(yawRadians) * Math.sin(pitchRadians) * Math.sin(rollRadians) - Math.sin(yawRadians) * Math.cos(rollRadians)) + y * (Math.cos(yawRadians) * Math.sin(pitchRadians) * Math.cos(rollRadians) + Math.sin(yawRadians) * Math.sin(rollRadians));
zPos = x * Math.sin(yawRadians) * Math.cos(pitchRadians) + z * (Math.sin(yawRadians) * Math.sin(pitchRadians) * Math.sin(rollRadians) + Math.cos(yawRadians) * Math.cos(rollRadians)) + y * (Math.sin(yawRadians) * Math.sin(pitchRadians) * Math.cos(rollRadians) - Math.cos(yawRadians) * Math.sin(rollRadians));
yPos = -x * Math.sin(pitchRadians) + z * Math.cos(pitchRadians) * Math.sin(rollRadians) + y * Math.cos(pitchRadians) * Math.cos(rollRadians);
double xPos = x * Math.cos(yawRadians) * Math.cos(pitchRadians) + z * (Math.cos(yawRadians) * Math.sin(pitchRadians) * Math.sin(rollRadians) - Math.sin(yawRadians) * Math.cos(rollRadians)) + y * (Math.cos(yawRadians) * Math.sin(pitchRadians) * Math.cos(rollRadians) + Math.sin(yawRadians) * Math.sin(rollRadians));
double zPos = x * Math.sin(yawRadians) * Math.cos(pitchRadians) + z * (Math.sin(yawRadians) * Math.sin(pitchRadians) * Math.sin(rollRadians) + Math.cos(yawRadians) * Math.cos(rollRadians)) + y * (Math.sin(yawRadians) * Math.sin(pitchRadians) * Math.cos(rollRadians) - Math.cos(yawRadians) * Math.sin(rollRadians));
double yPos = -x * Math.sin(pitchRadians) + z * Math.cos(pitchRadians) * Math.sin(rollRadians) + y * Math.cos(pitchRadians) * Math.cos(rollRadians);
return new Pos3D(xPos, yPos, zPos);
}
@@ -2,7 +2,6 @@ package mekanism.api.transmitters;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import mekanism.api.Coord4D;
import mekanism.api.MekanismAPI;
@@ -12,9 +12,9 @@ public class ClientPlayerTracker
@SubscribeEvent
public void onPlayerChangedDimension(PlayerChangedDimensionEvent event)
{
Mekanism.jetpackOn.remove(event.player);
Mekanism.gasmaskOn.remove(event.player);
Mekanism.flamethrowerActive.remove(event.player);
Mekanism.freeRunnerOn.remove(event.player);
Mekanism.jetpackOn.remove(event.player.getName());
Mekanism.gasmaskOn.remove(event.player.getName());
Mekanism.flamethrowerActive.remove(event.player.getName());
Mekanism.freeRunnerOn.remove(event.player.getName());
}
}
@@ -17,7 +17,7 @@ public final class HolidayManager
private static Calendar calendar = Calendar.getInstance();
private static Minecraft mc = Minecraft.getMinecraft();
public static List<Holiday> holidays = new ArrayList<>();
private static List<Holiday> holidays = new ArrayList<>();
private static List<Holiday> holidaysNotified = new ArrayList<>();
public static void init()
@@ -115,23 +115,25 @@ public final class HolidayManager
@Override
public ResourceLocation filterSound(ResourceLocation sound)
{
if(sound.toString().contains("machine.enrichment"))
String soundResourceLocationString = sound.toString();
if(soundResourceLocationString.contains("machine.enrichment"))
{
return new ResourceLocation(sound.toString().replace("machine.enrichment", nutcracker[0]));
}
else if(sound.equals("machine.metalinfuser"))
else if(soundResourceLocationString.contains("machine.metalinfuser"))
{
return new ResourceLocation(sound.toString().replace("machine.metalinfuser", nutcracker[1]));
}
else if(sound.equals("machine.purification"))
else if(soundResourceLocationString.contains("machine.purification"))
{
return new ResourceLocation(sound.toString().replace("machine.purification", nutcracker[2]));
}
else if(sound.equals("machine.smelter"))
else if(soundResourceLocationString.contains("machine.smelter"))
{
return new ResourceLocation(sound.toString().replace("machine.smelter", nutcracker[3]));
}
else if(sound.equals("machine.dissolution"))
else if(soundResourceLocationString.contains("machine.dissolution"))
{
return new ResourceLocation(sound.toString().replace("machine.dissolution", nutcracker[4]));
}
@@ -84,7 +84,7 @@ public class GuiDynamicTank extends GuiMekanism
while(true)
{
int renderRemaining = 0;
int renderRemaining;
if(scale > 16)
{
@@ -80,7 +80,7 @@ public class GuiInductionMatrix extends GuiMekanism
while(true)
{
int renderRemaining = 0;
int renderRemaining;
if(scale > 16)
{
@@ -156,10 +156,8 @@ public class GuiSeismicReader extends GuiScreen
}
String capitalised = renderString.substring(0, 1).toUpperCase() + renderString.substring(1);
float renderScale = 1.0f;
int lengthX = fontRenderer.getStringWidth(capitalised);
renderScale = lengthX > 53 ? 53f / lengthX : 1.0f;
float renderScale = lengthX > 53 ? 53f / lengthX : 1.0f;
GlStateManager.pushMatrix();
GlStateManager.translate(guiWidth + 72, guiHeight + 16, 0);
@@ -133,7 +133,7 @@ public class GuiThermoelectricBoiler extends GuiMekanism
while(true)
{
int renderRemaining = 0;
int renderRemaining;
if(scale > 16)
{
@@ -210,7 +210,7 @@ public class GuiUpgradeManagement extends GuiMekanism
int xPos = 25;
int yPos = 7 + (i*12);
int yRender = 0;
int yRender;
if(upgrade == selectedType)
{
@@ -88,7 +88,7 @@ public abstract class GuiGauge<T> extends GuiElement
while(scale > 0)
{
int renderRemaining = 0;
int renderRemaining;
if(scale > 16)
{
@@ -115,7 +115,7 @@ public abstract class BaseRecipeCategory implements IRecipeCategory, IGuiWrapper
while(true)
{
int renderRemaining = 0;
int renderRemaining;
if(scale > 16)
{
@@ -39,7 +39,6 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.Timer;
import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.common.MinecraftForge;
@@ -539,12 +538,7 @@ public class MekanismRenderer
public static float getPartialTick()
{
try {
Timer t = (Timer)ReflectionUtils.getPrivateValue(Minecraft.getMinecraft(), Minecraft.class, ObfuscatedNames.Minecraft_timer);
return t.renderPartialTicks;
} catch(Exception e) {}
return 0;
return Minecraft.getMinecraft().getRenderPartialTicks();
}
public static ResourceLocation getBlocksTexture()
@@ -489,7 +489,7 @@ public class RenderResizableCuboid {
double[] arr = points[i];
for (int j = 0; j < arr.length; j++) {
double d = arr[j];
int used = 0;
int used;
if (j == 3 || j == 6) {// Shade or unused
used = (int) d;
} else {
@@ -12,8 +12,10 @@ import net.minecraft.block.Block;
public final class BoxBlacklistParser
{
public static File mekanismDir = new File(Mekanism.proxy.getMinecraftDir(), "config/mekanism");
public static File boxBlacklistFile = new File(mekanismDir, "BoxBlacklist.txt");
private static File mekanismDir = new File(Mekanism.proxy.getMinecraftDir(), "config/mekanism");
private static File boxBlacklistFile = new File(mekanismDir, "BoxBlacklist.txt");
private BoxBlacklistParser() {}
public static void load()
{
@@ -21,7 +23,7 @@ public final class BoxBlacklistParser
generateFiles();
readBlacklist();
} catch(Exception e) {
e.printStackTrace();
Mekanism.logger.warn("Couldn't load Cardboard Box blacklist", e);
}
}
@@ -49,61 +51,60 @@ public final class BoxBlacklistParser
private static void readBlacklist() throws IOException
{
BufferedReader reader = new BufferedReader(new FileReader(boxBlacklistFile));
int entries = 0;
String readingLine;
int line = 0;
while((readingLine = reader.readLine()) != null)
try(BufferedReader reader = new BufferedReader(new FileReader((boxBlacklistFile))))
{
line++;
int entries = 0;
if(readingLine.startsWith("#") || readingLine.trim().isEmpty())
String readingLine;
int line = 0;
while((readingLine = reader.readLine()) != null)
{
continue;
}
line++;
String[] split = readingLine.split(" ");
if(readingLine.startsWith("#") || readingLine.trim().isEmpty())
{
continue;
}
if(split.length != 2 || !isInteger(split[split.length-1]))
{
Mekanism.logger.error("BoxBlacklist.txt: Couldn't parse blacklist data on line " + line);
continue;
}
String blockName = split[0].trim();
Block block = Block.getBlockFromName(blockName);
if(block == null)
{
Mekanism.logger.error("BoxBlacklist.txt: Couldn't find specified block on line " + line);
continue;
}
String[] split = readingLine.split(" ");
MekanismAPI.addBoxBlacklist(block, Integer.parseInt(split[split.length-1]));
entries++;
if(split.length != 2 || !isInteger(split[split.length-1]))
{
Mekanism.logger.error("BoxBlacklist.txt: Couldn't parse blacklist data on line " + line);
continue;
}
String blockName = split[0].trim();
Block block = Block.getBlockFromName(blockName);
if(block == null)
{
Mekanism.logger.error("BoxBlacklist.txt: Couldn't find specified block on line " + line);
continue;
}
MekanismAPI.addBoxBlacklist(block, Integer.parseInt(split[split.length-1]));
entries++;
Mekanism.logger.info("Finished loading Cardboard Box blacklist (loaded " + entries + " entries)");
}
}
reader.close();
Mekanism.logger.info("Finished loading Cardboard Box blacklist (loaded " + entries + " entries)");
}
private static void writeExamples() throws IOException
{
BufferedWriter writer = new BufferedWriter(new FileWriter(boxBlacklistFile));
try(BufferedWriter writer = new BufferedWriter(new FileWriter(boxBlacklistFile)))
{
writer.append("# Use this file to tell Mekanism which blocks should not be picked up by a cardboard box.");
writer.newLine();
writer.append("# Use this file to tell Mekanism which blocks should not be picked up by a cardboard box.");
writer.newLine();
writer.append("# Proper syntax is \"NAME META\". Example (for stone):");
writer.newLine();
writer.append("# Proper syntax is \"NAME META\". Example (for stone):");
writer.newLine();
writer.append("# minecraft:stone 0");
writer.flush();
writer.close();
writer.append("# minecraft:stone 0");
}
}
}
@@ -2,17 +2,15 @@ package mekanism.common;
public final class ObfuscatedNames
{
public static String[] Minecraft_timer = new String[] {"timer", "field_71428_T"};
public static String[] GuiContainer_xSize = new String[] {"xSize", "field_146999_f"};
public static String[] GuiContainer_ySize = new String[] {"ySize", "field_147000_g"};
public static String[] GuiContainer_guiLeft = new String[] {"guiLeft", "field_147003_i"};
public static String[] GuiContainer_guiTop = new String[] {"guiTop", "field_147009_r"};
public static String[] NetHandlerPlayServer_floatingTickCount = new String[] {"floatingTickCount", "field_147365_f"};
public static String[] SoundHandler_sndManager = new String[] {"sndManager", "field_147694_f"};
public static String[] SoundManager_sndSystem = new String[] {"sndSystem", "field_148620_e"};
public static String[] SoundManager_invPlayingSounds = new String[] {"invPlayingSounds", "field_148630_i"};
public static String[] AbstractClientPlayer_getPlayerInfo = new String[] {"getPlayerInfo", "func_175155_b"};
public static String[] NetworkPlayerInfo_playerTextures = new String[] {"playerTextures", "field_187107_a"};
public static String[] Entity_copyDataFromOld = new String[] {"copyDataFromOld", "func_180432_n"};
public static String[] VertexBuffer_isDrawing = new String[] {"isDrawing", "field_179010_r"};
}
}
@@ -92,7 +92,7 @@ public class ThreadMinerSearch extends Thread
if(info.block != null && !tileEntity.getWorld().isAirBlock(new BlockPos(x, y, z)) && state.getBlockHardness(tileEntity.getWorld(), new BlockPos(x, y, z)) >= 0)
{
MinerFilter filterFound = null;
boolean canFilter = false;
boolean canFilter;
if(acceptedItems.containsKey(info))
{
@@ -461,7 +461,7 @@ public class TransporterManager
}
int amountRemaining = ((TileEntityBin)tileEntity).getMaxStoredCount()-copy.binAmount;
ItemStack ret = null;
ItemStack ret;
if(toInsert.getCount() <= amountRemaining)
{
@@ -238,7 +238,7 @@ public class EntityFlame extends Entity implements IEntityAdditionalSpawnData
return false;
}
ItemStack result = ItemStack.EMPTY;
ItemStack result;
try {
result = FurnaceRecipes.instance().getSmeltingResult(block.getStack(world));
@@ -76,11 +76,6 @@ public final class MekanismHooks
{
loadCCPeripheralProviders();
}
if(MetallurgyCoreLoaded)
{
//loadMettallurgy();
}
}
@Method(modid = IC2Integration.MODID)
@@ -181,59 +176,4 @@ public final class MekanismHooks
}
}
/*public void loadMetallurgy()
{
try
{
String[] setNames = {"base", "precious", "nether", "fantasy", "ender", "utility"};
for (String setName : setNames)
{
for (IOreInfo oreInfo : MetallurgyAPI.getMetalSet(setName).getOreList().values())
{
switch (oreInfo.getType())
{
case ALLOY:
if (oreInfo.getIngot() != null && oreInfo.getDust() != null)
{
RecipeHandler.addCrusherRecipe(MekanismUtils.size(oreInfo.getIngot(), 1), MekanismUtils.size(oreInfo.getDust(), 1));
}
break;
case DROP:
ItemStack ore = oreInfo.getOre();
ItemStack drop = oreInfo.getDrop();
if (drop != null && ore != null)
{
RecipeHandler.addEnrichmentChamberRecipe(MekanismUtils.size(ore, 1), MekanismUtils.size(drop, 12));
}
break;
default:
ItemStack ore = oreInfo.getOre();
ItemStack dust = oreInfo.getDust();
ItemStack ingot = oreInfo.getIngot();
if (ore != null && dust != null)
{
RecipeHandler.addEnrichmentChamberRecipe(MekanismUtils.size(ore, 1), MekanismUtils.size(dust, 2));
RecipeHandler.addCombinerRecipe(MekanismUtils.size(dust, 8), MekanismUtils.size(ore, 1));
}
if (ingot != null && dust != null)
{
RecipeHandler.addCrusherRecipe(MekanismUtils.size(ingot, 1), MekanismUtils.size(dust, 1));
}
break;
}
}
}
}
catch (Exception e)
{
}
}*/
}
@@ -3,6 +3,7 @@ package mekanism.common.integration.multipart;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Optional;
import io.netty.buffer.ByteBuf;
import mcmultipart.api.container.IMultipartContainer;
@@ -58,11 +59,15 @@ public class MultipartTileNetworkJoiner implements ITileNetwork
{
for(IPartSlot slot : container.getParts().keySet())
{
int tileIndex = tileList.indexOf(container.getPartTile(slot).get().getTileEntity());
if(tileIndex >= 0)
Optional<IMultipartTile> partTile = container.getPartTile(slot);
if(partTile.isPresent())
{
byte slotValue = slot instanceof EnumFaceSlot ? (byte)((EnumFaceSlot)slot).ordinal() : 6;
tileSideMap.put(slotValue, tileList.get(tileIndex));
int tileIndex = tileList.indexOf(partTile.get().getTileEntity());
if (tileIndex >= 0)
{
byte slotValue = slot instanceof EnumFaceSlot ? (byte) ((EnumFaceSlot) slot).ordinal() : 6;
tileSideMap.put(slotValue, tileList.get(tileIndex));
}
}
}
}
@@ -57,7 +57,7 @@ public class ItemBlockOre extends ItemBlock
@Override
public String getUnlocalizedName(ItemStack itemstack)
{
String name = "";
String name;
switch(itemstack.getItemDamage())
{
@@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
@@ -85,7 +86,7 @@ public class MultiblockManager<T extends SynchronizedData<T>>
{
TileEntity tileEntity = obj.getTileEntity(world);
if(!(tileEntity instanceof TileEntityMultiblock) || ((TileEntityMultiblock)tileEntity).getManager() != this || (getStructureId(((TileEntityMultiblock<?>)tileEntity)) != null && getStructureId(((TileEntityMultiblock)tileEntity)) != inventoryID))
if(!(tileEntity instanceof TileEntityMultiblock) || ((TileEntityMultiblock)tileEntity).getManager() != this || (getStructureId(((TileEntityMultiblock<?>)tileEntity)) != null && !Objects.equals(getStructureId(((TileEntityMultiblock) tileEntity)), inventoryID)))
{
if(!tilesToKill.containsKey(inventoryID))
{
@@ -37,8 +37,6 @@ public abstract class UpdateProtocol<T extends SynchronizedData<T>>
*/
public void loopThrough(Coord4D coord)
{
World world = pointer.getWorld();
int origX = coord.x, origY = coord.y, origZ = coord.z;
boolean isCorner = true;
@@ -52,8 +50,6 @@ public abstract class UpdateProtocol<T extends SynchronizedData<T>>
int x = 0, y = 0, z = 0;
int volume = 0;
if((isViableNode(origX + 1, origY, origZ) && isViableNode(origX - 1, origY, origZ)) ||
(isViableNode(origX, origY + 1, origZ) && isViableNode(origX, origY - 1, origZ)) ||
(isViableNode(origX, origY, origZ + 1) && isViableNode(origX, origY, origZ - 1)))
@@ -163,8 +159,6 @@ public abstract class UpdateProtocol<T extends SynchronizedData<T>>
innerNodes.add(new Coord4D(origX+x, origY+y, origZ+z, pointer.getWorld().provider.getDimension()));
}
}
volume++;
}
}
@@ -181,8 +175,6 @@ public abstract class UpdateProtocol<T extends SynchronizedData<T>>
}
}
volume += locations.size();
if(Math.abs(xmax-xmin)+1 <= 18 && Math.abs(ymax-ymin)+1 <= 18 && Math.abs(zmax-zmin)+1 <= 18)
{
if(rightBlocks && rightFrame && isHollow && isCorner)
@@ -114,7 +114,7 @@ public class PacketDigitalMinerGui implements IMessageHandler<DigitalMinerGuiMes
public static void openServerGui(MinerGuiPacket t, int guiType, World world, EntityPlayerMP playerMP, Coord4D obj, int i)
{
Container container = null;
Container container;
playerMP.closeContainer();
@@ -11,7 +11,6 @@ import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.MinecraftForge;
@@ -1,7 +1,6 @@
package mekanism.common.recipe;
import com.google.gson.JsonObject;
import mekanism.common.Mekanism;
import mekanism.common.config.MekanismConfig;
import net.minecraft.util.JsonUtils;
import net.minecraftforge.common.crafting.IConditionFactory;
@@ -4,7 +4,6 @@ import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import mekanism.common.Mekanism;
import mekanism.common.block.states.BlockStateMachine;
import mekanism.common.item.ItemControlCircuit;
import mekanism.generators.common.block.states.BlockStateGenerator;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
@@ -192,7 +192,7 @@ public class TileEntityElectrolyticSeparator extends TileEntityMachine implement
public int getUpgradedUsage(SeparatorRecipe recipe)
{
int possibleProcess = 0;
int possibleProcess
if(leftTank.getGasType() == recipe.recipeOutput.leftGas.getGas())
{
@@ -765,7 +765,7 @@ public class TileEntityQuantumEntangloporter extends TileEntityElectricBlock imp
@Override
public Set<ChunkPos> getChunkSet()
{
Set<ChunkPos> ret = new HashSet<ChunkPos>();
Set<ChunkPos> ret = new HashSet<>();
ret.add(new Chunk3D(Coord4D.get(this)).getPos());
@@ -99,7 +99,7 @@ public class TransmitterImpl<A, N extends DynamicNetwork<A,N>> extends Transmitt
{
IGridTransmitter transmitter = CapabilityUtils.getCapability(tile, Capabilities.GRID_TRANSMITTER_CAPABILITY, null);
if(TransmissionType.checkTransmissionType(transmitter, getTransmissionType()));
if(TransmissionType.checkTransmissionType(transmitter, getTransmissionType()))
{
return ((IGridTransmitter<A, N>)transmitter).getTransmitterNetwork();
}
@@ -142,7 +142,7 @@ public class GuiIndustrialTurbine extends GuiMekanism
while(true)
{
int renderRemaining = 0;
int renderRemaining;
if(scale > 16)
{
@@ -8,7 +8,6 @@ import mekanism.generators.common.content.turbine.SynchronizedTurbineData;
import mekanism.generators.common.tile.turbine.TileEntityTurbineRotor;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@@ -3,8 +3,6 @@ package mekanism.generators.common;
import buildcraft.api.mj.MjAPI;
import io.netty.buffer.ByteBuf;
import java.io.IOException;
import mekanism.api.MekanismAPI;
import mekanism.api.gas.Gas;
import mekanism.api.gas.GasRegistry;
@@ -243,7 +243,7 @@ public class TileEntityBioGenerator extends TileEntityGenerator implements IFlui
{
if(resource.getFluid() == FluidRegistry.getFluid("bioethanol"))
{
int fuelTransfer = 0;
int fuelTransfer;
int fuelNeeded = bioFuelSlot.MAX_FLUID - bioFuelSlot.fluidStored;
int attemptTransfer = resource.amount;
@@ -93,7 +93,7 @@ public class TileEntityGasGenerator extends TileEntityGenerator implements IGasH
{
setActive(true);
FuelGas fuel = null;
FuelGas fuel;
if(fuelTank.getStored() != 0)
{
@@ -118,11 +118,9 @@ public class TileEntitySolarGenerator extends TileEntityGenerator
public double getProduction()
{
double ret = 0;
if(seesSun)
{
ret = GENERATION_RATE;
double ret = GENERATION_RATE;
if(MekanismUtils.existsAndInstance(world.provider, "micdoodle8.mods.galacticraft.api.world.ISolarLevel"))
{
@@ -2,7 +2,6 @@ package mekanism.tools.common;
import io.netty.buffer.ByteBuf;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;