Skip to content

Commit

Permalink
Merge pull request #188 from balugaq/master
Browse files Browse the repository at this point in the history
Resolves #182 & #186
  • Loading branch information
balugaq authored Nov 23, 2024
2 parents cd39a8e + e41c3ed commit e426b10
Show file tree
Hide file tree
Showing 16 changed files with 191 additions and 737 deletions.
10 changes: 1 addition & 9 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
Unless otherwise specified, all code in this repository is licensed under the GPL-3.0 license.

Licenses:
- LICENSES/GPL-3.0 - GNU General Public License v3.0
- LICENSES/MIT - The MIT License

See LICENSES/GPL-3.0 for original license text.
The following is a copy of LICENSES/GPL-3.0:

All code in this repository is licensed under the GPL-3.0 license.
Valid-License-Identifier: GPL-3.0
License-Text:

Expand Down
677 changes: 0 additions & 677 deletions LICENSES/GPL-3.0

This file was deleted.

26 changes: 0 additions & 26 deletions LICENSES/MIT

This file was deleted.

2 changes: 1 addition & 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.1-Alpha-10</version>
<version>2.1-Alpha-11</version>

<distributionManagement>
<repository>
Expand Down
44 changes: 37 additions & 7 deletions src/main/java/com/balugaq/netex/utils/LineOperationUtil.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.balugaq.netex.utils;

import com.balugaq.netex.api.enums.TransportMode;
import com.xzavier0722.mc.plugin.slimefun4.storage.controller.SlimefunBlockData;
import com.xzavier0722.mc.plugin.slimefun4.storage.util.StorageCacheUtils;
import io.github.sefiraat.networks.network.NetworkRoot;
import io.github.sefiraat.networks.network.stackcaches.ItemRequest;
Expand Down Expand Up @@ -57,6 +58,39 @@ public static void doOperation(Location startLocation, BlockFace direction, int
}
}

public static void doEnergyOperation(Location startLocation, BlockFace direction, int limit, Consumer<BlockMenu> consumer) {
doEnergyOperation(startLocation, direction, limit, true, true, consumer);
}

public static void doEnergyOperation(Location startLocation, BlockFace direction, int limit, boolean allowNoMenu, Consumer<BlockMenu> consumer) {
doEnergyOperation(startLocation, direction, limit, allowNoMenu, true, consumer);
}

public static void doEnergyOperation(Location startLocation, BlockFace direction, int limit, boolean allowNoMenu, boolean optimizeExperience, Consumer<BlockMenu> consumer) {
Location location = startLocation.clone();
int finalLimit = limit;
if (optimizeExperience) {
finalLimit += 1;
}
for (int i = 0; i < finalLimit; i++) {
switch (direction) {
case NORTH -> location.setZ(location.getZ() - 1);
case SOUTH -> location.setZ(location.getZ() + 1);
case EAST -> location.setX(location.getX() + 1);
case WEST -> location.setX(location.getX() - 1);
case UP -> location.setY(location.getY() + 1);
case DOWN -> location.setY(location.getY() - 1);
}
final BlockMenu blockMenu = StorageCacheUtils.getMenu(location);
if (blockMenu == null) {
if (!allowNoMenu) {
return;
}
}
consumer.accept(blockMenu);
}
}

public static void grabItem(
@Nonnull NetworkRoot root,
@Nonnull BlockMenu blockMenu,
Expand Down Expand Up @@ -412,7 +446,7 @@ public static void pushItem(
}

public static void outPower(@Nonnull Location location, @Nonnull NetworkRoot root, int rate) {
var blockData = StorageCacheUtils.getBlock(location);
final SlimefunBlockData blockData = StorageCacheUtils.getBlock(location);
if (blockData == null) {
return;
}
Expand All @@ -427,14 +461,10 @@ public static void outPower(@Nonnull Location location, @Nonnull NetworkRoot roo
return;
}

final String charge = blockData.getData("energy-charge");
int chargeInt = 0;
if (charge != null) {
chargeInt = Integer.parseInt(charge);
}
int existingCharge = component.getCharge(location);

final int capacity = component.getCapacity();
final int space = capacity - chargeInt;
final int space = capacity - existingCharge;

if (space <= 0) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,14 @@ public void init() {
drawBackground(Icon.OUTPUT_BACKGROUND_STACK, OUTPUT_BACKGROUND);
}

@Override
public void newInstance(@Nonnull BlockMenu menu, @Nonnull Block b) {
addMenuClickHandler(BLUEPRINT_SLOT, (player, slot, clickedItem, clickAction) -> {
releaseCache(menu);
return true;
});
}

@Override
public boolean canOpen(@Nonnull Block block, @Nonnull Player player) {
return player.hasPermission("slimefun.inventory.bypass") || (this.getSlimefunItem().canUse(player, false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,14 @@ public void init() {
drawBackground(Icon.OUTPUT_BACKGROUND_STACK, OUTPUT_BACKGROUND);
}

@Override
public void newInstance(@Nonnull BlockMenu menu, @Nonnull Block b) {
addMenuClickHandler(BLUEPRINT_SLOT, (player, slot, clickedItem, clickAction) -> {
releaseCache(menu);
return true;
});
}

@Override
public boolean canOpen(@Nonnull Block block, @Nonnull Player player) {
return player.hasPermission("slimefun.inventory.bypass") || (this.getSlimefunItem().canUse(player, false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private void outPower(@Nonnull BlockMenu blockMenu) {

final NetworkRoot root = definition.getNode().getRoot();
final BlockFace blockFace = getCurrentDirection(blockMenu);
LineOperationUtil.doOperation(blockMenu.getLocation(), blockFace, this.maxDistance, false, (targetMenu) -> {
LineOperationUtil.doEnergyOperation(blockMenu.getLocation(), blockFace, this.maxDistance, true, false, (targetMenu) -> {
LineOperationUtil.outPower(targetMenu.getLocation(), root, this.rate);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
@SuppressWarnings("unused")
public class ItemMover extends SpecialSlimefunItem implements DistinctiveItem {
@Nonnull
public static final Interaction[] CHECK_INTERACTIONS = new Interaction[] {
public static final Interaction[] CHECK_INTERACTIONS = new Interaction[]{
Interaction.PLACE_BLOCK, Interaction.BREAK_BLOCK, Interaction.INTERACT_BLOCK
};
@Nonnull
Expand Down Expand Up @@ -452,11 +452,6 @@ private static List<String> cloneDefaultLore() {
return new ArrayList<>(DEFAULT_LORE);
}

@Override
public boolean canStack(@Nonnull ItemMeta itemMeta, @Nonnull ItemMeta itemMeta1) {
return itemMeta.getPersistentDataContainer().equals(itemMeta1.getPersistentDataContainer());
}

public static boolean hasPermission(Player player, Location location) {
for (Interaction interaction : CHECK_INTERACTIONS) {
if (!Slimefun.getProtectionManager().hasPermission(player, location, interaction)) {
Expand All @@ -471,4 +466,9 @@ public static boolean hasPermission(Player player, Location location) {

return true;
}

@Override
public boolean canStack(@Nonnull ItemMeta itemMeta, @Nonnull ItemMeta itemMeta1) {
return itemMeta.getPersistentDataContainer().equals(itemMeta1.getPersistentDataContainer());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

/**
* @author Final_ROOT
* @author balugaq
* @since 2.0
*/
public class ParticleUtil {
Expand Down Expand Up @@ -137,4 +138,47 @@ public static void drawCubeByLocations(@Nonnull Plugin plugin, @Nonnull Particle
}
ParticleUtil.drawCubeByLocations(plugin, particle, interval, locations);
}

public static void drawRegionOutline(@Nonnull Plugin plugin, @Nonnull Particle particle, long interval, @Nonnull Location corner1, @Nonnull Location corner2) {
World world = corner1.getWorld();
if (world == null || corner1.getWorld() != corner2.getWorld()) {
return;
}

double minX = Math.min(corner1.getX(), corner2.getX());
double minY = Math.min(corner1.getY(), corner2.getY());
double minZ = Math.min(corner1.getZ(), corner2.getZ());
double maxX = Math.max(corner1.getX(), corner2.getX());
double maxY = Math.max(corner1.getY(), corner2.getY());
double maxZ = Math.max(corner1.getZ(), corner2.getZ());

Location[] corners = new Location[]{
new Location(world, minX, minY, minZ),
new Location(world, minX, minY, maxZ + 1),
new Location(world, maxX + 1, minY, maxZ + 1),
new Location(world, maxX + 1, minY, minZ),
new Location(world, minX, maxY + 1, minZ),
new Location(world, minX, maxY + 1, maxZ + 1),
new Location(world, maxX + 1, maxY + 1, maxZ + 1),
new Location(world, maxX + 1, maxY + 1, minZ)
};

drawLineByDistance(plugin, particle, interval, 0.25, corners[0], corners[1]);
drawLineByDistance(plugin, particle, interval, 0.25, corners[0], corners[3]);
drawLineByDistance(plugin, particle, interval, 0.25, corners[0], corners[4]);

drawLineByDistance(plugin, particle, interval, 0.25, corners[1], corners[2]);
drawLineByDistance(plugin, particle, interval, 0.25, corners[1], corners[5]);

drawLineByDistance(plugin, particle, interval, 0.25, corners[2], corners[3]);
drawLineByDistance(plugin, particle, interval, 0.25, corners[2], corners[6]);

drawLineByDistance(plugin, particle, interval, 0.25, corners[3], corners[7]);
drawLineByDistance(plugin, particle, interval, 0.25, corners[4], corners[5]);

drawLineByDistance(plugin, particle, interval, 0.25, corners[4], corners[7]);
drawLineByDistance(plugin, particle, interval, 0.25, corners[5], corners[6]);

drawLineByDistance(plugin, particle, interval, 0.25, corners[6], corners[7]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
import java.lang.reflect.Field;
import java.lang.reflect.Method;


/**
* @author Final_ROOT
*/
@UtilityClass
public class ReflectionUtil {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public static void saveAmountChange() {
}
}
Networks.getInstance().getLogger().info(Networks.getLocalizationService().getString("messages.data-saving.saved-drawer"));
Networks.getInstance().debug("Task amount: " + Networks.getQueryQueue().getTaskAmount());
}

public static boolean isContainerLoaded(int id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.bukkit.Location;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
Expand Down
Loading

0 comments on commit e426b10

Please sign in to comment.