Skip to content

Commit

Permalink
Merge pull request #1016 from jaquadro/1.18-BlocksAndRefactoring
Browse files Browse the repository at this point in the history
Improve drawer interaction logic and a bunch of refactoring
  • Loading branch information
jaquadro committed May 5, 2022
2 parents f9fcd00 + c4721b1 commit fdc3047
Show file tree
Hide file tree
Showing 89 changed files with 1,371 additions and 1,555 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ buildscript {
}
dependencies {
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '5.1.+', changing: true
classpath 'org.spongepowered:mixingradle:0.7.+'
}
}

Expand All @@ -16,6 +17,7 @@ plugins {
apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'idea'
apply plugin: 'maven-publish'
apply plugin: 'org.spongepowered.mixin'

version = "${minecraft_version}-${mod_version}"
group= "com.jaquadro.minecraft.storagedrawers" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
Expand Down Expand Up @@ -159,6 +161,7 @@ dependencies {

implementation fg.deobf("curse.maven:the-one-probe-245211:${top_id}")
implementation fg.deobf("curse.maven:jade-324717:${jade_id}")
// implementation fg.deobf("curse.maven:spark-361579:3670050")

//deobfCompile "MineTweaker3:MineTweaker3-API:${mt_version}"
//deobfCompile "org.ow2.asm:asm-debug-all:5.0.3"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.InterModComms;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
Expand All @@ -39,9 +38,6 @@ public class StorageDrawers
public static final String MOD_ID = "storagedrawers";
public static final Api api = new Api();
public static Logger log = LogManager.getLogger();

public static CommonProxy proxy;

//public static ConfigManager config;
public static CompTierRegistry compRegistry;
//public static OreDictRegistry oreDictRegistry;
Expand All @@ -54,8 +50,6 @@ public class StorageDrawers
public static final RegistryObject<RecipeSerializer<AddUpgradeRecipe>> UPGRADE_RECIPE_SERIALIZER = RECIPES.register("add_upgrade", () -> new SimpleRecipeSerializer<>(AddUpgradeRecipe::new));

public StorageDrawers () {
proxy = DistExecutor.runForDist(() -> ClientProxy::new, () -> CommonProxy::new);

ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, CommonConfig.spec);
ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, ClientConfig.spec);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package com.jaquadro.minecraft.storagedrawers.api;

import com.jaquadro.minecraft.storagedrawers.api.registry.IRenderRegistry;
import com.jaquadro.minecraft.storagedrawers.api.registry.IWailaRegistry;

public interface IStorageDrawersApi
{
//IRenderRegistry renderRegistry ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class StorageDrawersApi
public static IStorageDrawersApi instance () {
if (instance == null) {
try {
Class classApi = Class.forName( "com.jaquadro.minecraft.storagedrawers.core.Api" );
Class<?> classApi = Class.forName( "com.jaquadro.minecraft.storagedrawers.core.Api" );
instance = (IStorageDrawersApi) classApi.getField("instance").get(null);
}
catch (Throwable t) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.jaquadro.minecraft.storagedrawers.api.capabilities;

import net.minecraft.world.item.ItemStack;
import net.minecraft.core.NonNullList;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nonnull;
import java.util.function.Predicate;

/**
Expand All @@ -23,7 +23,7 @@ public interface IItemRepository
* @return A list of zero or more items in the inventory.
*/
@Nonnull
@NotNull
NonNullList<ItemRecord> getAllItems ();

/**
Expand All @@ -35,11 +35,11 @@ public interface IItemRepository
* @return The remaining ItemStack that was not inserted. If the entire stack was accepted, returns
* ItemStack.EMPTY instead.
*/
@Nonnull
ItemStack insertItem (@Nonnull ItemStack stack, boolean simulate, Predicate<ItemStack> predicate);
@NotNull
ItemStack insertItem (@NotNull ItemStack stack, boolean simulate, Predicate<ItemStack> predicate);

@Nonnull
default ItemStack insertItem (@Nonnull ItemStack stack, boolean simulate) {
@NotNull
default ItemStack insertItem (@NotNull ItemStack stack, boolean simulate) {
return insertItem(stack, simulate, null);
}

Expand All @@ -54,11 +54,11 @@ default ItemStack insertItem (@Nonnull ItemStack stack, boolean simulate) {
* @param predicate See interface notes about predicates. Passing null specifies default matching.
* @return ItemStack extracted from the inventory, or ItemStack.EMPTY if nothing could be extracted.
*/
@Nonnull
ItemStack extractItem (@Nonnull ItemStack stack, int amount, boolean simulate, Predicate<ItemStack> predicate);
@NotNull
ItemStack extractItem (@NotNull ItemStack stack, int amount, boolean simulate, Predicate<ItemStack> predicate);

@Nonnull
default ItemStack extractItem (@Nonnull ItemStack stack, int amount, boolean simulate) {
@NotNull
default ItemStack extractItem (@NotNull ItemStack stack, int amount, boolean simulate) {
return extractItem(stack, amount, simulate, null);
}

Expand All @@ -69,12 +69,12 @@ default ItemStack extractItem (@Nonnull ItemStack stack, int amount, boolean sim
* @param predicate See interface notes about predicates. Passing null specifies default matching.
* @return The number of stored matching items. A value of Integer.MAX_VALUE may indicate an infinite item source.
*/
default int getStoredItemCount (@Nonnull ItemStack stack, Predicate<ItemStack> predicate) {
default int getStoredItemCount (@NotNull ItemStack stack, Predicate<ItemStack> predicate) {
ItemStack amount = extractItem(stack, Integer.MAX_VALUE, true, predicate);
return amount.getCount();
}

default int getStoredItemCount (@Nonnull ItemStack stack) {
default int getStoredItemCount (@NotNull ItemStack stack) {
return getStoredItemCount(stack, null);
}

Expand All @@ -86,14 +86,14 @@ default int getStoredItemCount (@Nonnull ItemStack stack) {
* @param predicate See interface notes about predicates. Passing null specifies default matching.
* @return The available remaining space for matching items.
*/
default int getRemainingItemCapacity (@Nonnull ItemStack stack, Predicate<ItemStack> predicate) {
default int getRemainingItemCapacity (@NotNull ItemStack stack, Predicate<ItemStack> predicate) {
stack = stack.copy();
stack.setCount(Integer.MAX_VALUE);
ItemStack remainder = insertItem(stack, true, predicate);
return Integer.MAX_VALUE - remainder.getCount();
}

default int getRemainingItemCapacity (@Nonnull ItemStack stack) {
default int getRemainingItemCapacity (@NotNull ItemStack stack) {
return getRemainingItemCapacity(stack, null);
}

Expand All @@ -105,14 +105,14 @@ default int getRemainingItemCapacity (@Nonnull ItemStack stack) {
* @param predicate See interface notes about predicates. Passing null specifies default matching.
* @return The total capacity for matching items.
*/
default int getItemCapacity (@Nonnull ItemStack stack, Predicate<ItemStack> predicate) {
long capacity = getStoredItemCount(stack, predicate) + getRemainingItemCapacity(stack, predicate);
default int getItemCapacity (@NotNull ItemStack stack, Predicate<ItemStack> predicate) {
long capacity = (long) getStoredItemCount(stack, predicate) + getRemainingItemCapacity(stack, predicate);
if (capacity > Integer.MAX_VALUE)
return Integer.MAX_VALUE;
return (int)capacity;
}

default int getItemCapacity (@Nonnull ItemStack stack) {
default int getItemCapacity (@NotNull ItemStack stack) {
return getItemCapacity(stack, null);
}

Expand All @@ -124,11 +124,11 @@ default int getItemCapacity (@Nonnull ItemStack stack) {
*/
class ItemRecord
{
@Nonnull
@NotNull
public final ItemStack itemPrototype;
public final int count;

public ItemRecord (@Nonnull ItemStack itemPrototype, int count) {
public ItemRecord (@NotNull ItemStack itemPrototype, int count) {
this.itemPrototype = itemPrototype;
this.count = count;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@

public interface IRenderLabel
{
void render (BlockEntity tileEntity, IDrawerGroup drawerGroup, int slot, float brightness, float partialTickTime);
void render (BlockEntity blockEntity, IDrawerGroup drawerGroup, int slot, float brightness, float partialTickTime);
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.jaquadro.minecraft.storagedrawers.api.storage;

import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nonnull;
import java.util.function.Predicate;

public class Drawers
Expand All @@ -12,15 +12,15 @@ public class Drawers

private static class DisabledDrawer implements IDrawer
{
@Nonnull
@NotNull
@Override
public ItemStack getStoredItemPrototype () {
return ItemStack.EMPTY;
}

@Nonnull
@NotNull
@Override
public IDrawer setStoredItem (@Nonnull ItemStack itemPrototype) {
public IDrawer setStoredItem (@NotNull ItemStack itemPrototype) {
return this;
}

Expand All @@ -35,7 +35,7 @@ public void setStoredItemCount (int amount) {
}

@Override
public int getMaxCapacity (@Nonnull ItemStack itemPrototype) {
public int getMaxCapacity (@NotNull ItemStack itemPrototype) {
return 0;
}

Expand All @@ -45,12 +45,12 @@ public int getRemainingCapacity () {
}

@Override
public boolean canItemBeStored (@Nonnull ItemStack itemPrototype, Predicate<ItemStack> matchPredicate) {
public boolean canItemBeStored (@NotNull ItemStack itemPrototype, Predicate<ItemStack> matchPredicate) {
return false;
}

@Override
public boolean canItemBeExtracted (@Nonnull ItemStack itemPrototype, Predicate<ItemStack> matchPredicate) {
public boolean canItemBeExtracted (@NotNull ItemStack itemPrototype, Predicate<ItemStack> matchPredicate) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.jaquadro.minecraft.storagedrawers.api.storage;

import net.minecraft.util.StringRepresentable;

import javax.annotation.Nonnull;
import org.jetbrains.annotations.NotNull;

public enum EnumBasicDrawer implements IDrawerGeometry, StringRepresentable
{
Expand Down Expand Up @@ -58,7 +57,7 @@ public String toString () {
}

@Override
@Nonnull
@NotNull
public String getSerializedName () {
return name;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.jaquadro.minecraft.storagedrawers.api.storage;

import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nonnull;
import java.util.function.Predicate;

public interface IDrawer
Expand All @@ -13,7 +13,7 @@ public interface IDrawer
*
* To emphasize, DO NOT MODIFY THE ITEM STACK RETURNED BY THIS METHOD.
*/
@Nonnull
@NotNull
ItemStack getStoredItemPrototype ();

/**
Expand All @@ -22,8 +22,8 @@ public interface IDrawer
* @param itemPrototype An ItemStack representing the type, metadata, and tags of the item to store.
* @return The IDrawer actually set with the prototype. Some drawer groups can redirect a set operation to another member.
*/
@Nonnull
IDrawer setStoredItem (@Nonnull ItemStack itemPrototype);
@NotNull
IDrawer setStoredItem (@NotNull ItemStack itemPrototype);

/**
* Sets the type of the stored item and initializes it to the given amount. Any existing item will be replaced.
Expand All @@ -32,8 +32,8 @@ public interface IDrawer
* @param amount The amount of items stored in this drawer.
* @return The IDrawer actually set with the prototype. Some drawer groups can redirect a set operation to another member.
*/
@Nonnull
default IDrawer setStoredItem (@Nonnull ItemStack itemPrototype, int amount) {
@NotNull
default IDrawer setStoredItem (@NotNull ItemStack itemPrototype, int amount) {
IDrawer drawer = setStoredItem(itemPrototype);
drawer.setStoredItemCount(amount);
return drawer;
Expand Down Expand Up @@ -87,15 +87,15 @@ default int getMaxCapacity () {
*
* @param itemPrototype The item type to query. Pass the empty stack to get the max capacity for an empty slot.
*/
int getMaxCapacity (@Nonnull ItemStack itemPrototype);
int getMaxCapacity (@NotNull ItemStack itemPrototype);

/**
* Gets the maximum number of items that would be accepted for storage by this drawer.
*
* Because a drawer may be able to handle items in excess of its full capacity, this value may be larger than
* the result of getMaxCapacity().
*/
default int getAcceptingMaxCapacity (@Nonnull ItemStack itemPrototype) {
default int getAcceptingMaxCapacity (@NotNull ItemStack itemPrototype) {
return getMaxCapacity(itemPrototype);
}

Expand All @@ -118,7 +118,7 @@ default int getAcceptingRemainingCapacity () {
* Gets the max stack size of the item type stored in this drawer.
*/
default int getStoredItemStackSize () {
@Nonnull ItemStack protoStack = getStoredItemPrototype();
@NotNull ItemStack protoStack = getStoredItemPrototype();
if (protoStack.isEmpty())
return 0;

Expand All @@ -135,9 +135,9 @@ default int getStoredItemStackSize () {
* @param matchPredicate A custom predicate for testing the stored ItemStack for equivalence.
* @return
*/
boolean canItemBeStored (@Nonnull ItemStack itemPrototype, Predicate<ItemStack> matchPredicate);
boolean canItemBeStored (@NotNull ItemStack itemPrototype, Predicate<ItemStack> matchPredicate);

default boolean canItemBeStored (@Nonnull ItemStack itemPrototype) {
default boolean canItemBeStored (@NotNull ItemStack itemPrototype) {
return canItemBeStored(itemPrototype, null);
}

Expand All @@ -151,9 +151,9 @@ default boolean canItemBeStored (@Nonnull ItemStack itemPrototype) {
* @param itemPrototype An ItemStack representing the type, metadata, and tags of an item.
* @param matchPredicate A custom predicate for testing the stored ItemStack for equivalence.
*/
boolean canItemBeExtracted (@Nonnull ItemStack itemPrototype, Predicate<ItemStack> matchPredicate);
boolean canItemBeExtracted (@NotNull ItemStack itemPrototype, Predicate<ItemStack> matchPredicate);

default boolean canItemBeExtracted (@Nonnull ItemStack itemPrototype) {
default boolean canItemBeExtracted (@NotNull ItemStack itemPrototype) {
return canItemBeExtracted(itemPrototype, null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.common.util.LazyOptional;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public interface IDrawerGroup extends ICapabilityProvider
{
Expand All @@ -18,13 +17,12 @@ public interface IDrawerGroup extends ICapabilityProvider
/**
* Gets the drawer at the given slot within this group.
*/
@Nonnull
@NotNull
IDrawer getDrawer (int slot);

/**
* Gets the list of available drawer slots in priority order.
*/
@Nonnull
int[] getAccessibleDrawerSlots ();

/**
Expand All @@ -34,9 +32,9 @@ default boolean isGroupValid () {
return true;
};

@Nonnull
@Override
default <T> LazyOptional<T> getCapability (@Nonnull final Capability<T> cap, final @Nullable Direction side) {
@NotNull
default <T> LazyOptional<T> getCapability (@NotNull final Capability<T> cap, final @Nullable Direction side) {
return LazyOptional.empty();
}
}
Loading

0 comments on commit fdc3047

Please sign in to comment.