Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-11-17 05:20:05 +01:00
[Bleeding] Implementation of the brewing stand.
Dieser Commit ist enthalten in:
Ursprung
387d7319bc
Commit
edbb7358fc
212
src/main/java/net/minecraft/server/TileEntityBrewingStand.java
Normale Datei
212
src/main/java/net/minecraft/server/TileEntityBrewingStand.java
Normale Datei
@ -0,0 +1,212 @@
|
||||
package net.minecraft.server;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TileEntityBrewingStand extends TileEntity implements IInventory {
|
||||
|
||||
public ItemStack[] a = new ItemStack[4]; // CraftBukkit private -> public
|
||||
public int b; // CraftBukkit private -> public
|
||||
private int c;
|
||||
private int d;
|
||||
|
||||
public TileEntityBrewingStand() {}
|
||||
|
||||
// CraftBukkit start
|
||||
public ItemStack[] getContents() {
|
||||
return this.a;
|
||||
}
|
||||
// CraftBukkit end
|
||||
|
||||
public String getName() {
|
||||
return "Brewing Stand";
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return this.a.length;
|
||||
}
|
||||
|
||||
public void l_() {
|
||||
if (this.b > 0) {
|
||||
--this.b;
|
||||
if (this.b == 0) {
|
||||
this.p();
|
||||
this.update();
|
||||
} else if (!this.o()) {
|
||||
this.b = 0;
|
||||
this.update();
|
||||
} else if (this.d != this.a[3].id) {
|
||||
this.b = 0;
|
||||
this.update();
|
||||
}
|
||||
} else if (this.o()) {
|
||||
this.b = 400;
|
||||
this.d = this.a[3].id;
|
||||
}
|
||||
|
||||
int i = this.n();
|
||||
|
||||
if (i != this.c) {
|
||||
this.c = i;
|
||||
this.world.setData(this.x, this.y, this.z, i);
|
||||
}
|
||||
|
||||
super.l_();
|
||||
}
|
||||
|
||||
public int h() {
|
||||
return this.b;
|
||||
}
|
||||
|
||||
private boolean o() {
|
||||
if (this.a[3] != null && this.a[3].count > 0) {
|
||||
ItemStack itemstack = this.a[3];
|
||||
|
||||
if (!Item.byId[itemstack.id].n()) {
|
||||
return false;
|
||||
} else {
|
||||
boolean flag = false;
|
||||
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
if (this.a[i] != null && this.a[i].id == Item.POTION.id) {
|
||||
int j = this.a[i].getData();
|
||||
int k = this.b(j, itemstack);
|
||||
|
||||
if (!ItemPotion.c(j) && ItemPotion.c(k)) {
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
|
||||
List list = Item.POTION.b(j);
|
||||
List list1 = Item.POTION.b(k);
|
||||
|
||||
if ((j <= 0 || list != list1) && (list == null || !list.equals(list1) && list1 != null) && j != k) {
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return flag;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void p() {
|
||||
if (this.o()) {
|
||||
ItemStack itemstack = this.a[3];
|
||||
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
if (this.a[i] != null && this.a[i].id == Item.POTION.id) {
|
||||
int j = this.a[i].getData();
|
||||
int k = this.b(j, itemstack);
|
||||
List list = Item.POTION.b(j);
|
||||
List list1 = Item.POTION.b(k);
|
||||
|
||||
if ((j <= 0 || list != list1) && (list == null || !list.equals(list1) && list1 != null)) {
|
||||
if (j != k) {
|
||||
this.a[i].setData(k);
|
||||
}
|
||||
} else if (!ItemPotion.c(j) && ItemPotion.c(k)) {
|
||||
this.a[i].setData(k);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Item.byId[itemstack.id].k()) {
|
||||
this.a[3] = new ItemStack(Item.byId[itemstack.id].j());
|
||||
} else {
|
||||
--this.a[3].count;
|
||||
if (this.a[3].count <= 0) {
|
||||
this.a[3] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int b(int i, ItemStack itemstack) {
|
||||
return itemstack == null ? i : (Item.byId[itemstack.id].n() ? PotionBrewer.a(i, Item.byId[itemstack.id].m()) : i);
|
||||
}
|
||||
|
||||
public void a(NBTTagCompound nbttagcompound) {
|
||||
super.a(nbttagcompound);
|
||||
NBTTagList nbttaglist = nbttagcompound.getList("Items");
|
||||
|
||||
this.a = new ItemStack[this.getSize()];
|
||||
|
||||
for (int i = 0; i < nbttaglist.size(); ++i) {
|
||||
NBTTagCompound nbttagcompound1 = (NBTTagCompound) nbttaglist.get(i);
|
||||
byte b0 = nbttagcompound1.getByte("Slot");
|
||||
|
||||
if (b0 >= 0 && b0 < this.a.length) {
|
||||
this.a[b0] = ItemStack.a(nbttagcompound1);
|
||||
}
|
||||
}
|
||||
|
||||
this.b = nbttagcompound.getShort("BrewTime");
|
||||
}
|
||||
|
||||
public void b(NBTTagCompound nbttagcompound) {
|
||||
super.b(nbttagcompound);
|
||||
nbttagcompound.setShort("BrewTime", (short) this.b);
|
||||
NBTTagList nbttaglist = new NBTTagList();
|
||||
|
||||
for (int i = 0; i < this.a.length; ++i) {
|
||||
if (this.a[i] != null) {
|
||||
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
|
||||
|
||||
nbttagcompound1.setByte("Slot", (byte) i);
|
||||
this.a[i].b(nbttagcompound1);
|
||||
nbttaglist.add(nbttagcompound1);
|
||||
}
|
||||
}
|
||||
|
||||
nbttagcompound.set("Items", nbttaglist);
|
||||
}
|
||||
|
||||
public ItemStack getItem(int i) {
|
||||
return i >= 0 && i < this.a.length ? this.a[i] : null;
|
||||
}
|
||||
|
||||
public ItemStack splitStack(int i, int j) {
|
||||
if (i >= 0 && i < this.a.length) {
|
||||
ItemStack itemstack = this.a[i];
|
||||
|
||||
this.a[i] = null;
|
||||
return itemstack;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void setItem(int i, ItemStack itemstack) {
|
||||
if (i >= 0 && i < this.a.length) {
|
||||
this.a[i] = itemstack;
|
||||
}
|
||||
}
|
||||
|
||||
public int getMaxStackSize() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public boolean a(EntityHuman entityhuman) {
|
||||
return this.world.getTileEntity(this.x, this.y, this.z) != this ? false : entityhuman.e((double) this.x + 0.5D, (double) this.y + 0.5D, (double) this.z + 0.5D) <= 64.0D;
|
||||
}
|
||||
|
||||
public void f() {}
|
||||
|
||||
public void g() {}
|
||||
|
||||
public int n() {
|
||||
int i = 0;
|
||||
|
||||
for (int j = 0; j < 3; ++j) {
|
||||
if (this.a[j] != null) {
|
||||
i |= 1 << j;
|
||||
}
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
}
|
@ -231,6 +231,8 @@ public class CraftBlock implements Block {
|
||||
return new CraftNoteBlock(this);
|
||||
case JUKEBOX:
|
||||
return new CraftJukebox(this);
|
||||
case BREWING_STAND:
|
||||
return new CraftBrewingStand(this);
|
||||
default:
|
||||
return new CraftBlockState(this);
|
||||
}
|
||||
|
43
src/main/java/org/bukkit/craftbukkit/block/CraftBrewingStand.java
Normale Datei
43
src/main/java/org/bukkit/craftbukkit/block/CraftBrewingStand.java
Normale Datei
@ -0,0 +1,43 @@
|
||||
package org.bukkit.craftbukkit.block;
|
||||
|
||||
import net.minecraft.server.TileEntityBrewingStand;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BrewingStand;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.craftbukkit.inventory.CraftInventory;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
public class CraftBrewingStand extends CraftBlockState implements BrewingStand {
|
||||
private final CraftWorld world;
|
||||
private final TileEntityBrewingStand brewingStand;
|
||||
|
||||
public CraftBrewingStand(Block block) {
|
||||
super(block);
|
||||
|
||||
world = (CraftWorld) block.getWorld();
|
||||
brewingStand = (TileEntityBrewingStand) world.getTileEntityAt(getX(), getY(), getZ());
|
||||
}
|
||||
|
||||
public Inventory getInventory() {
|
||||
return new CraftInventory(brewingStand);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean update(boolean force) {
|
||||
boolean result = super.update(force);
|
||||
|
||||
if (result) {
|
||||
brewingStand.update();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public int getBrewingTime() {
|
||||
return brewingStand.b;
|
||||
}
|
||||
|
||||
public void setBrewingTime(int brewTime) {
|
||||
brewingStand.b = brewTime;
|
||||
}
|
||||
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren