mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-22 02:25:28 +01:00
#660: Add support to change block's lid state
This commit is contained in:
parent
c3a22e7850
commit
8fb65851f1
@ -1,6 +1,6 @@
|
|||||||
--- a/net/minecraft/server/TileEntityBarrel.java
|
--- a/net/minecraft/server/TileEntityBarrel.java
|
||||||
+++ b/net/minecraft/server/TileEntityBarrel.java
|
+++ b/net/minecraft/server/TileEntityBarrel.java
|
||||||
@@ -1,7 +1,54 @@
|
@@ -1,7 +1,55 @@
|
||||||
package net.minecraft.server;
|
package net.minecraft.server;
|
||||||
|
|
||||||
+// CraftBukkit start
|
+// CraftBukkit start
|
||||||
@ -21,6 +21,7 @@
|
|||||||
+ // CraftBukkit start - add fields and methods
|
+ // CraftBukkit start - add fields and methods
|
||||||
+ public List<HumanEntity> transaction = new ArrayList<>();
|
+ public List<HumanEntity> transaction = new ArrayList<>();
|
||||||
+ private int maxStack = MAX_STACK;
|
+ private int maxStack = MAX_STACK;
|
||||||
|
+ public boolean opened;
|
||||||
+
|
+
|
||||||
+ @Override
|
+ @Override
|
||||||
+ public List<ItemStack> getContents() {
|
+ public List<ItemStack> getContents() {
|
||||||
@ -55,3 +56,26 @@
|
|||||||
private NonNullList<ItemStack> items;
|
private NonNullList<ItemStack> items;
|
||||||
private int b;
|
private int b;
|
||||||
|
|
||||||
|
@@ -100,7 +148,7 @@
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
- boolean flag = (Boolean) iblockdata.get(BlockBarrel.b);
|
||||||
|
+ boolean flag = (Boolean) iblockdata.get(BlockBarrel.b) && !opened; // CraftBukkit - only set flag if Barrel isn't set open by API.
|
||||||
|
|
||||||
|
if (flag) {
|
||||||
|
this.a(iblockdata, SoundEffects.BLOCK_BARREL_CLOSE);
|
||||||
|
@@ -118,11 +166,11 @@
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
- private void a(IBlockData iblockdata, boolean flag) {
|
||||||
|
+ public void a(IBlockData iblockdata, boolean flag) { // PAIL private -> public, rename setFlag
|
||||||
|
this.world.setTypeAndData(this.getPosition(), (IBlockData) iblockdata.set(BlockBarrel.b, flag), 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
- private void a(IBlockData iblockdata, SoundEffect soundeffect) {
|
||||||
|
+ public void a(IBlockData iblockdata, SoundEffect soundeffect) { // PAIL private -> public, rename playSound
|
||||||
|
BaseBlockPosition baseblockposition = ((EnumDirection) iblockdata.get(BlockBarrel.a)).p();
|
||||||
|
double d0 = (double) this.position.getX() + 0.5D + (double) baseblockposition.getX() / 2.0D;
|
||||||
|
double d1 = (double) this.position.getY() + 0.5D + (double) baseblockposition.getY() / 2.0D;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
--- a/net/minecraft/server/TileEntityChest.java
|
--- a/net/minecraft/server/TileEntityChest.java
|
||||||
+++ b/net/minecraft/server/TileEntityChest.java
|
+++ b/net/minecraft/server/TileEntityChest.java
|
||||||
@@ -2,6 +2,10 @@
|
@@ -2,15 +2,50 @@
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -11,13 +11,17 @@
|
|||||||
|
|
||||||
public class TileEntityChest extends TileEntityLootable implements ITickable {
|
public class TileEntityChest extends TileEntityLootable implements ITickable {
|
||||||
|
|
||||||
@@ -11,6 +15,36 @@
|
private NonNullList<ItemStack> items;
|
||||||
protected int viewingCount;
|
protected float a;
|
||||||
|
protected float b;
|
||||||
|
- protected int viewingCount;
|
||||||
|
+ public int viewingCount; // PAIL protected -> public
|
||||||
private int j;
|
private int j;
|
||||||
|
|
||||||
+ // CraftBukkit start - add fields and methods
|
+ // CraftBukkit start - add fields and methods
|
||||||
+ public List<HumanEntity> transaction = new java.util.ArrayList<HumanEntity>();
|
+ public List<HumanEntity> transaction = new java.util.ArrayList<HumanEntity>();
|
||||||
+ private int maxStack = MAX_STACK;
|
+ private int maxStack = MAX_STACK;
|
||||||
|
+ public boolean opened;
|
||||||
+
|
+
|
||||||
+ public List<ItemStack> getContents() {
|
+ public List<ItemStack> getContents() {
|
||||||
+ return this.items;
|
+ return this.items;
|
||||||
@ -48,7 +52,30 @@
|
|||||||
protected TileEntityChest(TileEntityTypes<?> tileentitytypes) {
|
protected TileEntityChest(TileEntityTypes<?> tileentitytypes) {
|
||||||
super(tileentitytypes);
|
super(tileentitytypes);
|
||||||
this.items = NonNullList.a(27, ItemStack.b);
|
this.items = NonNullList.a(27, ItemStack.b);
|
||||||
@@ -155,8 +189,20 @@
|
@@ -61,6 +96,13 @@
|
||||||
|
this.b = this.a;
|
||||||
|
float f = 0.1F;
|
||||||
|
|
||||||
|
+ // CraftBukkit start - If chest is forced open by API, remove a viewer due to playBlockAction() call and don't tick to prevent sound effects.
|
||||||
|
+ if (opened) {
|
||||||
|
+ this.viewingCount--;
|
||||||
|
+ return;
|
||||||
|
+ }
|
||||||
|
+ // CraftBukkit end
|
||||||
|
+
|
||||||
|
if (this.viewingCount > 0 && this.a == 0.0F) {
|
||||||
|
this.a(SoundEffects.BLOCK_CHEST_OPEN);
|
||||||
|
}
|
||||||
|
@@ -120,7 +162,7 @@
|
||||||
|
return l;
|
||||||
|
}
|
||||||
|
|
||||||
|
- private void a(SoundEffect soundeffect) {
|
||||||
|
+ public void a(SoundEffect soundeffect) { // PAIL private -> public, rename playSound
|
||||||
|
BlockPropertyChestType blockpropertychesttype = (BlockPropertyChestType) this.getBlock().get(BlockChest.c);
|
||||||
|
|
||||||
|
if (blockpropertychesttype != BlockPropertyChestType.LEFT) {
|
||||||
|
@@ -155,8 +197,20 @@
|
||||||
if (this.viewingCount < 0) {
|
if (this.viewingCount < 0) {
|
||||||
this.viewingCount = 0;
|
this.viewingCount = 0;
|
||||||
}
|
}
|
||||||
@ -69,7 +96,7 @@
|
|||||||
this.onOpen();
|
this.onOpen();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,7 +211,18 @@
|
@@ -165,7 +219,18 @@
|
||||||
@Override
|
@Override
|
||||||
public void closeContainer(EntityHuman entityhuman) {
|
public void closeContainer(EntityHuman entityhuman) {
|
||||||
if (!entityhuman.isSpectator()) {
|
if (!entityhuman.isSpectator()) {
|
||||||
@ -88,7 +115,16 @@
|
|||||||
this.onOpen();
|
this.onOpen();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,4 +273,11 @@
|
@@ -175,7 +240,7 @@
|
||||||
|
Block block = this.getBlock().getBlock();
|
||||||
|
|
||||||
|
if (block instanceof BlockChest) {
|
||||||
|
- this.world.playBlockAction(this.position, block, 1, this.viewingCount);
|
||||||
|
+ if (!opened) this.world.playBlockAction(this.position, block, 1, this.viewingCount); // CraftBukkit
|
||||||
|
this.world.applyPhysics(this.position, block);
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -216,4 +281,11 @@
|
||||||
protected Container createContainer(int i, PlayerInventory playerinventory) {
|
protected Container createContainer(int i, PlayerInventory playerinventory) {
|
||||||
return ContainerChest.a(i, playerinventory, this);
|
return ContainerChest.a(i, playerinventory, this);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
--- a/net/minecraft/server/TileEntityShulkerBox.java
|
--- a/net/minecraft/server/TileEntityShulkerBox.java
|
||||||
+++ b/net/minecraft/server/TileEntityShulkerBox.java
|
+++ b/net/minecraft/server/TileEntityShulkerBox.java
|
||||||
@@ -3,6 +3,10 @@
|
@@ -3,12 +3,16 @@
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@ -11,13 +11,21 @@
|
|||||||
|
|
||||||
public class TileEntityShulkerBox extends TileEntityLootable implements IWorldInventory, ITickable {
|
public class TileEntityShulkerBox extends TileEntityLootable implements IWorldInventory, ITickable {
|
||||||
|
|
||||||
@@ -16,6 +20,36 @@
|
private static final int[] a = IntStream.range(0, 27).toArray();
|
||||||
|
private NonNullList<ItemStack> contents;
|
||||||
|
- private int c;
|
||||||
|
+ public int c; // PAIL private -> public, rename viewerCount
|
||||||
|
private TileEntityShulkerBox.AnimationPhase i;
|
||||||
|
private float j;
|
||||||
|
private float k;
|
||||||
|
@@ -16,6 +20,37 @@
|
||||||
private EnumColor l;
|
private EnumColor l;
|
||||||
private boolean m;
|
private boolean m;
|
||||||
|
|
||||||
+ // CraftBukkit start - add fields and methods
|
+ // CraftBukkit start - add fields and methods
|
||||||
+ public List<HumanEntity> transaction = new java.util.ArrayList<HumanEntity>();
|
+ public List<HumanEntity> transaction = new java.util.ArrayList<HumanEntity>();
|
||||||
+ private int maxStack = MAX_STACK;
|
+ private int maxStack = MAX_STACK;
|
||||||
|
+ public boolean opened;
|
||||||
+
|
+
|
||||||
+ public List<ItemStack> getContents() {
|
+ public List<ItemStack> getContents() {
|
||||||
+ return this.contents;
|
+ return this.contents;
|
||||||
@ -48,3 +56,19 @@
|
|||||||
public TileEntityShulkerBox(@Nullable EnumColor enumcolor) {
|
public TileEntityShulkerBox(@Nullable EnumColor enumcolor) {
|
||||||
super(TileEntityTypes.SHULKER_BOX);
|
super(TileEntityTypes.SHULKER_BOX);
|
||||||
this.contents = NonNullList.a(27, ItemStack.b);
|
this.contents = NonNullList.a(27, ItemStack.b);
|
||||||
|
@@ -178,6 +213,7 @@
|
||||||
|
}
|
||||||
|
|
||||||
|
++this.c;
|
||||||
|
+ if (opened) return; // CraftBukkit - only animate if the ShulkerBox hasn't been forced open already by an API call.
|
||||||
|
this.world.playBlockAction(this.position, this.getBlock().getBlock(), 1, this.c);
|
||||||
|
if (this.c == 1) {
|
||||||
|
this.world.playSound((EntityHuman) null, this.position, SoundEffects.BLOCK_SHULKER_BOX_OPEN, SoundCategory.BLOCKS, 0.5F, this.world.random.nextFloat() * 0.1F + 0.9F);
|
||||||
|
@@ -190,6 +226,7 @@
|
||||||
|
public void closeContainer(EntityHuman entityhuman) {
|
||||||
|
if (!entityhuman.isSpectator()) {
|
||||||
|
--this.c;
|
||||||
|
+ if (opened) return; // CraftBukkit - only animate if the ShulkerBox hasn't been forced open already by an API call.
|
||||||
|
this.world.playBlockAction(this.position, this.getBlock().getBlock(), 1, this.c);
|
||||||
|
if (this.c <= 0) {
|
||||||
|
this.world.playSound((EntityHuman) null, this.position, SoundEffects.BLOCK_SHULKER_BOX_CLOSE, SoundCategory.BLOCKS, 0.5F, this.world.random.nextFloat() * 0.1F + 0.9F);
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package org.bukkit.craftbukkit.block;
|
package org.bukkit.craftbukkit.block;
|
||||||
|
|
||||||
|
import net.minecraft.server.IBlockData;
|
||||||
|
import net.minecraft.server.SoundEffects;
|
||||||
import net.minecraft.server.TileEntityBarrel;
|
import net.minecraft.server.TileEntityBarrel;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Barrel;
|
import org.bukkit.block.Barrel;
|
||||||
@ -30,4 +32,26 @@ public class CraftBarrel extends CraftLootable<TileEntityBarrel> implements Barr
|
|||||||
|
|
||||||
return new CraftInventory(this.getTileEntity());
|
return new CraftInventory(this.getTileEntity());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void open() {
|
||||||
|
requirePlaced();
|
||||||
|
if (!getTileEntity().opened) {
|
||||||
|
IBlockData blockData = getTileEntity().getBlock();
|
||||||
|
getTileEntity().a(blockData, true);
|
||||||
|
getTileEntity().a(blockData, SoundEffects.BLOCK_BARREL_OPEN);
|
||||||
|
}
|
||||||
|
getTileEntity().opened = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
requirePlaced();
|
||||||
|
if (getTileEntity().opened) {
|
||||||
|
IBlockData blockData = getTileEntity().getBlock();
|
||||||
|
getTileEntity().a(blockData, false);
|
||||||
|
getTileEntity().a(blockData, SoundEffects.BLOCK_BARREL_CLOSE);
|
||||||
|
}
|
||||||
|
getTileEntity().opened = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package org.bukkit.craftbukkit.block;
|
|||||||
import net.minecraft.server.BlockChest;
|
import net.minecraft.server.BlockChest;
|
||||||
import net.minecraft.server.Blocks;
|
import net.minecraft.server.Blocks;
|
||||||
import net.minecraft.server.ITileInventory;
|
import net.minecraft.server.ITileInventory;
|
||||||
|
import net.minecraft.server.SoundEffects;
|
||||||
import net.minecraft.server.TileEntityChest;
|
import net.minecraft.server.TileEntityChest;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
@ -54,4 +55,26 @@ public class CraftChest extends CraftLootable<TileEntityChest> implements Chest
|
|||||||
}
|
}
|
||||||
return inventory;
|
return inventory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void open() {
|
||||||
|
requirePlaced();
|
||||||
|
if (!getTileEntity().opened) {
|
||||||
|
net.minecraft.server.Block block = getTileEntity().getBlock().getBlock();
|
||||||
|
getTileEntity().getWorld().playBlockAction(getTileEntity().getPosition(), block, 1, getTileEntity().viewingCount + 1);
|
||||||
|
getTileEntity().a(SoundEffects.BLOCK_CHEST_OPEN);
|
||||||
|
}
|
||||||
|
getTileEntity().opened = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
requirePlaced();
|
||||||
|
if (getTileEntity().opened) {
|
||||||
|
net.minecraft.server.Block block = getTileEntity().getBlock().getBlock();
|
||||||
|
getTileEntity().getWorld().playBlockAction(getTileEntity().getPosition(), block, 1, 0);
|
||||||
|
getTileEntity().a(SoundEffects.BLOCK_CHEST_CLOSE);
|
||||||
|
}
|
||||||
|
getTileEntity().opened = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
package org.bukkit.craftbukkit.block;
|
package org.bukkit.craftbukkit.block;
|
||||||
|
|
||||||
import net.minecraft.server.BlockShulkerBox;
|
import net.minecraft.server.BlockShulkerBox;
|
||||||
|
import net.minecraft.server.SoundCategory;
|
||||||
|
import net.minecraft.server.SoundEffects;
|
||||||
import net.minecraft.server.TileEntityShulkerBox;
|
import net.minecraft.server.TileEntityShulkerBox;
|
||||||
|
import net.minecraft.server.World;
|
||||||
import org.bukkit.DyeColor;
|
import org.bukkit.DyeColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
@ -40,4 +43,26 @@ public class CraftShulkerBox extends CraftLootable<TileEntityShulkerBox> impleme
|
|||||||
|
|
||||||
return DyeColor.getByWoolData((byte) ((BlockShulkerBox) block).color.getColorIndex());
|
return DyeColor.getByWoolData((byte) ((BlockShulkerBox) block).color.getColorIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void open() {
|
||||||
|
requirePlaced();
|
||||||
|
if (!getTileEntity().opened) {
|
||||||
|
World world = getTileEntity().getWorld();
|
||||||
|
world.playBlockAction(getPosition(), getTileEntity().getBlock().getBlock(), 1, 1);
|
||||||
|
world.playSound(null, getPosition(), SoundEffects.BLOCK_SHULKER_BOX_OPEN, SoundCategory.BLOCKS, 0.5F, world.random.nextFloat() * 0.1F + 0.9F);
|
||||||
|
}
|
||||||
|
getTileEntity().opened = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
requirePlaced();
|
||||||
|
if (getTileEntity().opened) {
|
||||||
|
World world = getTileEntity().getWorld();
|
||||||
|
world.playBlockAction(getPosition(), getTileEntity().getBlock().getBlock(), 1, 0);
|
||||||
|
world.playSound(null, getPosition(), SoundEffects.BLOCK_SHULKER_BOX_OPEN, SoundCategory.BLOCKS, 0.5F, world.random.nextFloat() * 0.1F + 0.9F);
|
||||||
|
}
|
||||||
|
getTileEntity().opened = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user