diff --git a/src/main/java/net/montoyo/wd/block/BlockKeyboardRight.java b/src/main/java/net/montoyo/wd/block/BlockKeyboardRight.java index 24b4c2d..3f1a9f3 100644 --- a/src/main/java/net/montoyo/wd/block/BlockKeyboardRight.java +++ b/src/main/java/net/montoyo/wd/block/BlockKeyboardRight.java @@ -31,6 +31,7 @@ import net.montoyo.wd.item.ItemLinker; import net.montoyo.wd.utilities.BlockSide; import net.montoyo.wd.utilities.Vector3i; +import javax.annotation.Nonnull; import java.util.Random; public class BlockKeyboardRight extends Block implements IPeripheral { @@ -49,6 +50,7 @@ public class BlockKeyboardRight extends Block implements IPeripheral { } @Override + @Nonnull protected BlockStateContainer createBlockState() { return new BlockStateContainer(this, properties); } @@ -84,11 +86,13 @@ public class BlockKeyboardRight extends Block implements IPeripheral { } @Override + @Nonnull public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) { return KEYBOARD_AABB; } @Override + @Nonnull public IBlockState getStateFromMeta(int meta) { return getDefaultState().withProperty(facing, meta); } @@ -99,11 +103,12 @@ public class BlockKeyboardRight extends Block implements IPeripheral { } @Override - public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player) { + @Nonnull + public ItemStack getPickBlock(@Nonnull IBlockState state, RayTraceResult target, @Nonnull World world, @Nonnull BlockPos pos, EntityPlayer player) { return new ItemStack(WebDisplays.INSTANCE.blockPeripheral, 1, 0); } - TileEntityKeyboard getTileEntity(World world, BlockPos pos) { + private TileEntityKeyboard getTileEntity(World world, BlockPos pos) { for(EnumFacing nf: EnumFacing.HORIZONTALS) { BlockPos np = pos.add(nf.getDirectionVec()); IBlockState ns = world.getBlockState(np); @@ -127,6 +132,7 @@ public class BlockKeyboardRight extends Block implements IPeripheral { } @Override + @Nonnull public EnumPushReaction getMobilityFlag(IBlockState state) { return EnumPushReaction.IGNORE; } @@ -176,7 +182,7 @@ public class BlockKeyboardRight extends Block implements IPeripheral { } @Override - public boolean removedByPlayer(IBlockState state, World world, BlockPos pos, EntityPlayer ply, boolean willHarvest) { + public boolean removedByPlayer(@Nonnull IBlockState state, World world, @Nonnull BlockPos pos, @Nonnull EntityPlayer ply, boolean willHarvest) { if(!world.isRemote) removeLeftPiece(world, pos, !ply.isCreative()); diff --git a/src/main/java/net/montoyo/wd/block/BlockPeripheral.java b/src/main/java/net/montoyo/wd/block/BlockPeripheral.java index d66677d..8f73f98 100644 --- a/src/main/java/net/montoyo/wd/block/BlockPeripheral.java +++ b/src/main/java/net/montoyo/wd/block/BlockPeripheral.java @@ -139,9 +139,10 @@ public class BlockPeripheral extends WDBlockContainer { if(te instanceof TileEntityPeripheralBase) return ((TileEntityPeripheralBase) te).onRightClick(player, hand, BlockSide.values()[facing.ordinal()]); - else if(te instanceof TileEntityServer) - return ((TileEntityServer) te).onPlayerRightClick(player); - else + else if(te instanceof TileEntityServer) { + ((TileEntityServer) te).onPlayerRightClick(player); + return true; + } else return false; } diff --git a/src/main/java/net/montoyo/wd/client/ClientProxy.java b/src/main/java/net/montoyo/wd/client/ClientProxy.java index 3c90cd9..a37aced 100644 --- a/src/main/java/net/montoyo/wd/client/ClientProxy.java +++ b/src/main/java/net/montoyo/wd/client/ClientProxy.java @@ -52,7 +52,6 @@ import net.montoyo.wd.core.JSServerRequest; import net.montoyo.wd.data.GuiData; import net.montoyo.wd.entity.TileEntityScreen; import net.montoyo.wd.item.ItemMulti; -import net.montoyo.wd.miniserv.Constants; import net.montoyo.wd.miniserv.client.Client; import net.montoyo.wd.net.server.SMessagePadCtrl; import net.montoyo.wd.net.server.SMessageScreenCtrl; @@ -71,7 +70,7 @@ public class ClientProxy extends SharedProxy implements IResourceManagerReloadLi public IBrowser view; private boolean isInHotbar; - private int id; + private final int id; private long lastURLSent; private PadData(String url, int id) { @@ -84,7 +83,7 @@ public class ClientProxy extends SharedProxy implements IResourceManagerReloadLi } private Minecraft mc; - private ArrayList modelBakers = new ArrayList<>(); + private final ArrayList modelBakers = new ArrayList<>(); private net.montoyo.mcef.api.API mcef; private MinePadRenderer minePadRenderer; private JSQueryDispatcher jsDispatcher; @@ -105,12 +104,12 @@ public class ClientProxy extends SharedProxy implements IResourceManagerReloadLi private long lastPointPacket; //Tracking - private ArrayList screenTracking = new ArrayList<>(); + private final ArrayList screenTracking = new ArrayList<>(); private int lastTracked = 0; //MinePads Management - private HashMap padMap = new HashMap<>(); - private ArrayList padList = new ArrayList<>(); + private final HashMap padMap = new HashMap<>(); + private final ArrayList padList = new ArrayList<>(); private int minePadTickCounter = 0; /**************************************** INHERITED METHODS ****************************************/ diff --git a/src/main/java/net/montoyo/wd/client/ResourceModelPair.java b/src/main/java/net/montoyo/wd/client/ResourceModelPair.java index d70d55e..c1f6664 100644 --- a/src/main/java/net/montoyo/wd/client/ResourceModelPair.java +++ b/src/main/java/net/montoyo/wd/client/ResourceModelPair.java @@ -9,8 +9,8 @@ import net.montoyo.wd.client.renderers.IModelBaker; public class ResourceModelPair { - private ModelResourceLocation resLoc; - private IModelBaker model; + private final ModelResourceLocation resLoc; + private final IModelBaker model; public ResourceModelPair(ModelResourceLocation rl, IModelBaker m) { resLoc = rl; diff --git a/src/main/java/net/montoyo/wd/client/StaticStateMapper.java b/src/main/java/net/montoyo/wd/client/StaticStateMapper.java index 1a06028..ad5f825 100644 --- a/src/main/java/net/montoyo/wd/client/StaticStateMapper.java +++ b/src/main/java/net/montoyo/wd/client/StaticStateMapper.java @@ -8,16 +8,19 @@ import net.minecraft.block.state.IBlockState; import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.client.renderer.block.statemap.StateMapperBase; +import javax.annotation.Nonnull; + public class StaticStateMapper extends StateMapperBase { - private ModelResourceLocation resLoc; + private final ModelResourceLocation resLoc; public StaticStateMapper(ModelResourceLocation rl) { resLoc = rl; } @Override - protected ModelResourceLocation getModelResourceLocation(IBlockState state) { + @Nonnull + protected ModelResourceLocation getModelResourceLocation(@Nonnull IBlockState state) { return resLoc; } diff --git a/src/main/java/net/montoyo/wd/client/WDScheme.java b/src/main/java/net/montoyo/wd/client/WDScheme.java index f3e547b..8baa669 100644 --- a/src/main/java/net/montoyo/wd/client/WDScheme.java +++ b/src/main/java/net/montoyo/wd/client/WDScheme.java @@ -17,7 +17,6 @@ import net.montoyo.wd.utilities.Util; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; -import java.net.URLEncoder; import java.util.UUID; public class WDScheme implements IScheme { diff --git a/src/main/java/net/montoyo/wd/client/gui/GuiScreenConfig.java b/src/main/java/net/montoyo/wd/client/gui/GuiScreenConfig.java index 1e9709b..d0783a9 100644 --- a/src/main/java/net/montoyo/wd/client/gui/GuiScreenConfig.java +++ b/src/main/java/net/montoyo/wd/client/gui/GuiScreenConfig.java @@ -23,8 +23,8 @@ import java.util.UUID; public class GuiScreenConfig extends WDScreen { //Screen data - private TileEntityScreen tes; - private BlockSide side; + private final TileEntityScreen tes; + private final BlockSide side; private NameUUIDPair owner; private NameUUIDPair[] friends; private int friendRights; @@ -36,7 +36,7 @@ public class GuiScreenConfig extends WDScreen { private boolean waitingAC; private int acFailTicks = -1; - private ArrayList acResults = new ArrayList<>(); + private final ArrayList acResults = new ArrayList<>(); private boolean adding; //Controls @@ -422,7 +422,7 @@ public class GuiScreenConfig extends WDScreen { public void updateMyRights() { NameUUIDPair me = new NameUUIDPair(mc.player.getGameProfile()); - int myRights = 0; + int myRights; boolean clientIsOwner = false; if(me.equals(owner)) { diff --git a/src/main/java/net/montoyo/wd/client/gui/GuiSetURL2.java b/src/main/java/net/montoyo/wd/client/gui/GuiSetURL2.java index f475927..63f31e5 100644 --- a/src/main/java/net/montoyo/wd/client/gui/GuiSetURL2.java +++ b/src/main/java/net/montoyo/wd/client/gui/GuiSetURL2.java @@ -8,7 +8,6 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.EnumHand; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; -import net.montoyo.mcef.api.IBrowser; import net.montoyo.wd.WebDisplays; import net.montoyo.wd.client.ClientProxy; import net.montoyo.wd.client.gui.controls.Button; @@ -31,10 +30,10 @@ public class GuiSetURL2 extends WDScreen { private Vector3i remoteLocation; //Pad data - private boolean isPad; + private final boolean isPad; //Common - private String screenURL; + private final String screenURL; @FillControl private TextField tfURL; diff --git a/src/main/java/net/montoyo/wd/client/gui/WDScreen.java b/src/main/java/net/montoyo/wd/client/gui/WDScreen.java index 0bf9b04..b70d286 100644 --- a/src/main/java/net/montoyo/wd/client/gui/WDScreen.java +++ b/src/main/java/net/montoyo/wd/client/gui/WDScreen.java @@ -21,11 +21,13 @@ import net.montoyo.wd.client.gui.loading.GuiLoader; import net.montoyo.wd.client.gui.loading.JsonOWrapper; import net.montoyo.wd.net.server.SMessageACQuery; import net.montoyo.wd.utilities.BlockSide; +import net.montoyo.wd.utilities.Bounds; import net.montoyo.wd.utilities.Log; import net.montoyo.wd.utilities.NameUUIDPair; import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; +import javax.annotation.Nonnull; import java.io.IOException; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; @@ -39,9 +41,9 @@ public abstract class WDScreen extends GuiScreen { public static WDScreen CURRENT_SCREEN = null; - protected ArrayList controls = new ArrayList<>(); - protected ArrayList postDrawList = new ArrayList<>(); - private HashMap, Method> eventMap = new HashMap<>(); + protected final ArrayList controls = new ArrayList<>(); + protected final ArrayList postDrawList = new ArrayList<>(); + private final HashMap, Method> eventMap = new HashMap<>(); protected boolean quitOnEscape = true; protected boolean defaultBackground = true; protected int syncTicks = 40; @@ -91,33 +93,11 @@ public abstract class WDScreen extends GuiScreen { protected void centerControls() { //Determine bounding box - int minX = Integer.MAX_VALUE; - int minY = Integer.MAX_VALUE; - int maxX = Integer.MIN_VALUE; - int maxY = Integer.MIN_VALUE; - - for(Control ctrl : controls) { - int x = ctrl.getX(); - int y = ctrl.getY(); - if(x < minX) - minX = x; - - if(y < minY) - minY = y; - - x += ctrl.getWidth(); - y += ctrl.getHeight(); - - if(x > maxX) - maxX = x; - - if(y >= maxY) - maxY = y; - } + Bounds bounds = Control.findBounds(controls); //Translation vector - int diffX = (width - maxX - minX) / 2; - int diffY = (height - maxY - minY) / 2; + int diffX = (width - bounds.maxX - bounds.minX) / 2; + int diffY = (height - bounds.maxY - bounds.minY) / 2; //Translate controls for(Control ctrl : controls) { @@ -152,7 +132,7 @@ public abstract class WDScreen extends GuiScreen { } @Override - protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { + protected void mouseClicked(int mouseX, int mouseY, int mouseButton) { for(Control ctrl: controls) ctrl.mouseClicked(mouseX, mouseY, mouseButton); } @@ -316,7 +296,7 @@ public abstract class WDScreen extends GuiScreen { } @Override - public void onResize(Minecraft mcIn, int w, int h) { + public void onResize(@Nonnull Minecraft mcIn, int w, int h) { for(Control ctrl : controls) ctrl.destroy(); diff --git a/src/main/java/net/montoyo/wd/client/gui/controls/Button.java b/src/main/java/net/montoyo/wd/client/gui/controls/Button.java index 573fe8e..007df39 100644 --- a/src/main/java/net/montoyo/wd/client/gui/controls/Button.java +++ b/src/main/java/net/montoyo/wd/client/gui/controls/Button.java @@ -8,8 +8,6 @@ import net.minecraft.client.gui.GuiButton; import net.montoyo.wd.client.gui.loading.JsonOWrapper; import org.lwjgl.input.Keyboard; -import java.io.IOException; - public class Button extends Control { protected final GuiButton btn; @@ -20,7 +18,7 @@ public class Button extends Control { public static class ClickEvent extends Event