Skip to content

Commit

Permalink
Merge pull request Sefiraat#93 from balugaq/master
Browse files Browse the repository at this point in the history
  • Loading branch information
balugaq authored Sep 9, 2024
2 parents fa7df45 + d90ae84 commit 01b8d5d
Show file tree
Hide file tree
Showing 17 changed files with 244 additions and 95 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[GitHub 仓库](https://github.com/ytdd9527/NetworksExpansion/tree/master) 的 jar 文件夹内

## 网络拓展2.1版本更新计划:
- [ ] **0**.链式网络插口 (32 64 256 1024... 同量子存储的大小)
完成 issues 里的所有功能

## 网络拓展

Expand Down
Binary file not shown.
Binary file added lib/FluffyMachines.jar
Binary file not shown.
10 changes: 9 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.ytdd9527.networksexpansion</groupId>
<artifactId>NetworksExpansion</artifactId>
<version>2.0.9-Alpha-23</version>
<version>2.0.9-Alpha-30</version>

<distributionManagement>
<repository>
Expand Down Expand Up @@ -264,5 +264,13 @@
<version>0.2.6</version>
<scope>compile</scope>
</dependency>
<!-- Support FluffyMachines -->
<dependency>
<groupId>com.github.SlimefunGuguProject</groupId>
<artifactId>FluffyMachines</artifactId>
<version>035fe56381</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/FluffyMachines.jar</systemPath>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public class ExpansionItemStacks {
"",
"目前支持:",
"无尽科技 - 存储单元",
"蓬松科技 - 蓬松桶",
"网络 - 量子存储",
TextUtil.colorPseudorandomString("网络拓展 - 网络抽屉")
);
Expand All @@ -142,6 +143,7 @@ public class ExpansionItemStacks {
"",
"目前支持:",
"无尽科技 - 存储单元",
"蓬松科技 - 蓬松桶",
"网络 - 量子存储",
TextUtil.colorPseudorandomString("网络拓展 - 网络抽屉")
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
Expand Down Expand Up @@ -416,15 +417,20 @@ private static void addClickHandler(Location l) {
if (action.isRightClicked()) {
itemRequest.setAmount(take.getMaxStackSize());
} else if (action.isShiftClicked()) {
itemRequest.setAmount(take.getMaxStackSize() * 36);
itemRequest.setAmount(take.getMaxStackSize()*36);
}

ItemStack requestedItemStack = data.requestItem(itemRequest);
if (requestedItemStack != null) {
HashMap<Integer, ItemStack> remnat = player.getInventory().addItem(requestedItemStack);
remnat.values().stream().findFirst().ifPresent(leftOver -> {
data.depositItemStack(leftOver, false);
});
do {
int max = Math.min(requestedItemStack.getAmount(), requestedItemStack.getMaxStackSize());
ItemStack clone = StackUtils.getAsQuantity(requestedItemStack, max);
requestedItemStack.setAmount(requestedItemStack.getAmount() - max);
HashMap<Integer, ItemStack> remnat = player.getInventory().addItem(clone);
remnat.values().stream().findFirst().ifPresent(leftOver -> {
data.depositItemStack(leftOver, false);
});
} while (requestedItemStack.getAmount() > 0);
}
} else {
for (ItemStack each : player.getInventory().getStorageContents()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,34 @@
import dev.rosewood.rosestacker.api.RoseStackerAPI;
import dev.rosewood.rosestacker.stack.StackedItem;
import io.github.sefiraat.networks.Networks;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.entity.Item;

public class SupportedPluginManager {

@Getter
private static SupportedPluginManager instance;

private final boolean infinityExpansion;
private final boolean netheopoiesis;
private final boolean slimeHud;
private final boolean roseStacker;
private final boolean wildStacker;
private final @Getter boolean infinityExpansion;
private final @Getter boolean fluffyMachines;
private final @Getter boolean netheopoiesis;
private final @Getter boolean slimeHud;
private final @Getter boolean roseStacker;
private final @Getter boolean wildStacker;

private RoseStackerAPI roseStackerAPI;
private @Getter RoseStackerAPI roseStackerAPI;
// region First Tick Only Registrations
private boolean mcMMO;
private boolean wildChests;
private @Getter boolean mcMMO;
private @Getter boolean wildChests;

// endregion

public SupportedPluginManager() {
Preconditions.checkArgument(instance == null, "Cannot instantiate class");
instance = this;
this.infinityExpansion = Bukkit.getPluginManager().isPluginEnabled("InfinityExpansion");
this.fluffyMachines = Bukkit.getPluginManager().isPluginEnabled("FluffyMachines");
this.netheopoiesis = Bukkit.getPluginManager().isPluginEnabled("Netheopoiesis");
this.slimeHud = Bukkit.getPluginManager().isPluginEnabled("SlimeHUD");

Expand All @@ -44,10 +48,6 @@ public SupportedPluginManager() {
.runTaskLater(Networks.getInstance(), this::firstTickRegistrations, 1);
}

public static SupportedPluginManager getInstance() {
return instance;
}

public static int getStackAmount(Item item) {
if (getInstance().isWildStacker()) {
return WildStackerAPI.getItemAmount(item);
Expand Down Expand Up @@ -76,36 +76,4 @@ private void firstTickRegistrations() {
this.wildChests = Bukkit.getPluginManager().isPluginEnabled("WildChests");
this.mcMMO = Bukkit.getPluginManager().isPluginEnabled("mcMMO");
}

public boolean isInfinityExpansion() {
return infinityExpansion;
}

public boolean isNetheopoiesis() {
return netheopoiesis;
}

public boolean isSlimeHud() {
return slimeHud;
}

public boolean isMcMMO() {
return mcMMO;
}

public boolean isWildChests() {
return wildChests;
}

public boolean isRoseStacker() {
return roseStacker;
}

public RoseStackerAPI getRoseStackerAPI() {
return roseStackerAPI;
}

public boolean isWildStacker() {
return wildStacker;
}
}
93 changes: 79 additions & 14 deletions src/main/java/io/github/sefiraat/networks/network/NetworkRoot.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import com.ytdd9527.networksexpansion.implementation.items.machines.networks.advanced.AdvancedGreedyBlock;
import com.ytdd9527.networksexpansion.implementation.items.machines.unit.CargoStorageUnit;
import com.ytdd9527.networksexpansion.utils.NetworksVersionedParticle;
import io.github.mooy1.infinityexpansion.items.storage.StorageCache;
import io.github.mooy1.infinityexpansion.items.storage.StorageUnit;
import io.github.sefiraat.networks.Networks;
import io.github.sefiraat.networks.network.barrel.FluffyBarrel;
import io.github.sefiraat.networks.network.barrel.InfinityBarrel;
import io.github.sefiraat.networks.network.barrel.NetworkStorage;
import io.github.sefiraat.networks.network.stackcaches.BarrelIdentity;
Expand All @@ -20,10 +22,12 @@
import io.github.sefiraat.networks.slimefun.network.NetworkQuantumStorage;
import io.github.sefiraat.networks.utils.StackUtils;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
import io.ncbpfluffybear.fluffymachines.items.Barrel;
import lombok.Getter;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.inventory.ItemStack;

Expand All @@ -38,7 +42,6 @@
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

// TODO: support fluffy barrels
@SuppressWarnings("unused")
public class NetworkRoot extends NetworkNode {
@Getter
Expand Down Expand Up @@ -564,9 +567,17 @@ public Set<BarrelIdentity> getBarrels() {
barrelSet.add(infinityBarrel);
}
continue;
}

if (slimefunItem instanceof NetworkQuantumStorage) {
} else if (Networks.getSupportedPluginManager().isFluffyMachines() && slimefunItem instanceof Barrel barrel) {
final BlockMenu menu = StorageCacheUtils.getMenu(testLocation);
if (menu == null) {
continue;
}
final FluffyBarrel fluffyBarrel = getFluffyBarrel(menu, barrel);
if (fluffyBarrel != null) {
barrelSet.add(fluffyBarrel);
}
continue;
} else if (slimefunItem instanceof NetworkQuantumStorage) {
final BlockMenu menu = StorageCacheUtils.getMenu(testLocation);
if (menu == null) {
continue;
Expand Down Expand Up @@ -624,6 +635,9 @@ public Map<StorageUnitData, Location> getCargoStorageUnitDatas() {
private InfinityBarrel getInfinityBarrel(@Nonnull BlockMenu blockMenu, @Nonnull StorageUnit storageUnit) {
final ItemStack itemStack = blockMenu.getItemInSlot(16);
final var data = StorageCacheUtils.getBlock(blockMenu.getLocation());
if (data == null) {
return null;
}
final String storedString = data.getData("stored");

if (storedString == null) {
Expand All @@ -636,7 +650,8 @@ private InfinityBarrel getInfinityBarrel(@Nonnull BlockMenu blockMenu, @Nonnull
return null;
}

final io.github.mooy1.infinityexpansion.items.storage.StorageCache cache = storageUnit.getCache(blockMenu.getLocation());

final StorageCache cache = storageUnit.getCache(blockMenu.getLocation());

if (cache == null) {
return null;
Expand All @@ -653,6 +668,39 @@ private InfinityBarrel getInfinityBarrel(@Nonnull BlockMenu blockMenu, @Nonnull
);
}

@Nullable
private FluffyBarrel getFluffyBarrel(@Nonnull BlockMenu blockMenu, @Nonnull Barrel barrel) {
Block block = blockMenu.getBlock();
ItemStack itemStack;
try {
itemStack = barrel.getStoredItem(block);
} catch (NullPointerException ignored) {
return null;
}

if (itemStack == null || itemStack.getType().isAir()) {
return null;
}

final ItemStack clone = itemStack.clone();

int stored = barrel.getStored(block);

if (stored <= 0) {
return null;
}
int limit = barrel.getCapacity(block);
boolean voidExcess = Boolean.parseBoolean(StorageCacheUtils.getData(blockMenu.getLocation(), "trash"));

return new FluffyBarrel(
blockMenu.getLocation(),
clone,
stored,
limit,
voidExcess
);
}

@Nullable
private NetworkStorage getNetworkStorage(@Nonnull BlockMenu blockMenu) {

Expand Down Expand Up @@ -770,8 +818,6 @@ public synchronized ItemStack getItemStackAsync(@Nonnull ItemRequest request) {
ItemStack stackToReturn = null;

if (request.getAmount() <= 0) {
stackToReturn = request.getItemStack().clone();
stackToReturn.setAmount(request.getAmount());
progressing = false;
notifyAll();
return stackToReturn;
Expand All @@ -787,6 +833,7 @@ public synchronized ItemStack getItemStackAsync(@Nonnull ItemRequest request) {
}

boolean infinity = barrelIdentity instanceof InfinityBarrel;
boolean fluffy = barrelIdentity instanceof FluffyBarrel;
final ItemStack fetched = barrelIdentity.requestItem(request);
if (fetched == null || fetched.getType().isAir() || (infinity && fetched.getAmount() == 1)) {
continue;
Expand All @@ -798,7 +845,7 @@ public synchronized ItemStack getItemStackAsync(@Nonnull ItemRequest request) {
stackToReturn.setAmount(0);
}

final int preserveAmount = infinity ? fetched.getAmount() - 1 : fetched.getAmount();
final int preserveAmount = (infinity || fluffy) ? fetched.getAmount() - 1 : fetched.getAmount();

if (request.getAmount() <= preserveAmount) {
stackToReturn.setAmount(stackToReturn.getAmount() + request.getAmount());
Expand Down Expand Up @@ -1645,8 +1692,7 @@ public Set<BarrelIdentity> getInputAbleBarrels() {

final SlimefunItem slimefunItem = StorageCacheUtils.getSfItem(testLocation);

if (Networks.getSupportedPluginManager()
.isInfinityExpansion() && slimefunItem instanceof StorageUnit unit) {
if (Networks.getSupportedPluginManager().isInfinityExpansion() && slimefunItem instanceof StorageUnit unit) {
final BlockMenu menu = StorageCacheUtils.getMenu(testLocation);
if (menu == null) {
continue;
Expand All @@ -1657,7 +1703,17 @@ public Set<BarrelIdentity> getInputAbleBarrels() {
}
continue;
}

if (Networks.getSupportedPluginManager().isFluffyMachines() && slimefunItem instanceof Barrel barrel) {
final BlockMenu menu = StorageCacheUtils.getMenu(testLocation);
if (menu == null) {
continue;
}
final FluffyBarrel fluffyBarrel = getFluffyBarrel(menu, barrel);
if (fluffyBarrel != null) {
barrelSet.add(fluffyBarrel);
}
continue;
}
if (slimefunItem instanceof NetworkQuantumStorage) {
final BlockMenu menu = StorageCacheUtils.getMenu(testLocation);
if (menu == null) {
Expand Down Expand Up @@ -1704,8 +1760,7 @@ public Set<BarrelIdentity> getOutputAbleBarrels() {

final SlimefunItem slimefunItem = StorageCacheUtils.getSfItem(testLocation);

if (Networks.getSupportedPluginManager()
.isInfinityExpansion() && slimefunItem instanceof StorageUnit unit) {
if (Networks.getSupportedPluginManager().isInfinityExpansion() && slimefunItem instanceof StorageUnit unit) {
final BlockMenu menu = StorageCacheUtils.getMenu(testLocation);
if (menu == null) {
continue;
Expand All @@ -1716,7 +1771,17 @@ public Set<BarrelIdentity> getOutputAbleBarrels() {
}
continue;
}

if (Networks.getSupportedPluginManager().isFluffyMachines() && slimefunItem instanceof Barrel barrel) {
final BlockMenu menu = StorageCacheUtils.getMenu(testLocation);
if (menu == null) {
continue;
}
final FluffyBarrel fluffyBarrel = getFluffyBarrel(menu, barrel);
if (fluffyBarrel != null) {
barrelSet.add(fluffyBarrel);
}
continue;
}
if (slimefunItem instanceof NetworkQuantumStorage) {
final BlockMenu menu = StorageCacheUtils.getMenu(testLocation);
if (menu == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ default void depositItemStack(ItemStack itemToDeposit) {

void depositItemStack(ItemStack[] itemsToDeposit);

int getInputSlot();
int[] getInputSlot();

int getOutputSlot();
int[] getOutputSlot();
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ public enum BarrelType {
NETWORKS,
INFINITY,
FLUFFY,
STORAGE_UNIT,
UNKNOWN
}
Loading

0 comments on commit 01b8d5d

Please sign in to comment.