Skip to content

Commit

Permalink
Refactoring and clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
RusTit committed Apr 7, 2018
1 parent 491bca8 commit f9efc57
Show file tree
Hide file tree
Showing 17 changed files with 78 additions and 63 deletions.
13 changes: 4 additions & 9 deletions core/src/main/java/binnie/core/AbstractMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import binnie.core.network.IPacketProvider;
import binnie.core.network.packet.MessageBinnie;
import binnie.core.proxy.IProxyCore;
import binnie.core.util.EmptyHelper;

public abstract class AbstractMod implements IPacketProvider, IInitializable {
protected final List<IInitializable> modules;
Expand All @@ -38,23 +39,17 @@ public AbstractMod() {

public abstract String getChannel();

private static final IPacketID[] PACKET_IDS_EMPTY = new IPacketID[0];

@Override
public IPacketID[] getPacketIDs() {
return PACKET_IDS_EMPTY;
return EmptyHelper.PACKET_IDS_EMPTY;
}

private static final IBinnieGUID[] BINNIE_GUIDS_EMPTY = new IBinnieGUID[0];

public IBinnieGUID[] getGUIDs() {
return BINNIE_GUIDS_EMPTY;
return EmptyHelper.BINNIE_GUIDS_EMPTY;
}

private static final Class<?>[] CLASS_CONFIG_EMPTY = new Class[0];

public Class<?>[] getConfigs() {
return CLASS_CONFIG_EMPTY;
return EmptyHelper.CLASS_ARRAY_EMPTY;
}

public abstract IProxyCore getProxy();
Expand Down
5 changes: 3 additions & 2 deletions core/src/main/java/binnie/core/gui/genesis/WindowGenesis.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import binnie.core.gui.minecraft.control.ControlTabIcon;
import binnie.core.gui.window.Panel;
import binnie.core.util.I18N;
import binnie.core.util.EmptyHelper;
import binnie.core.gui.ControlGenesisOption;
import net.minecraftforge.fml.relauncher.SideOnly;

Expand Down Expand Up @@ -126,11 +127,11 @@ public void initialiseClient() {
this.refreshTemplate(null);
}

private static final IChromosomeType[] CHROMOSOME_TYPES_EMPTY = new IChromosomeType[0];


private void refreshTemplate(@Nullable IChromosomeType selection) {
List<Gene> genes = new ArrayList<>();
IChromosomeType[] chromosomeTypes = Binnie.GENETICS.getChromosomeMap(this.root).keySet().toArray(CHROMOSOME_TYPES_EMPTY);
IChromosomeType[] chromosomeTypes = Binnie.GENETICS.getChromosomeMap(this.root).keySet().toArray(EmptyHelper.CHROMOSOME_TYPES_EMPTY);
for (IChromosomeType type : chromosomeTypes) {
IAllele allele = this.template[type.ordinal()];
if (allele == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import binnie.core.machines.transfer.TransferRequest;
import binnie.core.machines.transfer.TransferResult;
import binnie.core.network.packet.MessageContainerUpdate;
import binnie.core.util.EmptyHelper;
import com.google.common.base.Preconditions;
import com.google.common.collect.Sets;
import com.mojang.authlib.GameProfile;
Expand Down Expand Up @@ -383,7 +384,7 @@ public int getErrorType() {
return this.errorType;
}

private static final CustomSlot[] CUSTOM_SLOTS_EMPTY = new CustomSlot[0];


public CustomSlot[] getCustomSlots() {
final List<CustomSlot> slots = new ArrayList<>();
Expand All @@ -392,7 +393,7 @@ public CustomSlot[] getCustomSlots() {
slots.add((CustomSlot) object);
}
}
return slots.toArray(CUSTOM_SLOTS_EMPTY);
return slots.toArray(EmptyHelper.CUSTOM_SLOTS_EMPTY);
}

@SideOnly(Side.CLIENT)
Expand Down
5 changes: 2 additions & 3 deletions core/src/main/java/binnie/core/machines/MachineComponent.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package binnie.core.machines;

import binnie.core.util.EmptyHelper;
import net.minecraft.inventory.IInventory;
import net.minecraft.nbt.NBTTagCompound;

Expand Down Expand Up @@ -36,12 +37,10 @@ public NBTTagCompound writeToNBT(final NBTTagCompound nbttagcompound) {
public void onUpdate() {
}

private static final Class[] CLASSES_EMPTY = new Class[0];

public Class<?>[] getComponentInterfaces() {
Class<?>[] componentInterfaces = Binnie.MACHINE.getComponentInterfaces(this.getClass());
if (componentInterfaces == null) {
return CLASSES_EMPTY;
return EmptyHelper.CLASS_ARRAY_EMPTY;
}
return componentInterfaces;
}
Expand Down
5 changes: 2 additions & 3 deletions core/src/main/java/binnie/core/machines/ManagerMachine.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import binnie.core.machines.inventory.ValidatorSprite;
import binnie.core.machines.render.RenderTESRMachine;
import binnie.core.proxy.IBinnieProxy;
import binnie.core.util.EmptyHelper;
import forestry.api.core.INbtReadable;
import forestry.api.core.INbtWritable;

Expand Down Expand Up @@ -64,8 +65,6 @@ public MachinePackage getPackage(final String group, final String name) {
return (machineGroup == null) ? null : machineGroup.getPackage(name);
}

private static final Class[] CLASSES_EMPTY = new Class[0];

private void registerComponentClass(final Class<? extends MachineComponent> component) {
if (this.componentInterfaceMap.containsKey(component)) {
return;
Expand All @@ -76,7 +75,7 @@ private void registerComponentClass(final Class<? extends MachineComponent> comp
}
interfaces.remove(INbtWritable.class);
interfaces.remove(INbtReadable.class);
this.componentInterfaceMap.put(component, interfaces.toArray(CLASSES_EMPTY));
this.componentInterfaceMap.put(component, interfaces.toArray(EmptyHelper.CLASS_ARRAY_EMPTY));
final int networkID = this.nextNetworkID++;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.util.text.TextComponentString;

import binnie.core.machines.inventory.IInventoryMachine;
import binnie.core.util.EmptyHelper;

class DefaultMachineInventory implements IInventoryMachine {
private final DefaultInventory inventory;
Expand All @@ -30,11 +31,9 @@ public boolean isUsableByPlayer(final EntityPlayer entityplayer) {
public void markDirty() {
}

private static final int[] SLOTS_FOR_FACE_EMPTY = new int[0];

@Override
public int[] getSlotsForFace(EnumFacing side) {
return SLOTS_FOR_FACE_EMPTY;
return EmptyHelper.INT_ARRAY_EMPTY;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import javax.annotation.Nullable;

import binnie.core.util.EmptyHelper;
import net.minecraft.util.EnumFacing;

import net.minecraft.util.ResourceLocation;
Expand All @@ -15,11 +16,9 @@

class DefaultTankContainer implements ITankMachine {

private static final TankInfo[] TANK_INFOS_EMPTY = new TankInfo[0];

@Override
public TankInfo[] getTankInfos() {
return TANK_INFOS_EMPTY;
return EmptyHelper.TANK_INFO_EMPTY;
}

@Override
Expand Down Expand Up @@ -64,10 +63,8 @@ public IFluidHandler getHandler(int[] targetTanks) {
return null;
}

private static final IFluidTank[] FLUID_TANKS_EMPTY = new IFluidTank[0];

@Override
public IFluidTank[] getTanks() {
return FLUID_TANKS_EMPTY;
return EmptyHelper.FLUID_TANKS_EMPTY;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import binnie.core.machines.inventory.InventorySlot;
import binnie.core.machines.inventory.SlotValidator;
import binnie.core.machines.inventory.Validator;
import binnie.core.util.EmptyHelper;
import it.unimi.dsi.fastutil.ints.IntArraySet;
import it.unimi.dsi.fastutil.ints.IntSet;
import net.minecraft.entity.player.InventoryPlayer;
Expand Down Expand Up @@ -41,11 +42,9 @@ public ErrorState(IErrorStateDefinition definition, int data) {
}

public ErrorState(IErrorStateDefinition nameDefinition, IErrorStateDefinition definition) {
this(nameDefinition, definition, DATA_EMPTY);
this(nameDefinition, definition, EmptyHelper.INT_ARRAY_EMPTY);
}

private static final int[] DATA_EMPTY = new int[0];

public ErrorState(IErrorStateDefinition nameDefinition, IErrorStateDefinition definition, int[] data) {
EnumErrorType type = definition.getType();
this.data = data;
Expand All @@ -57,7 +56,7 @@ public ErrorState(IErrorStateDefinition nameDefinition, IErrorStateDefinition de
}

public ErrorState(NBTTagCompound nbtTagCompound) {
this.data = DATA_EMPTY;
this.data = EmptyHelper.INT_ARRAY_EMPTY;
this.itemError = false;
this.tankError = false;
this.powerError = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import binnie.core.machines.MachineComponent;
import binnie.core.machines.power.ITankMachine;
import binnie.core.machines.power.TankInfo;
import binnie.core.util.EmptyHelper;
import binnie.core.util.NBTUtil;

public class ComponentTankContainer extends MachineComponent implements ITankMachine {
Expand Down Expand Up @@ -129,15 +130,13 @@ public IFluidTank getTank(final int index) {
return this.getTanks()[index];
}

private static final IFluidTank[] FLUID_TANKS_EMPTY = new IFluidTank[0];

@Override
public IFluidTank[] getTanks() {
final List<IFluidTank> tankList = new ArrayList<>();
for (final TankSlot tank : this.tanks.values()) {
tankList.add(tank.getTank());
}
return tankList.toArray(FLUID_TANKS_EMPTY);
return tankList.toArray(EmptyHelper.FLUID_TANKS_EMPTY);
}

@Override
Expand Down Expand Up @@ -231,7 +230,7 @@ private IFluidTank[] getTanks() {
for (final TankSlot tank : this.tanks.values()) {
ltanks.add(tank.getTank());
}
return ltanks.toArray(FLUID_TANKS_EMPTY);
return ltanks.toArray(EmptyHelper.FLUID_TANKS_EMPTY);
}

private static int getTankIndexToFill(Map<Integer, TankSlot> tanks, @Nullable EnumFacing from, final FluidStack resource) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import binnie.core.gui.window.Panel;
import binnie.core.machines.Machine;
import binnie.core.machines.transfer.TransferRequest;
import binnie.core.util.EmptyHelper;

public class WindowCompartment extends WindowMachine implements IWindowAffectsShiftClick {
private final Map<Panel, Integer> panels;
Expand All @@ -63,8 +64,6 @@ public WindowCompartment(final EntityPlayer player, @Nullable final IInventory i
this.currentTab = 0;
}

private static final Integer[] DEFAULT_TABS_EMPTY = new Integer[0];

//TODO: Clean Up, Localise
@Override
@SideOnly(Side.CLIENT)
Expand All @@ -76,8 +75,8 @@ public void initialiseClient() {
int x = 16;
final int y = 32;
final ComponentCompartmentInventory inv = machine.getInterface(ComponentCompartmentInventory.class);
Integer[] tabs1 = DEFAULT_TABS_EMPTY;
Integer[] tabs2 = DEFAULT_TABS_EMPTY;
Integer[] tabs1 = EmptyHelper.DEFAULT_TABS_EMPTY;
Integer[] tabs2 = EmptyHelper.DEFAULT_TABS_EMPTY;
if (inv.getTabCount() == 4) {
tabs1 = new Integer[]{0, 1};
tabs2 = new Integer[]{2, 3};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import binnie.core.machines.inventory.IInventorySlots;
import binnie.core.machines.inventory.InventorySlot;
import binnie.core.machines.power.ITankMachine;
import binnie.core.util.EmptyHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
Expand All @@ -32,20 +33,18 @@ public class TransferRequest {
private boolean ignoreReadOnly;
private final List<TransferSlot> insertedSlots;

private static final int[] DEFAULT_SLOTS_TANKS_EMPTY = new int[0];

public TransferRequest(final ItemStack toTransfer, final IInventory destination) {
this.returnItem = ItemStack.EMPTY;
this.targetSlots = DEFAULT_SLOTS_TANKS_EMPTY;
this.targetTanks = DEFAULT_SLOTS_TANKS_EMPTY;
this.targetSlots = EmptyHelper.INT_ARRAY_EMPTY;
this.targetTanks = EmptyHelper.INT_ARRAY_EMPTY;
this.transferLiquids = true;
this.ignoreReadOnly = false;
this.insertedSlots = new ArrayList<>();
final int[] target = new int[destination.getSizeInventory()];
for (int i = 0; i < target.length; ++i) {
target[i] = i;
}
int[] targetTanks = DEFAULT_SLOTS_TANKS_EMPTY;
int[] targetTanks = EmptyHelper.INT_ARRAY_EMPTY;
if (destination instanceof ITankMachine) {
targetTanks = new int[((ITankMachine) destination).getTanks().length];
for (int j = 0; j < targetTanks.length; ++j) {
Expand Down
34 changes: 34 additions & 0 deletions core/src/main/java/binnie/core/util/EmptyHelper.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,41 @@
package binnie.core.util;

import binnie.core.api.genetics.IGene;
import binnie.core.gui.IBinnieGUID;
import binnie.core.gui.minecraft.CustomSlot;
import binnie.core.machines.power.TankInfo;
import binnie.core.network.IPacketID;
import forestry.api.genetics.IChromosomeType;
import net.minecraft.block.properties.IProperty;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.IFluidTank;

public final class EmptyHelper {
private EmptyHelper() {}

public static final String EMPTY_STRING = "";

public static final IPacketID[] PACKET_IDS_EMPTY = new IPacketID[0];

public static final IBinnieGUID[] BINNIE_GUIDS_EMPTY = new IBinnieGUID[0];

public static final Class<?>[] CLASS_ARRAY_EMPTY = new Class[0];

public static final IChromosomeType[] CHROMOSOME_TYPES_EMPTY = new IChromosomeType[0];

public static final CustomSlot[] CUSTOM_SLOTS_EMPTY = new CustomSlot[0];

public static final int[] INT_ARRAY_EMPTY = new int[0];

public static final TankInfo[] TANK_INFO_EMPTY = new TankInfo[0];

public static final IFluidTank[] FLUID_TANKS_EMPTY = new IFluidTank[0];

public static final Integer[] DEFAULT_TABS_EMPTY = new Integer[0];

public static final IProperty[] PROPERTIES_EMPTY = new IProperty[0];

public static final ItemStack[] ITEM_STACKS_EMPTY = new ItemStack[0];

public static final IGene[] GENES_EMPTY = new IGene[0];
}
6 changes: 2 additions & 4 deletions design/src/main/java/binnie/design/blocks/BlockDesign.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import binnie.design.api.IDesignSystem;
import binnie.design.api.IToolHammer;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.ItemMeshDefinition;
Expand Down Expand Up @@ -57,6 +56,7 @@
import binnie.core.models.ModelManager;
import binnie.core.models.ModelMutlipass;
import binnie.core.util.TileUtil;
import binnie.core.util.EmptyHelper;

public abstract class BlockDesign extends BlockMetadata implements IMultipassBlock<BlockDesign.Key>, IColoredBlock, ISpriteRegister, IItemModelRegister, IStateMapperRegister {
public static final EnumFacing[] RENDER_DIRECTIONS = new EnumFacing[]{EnumFacing.DOWN, EnumFacing.UP, EnumFacing.EAST, EnumFacing.WEST, EnumFacing.NORTH, EnumFacing.SOUTH};
Expand Down Expand Up @@ -199,11 +199,9 @@ public void registerModel(Item item, IModelManager manager) {
manager.registerItemModel(item, new DesignMeshDefinition());
}

private static final IProperty[] PROPERTIES_EMPTY = new IProperty[0];

@Override
protected BlockStateContainer createBlockState() {
return new ExtendedBlockState(this, PROPERTIES_EMPTY, new IUnlistedProperty[]{UnlistedBlockPos.POS, UnlistedBlockAccess.BLOCKACCESS});
return new ExtendedBlockState(this, EmptyHelper.PROPERTIES_EMPTY, new IUnlistedProperty[]{UnlistedBlockPos.POS, UnlistedBlockAccess.BLOCKACCESS});
}

@Override
Expand Down
Loading

0 comments on commit f9efc57

Please sign in to comment.