Permalink
Browse files

Minor optimisation for RangedCollector

  • Loading branch information...
me4502 committed Aug 10, 2017
1 parent 02e3009 commit 2ed2975b6ded90791e3420111c8c1d9b95ab5c8f
Showing with 51 additions and 60 deletions.
  1. +6 −13 pom.xml
  2. +45 −47 src/main/java/com/sk89q/craftbook/mechanics/ic/gates/world/items/RangedCollector.java
View
19 pom.xml
@@ -28,6 +28,10 @@
<id>spigot</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>bukkit-repo</id>
<url>http://repo.bukkit.org/content/groups/public/</url>
</repository>
<repository>
<id>Apache</id>
<url>http://repo.maven.apache.org/maven2</url>
@@ -104,8 +108,8 @@
</dependency>
<dependency>
<groupId>fr.neatmonster</groupId>
<artifactId>ncpcore</artifactId>
<version>static</version>
<artifactId>nocheatplus</artifactId>
<version>3.15.1-RC</version>
</dependency>
</dependencies>
<distributionManagement>
@@ -242,17 +246,6 @@
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
<configuration>
<preparationGoals>assembly:assembly</preparationGoals>
<goals>assembly:assembly</goals>
<tagNameFormat>@{project.version}</tagNameFormat>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
@@ -62,14 +62,14 @@ public void trigger (ChipState chip) {
chip.setOutput(0, collect());
}
Vector radius;
Location centre;
private Vector radius;
private Location centre;
boolean include = false;
private boolean include = false;
Block chest;
private Block chest;
List<ItemStack> filters = new ArrayList<>();
private List<ItemStack> filters = new ArrayList<>();
@Override
public void load() {
@@ -106,62 +106,60 @@ public boolean collect() {
for (Entity entity : LocationUtil.getNearbyEntities(centre, radius)) {
if (entity.isValid() && entity instanceof Item) {
if (LocationUtil.isWithinRadius(centre, entity.getLocation(), radius)) {
ItemStack stack = ((Item) entity).getItemStack();
ItemStack stack = ((Item) entity).getItemStack();
if(!ItemUtil.isStackValid(stack))
return false;
if(!ItemUtil.isStackValid(stack))
return false;
boolean passed = filters.isEmpty() || !include;
boolean passed = filters.isEmpty() || !include;
for(ItemStack filter : filters) {
if(!ItemUtil.isStackValid(filter))
continue;
for(ItemStack filter : filters) {
if(!ItemUtil.isStackValid(filter))
continue;
if(include && ItemUtil.areItemsIdentical(filter, stack)) {
passed = true;
break;
} else if(!include && ItemUtil.areItemsIdentical(filter, stack)) {
passed = false;
break;
}
if(include && ItemUtil.areItemsIdentical(filter, stack)) {
passed = true;
break;
} else if(!include && ItemUtil.areItemsIdentical(filter, stack)) {
passed = false;
break;
}
}
if (!passed) {
continue;
}
if (!passed) {
continue;
}
BlockFace back = SignUtil.getBack(BukkitUtil.toSign(getSign()).getBlock());
Block pipe = getBackBlock().getRelative(back);
BlockFace back = SignUtil.getBack(BukkitUtil.toSign(getSign()).getBlock());
Block pipe = getBackBlock().getRelative(back);
PipeRequestEvent event = new PipeRequestEvent(pipe, new ArrayList<>(Collections.singletonList(stack)), getBackBlock());
Bukkit.getPluginManager().callEvent(event);
PipeRequestEvent event = new PipeRequestEvent(pipe, new ArrayList<>(Collections.singletonList(stack)), getBackBlock());
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
continue;
}
if(event.getItems().isEmpty()) {
entity.remove();
return true;
}
if (event.isCancelled()) {
continue;
}
if(!InventoryUtil.doesBlockHaveInventory(chest))
return false;
if(event.getItems().isEmpty()) {
entity.remove();
return true;
}
// Add the items to a container, and destroy them.
List<ItemStack> leftovers = InventoryUtil.addItemsToInventory((InventoryHolder)chest.getState(), stack);
if(leftovers.isEmpty()) {
entity.remove();
if(!InventoryUtil.doesBlockHaveInventory(chest))
return false;
// Add the items to a container, and destroy them.
List<ItemStack> leftovers = InventoryUtil.addItemsToInventory((InventoryHolder)chest.getState(), stack);
if(leftovers.isEmpty()) {
entity.remove();
return true;
} else {
if(ItemUtil.areItemsIdentical(leftovers.get(0), stack) && leftovers.get(0).getAmount() != stack.getAmount()) {
((Item) entity).setItemStack(leftovers.get(0));
return true;
} else {
if(ItemUtil.areItemsIdentical(leftovers.get(0), stack) && leftovers.get(0).getAmount() != stack.getAmount()) {
((Item) entity).setItemStack(leftovers.get(0));
return true;
}
}
}
collected = true;
}
}

0 comments on commit 2ed2975

Please sign in to comment.