mirror of
https://hub.spigotmc.org/stash/scm/spigot/spigot.git
synced 2025-10-23 04:14:03 +00:00
181 lines
9.4 KiB
Diff
181 lines
9.4 KiB
Diff
From 7866bfdf87ba6caa7a82ec3e5a1101dcfe015476 Mon Sep 17 00:00:00 2001
|
|
From: erocs <github@erocs.org>
|
|
Date: Sun, 8 Sep 2013 12:06:15 -0700
|
|
Subject: [PATCH] Hopper Customisations
|
|
|
|
Allows editing hopper cooldowns and amount transferred per tick.
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/block/entity/TileEntityHopper.java b/src/main/java/net/minecraft/world/level/block/entity/TileEntityHopper.java
|
|
index b0ff4f18f..772909ba3 100644
|
|
--- a/src/main/java/net/minecraft/world/level/block/entity/TileEntityHopper.java
|
|
+++ b/src/main/java/net/minecraft/world/level/block/entity/TileEntityHopper.java
|
|
@@ -149,9 +149,14 @@ public class TileEntityHopper extends TileEntityLootable implements IHopper {
|
|
tileentityhopper.tickedGameTime = world.getGameTime();
|
|
if (!tileentityhopper.isOnCooldown()) {
|
|
tileentityhopper.setCooldown(0);
|
|
- tryMoveItems(world, blockposition, iblockdata, tileentityhopper, () -> {
|
|
+ // Spigot start
|
|
+ boolean result = tryMoveItems(world, blockposition, iblockdata, tileentityhopper, () -> {
|
|
return suckInItems(world, tileentityhopper);
|
|
});
|
|
+ if (!result && tileentityhopper.level.spigotConfig.hopperCheck > 1) {
|
|
+ tileentityhopper.setCooldown(tileentityhopper.level.spigotConfig.hopperCheck);
|
|
+ }
|
|
+ // Spigot end
|
|
}
|
|
|
|
}
|
|
@@ -172,7 +177,7 @@ public class TileEntityHopper extends TileEntityLootable implements IHopper {
|
|
}
|
|
|
|
if (flag) {
|
|
- tileentityhopper.setCooldown(8);
|
|
+ tileentityhopper.setCooldown(world.spigotConfig.hopperTransfer); // Spigot
|
|
setChanged(world, blockposition, iblockdata);
|
|
return true;
|
|
}
|
|
@@ -210,7 +215,7 @@ public class TileEntityHopper extends TileEntityLootable implements IHopper {
|
|
int j = itemstack.getCount();
|
|
// CraftBukkit start - Call event when pushing items into other inventories
|
|
ItemStack original = itemstack.copy();
|
|
- CraftItemStack oitemstack = CraftItemStack.asCraftMirror(tileentityhopper.removeItem(i, 1));
|
|
+ CraftItemStack oitemstack = CraftItemStack.asCraftMirror(tileentityhopper.removeItem(i, world.spigotConfig.hopperAmount)); // Spigot
|
|
|
|
Inventory destinationInventory;
|
|
// Have to special case large chests as they work oddly
|
|
@@ -226,9 +231,10 @@ public class TileEntityHopper extends TileEntityLootable implements IHopper {
|
|
world.getCraftServer().getPluginManager().callEvent(event);
|
|
if (event.isCancelled()) {
|
|
tileentityhopper.setItem(i, original);
|
|
- tileentityhopper.setCooldown(8); // Delay hopper checks
|
|
+ tileentityhopper.setCooldown(world.spigotConfig.hopperTransfer); // Delay hopper checks // Spigot
|
|
return false;
|
|
}
|
|
+ int origCount = event.getItem().getAmount(); // Spigot
|
|
ItemStack itemstack1 = addItem(tileentityhopper, iinventory, CraftItemStack.asNMSCopy(event.getItem()), enumdirection);
|
|
// CraftBukkit end
|
|
|
|
@@ -238,7 +244,10 @@ public class TileEntityHopper extends TileEntityLootable implements IHopper {
|
|
}
|
|
|
|
itemstack.setCount(j);
|
|
- if (j == 1) {
|
|
+ // Spigot start
|
|
+ itemstack.shrink(origCount - itemstack1.getCount());
|
|
+ if (j <= world.spigotConfig.hopperAmount) {
|
|
+ // Spigot end
|
|
tileentityhopper.setItem(i, itemstack);
|
|
}
|
|
}
|
|
@@ -305,7 +314,7 @@ public class TileEntityHopper extends TileEntityLootable implements IHopper {
|
|
EnumDirection enumdirection = EnumDirection.DOWN;
|
|
|
|
for (int i : getSlots(iinventory, enumdirection)) {
|
|
- if (tryTakeInItemFromSlot(ihopper, iinventory, i, enumdirection)) {
|
|
+ if (tryTakeInItemFromSlot(ihopper, iinventory, i, enumdirection, world)) { // Spigot
|
|
return true;
|
|
}
|
|
}
|
|
@@ -326,14 +335,14 @@ public class TileEntityHopper extends TileEntityLootable implements IHopper {
|
|
}
|
|
}
|
|
|
|
- private static boolean tryTakeInItemFromSlot(IHopper ihopper, IInventory iinventory, int i, EnumDirection enumdirection) {
|
|
+ private static boolean tryTakeInItemFromSlot(IHopper ihopper, IInventory iinventory, int i, EnumDirection enumdirection, World world) { // Spigot
|
|
ItemStack itemstack = iinventory.getItem(i);
|
|
|
|
if (!itemstack.isEmpty() && canTakeItemFromContainer(ihopper, iinventory, itemstack, i, enumdirection)) {
|
|
int j = itemstack.getCount();
|
|
// CraftBukkit start - Call event on collection of items from inventories into the hopper
|
|
ItemStack original = itemstack.copy();
|
|
- CraftItemStack oitemstack = CraftItemStack.asCraftMirror(iinventory.removeItem(i, 1));
|
|
+ CraftItemStack oitemstack = CraftItemStack.asCraftMirror(iinventory.removeItem(i, world.spigotConfig.hopperAmount)); // Spigot
|
|
|
|
Inventory sourceInventory;
|
|
// Have to special case large chests as they work oddly
|
|
@@ -352,11 +361,12 @@ public class TileEntityHopper extends TileEntityLootable implements IHopper {
|
|
iinventory.setItem(i, original);
|
|
|
|
if (ihopper instanceof TileEntityHopper) {
|
|
- ((TileEntityHopper) ihopper).setCooldown(8); // Delay hopper checks
|
|
+ ((TileEntityHopper) ihopper).setCooldown(world.spigotConfig.hopperTransfer); // Spigot
|
|
}
|
|
|
|
return false;
|
|
}
|
|
+ int origCount = event.getItem().getAmount(); // Spigot
|
|
ItemStack itemstack1 = addItem(iinventory, ihopper, CraftItemStack.asNMSCopy(event.getItem()), null);
|
|
// CraftBukkit end
|
|
|
|
@@ -366,7 +376,10 @@ public class TileEntityHopper extends TileEntityLootable implements IHopper {
|
|
}
|
|
|
|
itemstack.setCount(j);
|
|
- if (j == 1) {
|
|
+ // Spigot start
|
|
+ itemstack.shrink(origCount - itemstack1.getCount());
|
|
+ if (j <= world.spigotConfig.hopperAmount) {
|
|
+ // Spigot end
|
|
iinventory.setItem(i, itemstack);
|
|
}
|
|
}
|
|
@@ -467,6 +480,11 @@ public class TileEntityHopper extends TileEntityLootable implements IHopper {
|
|
boolean flag1 = iinventory1.isEmpty();
|
|
|
|
if (itemstack1.isEmpty()) {
|
|
+ // Spigot start - SPIGOT-6693, InventorySubcontainer#setItem
|
|
+ if (!itemstack.isEmpty() && itemstack.getCount() > iinventory1.getMaxStackSize()) {
|
|
+ itemstack = itemstack.split(iinventory1.getMaxStackSize());
|
|
+ }
|
|
+ // Spigot end
|
|
iinventory1.setItem(i, itemstack);
|
|
itemstack = ItemStack.EMPTY;
|
|
flag = true;
|
|
@@ -494,7 +512,7 @@ public class TileEntityHopper extends TileEntityLootable implements IHopper {
|
|
}
|
|
}
|
|
|
|
- tileentityhopper.setCooldown(8 - l);
|
|
+ tileentityhopper.setCooldown(tileentityhopper.level.spigotConfig.hopperTransfer - l); // Spigot
|
|
}
|
|
}
|
|
|
|
@@ -563,6 +581,7 @@ public class TileEntityHopper extends TileEntityLootable implements IHopper {
|
|
|
|
@Nullable
|
|
private static IInventory getBlockContainer(World world, BlockPosition blockposition, IBlockData iblockdata) {
|
|
+ if ( !world.spigotConfig.hopperCanLoadChunks && !world.hasChunkAt( blockposition ) ) return null; // Spigot
|
|
Block block = iblockdata.getBlock();
|
|
|
|
if (block instanceof IInventoryHolder) {
|
|
diff --git a/src/main/java/org/spigotmc/SpigotWorldConfig.java b/src/main/java/org/spigotmc/SpigotWorldConfig.java
|
|
index ab984b210..cec948a05 100644
|
|
--- a/src/main/java/org/spigotmc/SpigotWorldConfig.java
|
|
+++ b/src/main/java/org/spigotmc/SpigotWorldConfig.java
|
|
@@ -228,4 +228,22 @@ public class SpigotWorldConfig
|
|
otherTrackingRange = getInt( "entity-tracking-range.other", otherTrackingRange );
|
|
log( "Entity Tracking Range: Pl " + playerTrackingRange + " / An " + animalTrackingRange + " / Mo " + monsterTrackingRange + " / Mi " + miscTrackingRange + " / Di " + displayTrackingRange + " / Other " + otherTrackingRange );
|
|
}
|
|
+
|
|
+ public int hopperTransfer;
|
|
+ public int hopperCheck;
|
|
+ public int hopperAmount;
|
|
+ public boolean hopperCanLoadChunks;
|
|
+ private void hoppers()
|
|
+ {
|
|
+ // Set the tick delay between hopper item movements
|
|
+ hopperTransfer = getInt( "ticks-per.hopper-transfer", 8 );
|
|
+ if ( SpigotConfig.version < 11 )
|
|
+ {
|
|
+ set( "ticks-per.hopper-check", 1 );
|
|
+ }
|
|
+ hopperCheck = getInt( "ticks-per.hopper-check", 1 );
|
|
+ hopperAmount = getInt( "hopper-amount", 1 );
|
|
+ hopperCanLoadChunks = getBoolean( "hopper-can-load-chunks", false );
|
|
+ log( "Hopper Transfer: " + hopperTransfer + " Hopper Check: " + hopperCheck + " Hopper Amount: " + hopperAmount + " Hopper Can Load Chunks: " + hopperCanLoadChunks );
|
|
+ }
|
|
}
|
|
--
|
|
2.51.0
|
|
|