Silences shulker boxes but breaks sound/animation till tile is reloaded

Time for relaxation and sleep, too much actual effort expended today
This commit is contained in:
Jikoo
2016-11-19 02:01:52 -05:00
parent 9501d1c571
commit 476171911a
3 changed files with 34 additions and 5 deletions

View File

@@ -9,7 +9,7 @@
<artifactId>openinv</artifactId>
<name>OpenInv</name>
<version>2.5.2</version>
<version>2.5.3-SNAPSHOT</version>
<profiles>

View File

@@ -116,9 +116,11 @@ public class AnySilentContainer implements IAnySilentContainer {
player.b(StatisticList.ae);
if (silentchest) {
// TODO We need to go deeper: Box is not anumated, but sound plays.
if (silentchest && tile instanceof TileEntityShulkerBox) {
// TODO: This fixes sound, but the box is then silent for anyone until the tile entity is recreated
SilentContainerShulkerBox.increaseOpenQuantity((TileEntityShulkerBox) tile);
container = new SilentContainerShulkerBox(player.inventory, ((IInventory) tile), player);
SilentContainerShulkerBox.decreaseOpenQuantity((TileEntityShulkerBox) tile);
}
}

View File

@@ -1,22 +1,49 @@
package com.lishid.openinv.internal.v1_11_R1;
import java.lang.reflect.Field;
import net.minecraft.server.v1_11_R1.ContainerShulkerBox;
import net.minecraft.server.v1_11_R1.EntityHuman;
import net.minecraft.server.v1_11_R1.IInventory;
import net.minecraft.server.v1_11_R1.ItemStack;
import net.minecraft.server.v1_11_R1.PlayerInventory;
import net.minecraft.server.v1_11_R1.TileEntityShulkerBox;
public class SilentContainerShulkerBox extends ContainerShulkerBox {
private static Field h;
private static Field exposeOpenStatus() throws NoSuchFieldException, SecurityException {
if (h == null) {
h = TileEntityShulkerBox.class.getDeclaredField("h");
h.setAccessible(true);
}
return h;
}
public static void increaseOpenQuantity(TileEntityShulkerBox containerShulkerBox) {
try {
exposeOpenStatus().set(containerShulkerBox, ((Integer) exposeOpenStatus().get(containerShulkerBox)) + 1);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void decreaseOpenQuantity(TileEntityShulkerBox containerShulkerBox) {
try {
exposeOpenStatus().set(containerShulkerBox, ((Integer) exposeOpenStatus().get(containerShulkerBox)) - 1);
} catch (Exception e) {
e.printStackTrace();
}
}
public SilentContainerShulkerBox(PlayerInventory playerInventory, IInventory iInventory,
EntityHuman entityHuman) {
super(playerInventory, iInventory, entityHuman);
iInventory.closeContainer(entityHuman);
}
@Override
public void b(EntityHuman entityHuman) {
// Don't send close signal twice, might screw up
PlayerInventory playerinventory = entityHuman.inventory;
if (!playerinventory.getCarried().isEmpty()) {