Added Barrels as an option for ChestLinks!
This commit is contained in:
jameslfc19 2020-07-18 18:29:54 +01:00
parent 3a3b0bd780
commit c5e38b6711
17 changed files with 380 additions and 89 deletions

View File

@ -1,8 +1,9 @@
package com.jamesdpeters.minecraft.chests;
import org.bukkit.block.Chest;
import org.bukkit.block.Container;
import org.bukkit.inventory.Inventory;
public interface ChestOpener {
void setLidOpen(Inventory inventory, Chest chest, boolean open);
void setLidOpen(Inventory inventory, Container chest, boolean open);
}

View File

@ -0,0 +1,9 @@
package com.jamesdpeters.minecraft.chests;
import org.bukkit.entity.HumanEntity;
import java.util.List;
public interface TileEntityOpener {
void setViewers(List<HumanEntity> viewers);
}

View File

@ -1,37 +1,50 @@
package com.jamesdpeters.minecraft.chests.v1_14_R1;
import com.jamesdpeters.minecraft.chests.ChestOpener;
import com.jamesdpeters.minecraft.chests.TileEntityOpener;
import com.jamesdpeters.minecraft.chests.v1_14_R1.tileentities.CustomTileEntityBarrel;
import com.jamesdpeters.minecraft.chests.v1_14_R1.tileentities.CustomTileEntityChest;
import net.minecraft.server.v1_14_R1.BlockPosition;
import net.minecraft.server.v1_14_R1.TileEntity;
import net.minecraft.server.v1_14_R1.TileEntityBarrel;
import net.minecraft.server.v1_14_R1.TileEntityChest;
import net.minecraft.server.v1_14_R1.World;
import org.bukkit.block.Chest;
import org.bukkit.block.Container;
import org.bukkit.craftbukkit.v1_14_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_14_R1.block.CraftChest;
import org.bukkit.craftbukkit.v1_14_R1.block.CraftContainer;
import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.Inventory;
import java.util.List;
public class ChestOpener_1_14 implements ChestOpener {
@Override
public void setLidOpen(Inventory inventory, Chest chest, boolean open) {
CraftChest craftChest = (CraftChest) chest;
CraftWorld craftWorld = (CraftWorld) craftChest.getWorld();
public void setLidOpen(Inventory inventory, Container chest, boolean open) {
CraftContainer craftContainer = (CraftContainer) chest;
CraftWorld craftWorld = (CraftWorld) craftContainer.getWorld();
World world = craftWorld.getHandle();
BlockPosition position = craftChest.getPosition();
BlockPosition position = craftContainer.getPosition();
TileEntity tileEntity = world.getTileEntity(position);
if(tileEntity instanceof TileEntityChest){
boolean isCustomTileEntity = tileEntity instanceof CustomTileEntityChest;
CustomTileEntityChest customTileEntityChest;
if(!isCustomTileEntity){
customTileEntityChest = new CustomTileEntityChest();
world.removeTileEntity(position);
world.setTileEntity(position, customTileEntityChest);
//Checks if Tile Entity has already got custom Opener.
if(tileEntity instanceof TileEntityOpener){
((TileEntityOpener) tileEntity).setViewers(inventory.getViewers());
} else {
customTileEntityChest = (CustomTileEntityChest) tileEntity;
//If not set the new tile entity and set the viewers.
if (tileEntity instanceof TileEntityChest) {
setTileEnt(world, position, new CustomTileEntityChest(), inventory.getViewers());
} else if (tileEntity instanceof TileEntityBarrel) {
setTileEnt(world, position, new CustomTileEntityBarrel(), inventory.getViewers());
}
customTileEntityChest.setViewers(inventory.getViewers());
}
}
private <T extends TileEntity & TileEntityOpener> void setTileEnt(World world, BlockPosition position, T tileEntOpener, List<HumanEntity> viewers){
world.removeTileEntity(position);
world.setTileEntity(position, tileEntOpener);
tileEntOpener.setViewers(viewers);
}
}

View File

@ -0,0 +1,75 @@
package com.jamesdpeters.minecraft.chests.v1_14_R1.tileentities;
import com.jamesdpeters.minecraft.chests.TileEntityOpener;
import net.minecraft.server.v1_14_R1.BaseBlockPosition;
import net.minecraft.server.v1_14_R1.BlockBarrel;
import net.minecraft.server.v1_14_R1.EntityHuman;
import net.minecraft.server.v1_14_R1.EnumDirection;
import net.minecraft.server.v1_14_R1.IBlockData;
import net.minecraft.server.v1_14_R1.SoundCategory;
import net.minecraft.server.v1_14_R1.SoundEffect;
import net.minecraft.server.v1_14_R1.SoundEffects;
import net.minecraft.server.v1_14_R1.TileEntityBarrel;
import org.bukkit.entity.HumanEntity;
import java.util.List;
public class CustomTileEntityBarrel extends TileEntityBarrel implements TileEntityOpener {
private int phantomViewers = 0;
private List<HumanEntity> viewers;
@Override
public List<HumanEntity> getViewers() {
return viewers;
}
@Override
public void h() {
//super.h();
}
@Override
public void startOpen(EntityHuman entityhuman) {
//super.startOpen(entityhuman);
}
@Override
public void closeContainer(EntityHuman entityhuman) {
//do nothing.
}
@Override
public void setViewers(List<HumanEntity> viewers){
int previousViewers = phantomViewers;
phantomViewers = viewers.size();
this.viewers = viewers;
if(phantomViewers > 1 && previousViewers == 0) open();
if(phantomViewers == 0) close();
}
public void open(){
IBlockData iblockdata = this.getBlock();
a(iblockdata, SoundEffects.BLOCK_BARREL_OPEN);
a(iblockdata, true);
}
public void close(){
IBlockData iblockdata = this.getBlock();
a(iblockdata, SoundEffects.BLOCK_BARREL_CLOSE);
a(iblockdata, false);
}
private void a(IBlockData iblockdata, boolean flag) {
this.world.setTypeAndData(this.getPosition(), (IBlockData)iblockdata.set(BlockBarrel.b, flag), 3);
}
private void a(IBlockData iblockdata, SoundEffect soundeffect) {
BaseBlockPosition baseblockposition = ((EnumDirection)iblockdata.get(BlockBarrel.a)).n();
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;
double d2 = (double)this.position.getZ() + 0.5D + (double)baseblockposition.getZ() / 2.0D;
this.world.playSound((EntityHuman)null, d0, d1, d2, soundeffect, SoundCategory.BLOCKS, 0.5F, this.world.random.nextFloat() * 0.1F + 0.9F);
}
}

View File

@ -1,5 +1,6 @@
package com.jamesdpeters.minecraft.chests.v1_14_R1;
package com.jamesdpeters.minecraft.chests.v1_14_R1.tileentities;
import com.jamesdpeters.minecraft.chests.TileEntityOpener;
import net.minecraft.server.v1_14_R1.Block;
import net.minecraft.server.v1_14_R1.BlockChest;
import net.minecraft.server.v1_14_R1.BlockPropertyChestType;
@ -12,7 +13,7 @@ import org.bukkit.entity.HumanEntity;
import java.util.List;
public class CustomTileEntityChest extends TileEntityChest {
public class CustomTileEntityChest extends TileEntityChest implements TileEntityOpener {
private int phantomViewers = 0;
private List<HumanEntity> viewers;
@ -36,6 +37,7 @@ public class CustomTileEntityChest extends TileEntityChest {
}
}
@Override
public void setViewers(List<HumanEntity> viewers){
int previousViewers = phantomViewers;
phantomViewers = viewers.size();

View File

@ -1,37 +1,49 @@
package com.jamesdpeters.minecraft.chests.v1_15_R1;
import com.jamesdpeters.minecraft.chests.ChestOpener;
import com.jamesdpeters.minecraft.chests.TileEntityOpener;
import com.jamesdpeters.minecraft.chests.v1_15_R1.tileentities.CustomTileEntityBarrel;
import com.jamesdpeters.minecraft.chests.v1_15_R1.tileentities.CustomTileEntityChest;
import net.minecraft.server.v1_15_R1.BlockPosition;
import net.minecraft.server.v1_15_R1.TileEntity;
import net.minecraft.server.v1_15_R1.TileEntityBarrel;
import net.minecraft.server.v1_15_R1.TileEntityChest;
import net.minecraft.server.v1_15_R1.World;
import org.bukkit.block.Chest;
import org.bukkit.block.Container;
import org.bukkit.craftbukkit.v1_15_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_15_R1.block.CraftChest;
import org.bukkit.craftbukkit.v1_15_R1.block.CraftContainer;
import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.Inventory;
import java.util.List;
public class ChestOpener_1_15 implements ChestOpener {
@Override
public void setLidOpen(Inventory inventory, Chest chest, boolean open) {
CraftChest craftChest = (CraftChest) chest;
CraftWorld craftWorld = (CraftWorld) craftChest.getWorld();
public void setLidOpen(Inventory inventory, Container chest, boolean open) {
CraftContainer craftContainer = (CraftContainer) chest;
CraftWorld craftWorld = (CraftWorld) craftContainer.getWorld();
World world = craftWorld.getHandle();
BlockPosition position = craftChest.getPosition();
BlockPosition position = craftContainer.getPosition();
TileEntity tileEntity = world.getTileEntity(position);
if(tileEntity instanceof TileEntityChest){
boolean isCustomTileEntity = tileEntity instanceof CustomTileEntityChest;
CustomTileEntityChest customTileEntityChest;
if(!isCustomTileEntity){
customTileEntityChest = new CustomTileEntityChest();
world.removeTileEntity(position);
world.setTileEntity(position, customTileEntityChest);
//Checks if Tile Entity has already got custom Opener.
if(tileEntity instanceof TileEntityOpener){
((TileEntityOpener) tileEntity).setViewers(inventory.getViewers());
} else {
customTileEntityChest = (CustomTileEntityChest) tileEntity;
//If not set the new tile entity and set the viewers.
if (tileEntity instanceof TileEntityChest) {
setTileEnt(world, position, new CustomTileEntityChest(), inventory.getViewers());
} else if (tileEntity instanceof TileEntityBarrel) {
setTileEnt(world, position, new CustomTileEntityBarrel(), inventory.getViewers());
}
customTileEntityChest.setViewers(inventory.getViewers());
}
}
private <T extends TileEntity & TileEntityOpener> void setTileEnt(World world, BlockPosition position, T tileEntOpener, List<HumanEntity> viewers){
world.removeTileEntity(position);
world.setTileEntity(position, tileEntOpener);
tileEntOpener.setViewers(viewers);
}
}

View File

@ -0,0 +1,75 @@
package com.jamesdpeters.minecraft.chests.v1_15_R1.tileentities;
import com.jamesdpeters.minecraft.chests.TileEntityOpener;
import net.minecraft.server.v1_15_R1.BaseBlockPosition;
import net.minecraft.server.v1_15_R1.BlockBarrel;
import net.minecraft.server.v1_15_R1.EntityHuman;
import net.minecraft.server.v1_15_R1.EnumDirection;
import net.minecraft.server.v1_15_R1.IBlockData;
import net.minecraft.server.v1_15_R1.SoundCategory;
import net.minecraft.server.v1_15_R1.SoundEffect;
import net.minecraft.server.v1_15_R1.SoundEffects;
import net.minecraft.server.v1_15_R1.TileEntityBarrel;
import org.bukkit.entity.HumanEntity;
import java.util.List;
public class CustomTileEntityBarrel extends TileEntityBarrel implements TileEntityOpener {
private int phantomViewers = 0;
private List<HumanEntity> viewers;
@Override
public List<HumanEntity> getViewers() {
return viewers;
}
@Override
public void h() {
//super.h();
}
@Override
public void startOpen(EntityHuman entityhuman) {
//Do nothing
}
@Override
public void closeContainer(EntityHuman entityhuman) {
//do nothing.
}
@Override
public void setViewers(List<HumanEntity> viewers){
int previousViewers = phantomViewers;
phantomViewers = viewers.size();
this.viewers = viewers;
if(phantomViewers > 1 && previousViewers == 0) open();
if(phantomViewers == 0) close();
}
public void open(){
IBlockData iblockdata = this.getBlock();
a(iblockdata, SoundEffects.BLOCK_BARREL_OPEN);
a(iblockdata, true);
}
public void close(){
IBlockData iblockdata = this.getBlock();
a(iblockdata, SoundEffects.BLOCK_BARREL_CLOSE);
a(iblockdata, false);
}
private void a(IBlockData iblockdata, boolean flag) {
this.world.setTypeAndData(this.getPosition(), (IBlockData)iblockdata.set(BlockBarrel.b, flag), 3);
}
private void a(IBlockData iblockdata, SoundEffect soundeffect) {
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;
double d2 = (double)this.position.getZ() + 0.5D + (double)baseblockposition.getZ() / 2.0D;
this.world.playSound((EntityHuman)null, d0, d1, d2, soundeffect, SoundCategory.BLOCKS, 0.5F, this.world.random.nextFloat() * 0.1F + 0.9F);
}
}

View File

@ -1,5 +1,6 @@
package com.jamesdpeters.minecraft.chests.v1_15_R1;
package com.jamesdpeters.minecraft.chests.v1_15_R1.tileentities;
import com.jamesdpeters.minecraft.chests.TileEntityOpener;
import net.minecraft.server.v1_15_R1.Block;
import net.minecraft.server.v1_15_R1.BlockChest;
import net.minecraft.server.v1_15_R1.BlockPropertyChestType;
@ -13,7 +14,7 @@ import org.bukkit.entity.HumanEntity;
import java.util.List;
public class CustomTileEntityChest extends TileEntityChest {
public class CustomTileEntityChest extends TileEntityChest implements TileEntityOpener {
private int phantomViewers = 0;
private List<HumanEntity> viewers;

View File

@ -1,39 +1,50 @@
package com.jamesdpeters.minecraft.chests.v1_16_R1;
import com.jamesdpeters.minecraft.chests.ChestOpener;
import com.jamesdpeters.minecraft.chests.TileEntityOpener;
import com.jamesdpeters.minecraft.chests.v1_16_R1.tileentities.CustomTileEntityBarrel;
import com.jamesdpeters.minecraft.chests.v1_16_R1.tileentities.CustomTileEntityChest;
import net.minecraft.server.v1_16_R1.BlockPosition;
import net.minecraft.server.v1_16_R1.TileEntity;
import net.minecraft.server.v1_16_R1.TileEntityBarrel;
import net.minecraft.server.v1_16_R1.TileEntityChest;
import net.minecraft.server.v1_16_R1.World;
import org.bukkit.Bukkit;
import org.bukkit.block.Chest;
import org.bukkit.block.Container;
import org.bukkit.craftbukkit.v1_16_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_16_R1.block.CraftChest;
import org.bukkit.craftbukkit.v1_16_R1.block.CraftContainer;
import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.Inventory;
import java.util.List;
public class ChestOpener_1_16 implements ChestOpener {
@Override
public void setLidOpen(Inventory inventory, Chest chest, boolean open) {
CraftChest craftChest = (CraftChest) chest;
CraftWorld craftWorld = (CraftWorld) craftChest.getWorld();
public void setLidOpen(Inventory inventory, Container chest, boolean open) {
CraftContainer craftContainer = (CraftContainer) chest;
CraftWorld craftWorld = (CraftWorld) craftContainer.getWorld();
World world = craftWorld.getHandle();
BlockPosition position = craftChest.getPosition();
BlockPosition position = craftContainer.getPosition();
TileEntity tileEntity = world.getTileEntity(position);
if(tileEntity instanceof TileEntityChest){
boolean isCustomTileEntity = tileEntity instanceof CustomTileEntityChest;
CustomTileEntityChest customTileEntityChest;
if(!isCustomTileEntity){
customTileEntityChest = new CustomTileEntityChest();
world.removeTileEntity(position);
world.setTileEntity(position, customTileEntityChest);
//Checks if Tile Entity has already got custom Opener.
if(tileEntity instanceof TileEntityOpener){
((TileEntityOpener) tileEntity).setViewers(inventory.getViewers());
} else {
customTileEntityChest = (CustomTileEntityChest) tileEntity;
//If not set the new tile entity and set the viewers.
if (tileEntity instanceof TileEntityChest) {
setTileEnt(world, position, new CustomTileEntityChest(), inventory.getViewers());
} else if (tileEntity instanceof TileEntityBarrel) {
setTileEnt(world, position, new CustomTileEntityBarrel(), inventory.getViewers());
}
customTileEntityChest.setViewers(inventory.getViewers());
}
}
private <T extends TileEntity & TileEntityOpener> void setTileEnt(World world, BlockPosition position, T tileEntOpener, List<HumanEntity> viewers){
world.removeTileEntity(position);
world.setTileEntity(position, tileEntOpener);
tileEntOpener.setViewers(viewers);
}
}

View File

@ -0,0 +1,75 @@
package com.jamesdpeters.minecraft.chests.v1_16_R1.tileentities;
import com.jamesdpeters.minecraft.chests.TileEntityOpener;
import net.minecraft.server.v1_16_R1.BaseBlockPosition;
import net.minecraft.server.v1_16_R1.BlockBarrel;
import net.minecraft.server.v1_16_R1.EntityHuman;
import net.minecraft.server.v1_16_R1.EnumDirection;
import net.minecraft.server.v1_16_R1.IBlockData;
import net.minecraft.server.v1_16_R1.SoundCategory;
import net.minecraft.server.v1_16_R1.SoundEffect;
import net.minecraft.server.v1_16_R1.SoundEffects;
import net.minecraft.server.v1_16_R1.TileEntityBarrel;
import org.bukkit.entity.HumanEntity;
import java.util.List;
public class CustomTileEntityBarrel extends TileEntityBarrel implements TileEntityOpener {
private int phantomViewers = 0;
private List<HumanEntity> viewers;
@Override
public List<HumanEntity> getViewers() {
return viewers;
}
@Override
public void h() {
//super.h();
}
@Override
public void startOpen(EntityHuman entityhuman) {
//Do nothing
}
@Override
public void closeContainer(EntityHuman entityhuman) {
//do nothing.
}
@Override
public void setViewers(List<HumanEntity> viewers){
int previousViewers = phantomViewers;
phantomViewers = viewers.size();
this.viewers = viewers;
if(phantomViewers > 1 && previousViewers == 0) open();
if(phantomViewers == 0) close();
}
public void open(){
IBlockData iblockdata = this.getBlock();
a(iblockdata, SoundEffects.BLOCK_BARREL_OPEN);
a(iblockdata, true);
}
public void close(){
IBlockData iblockdata = this.getBlock();
a(iblockdata, SoundEffects.BLOCK_BARREL_CLOSE);
a(iblockdata, false);
}
private void a(IBlockData iblockdata, boolean flag) {
this.world.setTypeAndData(this.getPosition(), (IBlockData)iblockdata.set(BlockBarrel.b, flag), 3);
}
private void a(IBlockData iblockdata, SoundEffect soundeffect) {
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;
double d2 = (double)this.position.getZ() + 0.5D + (double)baseblockposition.getZ() / 2.0D;
this.world.playSound((EntityHuman)null, d0, d1, d2, soundeffect, SoundCategory.BLOCKS, 0.5F, this.world.random.nextFloat() * 0.1F + 0.9F);
}
}

View File

@ -1,5 +1,6 @@
package com.jamesdpeters.minecraft.chests.v1_16_R1;
package com.jamesdpeters.minecraft.chests.v1_16_R1.tileentities;
import com.jamesdpeters.minecraft.chests.TileEntityOpener;
import net.minecraft.server.v1_16_R1.Block;
import net.minecraft.server.v1_16_R1.BlockChest;
import net.minecraft.server.v1_16_R1.BlockPropertyChestType;
@ -16,7 +17,7 @@ import org.bukkit.entity.HumanEntity;
import java.util.List;
public class CustomTileEntityChest extends TileEntityChest {
public class CustomTileEntityChest extends TileEntityChest implements TileEntityOpener {
private int phantomViewers = 0;
private List<HumanEntity> viewers;
@ -40,6 +41,7 @@ public class CustomTileEntityChest extends TileEntityChest {
}
}
@Override
public void setViewers(List<HumanEntity> viewers){
int previousViewers = phantomViewers;
phantomViewers = viewers.size();

View File

@ -15,6 +15,7 @@ import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.block.Chest;
import org.bukkit.block.Container;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -75,8 +76,8 @@ public class InventoryListener implements Listener {
event.getViewers().remove(event.getPlayer());
vHolder.getStorage().getLocations().forEach(locationInfo -> {
Block block = locationInfo.getLocation().getBlock();
if(block.getState() instanceof Chest){
Chest chest = (Chest) block.getState();
if(block.getState() instanceof Container){
Container chest = (Container) block.getState();
Bukkit.getScheduler().scheduleSyncDelayedTask(ChestsPlusPlus.PLUGIN, () -> ApiSpecific.getChestOpener().setLidOpen(event.getInventory(),chest,false),1);
}
});

View File

@ -10,11 +10,14 @@ import org.bukkit.*;
import org.bukkit.block.*;
import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.RegisteredListener;
import org.bukkit.util.Vector;
import java.util.*;
@ -26,10 +29,10 @@ public class Utils {
//Check if all chests should perform open animation.
if(Settings.isShouldAnimateAllChests()) {
storage.getLocations().forEach(locationInfo -> {
int chunkX = locationInfo.getLocation().getBlockX() >> 4;
int chunkZ = locationInfo.getLocation().getBlockZ() >> 4;
Location location = locationInfo.getLocation();
if (location != null) {
int chunkX = locationInfo.getLocation().getBlockX() >> 4;
int chunkZ = locationInfo.getLocation().getBlockZ() >> 4;
World world = location.getWorld();
if (world != null && world.isChunkLoaded(chunkX, chunkZ)) {
chestOpenAnimation(storage.getInventory(), locationInfo.getLocation());
@ -45,9 +48,8 @@ public class Utils {
private static void chestOpenAnimation(Inventory inventory, Location location){
if (location != null) {
Block block = location.getBlock();
if (block.getState() instanceof Chest) {
Chest chest = (Chest) block.getState();
// ApiSpecific.getChestOpener().setLidOpen(inventory, chest, true);
if (block.getState() instanceof Container) {
Container chest = (Container) block.getState();
Bukkit.getScheduler().scheduleSyncDelayedTask(ChestsPlusPlus.PLUGIN,() -> ApiSpecific.getChestOpener().setLidOpen(inventory, chest, true),1);
}
}

View File

@ -192,7 +192,7 @@ public abstract class AbstractStorage implements ConfigurationSerializable {
* This is the distance from a full block to the size of the storage block. (e.g Chest is smaller than a regular block.)
* @return
*/
public abstract double getBlockOffset();
public abstract double getBlockOffset(Block block);
/**
* This is called when a block is added to the storage system.
@ -417,6 +417,7 @@ public abstract class AbstractStorage implements ConfigurationSerializable {
if(world != null) {
if(location.getSignLocation() == null) return;
Block storageBlock = location.getLocation().getBlock();
Block anchor = location.getSignLocation().getBlock();
BlockFace facing;
if(anchor.getBlockData() instanceof Directional){
@ -428,7 +429,7 @@ public abstract class AbstractStorage implements ConfigurationSerializable {
boolean isBlock = !ApiSpecific.getMaterialChecker().isGraphically2D(displayItem);
boolean isTool = ApiSpecific.getMaterialChecker().isTool(displayItem);
Location standLoc = isTool ? getHeldItemArmorStandLoc(anchor, facing) : getArmorStandLoc(anchor, facing, isBlock);
Location standLoc = isTool ? getHeldItemArmorStandLoc(storageBlock,anchor, facing) : getArmorStandLoc(storageBlock, anchor, facing, isBlock);
//Get currently stored armorStand if there isn't one spawn it.
ArmorStand stand = isTool ? location.getToolItemStand() : (isBlock ? location.getBlockStand() : location.getItemStand());
@ -494,29 +495,29 @@ public abstract class AbstractStorage implements ConfigurationSerializable {
* @param isBlock - true if the @{@link ItemStack} is a Block / false if an Item.
* @return the calculated location for the @{@link ArmorStand}
*/
private Location getArmorStandLoc(Block anchor, BlockFace facing, boolean isBlock){
private Location getArmorStandLoc(Block storageBlock, Block anchor, BlockFace facing, boolean isBlock){
double directionFactor = isBlock ? 0.65 : 0.275;
double perpendicularFactor = isBlock ? 0.025 : 0.125;
double y = isBlock ? -0.3 : 0.1;
float yaw = 180;
return getArmorStandLoc(anchor, facing, directionFactor, perpendicularFactor, y, yaw);
return getArmorStandLoc(storageBlock, anchor, facing, directionFactor, perpendicularFactor, y, yaw);
}
private Location getHeldItemArmorStandLoc(Block anchor, BlockFace facing){
private Location getHeldItemArmorStandLoc(Block storageBlock, Block anchor, BlockFace facing){
double directionFactor = 0.36;
double perpendicularFactor = 0;
double y = 0.275;
float yaw = -90;
return getArmorStandLoc(anchor, facing, directionFactor, perpendicularFactor, y, yaw);
return getArmorStandLoc(storageBlock, anchor, facing, directionFactor, perpendicularFactor, y, yaw);
}
private Location getArmorStandLoc(Block anchor, BlockFace facing, double directionFactor, double perpendicularFactor, double y, float yaw){
private Location getArmorStandLoc(Block storageBlock, Block anchor, BlockFace facing, double directionFactor, double perpendicularFactor, double y, float yaw){
//Get centre of block location.
Location standLoc = anchor.getLocation().add(0.5,-0.5,0.5);
Vector direction = facing.getDirection();
directionFactor = directionFactor + getBlockOffset();
directionFactor = directionFactor + getBlockOffset(storageBlock);
double x = directionFactor*direction.getX() - perpendicularFactor*direction.getZ();
double z = directionFactor*direction.getZ() + perpendicularFactor*direction.getX();

View File

@ -83,7 +83,7 @@ public class AutoCraftingStorage extends AbstractStorage implements Configuratio
}
@Override
public double getBlockOffset() {
public double getBlockOffset(Block block) {
return -0.07;
}

View File

@ -17,11 +17,14 @@ import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.block.Barrel;
import org.bukkit.block.Block;
import org.bukkit.block.Chest;
import org.bukkit.block.Container;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.configuration.serialization.SerializableAs;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryMoveItemEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
@ -47,10 +50,10 @@ public class ChestLinkStorage extends AbstractStorage implements ConfigurationSe
this.sortMethod = SortMethod.OFF;
Block block = location.getBlock();
if(block.getState() instanceof Chest){
Chest chest = (Chest) block.getState();
getInventory().setContents(chest.getInventory().getContents());
chest.getInventory().clear();
if(block.getState() instanceof Container) {
Container container = (Container) block.getState();
getInventory().setContents(container.getInventory().getContents());
container.getInventory().clear();
updateDisplayItem();
}
init();
@ -101,8 +104,8 @@ public class ChestLinkStorage extends AbstractStorage implements ConfigurationSe
@Override
public void onStorageAdded(Block block, Player player) {
//Migrates that chest into InventoryStorage and if full drops it at the chest location.
if(block.getState() instanceof Chest) {
Chest chest = (Chest) block.getState();
if(block.getState() instanceof Container) {
Container chest = (Container) block.getState();
boolean hasOverflow = false;
for (ItemStack chestItem : chest.getInventory().getContents()) {
if (chestItem != null) {
@ -205,8 +208,10 @@ public class ChestLinkStorage extends AbstractStorage implements ConfigurationSe
}
@Override
public double getBlockOffset() {
return 0;
public double getBlockOffset(Block block) {
if(block.getState() instanceof Chest) return 0;
//Barrel is full block.
else return -0.07;
}
@Override

View File

@ -10,9 +10,11 @@ import com.jamesdpeters.minecraft.chests.storage.abstracts.StorageType;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.block.Barrel;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Chest;
import org.bukkit.block.Container;
import org.bukkit.block.data.Directional;
import org.bukkit.entity.Player;
@ -38,13 +40,13 @@ public class ChestLinkStorageType extends StorageType<ChestLinkStorage> {
@Override
public boolean isValidBlockType(Block block) {
return (block.getState() instanceof Chest);
return (block.getState() instanceof Chest) || (block.getState() instanceof Barrel);
}
@Override
public void onSignRemoval(Block block) {
if(block.getState() instanceof Chest){
((Chest) block.getState()).getInventory().clear();
if(block.getState() instanceof Container){
((Container) block.getState()).getInventory().clear();
}
}
@ -55,8 +57,13 @@ public class ChestLinkStorageType extends StorageType<ChestLinkStorage> {
@Override
public void createStorage(Player player, OfflinePlayer owner, Block block, String identifier, boolean requireSign) {
if(block.getState() instanceof Chest){
if(block.getState() instanceof Chest) {
new ChestLinkVerifier(block).withDelay(0).check();
}
createStorageForBlock(player, owner, block, identifier, requireSign);
}
private void createStorageForBlock(Player player, OfflinePlayer owner, Block block, String identifier, boolean requireSign){
if(block.getBlockData() instanceof Directional) {
Directional chest = (Directional) block.getBlockData();
BlockFace facing = chest.getFacing();
@ -64,7 +71,6 @@ public class ChestLinkStorageType extends StorageType<ChestLinkStorage> {
placeSign(block,toReplace,facing,player,owner,identifier,Values.ChestLinkTag, requireSign);
}
}
}
@Override
public void createStorageFacing(Player player, OfflinePlayer owner, Block block, String identifier, BlockFace facing, boolean requireSign) {