Formatting and code readability cleanup (#5467)

* First pass reformatting code to be more readable (common still not done)

* Replace google common collect calls with Java calls where possible

* Remove a bunch of unnecessary parenthesis leaving clarifying ones

* Add some missing @Nonnull annotations

* Fix checking wrong type

* Remove unnecessary continue/return statements and simplify comparision check

* Pass exception instead of directly printing stack trace

* Work on cleaning up common, through config so far

* Work on cleaning up common, through integration so far

* Work on cleaning up common, through network so far

* Work on cleaning up common, through tier so far

* Remove empty constructors that get created by default anyways

* Work on cleaning up common, through transmitters so far

* Work on cleaning up common, through utils so far

* Finish cleaning up spacing for common
This commit is contained in:
Richard Freimer authored and GitHub committed 2019-05-11 14:13:24 -04:00
1 parent 91ef2a5c3d
commit 0d4b50908f
909 files changed
+6234 -15623

No files matched your search

@@ -12,14 +12,14 @@ import mekanism.client.MekKeyHandler;
import mekanism.client.MekanismKeyHandler;
import mekanism.common.Mekanism;
import mekanism.common.MekanismBlocks;
import mekanism.common.tier.BaseTier;
import mekanism.common.tier.BinTier;
import mekanism.common.tier.InductionCellTier;
import mekanism.common.tier.InductionProviderTier;
import mekanism.common.base.ITierItem;
import mekanism.common.block.states.BlockStateBasic.BasicBlockType;
import mekanism.common.inventory.InventoryBin;
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
import mekanism.common.tier.BaseTier;
import mekanism.common.tier.BinTier;
import mekanism.common.tier.InductionCellTier;
import mekanism.common.tier.InductionProviderTier;
import mekanism.common.tile.TileEntityBin;
import mekanism.common.tile.TileEntityInductionCell;
import mekanism.common.tile.TileEntityInductionProvider;
@@ -43,12 +43,10 @@ import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
/**
* Item class for handling multiple metal block IDs. 0:0: Osmium Block 0:1: Bronze Block 0:2: Refined Obsidian 0:3:
* Charcoal Block 0:4: Refined Glowstone 0:5: Steel Block 0:6: Bin 0:7: Teleporter Frame 0:8: Steel Casing 0:9: Dynamic
* Tank 0:10: Structural Glass 0:11: Dynamic Valve 0:12: Copper Block 0:13: Tin Block 0:14: Thermal Evaporation
* Controller 0:15: Thermal Evaporation Valve 1:0: Thermal Evaporation Block 1:1: Induction Casing 1:2: Induction Port
* 1:3: Induction Cell 1:4: Induction Provider 1:5: Superheating Element 1:6: Pressure Disperser 1:7: Boiler Casing 1:8:
* Boiler Valve 1:9: Security Desk
* Item class for handling multiple metal block IDs. 0:0: Osmium Block 0:1: Bronze Block 0:2: Refined Obsidian 0:3: Charcoal Block 0:4: Refined Glowstone 0:5: Steel Block
* 0:6: Bin 0:7: Teleporter Frame 0:8: Steel Casing 0:9: Dynamic Tank 0:10: Structural Glass 0:11: Dynamic Valve 0:12: Copper Block 0:13: Tin Block 0:14: Thermal
* Evaporation Controller 0:15: Thermal Evaporation Valve 1:0: Thermal Evaporation Block 1:1: Induction Casing 1:2: Induction Port 1:3: Induction Cell 1:4: Induction
* Provider 1:5: Superheating Element 1:6: Pressure Disperser 1:7: Boiler Casing 1:8: Boiler Valve 1:9: Security Desk
*
* @author AidanBrady
*/
@@ -67,21 +65,18 @@ public class ItemBlockBasic extends ItemBlock implements IEnergizedItem, ITierIt
if (BasicBlockType.get(stack) == BasicBlockType.BIN) {
return 1; // Temporary no stacking due to #
}
return super.getItemStackLimit(stack);
}
public ItemStack getUnchargedCell(InductionCellTier tier) {
ItemStack stack = new ItemStack(MekanismBlocks.BasicBlock2, 1, 3);
setBaseTier(stack, tier.getBaseTier());
return stack;
}
public ItemStack getUnchargedProvider(InductionProviderTier tier) {
ItemStack stack = new ItemStack(MekanismBlocks.BasicBlock2, 1, 4);
setBaseTier(stack, tier.getBaseTier());
return stack;
}
@@ -90,7 +85,6 @@ public class ItemBlockBasic extends ItemBlock implements IEnergizedItem, ITierIt
if (itemstack.getTagCompound() == null) {
return BaseTier.BASIC;
}
return BaseTier.values()[itemstack.getTagCompound().getInteger("tier")];
}
@@ -99,7 +93,6 @@ public class ItemBlockBasic extends ItemBlock implements IEnergizedItem, ITierIt
if (itemstack.getTagCompound() == null) {
itemstack.setTagCompound(new NBTTagCompound());
}
itemstack.getTagCompound().setInteger("tier", tier.ordinal());
}
@@ -110,50 +103,35 @@ public class ItemBlockBasic extends ItemBlock implements IEnergizedItem, ITierIt
@Override
@SideOnly(Side.CLIENT)
public void addInformation(@Nonnull ItemStack itemstack, World world, @Nonnull List<String> list,
@Nonnull ITooltipFlag flag) {
public void addInformation(@Nonnull ItemStack itemstack, World world, @Nonnull List<String> list, @Nonnull ITooltipFlag flag) {
BasicBlockType type = BasicBlockType.get(itemstack);
if (type != null && type.hasDescription) {
if (!MekKeyHandler.getIsKeyPressed(MekanismKeyHandler.sneakKey)) {
if (type == BasicBlockType.BIN) {
InventoryBin inv = new InventoryBin(itemstack);
if (inv.getItemCount() > 0) {
list.add(EnumColor.BRIGHT_GREEN + inv.getItemType().getDisplayName());
String amountStr = inv.getItemCount() == Integer.MAX_VALUE ? LangUtils.localize("gui.infinite")
: "" + inv.getItemCount();
list.add(EnumColor.PURPLE + LangUtils.localize("tooltip.itemAmount") + ": " + EnumColor.GREY
+ amountStr);
String amountStr = inv.getItemCount() == Integer.MAX_VALUE ? LangUtils.localize("gui.infinite") : "" + inv.getItemCount();
list.add(EnumColor.PURPLE + LangUtils.localize("tooltip.itemAmount") + ": " + EnumColor.GREY + amountStr);
} else {
list.add(EnumColor.DARK_RED + LangUtils.localize("gui.empty"));
}
int cap = BinTier.values()[getBaseTier(itemstack).ordinal()].getStorage();
list.add(EnumColor.INDIGO + LangUtils.localize("tooltip.capacity") + ": " + EnumColor.GREY + (
cap == Integer.MAX_VALUE ? LangUtils.localize("gui.infinite") : cap) + " " + LangUtils
.localize("transmission.Items"));
list.add(EnumColor.INDIGO + LangUtils.localize("tooltip.capacity") + ": " + EnumColor.GREY +
(cap == Integer.MAX_VALUE ? LangUtils.localize("gui.infinite") : cap) + " " + LangUtils.localize("transmission.Items"));
} else if (type == BasicBlockType.INDUCTION_CELL) {
InductionCellTier tier = InductionCellTier.values()[getBaseTier(itemstack).ordinal()];
list.add(
tier.getBaseTier().getColor() + LangUtils.localize("tooltip.capacity") + ": " + EnumColor.GREY
+ MekanismUtils.getEnergyDisplay(tier.getMaxEnergy()));
list.add(tier.getBaseTier().getColor() + LangUtils.localize("tooltip.capacity") + ": " + EnumColor.GREY + MekanismUtils.getEnergyDisplay(tier.getMaxEnergy()));
} else if (type == BasicBlockType.INDUCTION_PROVIDER) {
InductionProviderTier tier = InductionProviderTier.values()[getBaseTier(itemstack).ordinal()];
list.add(tier.getBaseTier().getColor() + LangUtils.localize("tooltip.outputRate") + ": "
+ EnumColor.GREY + MekanismUtils.getEnergyDisplay(tier.getOutput()));
list.add(tier.getBaseTier().getColor() + LangUtils.localize("tooltip.outputRate") + ": " + EnumColor.GREY + MekanismUtils.getEnergyDisplay(tier.getOutput()));
}
if (getMaxEnergy(itemstack) > 0) {
list.add(EnumColor.BRIGHT_GREEN + LangUtils.localize("tooltip.storedEnergy") + ": " + EnumColor.GREY
+ MekanismUtils.getEnergyDisplay(getEnergy(itemstack)));
list.add(EnumColor.BRIGHT_GREEN + LangUtils.localize("tooltip.storedEnergy") + ": " + EnumColor.GREY + MekanismUtils.getEnergyDisplay(getEnergy(itemstack)));
}
list.add(LangUtils.localize("tooltip.hold") + " " + EnumColor.INDIGO + GameSettings
.getKeyDisplayString(MekanismKeyHandler.sneakKey.getKeyCode()) + EnumColor.GREY + " " + LangUtils
.localize("tooltip.forDetails") + ".");
list.add(LangUtils.localize("tooltip.hold") + " " + EnumColor.INDIGO + GameSettings.getKeyDisplayString(MekanismKeyHandler.sneakKey.getKeyCode()) +
EnumColor.GREY + " " + LangUtils.localize("tooltip.forDetails") + ".");
} else {
list.addAll(MekanismUtils.splitTooltip(type.getDescription(), itemstack));
}
@@ -172,29 +150,23 @@ public class ItemBlockBasic extends ItemBlock implements IEnergizedItem, ITierIt
if (!ItemDataUtils.hasData(stack, "newCount")) {
return ItemStack.EMPTY;
}
int newCount = ItemDataUtils.getInt(stack, "newCount");
ItemDataUtils.removeData(stack, "newCount");
ItemStack ret = stack.copy();
ItemDataUtils.setInt(ret, "itemCount", newCount);
return ret;
}
return ItemStack.EMPTY;
}
@Override
public boolean placeBlockAt(@Nonnull ItemStack stack, @Nonnull EntityPlayer player, World world,
@Nonnull BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, @Nonnull IBlockState state) {
public boolean placeBlockAt(@Nonnull ItemStack stack, @Nonnull EntityPlayer player, World world, @Nonnull BlockPos pos, EnumFacing side, float hitX, float hitY,
float hitZ, @Nonnull IBlockState state) {
boolean place = true;
BasicBlockType type = BasicBlockType.get(stack);
if (type == BasicBlockType.SECURITY_DESK) {
if (world.isOutsideBuildHeight(pos.up()) || !world.getBlockState(pos.up()).getBlock()
.isReplaceable(world, pos.up())) {
if (world.isOutsideBuildHeight(pos.up()) || !world.getBlockState(pos.up()).getBlock().isReplaceable(world, pos.up())) {
place = false;
}
}
@@ -203,39 +175,31 @@ public class ItemBlockBasic extends ItemBlock implements IEnergizedItem, ITierIt
if (type == BasicBlockType.BIN && stack.getTagCompound() != null) {
TileEntityBin tileEntity = (TileEntityBin) world.getTileEntity(pos);
InventoryBin inv = new InventoryBin(stack);
tileEntity.tier = BinTier.values()[getBaseTier(stack).ordinal()];
if (!inv.getItemType().isEmpty()) {
tileEntity.setItemType(inv.getItemType());
}
tileEntity.setItemCount(inv.getItemCount());
} else if (type == BasicBlockType.INDUCTION_CELL) {
TileEntityInductionCell tileEntity = (TileEntityInductionCell) world.getTileEntity(pos);
tileEntity.tier = InductionCellTier.values()[getBaseTier(stack).ordinal()];
if (!world.isRemote) {
Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(Coord4D.get(tileEntity),
tileEntity.getNetworkedData(new TileNetworkList())), new Range4D(Coord4D.get(tileEntity)));
Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(Coord4D.get(tileEntity), tileEntity.getNetworkedData(new TileNetworkList())),
new Range4D(Coord4D.get(tileEntity)));
}
} else if (type == BasicBlockType.INDUCTION_PROVIDER) {
TileEntityInductionProvider tileEntity = (TileEntityInductionProvider) world.getTileEntity(pos);
tileEntity.tier = InductionProviderTier.values()[getBaseTier(stack).ordinal()];
if (!world.isRemote) {
Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(Coord4D.get(tileEntity),
tileEntity.getNetworkedData(new TileNetworkList())), new Range4D(Coord4D.get(tileEntity)));
Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(Coord4D.get(tileEntity), tileEntity.getNetworkedData(new TileNetworkList())),
new Range4D(Coord4D.get(tileEntity)));
}
}
TileEntity tileEntity = world.getTileEntity(pos);
if (tileEntity instanceof IStrictEnergyStorage && !(tileEntity instanceof TileEntityMultiblock<?>)) {
((IStrictEnergyStorage) tileEntity).setEnergy(getEnergy(stack));
}
}
return place;
}
@@ -243,18 +207,13 @@ public class ItemBlockBasic extends ItemBlock implements IEnergizedItem, ITierIt
@Override
public String getTranslationKey(ItemStack itemstack) {
BasicBlockType type = BasicBlockType.get(itemstack);
if (type != null) {
String name = getTranslationKey() + "." + type.name;
if (type == BasicBlockType.BIN || type == BasicBlockType.INDUCTION_CELL
|| type == BasicBlockType.INDUCTION_PROVIDER) {
if (type == BasicBlockType.BIN || type == BasicBlockType.INDUCTION_CELL || type == BasicBlockType.INDUCTION_PROVIDER) {
name += getBaseTier(itemstack).getSimpleName();
}
return name;
}
return "Invalid Basic Block";
}
@@ -263,7 +222,6 @@ public class ItemBlockBasic extends ItemBlock implements IEnergizedItem, ITierIt
if (BasicBlockType.get(itemStack) == BasicBlockType.INDUCTION_CELL) {
return ItemDataUtils.getDouble(itemStack, "energyStored");
}
return 0;
}
@@ -279,7 +237,6 @@ public class ItemBlockBasic extends ItemBlock implements IEnergizedItem, ITierIt
if (BasicBlockType.get(itemStack) == BasicBlockType.INDUCTION_CELL) {
return InductionCellTier.values()[getBaseTier(itemStack).ordinal()].getMaxEnergy();
}
return 0;
}
@@ -303,8 +260,7 @@ public class ItemBlockBasic extends ItemBlock implements IEnergizedItem, ITierIt
// If this is a block of charcoal, set burn time to 16000 ticks (per Minecraft standard)
if (this.metaBlock == MekanismBlocks.BasicBlock && itemStack.getMetadata() == 3) {
return 16000; // ticks
} else {
return super.getItemBurnTime(itemStack);
}
return super.getItemBurnTime(itemStack);
}
}
}