* Enhanced code

This commit is contained in:
Nicolas BARBOTIN 2018-02-12 17:56:59 +01:00
parent c6128dc065
commit 0206f18a33
43 changed files with 213 additions and 222 deletions

View File

@ -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());

View File

@ -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;
}

View File

@ -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<ResourceModelPair> modelBakers = new ArrayList<>();
private final ArrayList<ResourceModelPair> 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<TileEntityScreen> screenTracking = new ArrayList<>();
private final ArrayList<TileEntityScreen> screenTracking = new ArrayList<>();
private int lastTracked = 0;
//MinePads Management
private HashMap<Integer, PadData> padMap = new HashMap<>();
private ArrayList<PadData> padList = new ArrayList<>();
private final HashMap<Integer, PadData> padMap = new HashMap<>();
private final ArrayList<PadData> padList = new ArrayList<>();
private int minePadTickCounter = 0;
/**************************************** INHERITED METHODS ****************************************/

View File

@ -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;

View File

@ -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;
}

View File

@ -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 {

View File

@ -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<NameUUIDPair> acResults = new ArrayList<>();
private final ArrayList<NameUUIDPair> 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)) {

View File

@ -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;

View File

@ -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<Control> controls = new ArrayList<>();
protected ArrayList<Control> postDrawList = new ArrayList<>();
private HashMap<Class<? extends Event>, Method> eventMap = new HashMap<>();
protected final ArrayList<Control> controls = new ArrayList<>();
protected final ArrayList<Control> postDrawList = new ArrayList<>();
private final HashMap<Class<? extends Event>, 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();

View File

@ -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<Button> {
private boolean shiftDown;
private final boolean shiftDown;
private ClickEvent(Button btn) {
source = btn;
@ -46,7 +44,7 @@ public class Button extends Control {
}
@Override
public void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
if(mouseButton == 0 && btn.mousePressed(mc, mouseX, mouseY)) {
selected = true;
btn.playPressSound(mc.getSoundHandler());

View File

@ -10,8 +10,6 @@ import net.minecraft.init.SoundEvents;
import net.minecraft.util.ResourceLocation;
import net.montoyo.wd.client.gui.loading.JsonOWrapper;
import java.io.IOException;
public class CheckBox extends BasicControl {
private static final ResourceLocation texUnchecked = new ResourceLocation("webdisplays", "textures/gui/checkbox.png");
@ -21,7 +19,7 @@ public class CheckBox extends BasicControl {
public static class CheckedEvent extends Event<CheckBox> {
private boolean checked;
private final boolean checked;
private CheckedEvent(CheckBox cb) {
source = cb;
@ -59,7 +57,7 @@ public class CheckBox extends BasicControl {
}
@Override
public void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
if(mouseButton == 0 && !disabled) {
if(mouseX >= x && mouseX <= x + WIDTH + 2 + labelW && mouseY >= y && mouseY < y + HEIGHT) {
checked = !checked;

View File

@ -16,7 +16,7 @@ public abstract class Container extends BasicControl {
protected int paddingX = 0;
protected int paddingY = 0;
protected ArrayList<Control> childs = new ArrayList<>();
protected final ArrayList<Control> childs = new ArrayList<>();
public <T extends Control> T addControl(T ctrl) {
childs.add(ctrl);
@ -48,7 +48,7 @@ public abstract class Container extends BasicControl {
}
@Override
public void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
if(!disabled) {
mouseX -= x + paddingX;
mouseY -= y + paddingY;

View File

@ -15,6 +15,7 @@ import net.minecraft.client.shader.Framebuffer;
import net.minecraft.util.ResourceLocation;
import net.montoyo.wd.client.gui.WDScreen;
import net.montoyo.wd.client.gui.loading.JsonOWrapper;
import net.montoyo.wd.utilities.Bounds;
import java.io.IOException;
@ -64,7 +65,7 @@ public abstract class Control {
public void keyDown(int key) {
}
public void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
}
public void mouseReleased(int mouseX, int mouseY, int state) {
@ -250,4 +251,32 @@ public abstract class Control {
name = json.getString("name", "");
}
public static Bounds findBounds(java.util.List<Control> controlList) {
int minX = Integer.MAX_VALUE;
int minY = Integer.MAX_VALUE;
int maxX = Integer.MIN_VALUE;
int maxY = Integer.MIN_VALUE;
for(Control ctrl : controlList) {
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;
}
return new Bounds(minX, minY, maxX, maxY);
}
}

View File

@ -6,6 +6,7 @@ package net.montoyo.wd.client.gui.controls;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.montoyo.wd.client.gui.loading.JsonOWrapper;
import net.montoyo.wd.utilities.Bounds;
import static org.lwjgl.opengl.GL11.*;
@ -161,37 +162,12 @@ public class ControlGroup extends Container {
}
public void pack() {
int minX = Integer.MAX_VALUE;
int minY = Integer.MAX_VALUE;
int maxX = Integer.MIN_VALUE;
int maxY = Integer.MIN_VALUE;
for(Control ctrl : childs) {
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 = findBounds(childs);
for(Control ctrl : childs)
ctrl.setPos(ctrl.getX() - minX, ctrl.getY() - minY);
ctrl.setPos(ctrl.getX() - bounds.minX, ctrl.getY() - bounds.minY);
maxX -= minX;
maxY -= minY;
width = maxX + paddingX * 2;
height = maxY + paddingY * 2;
width = bounds.getWidth() + paddingX * 2;
height = bounds.getHeight() + paddingY * 2;
}
@Override

View File

@ -7,7 +7,6 @@ package net.montoyo.wd.client.gui.controls;
import net.minecraft.client.shader.Framebuffer;
import net.montoyo.wd.client.gui.loading.JsonOWrapper;
import java.io.IOException;
import java.util.ArrayList;
import static org.lwjgl.opengl.GL11.*;
@ -15,8 +14,8 @@ import static org.lwjgl.opengl.GL11.*;
public class List extends BasicControl {
private static class Entry {
public String text;
public Object userdata;
public final String text;
public final Object userdata;
public Entry(String t, Object o) {
text = t;
@ -27,8 +26,8 @@ public class List extends BasicControl {
public static class EntryClick extends Event<List> {
private int id;
private Entry entry;
private final int id;
private final Entry entry;
private EntryClick(List lst) {
source = lst;
@ -52,7 +51,7 @@ public class List extends BasicControl {
private int width;
private int height;
private ArrayList<Entry> content = new ArrayList<>();
private final ArrayList<Entry> content = new ArrayList<>();
private Framebuffer fbo;
private int selected = -1;
private boolean update;
@ -224,7 +223,7 @@ public class List extends BasicControl {
}
@Override
public void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
if(!disabled && mouseButton == 0) {
if(isInScrollbar(mouseX, mouseY)) {
scrolling = true;

View File

@ -8,14 +8,13 @@ import net.minecraft.client.gui.GuiTextField;
import net.montoyo.wd.client.gui.loading.JsonOWrapper;
import org.lwjgl.input.Keyboard;
import java.io.IOException;
import java.util.ArrayList;
public class TextField extends Control {
public static class EnterPressedEvent extends Event<TextField> {
private String text;
private final String text;
private EnterPressedEvent(TextField field) {
source = field;
@ -30,7 +29,7 @@ public class TextField extends Control {
public static class TabPressedEvent extends Event<TextField> {
private String beginning;
private final String beginning;
private TabPressedEvent(TextField field) {
source = field;
@ -57,8 +56,8 @@ public class TextField extends Control {
public static class TextChangedEvent extends Event<TextField> {
private String oldContent;
private String newContent;
private final String oldContent;
private final String newContent;
private TextChangedEvent(TextField tf, String old) {
source = tf;
@ -89,7 +88,7 @@ public class TextField extends Control {
private boolean enabled = true;
private int textColor = DEFAULT_TEXT_COLOR;
private int disabledColor = DEFAULT_DISABLED_COLOR;
private ArrayList<TextChangeListener> listeners = new ArrayList<>();
private final ArrayList<TextChangeListener> listeners = new ArrayList<>();
public TextField() {
field = new GuiTextField(0, font, 1, 1, 198, 20);
@ -105,7 +104,7 @@ public class TextField extends Control {
}
@Override
public void keyTyped(char typedChar, int keyCode) throws IOException {
public void keyTyped(char typedChar, int keyCode) {
if(keyCode == Keyboard.KEY_RETURN || keyCode == Keyboard.KEY_NUMPADENTER)
parent.actionPerformed(new EnterPressedEvent(this));
else if(keyCode == Keyboard.KEY_TAB)
@ -129,7 +128,7 @@ public class TextField extends Control {
}
@Override
public void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
field.mouseClicked(mouseX, mouseY, mouseButton);
}

View File

@ -9,7 +9,6 @@ import net.minecraft.client.renderer.RenderItem;
import net.minecraft.item.ItemStack;
import net.montoyo.wd.client.gui.loading.JsonOWrapper;
import java.io.IOException;
import java.util.ArrayList;
public class UpgradeGroup extends BasicControl {
@ -96,7 +95,7 @@ public class UpgradeGroup extends BasicControl {
}
@Override
public void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
if(mouseButton == 0)
clickStack = overStack;
}
@ -113,7 +112,7 @@ public class UpgradeGroup extends BasicControl {
public static class ClickEvent extends Event<UpgradeGroup> {
private ItemStack clickStack;
private final ItemStack clickStack;
private ClickEvent(UpgradeGroup src) {
source = src;

View File

@ -4,7 +4,6 @@
package net.montoyo.wd.client.gui.loading;
import com.google.common.base.Throwables;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import net.minecraft.client.Minecraft;
@ -20,18 +19,18 @@ import java.util.HashMap;
public class GuiLoader {
private static HashMap<String, Class<? extends Control>> controls = new HashMap<>();
private static HashMap<ResourceLocation, JsonObject> resources = new HashMap<>();
private static final HashMap<String, Class<? extends Control>> CONTROLS = new HashMap<>();
private static final HashMap<ResourceLocation, JsonObject> RESOURCES = new HashMap<>();
public static void register(Class<? extends Control> cls) {
if(Modifier.isAbstract(cls.getModifiers()))
throw new RuntimeException("GG retard, you just registered an abstract class...");
String name = cls.getSimpleName();
if(controls.containsKey(name))
if(CONTROLS.containsKey(name))
throw new RuntimeException("Control class already registered or name taken!");
controls.put(name, cls);
CONTROLS.put(name, cls);
}
static {
@ -50,7 +49,7 @@ public class GuiLoader {
Control ret;
try {
ret = controls.get(json.getString("type", null)).newInstance();
ret = CONTROLS.get(json.getString("type", null)).newInstance();
} catch(InstantiationException e) {
Log.errorEx("Could not create control from JSON: instantiation exception", e);
throw new RuntimeException(e);
@ -64,7 +63,7 @@ public class GuiLoader {
}
public static JsonObject getJson(ResourceLocation resLoc) {
JsonObject ret = resources.get(resLoc);
JsonObject ret = RESOURCES.get(resLoc);
if(ret == null) {
IResource resource;
@ -82,14 +81,14 @@ public class GuiLoader {
resource.close();
} catch(IOException e) {}
resources.put(resLoc, ret);
RESOURCES.put(resLoc, ret);
}
return ret;
}
public static void clearCache() {
resources.clear();
RESOURCES.clear();
}
}

View File

@ -13,9 +13,9 @@ import net.minecraftforge.fml.relauncher.SideOnly;
public final class ModelMinePad extends ModelBase {
// fields
ModelRenderer base;
ModelRenderer left;
ModelRenderer right;
private final ModelRenderer base;
private final ModelRenderer left;
private final ModelRenderer right;
public ModelMinePad() {
textureWidth = 64;
@ -26,19 +26,19 @@ public final class ModelMinePad extends ModelBase {
base.setRotationPoint(1F, 0F, 3.5F);
base.setTextureSize(64, 32);
base.mirror = true;
setRotation(base, 0F, 0F, 0F);
clearRotation(base);
left = new ModelRenderer(this, 0, 10);
left.addBox(0F, 0F, 0F, 1, 1, 7);
left.setRotationPoint(0F, 0F, 4.5F);
left.setTextureSize(64, 32);
left.mirror = true;
setRotation(left, 0F, 0F, 0F);
clearRotation(left);
right = new ModelRenderer(this, 30, 10);
right.addBox(0F, 0F, 0F, 1, 1, 7);
right.setRotationPoint(15F, 0F, 4.5F);
right.setTextureSize(64, 32);
right.mirror = true;
setRotation(right, 0F, 0F, 0F);
clearRotation(right);
}
public final void render(float f5) {
@ -47,10 +47,10 @@ public final class ModelMinePad extends ModelBase {
right.render(f5);
}
private void setRotation(ModelRenderer model, float x, float y, float z) {
model.rotateAngleX = x;
model.rotateAngleY = y;
model.rotateAngleZ = z;
private void clearRotation(ModelRenderer model) {
model.rotateAngleX = 0.0f;
model.rotateAngleY = 0.0f;
model.rotateAngleZ = 0.0f;
}
}

View File

@ -20,6 +20,7 @@ import net.montoyo.wd.utilities.BlockSide;
import net.montoyo.wd.utilities.Vector3f;
import net.montoyo.wd.utilities.Vector3i;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
@ -27,9 +28,9 @@ import java.util.List;
public class ScreenBaker implements IModelBaker {
private static final List<BakedQuad> noQuads = ImmutableList.of();
private TextureAtlasSprite[] texs = new TextureAtlasSprite[16];
private BlockSide[] blockSides = BlockSide.values();
private EnumFacing[] blockFacings = EnumFacing.values();
private final TextureAtlasSprite[] texs = new TextureAtlasSprite[16];
private final BlockSide[] blockSides = BlockSide.values();
private final EnumFacing[] blockFacings = EnumFacing.values();
@Override
public void loadTextures(TextureMap texMap) {
@ -89,6 +90,7 @@ public class ScreenBaker implements IModelBaker {
}
@Override
@Nonnull
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand) {
if(side == null)
return noQuads;
@ -122,16 +124,19 @@ public class ScreenBaker implements IModelBaker {
}
@Override
@Nonnull
public TextureAtlasSprite getParticleTexture() {
return texs[15];
}
@Override
@Nonnull
public ItemCameraTransforms getItemCameraTransforms() {
return ItemCameraTransforms.DEFAULT;
}
@Override
@Nonnull
public ItemOverrideList getOverrides() {
return ItemOverrideList.NONE;
}

View File

@ -14,7 +14,6 @@ import net.minecraft.util.math.AxisAlignedBB;
import net.montoyo.wd.WebDisplays;
import net.montoyo.wd.client.ClientProxy;
import net.montoyo.wd.entity.TileEntityScreen;
import net.montoyo.wd.utilities.Rotation;
import net.montoyo.wd.utilities.Vector3f;
import net.montoyo.wd.utilities.Vector3i;

View File

@ -8,6 +8,8 @@ import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemStack;
import net.montoyo.wd.WebDisplays;
import javax.annotation.Nonnull;
public class WDCreativeTab extends CreativeTabs {
public WDCreativeTab() {
@ -15,6 +17,7 @@ public class WDCreativeTab extends CreativeTabs {
}
@Override
@Nonnull
public ItemStack getTabIconItem() {
return new ItemStack(WebDisplays.INSTANCE.blockScreen);
}

View File

@ -18,6 +18,7 @@ import net.montoyo.wd.utilities.BlockSide;
import net.montoyo.wd.utilities.Log;
import net.montoyo.wd.utilities.Vector3i;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public abstract class TileEntityPeripheralBase extends TileEntity implements IPeripheral {
@ -40,6 +41,7 @@ public abstract class TileEntityPeripheralBase extends TileEntity implements IPe
}
@Override
@Nonnull
public NBTTagCompound writeToNBT(NBTTagCompound tag) {
super.writeToNBT(tag);

View File

@ -15,6 +15,8 @@ import net.montoyo.wd.data.RedstoneCtrlData;
import net.montoyo.wd.utilities.BlockSide;
import net.montoyo.wd.utilities.Util;
import javax.annotation.Nonnull;
public class TileEntityRedCtrl extends TileEntityPeripheralBase {
private String risingEdgeURL = "";
@ -31,6 +33,7 @@ public class TileEntityRedCtrl extends TileEntityPeripheralBase {
}
@Override
@Nonnull
public NBTTagCompound writeToNBT(NBTTagCompound tag) {
super.writeToNBT(tag);

View File

@ -207,7 +207,7 @@ public class TileEntityScreen extends TileEntity {
}
private ArrayList<Screen> screens = new ArrayList<>();
private final ArrayList<Screen> screens = new ArrayList<>();
private AxisAlignedBB renderBB = new AxisAlignedBB(0.0, 0.0, 0.0, 1.0, 1.0, 1.0);
private boolean loaded = true;
public float ytVolume = Float.POSITIVE_INFINITY;

View File

@ -37,16 +37,14 @@ public class TileEntityServer extends TileEntity {
markDirty();
}
public boolean onPlayerRightClick(EntityPlayer ply) {
public void onPlayerRightClick(EntityPlayer ply) {
if(world.isRemote)
return true;
return;
if(WebDisplays.INSTANCE.miniservPort == 0)
Util.toast(ply, "noMiniserv");
else if(owner != null && ply instanceof EntityPlayerMP)
(new ServerData(pos, owner)).sendTo((EntityPlayerMP) ply);
return true;
}
}

View File

@ -8,7 +8,6 @@ import com.mojang.realmsclient.gui.ChatFormatting;
import net.minecraft.client.resources.I18n;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.montoyo.wd.WebDisplays;
import net.montoyo.wd.core.CraftComponent;

View File

@ -4,7 +4,6 @@
package net.montoyo.wd.item;
import com.mojang.realmsclient.gui.ChatFormatting;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.resources.I18n;
import net.minecraft.client.util.ITooltipFlag;

View File

@ -23,6 +23,7 @@ import net.montoyo.wd.block.BlockScreen;
import net.montoyo.wd.entity.TileEntityScreen;
import net.montoyo.wd.utilities.*;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
@ -36,6 +37,7 @@ public class ItemOwnershipThief extends Item {
}
@Override
@Nonnull
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos_, EnumHand hand, EnumFacing side_, float hitX, float hitY, float hitZ) {
if(player.isSneaking())
return EnumActionResult.PASS;

View File

@ -20,6 +20,7 @@ import net.montoyo.wd.WebDisplays;
import net.montoyo.wd.block.BlockKeyboardRight;
import net.montoyo.wd.core.DefaultPeripheral;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
@ -30,7 +31,7 @@ public class ItemPeripheral extends ItemMultiTexture {
}
@Override
public boolean canPlaceBlockOnSide(World world, BlockPos pos_, EnumFacing side, EntityPlayer player, ItemStack stack) {
public boolean canPlaceBlockOnSide(World world, @Nonnull BlockPos pos_, @Nonnull EnumFacing side, EntityPlayer player, ItemStack stack) {
if(stack.getMetadata() != 0) //Keyboard
return true;
@ -51,13 +52,15 @@ public class ItemPeripheral extends ItemMultiTexture {
}
@Override
public void addInformation(ItemStack is, @Nullable World world, List<String> tt, ITooltipFlag ttFlags) {
if(is.getMetadata() == 1) //CC Interface
tt.add("" + ChatFormatting.RED + I18n.format("webdisplays.message.missingCC")); //CC is not available for 1.12.2
else if(is.getMetadata() == 2 && !WebDisplays.isOpenComputersAvailable()) //OC Interface
tt.add("" + ChatFormatting.RED + I18n.format("webdisplays.message.missingOC"));
else if(is.getMetadata() == 11 && WebDisplays.PROXY.isMiniservDisabled()) //Server
tt.add("" + ChatFormatting.RED + I18n.format("webdisplays.message.noMiniserv"));
public void addInformation(@Nullable ItemStack is, @Nullable World world, @Nullable List<String> tt, @Nullable ITooltipFlag ttFlags) {
if(is != null && tt != null) {
if(is.getMetadata() == 1) //CC Interface
tt.add("" + ChatFormatting.RED + I18n.format("webdisplays.message.missingCC")); //CC is not available for 1.12.2
else if(is.getMetadata() == 2 && !WebDisplays.isOpenComputersAvailable()) //OC Interface
tt.add("" + ChatFormatting.RED + I18n.format("webdisplays.message.missingOC"));
else if(is.getMetadata() == 11 && WebDisplays.PROXY.isMiniservDisabled()) //Server
tt.add("" + ChatFormatting.RED + I18n.format("webdisplays.message.noMiniserv"));
}
}
}

View File

@ -22,6 +22,8 @@ import net.montoyo.wd.utilities.Multiblock;
import net.montoyo.wd.utilities.Util;
import net.montoyo.wd.utilities.Vector3i;
import javax.annotation.Nonnull;
public class ItemScreenConfigurator extends Item {
public ItemScreenConfigurator() {
@ -32,6 +34,7 @@ public class ItemScreenConfigurator extends Item {
}
@Override
@Nonnull
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side_, float hitX, float hitY, float hitZ) {
if(player.isSneaking() || !(world.getBlockState(pos).getBlock() instanceof BlockScreen))
return EnumActionResult.PASS;

View File

@ -13,7 +13,6 @@ import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.ByteBuffer;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.SocketChannel;

View File

@ -6,23 +6,23 @@ package net.montoyo.wd.miniserv;
public abstract class Constants {
public static int FUPA_STATUS_BAD_NAME = 1;
public static int FUPA_STATUS_INVALID_SIZE = 2;
public static int FUPA_STATUS_EXCEEDS_QUOTA = 3;
public static int FUPA_STATUS_OCCUPIED = 4;
public static int FUPA_STATUS_FILE_EXISTS = 5;
public static int FUPA_STATUS_INTERNAL_ERROR = 6;
public static int FUPA_STATUS_USER_ABORT = 7;
public static int FUPA_STATUS_LIER = 8;
public static int FUPA_STATUS_CONNECTION_LOST = 9;
public static final int FUPA_STATUS_BAD_NAME = 1;
public static final int FUPA_STATUS_INVALID_SIZE = 2;
public static final int FUPA_STATUS_EXCEEDS_QUOTA = 3;
public static final int FUPA_STATUS_OCCUPIED = 4;
public static final int FUPA_STATUS_FILE_EXISTS = 5;
public static final int FUPA_STATUS_INTERNAL_ERROR = 6;
public static final int FUPA_STATUS_USER_ABORT = 7;
public static final int FUPA_STATUS_LIER = 8;
public static final int FUPA_STATUS_CONNECTION_LOST = 9;
public static int GETF_STATUS_BAD_NAME = 1;
public static int GETF_STATUS_NOT_FOUND = 2;
public static int GETF_STATUS_INTERNAL_ERROR = 3;
public static int GETF_STATUS_CONNECTION_LOST = 4;
public static int GETF_STATUS_TIMED_OUT = 5;
public static final int GETF_STATUS_BAD_NAME = 1;
public static final int GETF_STATUS_NOT_FOUND = 2;
public static final int GETF_STATUS_INTERNAL_ERROR = 3;
public static final int GETF_STATUS_CONNECTION_LOST = 4;
public static final int GETF_STATUS_TIMED_OUT = 5;
public static long CLIENT_TIMEOUT = 30000L;
public static long CLIENT_PING_PERIOD = 5000L;
public static final long CLIENT_TIMEOUT = 30000L;
public static final long CLIENT_PING_PERIOD = 5000L;
}

View File

@ -337,10 +337,6 @@ public class Client extends AbstractClient implements Runnable {
((ClientTaskDeleteFile) currentTask).onStatusPacket(dis.readByte());
}
@PacketHandler(PacketID.PING)
public void handlePing(DataInputStream dis) {
}
public void nextTask() {
if(currentTask != null)
currentTask.onFinished();

View File

@ -154,7 +154,6 @@ public class Server implements Runnable {
clientMap.put(chan, toAdd);
clientList.add(toAdd);
toAdd.onConnect();
}
}

View File

@ -50,9 +50,6 @@ public class ServerClient extends AbstractClient {
remove = true;
}
public void onConnect() {
}
void setShouldRemove() {
remove = true;
}

View File

@ -15,8 +15,8 @@ import java.util.ArrayList;
public abstract class Messages {
private static DefaultHandler DEFAULT_HANDLER = new DefaultHandler();
private static Class<? extends IMessage>[] messages;
private static final DefaultHandler DEFAULT_HANDLER = new DefaultHandler();
private static final Class<? extends IMessage>[] MESSAGES;
static {
ArrayList<Class<? extends IMessage>> l = new ArrayList<>();
l.add(CMessageAddScreen.class);
@ -34,11 +34,11 @@ public abstract class Messages {
l.add(CMessageServerInfo.class);
l.add(CMessageCloseGui.class);
messages = l.toArray(new Class[0]);
MESSAGES = l.toArray(new Class[0]);
}
public static void registerAll(SimpleNetworkWrapper wrapper) {
for(Class<? extends IMessage> md: messages) {
for(Class<? extends IMessage> md: MESSAGES) {
Message data = md.getAnnotation(Message.class);
if(data == null)
throw new RuntimeException("Missing @Message annotation for message class " + md.getSimpleName());

View File

@ -252,7 +252,7 @@ public class CMessageScreenUpdate implements IMessage, Runnable {
} else if(action == UPDATE_ROTATION)
tes.setRotation(side, rotation);
else
Log.warning("===> TODO"); //TODO
Log.warning("Caught invalid CMessageScreenUpdate with action ID %d", action);
}
}

View File

@ -18,7 +18,6 @@ import net.montoyo.wd.net.Message;
import net.montoyo.wd.net.client.CMessageACResult;
import net.montoyo.wd.utilities.NameUUIDPair;
import java.util.ArrayList;
import java.util.Arrays;
@Message(messageId = 5, side = Side.SERVER)

View File

@ -337,7 +337,7 @@ public class SMessageScreenCtrl implements IMessage, Runnable {
checkPermission(tes, ScreenRights.CHANGE_RESOLUTION);
tes.setRotation(side, rotation);
} else
Log.info("SMessageScreenCtrl: TODO"); //TODO: other ctrl messages
Log.warning("Caught SMessageScreenCtrl with invalid control ID %d from player %s (UUID %s)", ctrl, player.getName(), player.getGameProfile().getId().toString());
}
public static class Handler implements IMessageHandler<SMessageScreenCtrl, IMessage> {

View File

@ -0,0 +1,29 @@
/*
* Copyright (C) 2018 BARBOTIN Nicolas
*/
package net.montoyo.wd.utilities;
public final class Bounds {
public final int minX;
public final int minY;
public final int maxX;
public final int maxY;
public Bounds(int minX, int minY, int maxX, int maxY) {
this.minX = minX;
this.minY = minY;
this.maxX = maxX;
this.maxY = maxY;
}
public final int getWidth() {
return maxX - minX;
}
public final int getHeight() {
return maxY - minY;
}
}

View File

@ -6,7 +6,7 @@ package net.montoyo.wd.utilities;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.montoyo.wd.block.BlockScreen;
import net.montoyo.wd.WebDisplays;
public abstract class Multiblock {
@ -50,7 +50,7 @@ public abstract class Multiblock {
do {
pos.add(side.left);
pos.toBlock(bp);
} while(override.apply(pos, world.getBlockState(bp).getBlock() instanceof BlockScreen));
} while(override.apply(pos, world.getBlockState(bp).getBlock() == WebDisplays.INSTANCE.blockScreen));
pos.add(side.right);
@ -58,7 +58,7 @@ public abstract class Multiblock {
do {
pos.add(side.down);
pos.toBlock(bp);
} while(override.apply(pos, world.getBlockState(bp).getBlock() instanceof BlockScreen));
} while(override.apply(pos, world.getBlockState(bp).getBlock() == WebDisplays.INSTANCE.blockScreen));
pos.add(side.up);
}
@ -77,7 +77,7 @@ public abstract class Multiblock {
pos.add(side.up);
pos.toBlock(bp);
ret.y++;
} while(world.getBlockState(bp).getBlock() instanceof BlockScreen);
} while(world.getBlockState(bp).getBlock() == WebDisplays.INSTANCE.blockScreen);
pos.add(side.down);
@ -86,7 +86,7 @@ public abstract class Multiblock {
pos.add(side.right);
pos.toBlock(bp);
ret.x++;
} while(world.getBlockState(bp).getBlock() instanceof BlockScreen);
} while(world.getBlockState(bp).getBlock() == WebDisplays.INSTANCE.blockScreen);
return ret;
}
@ -102,17 +102,17 @@ public abstract class Multiblock {
for(int y = 0; y < size.y; y++) {
for(int x = 0; x < size.x; x++) {
pos.toBlock(bp);
if(!(world.getBlockState(bp).getBlock() instanceof BlockScreen))
if(!(world.getBlockState(bp).getBlock() == WebDisplays.INSTANCE.blockScreen))
return pos; //Hole
pos.add(side.forward);
pos.toBlock(bp);
if(world.getBlockState(bp).getBlock() instanceof BlockScreen)
if(world.getBlockState(bp).getBlock() == WebDisplays.INSTANCE.blockScreen)
return pos; //Back should be empty
pos.addMul(side.backward, 2);
pos.toBlock(bp);
if(world.getBlockState(bp).getBlock() instanceof BlockScreen)
if(world.getBlockState(bp).getBlock() == WebDisplays.INSTANCE.blockScreen)
return pos; //Front should be empty
pos.add(side.forward);
@ -129,7 +129,7 @@ public abstract class Multiblock {
for(int y = 0; y < size.y; y++) {
pos.toBlock(bp);
if(world.getBlockState(bp).getBlock() instanceof BlockScreen)
if(world.getBlockState(bp).getBlock() == WebDisplays.INSTANCE.blockScreen)
return pos; //Left edge should be empty
pos.add(side.up);
@ -141,7 +141,7 @@ public abstract class Multiblock {
for(int y = 0; y < size.y; y++) {
pos.toBlock(bp);
if(world.getBlockState(bp).getBlock() instanceof BlockScreen)
if(world.getBlockState(bp).getBlock() == WebDisplays.INSTANCE.blockScreen)
return pos; //Left edge should be empty
pos.add(side.up);
@ -153,7 +153,7 @@ public abstract class Multiblock {
for(int x = 0; x < size.x; x++) {
pos.toBlock(bp);
if(world.getBlockState(bp).getBlock() instanceof BlockScreen)
if(world.getBlockState(bp).getBlock() == WebDisplays.INSTANCE.blockScreen)
return pos; //Left edge should be empty
pos.add(side.right);
@ -165,7 +165,7 @@ public abstract class Multiblock {
for(int x = 0; x < size.x; x++) {
pos.toBlock(bp);
if(world.getBlockState(bp).getBlock() instanceof BlockScreen)
if(world.getBlockState(bp).getBlock() == WebDisplays.INSTANCE.blockScreen)
return pos; //Left edge should be empty
pos.add(side.right);

View File

@ -12,7 +12,6 @@ import net.minecraftforge.fml.common.network.ByteBufUtils;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringJoiner;
import java.util.UUID;
@ -108,33 +107,6 @@ public abstract class Util {
throw new RuntimeException(String.format("Cannot unserialize class %s!", cls.getName()));
}
public static String[] commaSplit(String str) {
ArrayList<String> lst = new ArrayList<>();
String out = "";
boolean escape = false;
for(int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
if(c == '\\' && !escape) {
escape = true;
continue; //Otherwise it'll set escape back to false
} else if(c == ',' && !escape) {
lst.add(out);
out = "";
} else
out += c;
if(escape)
escape = false;
}
lst.add(out);
String[] ret = new String[lst.size()];
return lst.toArray(ret);
}
public static String addSlashes(String str) {
String out = "";
for(int i = 0; i < str.length(); i++) {