diff --git a/src/main/java/com/gtnewhorizon/structurelib/ConfigurationHandler.java b/src/main/java/com/gtnewhorizon/structurelib/ConfigurationHandler.java index bcb479c6..a9868abc 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/ConfigurationHandler.java +++ b/src/main/java/com/gtnewhorizon/structurelib/ConfigurationHandler.java @@ -78,7 +78,7 @@ public enum ConfigurationHandler { 300, 0, 20000, - "Unit: milisecond. Minimal interval between two auto place round.\n" + "Unit: millisecond. Minimal interval between two auto place round.\n" + "As expected, server side settings will overrides client settings.\n" + "Note this relates to the wall clock, not in game ticks.\n" + "Value smaller than default is likely to be perceived as no minimal interval whatsoever."); diff --git a/src/main/java/com/gtnewhorizon/structurelib/GLHelper.java b/src/main/java/com/gtnewhorizon/structurelib/GLHelper.java deleted file mode 100644 index ae7a3192..00000000 --- a/src/main/java/com/gtnewhorizon/structurelib/GLHelper.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.gtnewhorizon.structurelib; - -import java.nio.ByteBuffer; -import org.lwjgl.opengl.ARBVertexBufferObject; -import org.lwjgl.opengl.ContextCapabilities; -import org.lwjgl.opengl.GL15; -import org.lwjgl.opengl.GLContext; - -class GLHelper { - public static final boolean vboSupported; - private static final boolean arbVbo; - - static { - ContextCapabilities contextcapabilities = GLContext.getCapabilities(); - - arbVbo = !contextcapabilities.OpenGL15 && contextcapabilities.GL_ARB_vertex_buffer_object; - vboSupported = contextcapabilities.OpenGL15 || arbVbo; - } - - public static int glGenBuffers() { - return arbVbo ? ARBVertexBufferObject.glGenBuffersARB() : GL15.glGenBuffers(); - } - - public static void glBindBuffer(int target, int buffer) { - if (arbVbo) { - ARBVertexBufferObject.glBindBufferARB(target, buffer); - } else { - GL15.glBindBuffer(target, buffer); - } - } - - public static void glBufferData(int target, ByteBuffer data, int usage) { - if (arbVbo) { - ARBVertexBufferObject.glBufferDataARB(target, data, usage); - } else { - GL15.glBufferData(target, data, usage); - } - } - - public static void glDeleteBuffers(int buffer) { - if (arbVbo) { - ARBVertexBufferObject.glDeleteBuffersARB(buffer); - } else { - GL15.glDeleteBuffers(buffer); - } - } - - public static boolean useVbo() { - return vboSupported; - } -} diff --git a/src/main/java/com/gtnewhorizon/structurelib/StructureLib.java b/src/main/java/com/gtnewhorizon/structurelib/StructureLib.java index a0b0100e..20d9aac6 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/StructureLib.java +++ b/src/main/java/com/gtnewhorizon/structurelib/StructureLib.java @@ -42,14 +42,14 @@ public class StructureLib { private static final String STRUCTURECOMPAT_MODID = "structurecompat"; public static boolean DEBUG_MODE; public static boolean PANIC_MODE = Boolean.getBoolean("structurelib.panic"); - public static Logger LOGGER = LogManager.getLogger("StructureLib"); + public static final Logger LOGGER = LogManager.getLogger("StructureLib"); @SidedProxy( serverSide = "com.gtnewhorizon.structurelib.CommonProxy", clientSide = "com.gtnewhorizon.structurelib.ClientProxy") static CommonProxy proxy; - static SimpleNetworkWrapper net = NetworkRegistry.INSTANCE.newSimpleChannel(StructureLibAPI.MOD_ID); + static final SimpleNetworkWrapper net = NetworkRegistry.INSTANCE.newSimpleChannel(StructureLibAPI.MOD_ID); static { net.registerMessage( diff --git a/src/main/java/com/gtnewhorizon/structurelib/alignment/IAlignmentLimits.java b/src/main/java/com/gtnewhorizon/structurelib/alignment/IAlignmentLimits.java index a5318a45..b616eeb0 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/alignment/IAlignmentLimits.java +++ b/src/main/java/com/gtnewhorizon/structurelib/alignment/IAlignmentLimits.java @@ -122,7 +122,7 @@ public interface IAlignmentLimits { } /** - * Prefers rotation over flip, so both flip will get translated to opposite rotation and no flip + * Prefers rotation to flip, so both flip will get translated to opposite rotation and no flip * * @param flip the preferred flip to be used Horizontal or vertical * @return this diff --git a/src/main/java/com/gtnewhorizon/structurelib/gui/GuiScrollableList.java b/src/main/java/com/gtnewhorizon/structurelib/gui/GuiScrollableList.java index 7f537d7a..a316a077 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/gui/GuiScrollableList.java +++ b/src/main/java/com/gtnewhorizon/structurelib/gui/GuiScrollableList.java @@ -29,10 +29,10 @@ import org.lwjgl.opengl.GL11; public abstract class GuiScrollableList { protected final int slotHeight; private final Minecraft mc = Minecraft.getMinecraft(); - protected int originX; - protected int originY; - protected int width; - protected int height; + protected final int originX; + protected final int originY; + protected final int width; + protected final int height; protected int minY; protected int maxY; protected int minX; @@ -41,7 +41,7 @@ public abstract class GuiScrollableList { protected int mouseY; protected int selectedIndex = -1; protected int margin = 4; - protected List> listeners = new CopyOnWriteArrayList<>(); + protected final List> listeners = new CopyOnWriteArrayList<>(); private int scrollUpButtonID; private int scrollDownButtonID; private float initialClickY = -2.0F; @@ -153,11 +153,11 @@ public abstract class GuiScrollableList { public void actionPerformed(GuiButton b) { if (b.enabled) { if (b.id == scrollUpButtonID) { - amountScrolled -= slotHeight * 2 / 3; + amountScrolled -= slotHeight * 2f / 3; initialClickY = -2.0F; clampScrollToBounds(); } else if (b.id == scrollDownButtonID) { - amountScrolled += slotHeight * 2 / 3; + amountScrolled += slotHeight * 2f / 3; initialClickY = -2.0F; clampScrollToBounds(); } @@ -325,9 +325,9 @@ public abstract class GuiScrollableList { public void handleDWheel(int mouseWheelDelta) { if (!Mouse.isButtonDown(0)) { if (mouseWheelDelta > 0) { - amountScrolled -= slotHeight / 2; + amountScrolled -= slotHeight / 2f; } else /* if (mouseWheelDelta < 0) */ { - amountScrolled += slotHeight / 2; + amountScrolled += slotHeight / 2f; } } } diff --git a/src/main/java/com/gtnewhorizon/structurelib/item/ItemBlockHint.java b/src/main/java/com/gtnewhorizon/structurelib/item/ItemBlockHint.java index c346caac..7dfe21f6 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/item/ItemBlockHint.java +++ b/src/main/java/com/gtnewhorizon/structurelib/item/ItemBlockHint.java @@ -56,12 +56,12 @@ public class ItemBlockHint extends ItemBlock { "structurelib.blockhint.desc.4")); // Make sure it does not contain Air material. break; case 15: - aList.add(EnumChatFormatting.BLUE.toString() + aList.add(EnumChatFormatting.BLUE + translateToLocal("structurelib.blockhint.desc.5")); // ERROR, what did u expect? break; default: // WTF? aList.add("Damn son where did you get that!?"); - aList.add(EnumChatFormatting.BLUE.toString() + "From outer space... I guess..."); + aList.add(EnumChatFormatting.BLUE + "From outer space... I guess..."); } } diff --git a/src/main/java/com/gtnewhorizon/structurelib/net/AlignmentMessage.java b/src/main/java/com/gtnewhorizon/structurelib/net/AlignmentMessage.java index d85d7a06..16e7248d 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/net/AlignmentMessage.java +++ b/src/main/java/com/gtnewhorizon/structurelib/net/AlignmentMessage.java @@ -45,10 +45,6 @@ public abstract class AlignmentMessage implements IMessage { ByteBufUtils.writeTag(pBuffer, tFXTag); } - /** - * {@link com.gtnewhorizon.structurelib.structure.IStructureDefinition#check(Object, String, World, ExtendedFacing, int, int, int, int, int, int, boolean)} - * @param provider - */ private AlignmentMessage(IAlignmentProvider provider) { if (!(provider instanceof TileEntity)) throw new IllegalArgumentException("Provider must be a TileEntity"); IAlignment alignment = provider.getAlignment(); diff --git a/src/main/java/com/gtnewhorizon/structurelib/net/SetChannelDataMessage.java b/src/main/java/com/gtnewhorizon/structurelib/net/SetChannelDataMessage.java index 70445ed7..efe11a5e 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/net/SetChannelDataMessage.java +++ b/src/main/java/com/gtnewhorizon/structurelib/net/SetChannelDataMessage.java @@ -17,7 +17,7 @@ import net.minecraft.item.ItemStack; import org.apache.commons.lang3.tuple.Pair; public class SetChannelDataMessage implements IMessage { - private List> data = new ArrayList<>(); + private final List> data = new ArrayList<>(); public SetChannelDataMessage() {} diff --git a/src/main/java/com/gtnewhorizon/structurelib/structure/IItemSource.java b/src/main/java/com/gtnewhorizon/structurelib/structure/IItemSource.java index 69c9eae1..d75706c2 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/structure/IItemSource.java +++ b/src/main/java/com/gtnewhorizon/structurelib/structure/IItemSource.java @@ -11,19 +11,32 @@ import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; +/** + * Represent an item source. Take only, cannot be placed back. + */ public interface IItemSource { /** - * We are probably not going to need to get a lot of items from this method + * We are probably not going to need to get a lot of items from this method, * so I don't care about the overhead of storing all fetched items even if downstream code doesn't need it */ @Nonnull Map take(Predicate predicate, boolean simulate, int count); + /** + * Take exactly one item that matches the predicate. + * + * @return item stack, or null if none matches + */ default ItemStack takeOne(Predicate predicate, boolean simulate) { Map take = take(predicate, simulate, 1); return take.isEmpty() ? null : take.keySet().iterator().next(); } + /** + * Take exactly count amount of items matching predicate. + * + * @return true if at least count amount of items can be/is taken. + */ default boolean takeAll(Predicate predicate, boolean simulate, int count) { // fast path for 1 item take requests if (count == 1) return takeOne(predicate, simulate) != null; @@ -33,22 +46,38 @@ public interface IItemSource { return true; } + /** + * Take exactly one item. ItemStack given must have a stack size of 1. + * + * @return true if found. false otherwise + */ default boolean takeOne(ItemStack stack, boolean simulate) { if (stack == null || stack.getItem() == null || stack.stackSize != 1) throw new IllegalArgumentException(); ItemStack took = takeOne(ItemStackPredicate.from(stack, NBTMode.EXACT), simulate); return took == null || took.stackSize <= 0; } + /** + * Take some item. Will not take item if it cannot find enough items to take. + * + * @return true if enough item can be/has been extracted. false otherwise + */ default boolean takeAll(ItemStack stack, boolean simulate) { // fast path for 1 item take requests if (stack.stackSize == 1) return takeOne(stack, simulate); ItemStackPredicate predicate = ItemStackPredicate.from(stack, NBTMode.EXACT); Map have = take(predicate, true, stack.stackSize); if (have.values().stream().mapToInt(Integer::intValue).sum() < stack.stackSize) return false; - take(predicate, simulate, stack.stackSize); + if (simulate) return true; + take(predicate, false, stack.stackSize); return true; } + /** + * Construct an IItemSource from inventories associated with given player. + *

+ * This will be backed by {@link InventoryUtility} + */ static IItemSource fromPlayer(EntityPlayerMP player) { return new IItemSource() { @Nonnull @@ -71,6 +100,11 @@ public interface IItemSource { }; } + /** + * Construct an IItemSource from given inventory + *

+ * This will be backed by {@link InventoryUtility} + */ static IItemSource fromInventory(IInventory inv) { return (p, s, c) -> InventoryUtility.takeFromInventory(new InventoryIterable<>(inv), p, s, c, true); } diff --git a/src/main/java/com/gtnewhorizon/structurelib/structure/IStructureDefinition.java b/src/main/java/com/gtnewhorizon/structurelib/structure/IStructureDefinition.java index 0530042f..ed0ac6fd 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/structure/IStructureDefinition.java +++ b/src/main/java/com/gtnewhorizon/structurelib/structure/IStructureDefinition.java @@ -141,7 +141,7 @@ public interface IStructureDefinition { } /** - * Build the multi in creative mode on a best effort basis. Does not guarantee the structure is correct after a + * Build the multi in creative mode on a best-effort basis. Does not guarantee the structure is correct after a * successful call. * * @param object context object. usually multiblock controller. @@ -402,7 +402,6 @@ public interface IStructureDefinition { /** * Create a new instance of builder. - * @return * @param type of context object */ static StructureDefinition.Builder builder() { diff --git a/src/main/java/com/gtnewhorizon/structurelib/structure/IWithExtendedContext.java b/src/main/java/com/gtnewhorizon/structurelib/structure/IWithExtendedContext.java index 07127bb3..740933fc 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/structure/IWithExtendedContext.java +++ b/src/main/java/com/gtnewhorizon/structurelib/structure/IWithExtendedContext.java @@ -3,7 +3,7 @@ package com.gtnewhorizon.structurelib.structure; /** * Implement this and use {@link StructureUtility#withContext(IStructureElement)} in case you need to record some * temporary states that don't need to live in your main context, which would usually live for the whole lifetime of the - * structure than just during structure check. Usually just save some few bytes, but becomes non trivial if you need to + * structure than just during structure check. Usually just save some few bytes, but becomes non-trivial if you need to * record too much stuff. *

* You will have to reset the context yourself though. The API can't guess when the old context becomes invalid. diff --git a/src/main/java/com/gtnewhorizon/structurelib/structure/StructureDefinition.java b/src/main/java/com/gtnewhorizon/structurelib/structure/StructureDefinition.java index e7ffe852..eb0946ca 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/structure/StructureDefinition.java +++ b/src/main/java/com/gtnewhorizon/structurelib/structure/StructureDefinition.java @@ -53,7 +53,7 @@ public class StructureDefinition implements IStructureDefinition { * + is anything but air * - is air checks * space bar is skip - * ~ is also skip (but marks controller position, optional and logically it is a space...) + * ~ is also skip (but marks controller position, optional. implementation wise it is a space...) * rest needs to be defined *

* next char is next block(a) diff --git a/src/main/java/com/gtnewhorizon/structurelib/structure/StructureUtility.java b/src/main/java/com/gtnewhorizon/structurelib/structure/StructureUtility.java index b99a4ad7..7c79f8dd 100644 --- a/src/main/java/com/gtnewhorizon/structurelib/structure/StructureUtility.java +++ b/src/main/java/com/gtnewhorizon/structurelib/structure/StructureUtility.java @@ -1947,6 +1947,7 @@ public class StructureUtility { * @deprecated renamed to partitionBy */ @SafeVarargs + @Deprecated public static IStructureElementDeferred defer( Function keyExtractor, IStructureElement... array) { return partitionBy(keyExtractor, array); @@ -2015,7 +2016,7 @@ public class StructureUtility { * @param array all possible structure element * @deprecated renamed to partitionBy */ - @SuppressWarnings("unchecked") + @Deprecated public static IStructureElementDeferred defer( Function keyExtractor, List> array) { return partitionBy(keyExtractor, array); @@ -2036,7 +2037,7 @@ public class StructureUtility { @SuppressWarnings("unchecked") public static IStructureElementDeferred partitionBy( Function keyExtractor, List> array) { - return defer(keyExtractor, array.toArray(new IStructureElement[0])); + return partitionBy(keyExtractor, array.toArray(new IStructureElement[0])); } /** @@ -2568,6 +2569,7 @@ public class StructureUtility { * @deprecated renamed to partitionBy */ @SafeVarargs + @Deprecated public static IStructureElementDeferred defer( Function keyExtractorCheck, BiFunction keyExtractor, @@ -2651,7 +2653,7 @@ public class StructureUtility { * @param array all possible structure element * @deprecated renamed to partitionBy */ - @SuppressWarnings("unchecked") + @Deprecated public static IStructureElementDeferred defer( Function keyExtractorCheck, BiFunction keyExtractor, @@ -2680,7 +2682,7 @@ public class StructureUtility { Function keyExtractorCheck, BiFunction keyExtractor, List> array) { - return defer(keyExtractorCheck, keyExtractor, array.toArray(new IStructureElement[0])); + return partitionBy(keyExtractorCheck, keyExtractor, array.toArray(new IStructureElement[0])); } // endregion