Fix SPIGOT-2806 for silent chests, various other issues
* Fixed anychest message spam * Changed AnySilentContainer again to reduce duplicate checks * #isAnyContainerNeeded should be checked before calling #activateContainer * reorganized ifs for doublechest creation into reverse-order if elses to prevent creating extras when someone's broken Minecraft and put 3+ adjacent to each other * Fixed incorrect block being checked for anychest in 1.11 * Progress on SilentContainerShulkerBox (we're getting there!) anychest and silentchest aren't quite at 100% after all these changes, but it won't be a priority to revisit logic until shulker boxes are done
This commit is contained in:
@@ -21,7 +21,7 @@ import java.lang.reflect.Field;
|
||||
import com.lishid.openinv.internal.IAnySilentContainer;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
// Volatile
|
||||
@@ -40,32 +40,31 @@ import org.bukkit.craftbukkit.v1_7_R3.entity.CraftPlayer;
|
||||
public class AnySilentContainer implements IAnySilentContainer {
|
||||
|
||||
@Override
|
||||
public boolean isAnySilentContainer(BlockState block) {
|
||||
return block instanceof org.bukkit.block.Chest;
|
||||
public boolean isAnySilentContainer(org.bukkit.block.Block block) {
|
||||
return block.getType() == Material.ENDER_CHEST || block.getState() instanceof org.bukkit.block.Chest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
||||
public boolean activateContainer(Player p, boolean silentchest, int x, int y, int z) {
|
||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||
World world = player.world;
|
||||
Object chest = world.getTileEntity(x, y, z);
|
||||
if (chest == null)
|
||||
return false;
|
||||
|
||||
if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
|
||||
if (chest == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int id = Block.b(world.getType(x, y, z));
|
||||
|
||||
if (Block.b(world.getType(x - 1, y, z)) == id)
|
||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
|
||||
if (Block.b(world.getType(x + 1, y, z)) == id)
|
||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z));
|
||||
if (Block.b(world.getType(x, y, z - 1)) == id)
|
||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest);
|
||||
if (Block.b(world.getType(x, y, z + 1)) == id)
|
||||
if (Block.b(world.getType(x, y, z + 1)) == id) {
|
||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
|
||||
} else if(Block.b(world.getType(x, y, z - 1)) == id) {
|
||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest);
|
||||
} else if (Block.b(world.getType(x + 1, y, z)) == id) {
|
||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z));
|
||||
} else if (Block.b(world.getType(x - 1, y, z)) == id) {
|
||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
|
||||
}
|
||||
|
||||
boolean returnValue = false;
|
||||
if (!silentchest) {
|
||||
@@ -138,12 +137,12 @@ public class AnySilentContainer implements IAnySilentContainer {
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #activateContainer(Player, boolean, boolean, int, int, int)}.
|
||||
* @deprecated Use {@link #activateContainer(Player, boolean, int, int, int)}.
|
||||
*/
|
||||
@Deprecated
|
||||
@Override
|
||||
public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z) {
|
||||
return !activateContainer(player, anychest, silentchest, x, y, z);
|
||||
return !activateContainer(player, silentchest, x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -20,6 +20,7 @@ package com.lishid.openinv.internal.v1_7_R3;
|
||||
import net.minecraft.server.v1_7_R3.ContainerChest;
|
||||
import net.minecraft.server.v1_7_R3.EntityHuman;
|
||||
import net.minecraft.server.v1_7_R3.IInventory;
|
||||
import net.minecraft.server.v1_7_R3.ItemStack;
|
||||
import net.minecraft.server.v1_7_R3.PlayerInventory;
|
||||
|
||||
public class SilentContainerChest extends ContainerChest {
|
||||
@@ -38,8 +39,9 @@ public class SilentContainerChest extends ContainerChest {
|
||||
PlayerInventory playerinventory = entityHuman.inventory;
|
||||
|
||||
if (playerinventory.getCarried() != null) {
|
||||
entityHuman.drop(playerinventory.getCarried(), false);
|
||||
ItemStack carried = playerinventory.getCarried();
|
||||
playerinventory.setCarried(null);
|
||||
entityHuman.drop(carried, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user