mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-30 04:02:50 +01:00
Implement Dropper interface. Adds BUKKIT-3750
This commit is contained in:
parent
978de7e9da
commit
ae19f2c46f
4 changed files with 57 additions and 1 deletions
|
@ -16,7 +16,7 @@ public class BlockDropper extends BlockDispenser {
|
|||
return new TileEntityDropper();
|
||||
}
|
||||
|
||||
protected void dispense(World world, int i, int j, int k) {
|
||||
public void dispense(World world, int i, int j, int k) { // CraftBukkit - protected -> public
|
||||
SourceBlock sourceblock = new SourceBlock(world, i, j, k);
|
||||
TileEntityDispenser tileentitydispenser = (TileEntityDispenser) sourceblock.getTileEntity();
|
||||
|
||||
|
|
|
@ -249,6 +249,8 @@ public class CraftBlock implements Block {
|
|||
return new CraftFurnace(this);
|
||||
case DISPENSER:
|
||||
return new CraftDispenser(this);
|
||||
case DROPPER:
|
||||
return new CraftDropper(this);
|
||||
case HOPPER:
|
||||
return new CraftHopper(this);
|
||||
case MOB_SPAWNER:
|
||||
|
|
50
src/main/java/org/bukkit/craftbukkit/block/CraftDropper.java
Normal file
50
src/main/java/org/bukkit/craftbukkit/block/CraftDropper.java
Normal file
|
@ -0,0 +1,50 @@
|
|||
package org.bukkit.craftbukkit.block;
|
||||
|
||||
import net.minecraft.server.BlockDropper;
|
||||
import net.minecraft.server.TileEntityDropper;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Dropper;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.craftbukkit.inventory.CraftInventory;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
public class CraftDropper extends CraftBlockState implements Dropper {
|
||||
private final CraftWorld world;
|
||||
private final TileEntityDropper dropper;
|
||||
|
||||
public CraftDropper(final Block block) {
|
||||
super(block);
|
||||
|
||||
world = (CraftWorld) block.getWorld();
|
||||
dropper = (TileEntityDropper) world.getTileEntityAt(getX(), getY(), getZ());
|
||||
}
|
||||
|
||||
public Inventory getInventory() {
|
||||
return new CraftInventory(dropper);
|
||||
}
|
||||
|
||||
public void drop() {
|
||||
Block block = getBlock();
|
||||
|
||||
synchronized (block) {
|
||||
if (block.getType() == Material.DROPPER) {
|
||||
BlockDropper drop = (BlockDropper) net.minecraft.server.Block.DROPPER;
|
||||
|
||||
drop.dispense(world.getHandle(), getX(), getY(), getZ());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean update(boolean force) {
|
||||
boolean result = super.update(force);
|
||||
|
||||
if (result) {
|
||||
dropper.update();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -15,6 +15,7 @@ import net.minecraft.server.PlayerInventory;
|
|||
import net.minecraft.server.TileEntityBeacon;
|
||||
import net.minecraft.server.TileEntityBrewingStand;
|
||||
import net.minecraft.server.TileEntityDispenser;
|
||||
import net.minecraft.server.TileEntityDropper;
|
||||
import net.minecraft.server.TileEntityFurnace;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
|
@ -423,10 +424,13 @@ public class CraftInventory implements Inventory {
|
|||
}
|
||||
|
||||
public InventoryType getType() {
|
||||
// Thanks to Droppers extending Dispensers, order is important.
|
||||
if (inventory instanceof InventoryCrafting) {
|
||||
return inventory.getSize() >= 9 ? InventoryType.WORKBENCH : InventoryType.CRAFTING;
|
||||
} else if (inventory instanceof PlayerInventory) {
|
||||
return InventoryType.PLAYER;
|
||||
} else if (inventory instanceof TileEntityDropper) {
|
||||
return InventoryType.DROPPER;
|
||||
} else if (inventory instanceof TileEntityDispenser) {
|
||||
return InventoryType.DISPENSER;
|
||||
} else if (inventory instanceof TileEntityFurnace) {
|
||||
|
|
Loading…
Reference in a new issue