mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-19 19:25:48 +00:00
Fixes #1798
This commit is contained in:
parent
64f1a9d991
commit
b013247ea2
@ -67,6 +67,7 @@
|
||||
* Fixed #1814
|
||||
* Fixed GEO Scanner being unable to deal with more than 28 different resources
|
||||
* Fixed #893
|
||||
* Fixed #1798
|
||||
|
||||
## Release Candidate 10 (28 Mar 2020)
|
||||
https://thebusybiscuit.github.io/builds/TheBusyBiscuit/Slimefun4/stable/#10
|
||||
|
@ -9,13 +9,11 @@ import org.bukkit.Nameable;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Dispenser;
|
||||
import org.bukkit.inventory.BlockInventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.BlockStateMeta;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
|
||||
import io.github.thebusybiscuit.cscorelib2.materials.MaterialCollections;
|
||||
import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion;
|
||||
import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting;
|
||||
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
@ -40,6 +38,12 @@ public class BlockPlacer extends SimpleSlimefunItem<BlockDispenseHandler> {
|
||||
@Override
|
||||
public BlockDispenseHandler getItemHandler() {
|
||||
return (e, dispenser, facedBlock, machine) -> {
|
||||
// Since vanilla Dispensers can already place Shulker boxes, we simply fallback
|
||||
// to the vanilla behaviour.
|
||||
if (isShulkerBox(e.getItem().getType())) {
|
||||
return;
|
||||
}
|
||||
|
||||
e.setCancelled(true);
|
||||
|
||||
if ((facedBlock.getType() == null || facedBlock.getType() == Material.AIR) && e.getItem().getType().isBlock() && !isBlacklisted(e.getItem().getType())) {
|
||||
@ -57,6 +61,10 @@ public class BlockPlacer extends SimpleSlimefunItem<BlockDispenseHandler> {
|
||||
};
|
||||
}
|
||||
|
||||
private boolean isShulkerBox(Material type) {
|
||||
return type == Material.SHULKER_BOX || type.name().endsWith("_SHULKER_BOX");
|
||||
}
|
||||
|
||||
private boolean isBlacklisted(Material type) {
|
||||
for (String blockType : blacklist.getValue()) {
|
||||
if (type.toString().equals(blockType)) {
|
||||
@ -83,23 +91,18 @@ public class BlockPlacer extends SimpleSlimefunItem<BlockDispenseHandler> {
|
||||
private void placeBlock(ItemStack item, Block facedBlock, Dispenser dispenser) {
|
||||
facedBlock.setType(item.getType());
|
||||
|
||||
if (item.hasItemMeta() && item.getItemMeta() instanceof BlockStateMeta) {
|
||||
BlockState itemBlockState = ((BlockStateMeta) item.getItemMeta()).getBlockState();
|
||||
BlockState blockState = facedBlock.getState();
|
||||
if (item.hasItemMeta()) {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
|
||||
if ((blockState instanceof Nameable) && item.getItemMeta().hasDisplayName()) {
|
||||
((Nameable) blockState).setCustomName(item.getItemMeta().getDisplayName());
|
||||
}
|
||||
if (meta.hasDisplayName()) {
|
||||
BlockState blockState = facedBlock.getState();
|
||||
|
||||
// Update block state after changing name
|
||||
blockState.update();
|
||||
if ((blockState instanceof Nameable)) {
|
||||
((Nameable) blockState).setCustomName(meta.getDisplayName());
|
||||
}
|
||||
|
||||
// Changing the inventory of the block based on the inventory of the block's itemstack (Currently only
|
||||
// applies to shulker boxes)
|
||||
// Inventory has to be changed after blockState.update() as updating it will create a different Inventory
|
||||
// for the object
|
||||
if (SlimefunPlugin.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_14) && blockState instanceof BlockInventoryHolder) {
|
||||
((BlockInventoryHolder) blockState).getInventory().setContents(((BlockInventoryHolder) itemBlockState).getInventory().getContents());
|
||||
// Update block state after changing name
|
||||
blockState.update();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -46,6 +46,7 @@ public class SlimefunStartupTask implements Runnable {
|
||||
|
||||
// Load all worlds
|
||||
SlimefunPlugin.getWorldSettingsService().load(Bukkit.getWorlds());
|
||||
|
||||
for (World world : Bukkit.getWorlds()) {
|
||||
new BlockStorage(world);
|
||||
}
|
||||
|
@ -780,8 +780,11 @@ public class SlimefunItem implements Placeable {
|
||||
return getByID(((SlimefunItemStack) item).getItemID());
|
||||
}
|
||||
|
||||
// This wrapper improves the heavy ItemStack#getItemMeta() call by caching it.
|
||||
ItemStackWrapper wrapper = new ItemStackWrapper(item);
|
||||
|
||||
if (item.hasItemMeta()) {
|
||||
Optional<String> itemID = SlimefunPlugin.getItemDataService().getItemData(item);
|
||||
Optional<String> itemID = SlimefunPlugin.getItemDataService().getItemData(wrapper);
|
||||
|
||||
if (itemID.isPresent()) {
|
||||
return getByID(itemID.get());
|
||||
@ -790,13 +793,12 @@ public class SlimefunItem implements Placeable {
|
||||
|
||||
// Quite expensive performance-wise
|
||||
// But necessary for supporting legacy items
|
||||
ItemStackWrapper wrapper = new ItemStackWrapper(item);
|
||||
|
||||
for (SlimefunItem sfi : SlimefunPlugin.getRegistry().getAllSlimefunItems()) {
|
||||
if (sfi.isItem(wrapper)) {
|
||||
// If we have to loop all items for the given item, then at least
|
||||
// set the id via PersistenDataAPI for future performance boosts
|
||||
SlimefunPlugin.getItemDataService().setItemData(item, sfi.getID());
|
||||
|
||||
return sfi;
|
||||
}
|
||||
}
|
||||
|
@ -176,9 +176,7 @@ public class SlimefunItemStack extends CustomItem {
|
||||
|
||||
@Override
|
||||
public ItemStack clone() {
|
||||
SlimefunItemStack item = (SlimefunItemStack) super.clone();
|
||||
item.id = getItemID();
|
||||
return item;
|
||||
return new SlimefunItemStack(id, this);
|
||||
}
|
||||
|
||||
public Optional<String> getSkullTexture() {
|
||||
|
Loading…
Reference in New Issue
Block a user