Skip to content
This repository has been archived by the owner on Jul 21, 2024. It is now read-only.

Commit

Permalink
Fixed #29 and added missing Redstone change event to TitleEntityChest…
Browse files Browse the repository at this point in the history
… also added missing ContainerChest patches
  • Loading branch information
Hexeption committed Nov 30, 2019
1 parent 84c958c commit cae2741
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 3 deletions.
66 changes: 66 additions & 0 deletions patches/net/minecraft/inventory/ContainerChest.java.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
--- ../src-base/minecraft/net/minecraft/inventory/ContainerChest.java
+++ ../src-work/minecraft/net/minecraft/inventory/ContainerChest.java
@@ -1,13 +1,19 @@
package net.minecraft.inventory;

import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
+import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventory;
+import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventoryView;

public class ContainerChest extends Container
{
private final IInventory lowerChestInventory;
private final int numRows;

+ private CraftInventoryView bukkitEntity = null;
+ private InventoryPlayer player;
+
public ContainerChest(IInventory playerInventory, IInventory chestInventory, EntityPlayer player)
{
this.lowerChestInventory = chestInventory;
@@ -15,6 +21,8 @@
chestInventory.openInventory(player);
int i = (this.numRows - 4) * 18;

+ this.player = (InventoryPlayer) playerInventory;
+
for (int j = 0; j < this.numRows; ++j)
{
for (int k = 0; k < 9; ++k)
@@ -39,6 +47,7 @@

public boolean canInteractWith(EntityPlayer playerIn)
{
+ if (!this.checkReachable) return true;
return this.lowerChestInventory.isUsableByPlayer(playerIn);
}

@@ -87,4 +96,26 @@
{
return this.lowerChestInventory;
}
+
+ @Override
+ public CraftInventoryView getBukkitView() {
+ if (bukkitEntity != null) {
+ return bukkitEntity;
+ }
+
+ CraftInventory inventory;
+ if (this.lowerChestInventory instanceof InventoryPlayer) {
+ inventory = new org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventoryPlayer(
+ (InventoryPlayer) this.lowerChestInventory);
+ } else if (this.lowerChestInventory instanceof InventoryLargeChest) {
+ inventory = new org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventoryDoubleChest(
+ (InventoryLargeChest) this.lowerChestInventory);
+ } else {
+ inventory = new CraftInventory(this.lowerChestInventory);
+ }
+
+ bukkitEntity = new CraftInventoryView(this.player.player.getBukkitEntity(), inventory,
+ this);
+ return bukkitEntity;
+ }
}
24 changes: 23 additions & 1 deletion patches/net/minecraft/tileentity/TileEntityChest.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,29 @@
this.world.notifyNeighborsOfStateChange(this.pos, this.getBlockType(), false);

if (this.getChestType() == BlockChest.Type.TRAP)
@@ -356,7 +394,7 @@
@@ -340,14 +378,21 @@
{
if (!player.isSpectator() && this.getBlockType() instanceof BlockChest)
{
+ int oldPower = Math.max(0, Math.min(15, this.numPlayersUsing)); // CraftBukkit - Get power before new viewer is added
--this.numPlayersUsing;
this.world.addBlockEvent(this.pos, this.getBlockType(), 1, this.numPlayersUsing);
this.world.notifyNeighborsOfStateChange(this.pos, this.getBlockType(), false);

+ // CraftBukkit start - Call redstone event
if (this.getChestType() == BlockChest.Type.TRAP)
{
+ int newPower = Math.max(0, Math.min(15, this.numPlayersUsing));
+ if (oldPower != newPower) {
+ org.bukkit.craftbukkit.v1_12_R1.event.CraftEventFactory.callRedstoneChange(world, pos.getX(), pos.getY(), pos.getZ(), oldPower, newPower);
+ }
this.world.notifyNeighborsOfStateChange(this.pos.down(), this.getBlockType(), false);
}
+ // CraftBukkit end
}
}

@@ -356,7 +401,7 @@
@SuppressWarnings("unchecked")
@Override
@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public String toString() {
}

public InventoryView getOpenInventory() {
return getHandle().inventoryContainer.getBukkitView();
return getHandle().openContainer.getBukkitView(); // Magma - Fixes #29
}

public InventoryView openInventory(Inventory inventory) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public CraftInventoryCustom(InventoryHolder owner, int size, String title) {
super(new MinecraftInventory(owner, size, title));
}

public CraftInventoryCustom(InventoryHolder owner, NonNullList<ItemStack> items) {
super(new MinecraftInventory(owner, items));
}

static class MinecraftInventory implements IInventory {
private final NonNullList<ItemStack> items;
private int maxStack = MAX_STACK;
Expand All @@ -61,7 +65,15 @@ public MinecraftInventory(InventoryHolder owner, int size, String title) {
Validate.notNull(title, "Title cannot be null");
this.items = NonNullList.withSize(size, ItemStack.EMPTY);
this.title = title;
this.viewers = new ArrayList<HumanEntity>();
this.viewers = new ArrayList<>();
this.owner = owner;
this.type = InventoryType.CHEST;
}

public MinecraftInventory(InventoryHolder owner, NonNullList<ItemStack> items) {
this.items = items;
this.title = "Chest";
this.viewers = new ArrayList<>();
this.owner = owner;
this.type = InventoryType.CHEST;
}
Expand Down

0 comments on commit cae2741

Please sign in to comment.