mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-19 19:25:48 +00:00
Added a deprecation warning to the SlimefunBlockHandler
Also converted the remaining machines to the new system
This commit is contained in:
parent
2d8ddfc675
commit
dbda4d0b23
@ -36,6 +36,7 @@
|
|||||||
* Added a new message when constructing a Multiblock successfully
|
* Added a new message when constructing a Multiblock successfully
|
||||||
* Added Crafting Motor
|
* Added Crafting Motor
|
||||||
* Block Placers can now place down cake
|
* Block Placers can now place down cake
|
||||||
|
* Added support for the "FunnyGuilds" plugin
|
||||||
* Added configurable enchantment level limit for both auto enchanter and auto disenchanter
|
* Added configurable enchantment level limit for both auto enchanter and auto disenchanter
|
||||||
|
|
||||||
#### Changes
|
#### Changes
|
||||||
|
@ -53,10 +53,7 @@ public class GEOMiner extends AContainer implements RecipeDisplayItem, HologramO
|
|||||||
public GEOMiner(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
|
public GEOMiner(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
|
||||||
super(category, item, recipeType, recipe);
|
super(category, item, recipeType, recipe);
|
||||||
|
|
||||||
addItemHandler(onPlace(), onBreak());
|
addItemHandler(onPlace());
|
||||||
|
|
||||||
// Unregister the Block handler from AContainer (Fixes #2914)
|
|
||||||
registerBlockHandler(getId(), null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@ -71,7 +68,8 @@ public class GEOMiner extends AContainer implements RecipeDisplayItem, HologramO
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private BlockBreakHandler onBreak() {
|
@Override
|
||||||
|
protected BlockBreakHandler onBlockBreak() {
|
||||||
return new SimpleBlockBreakHandler() {
|
return new SimpleBlockBreakHandler() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -192,6 +192,7 @@ public class BlockListener implements Listener {
|
|||||||
e.setDropItems(false);
|
e.setDropItems(false);
|
||||||
|
|
||||||
for (ItemStack drop : drops) {
|
for (ItemStack drop : drops) {
|
||||||
|
// Prevent null or air from being dropped
|
||||||
if (drop != null && drop.getType() != Material.AIR) {
|
if (drop != null && drop.getType() != Material.AIR) {
|
||||||
e.getBlock().getWorld().dropItemNaturally(e.getBlock().getLocation(), drop);
|
e.getBlock().getWorld().dropItemNaturally(e.getBlock().getLocation(), drop);
|
||||||
}
|
}
|
||||||
|
@ -532,6 +532,11 @@ public class SlimefunItem implements Placeable {
|
|||||||
// Send out deprecation warnings for any classes or interfaces
|
// Send out deprecation warnings for any classes or interfaces
|
||||||
checkForDeprecations(getClass());
|
checkForDeprecations(getClass());
|
||||||
|
|
||||||
|
// Inform addon developers about the BlockBreakHandler
|
||||||
|
if (SlimefunPlugin.getUpdater().getBranch() != SlimefunBranch.DEVELOPMENT && SlimefunPlugin.getRegistry().getBlockHandlers().containsKey(getId())) {
|
||||||
|
warn("This item uses a deprecated SlimefunBlockHandler which will be removed in the very near future! Please switch to the BlockBreakHandler as soon as possible.");
|
||||||
|
}
|
||||||
|
|
||||||
// Check for an illegal stack size
|
// Check for an illegal stack size
|
||||||
if (itemStackTemplate.getAmount() != 1) {
|
if (itemStackTemplate.getAmount() != 1) {
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
@ -805,14 +810,13 @@ public class SlimefunItem implements Placeable {
|
|||||||
Validate.notEmpty(handlers, "You cannot add zero handlers...");
|
Validate.notEmpty(handlers, "You cannot add zero handlers...");
|
||||||
Validate.noNullElements(handlers, "You cannot add any 'null' ItemHandler!");
|
Validate.noNullElements(handlers, "You cannot add any 'null' ItemHandler!");
|
||||||
|
|
||||||
|
// Make sure they are added before the item was registered.
|
||||||
if (state != ItemState.UNREGISTERED) {
|
if (state != ItemState.UNREGISTERED) {
|
||||||
throw new UnsupportedOperationException("You cannot add an ItemHandler after the SlimefunItem was registered.");
|
throw new UnsupportedOperationException("You cannot add an ItemHandler after the SlimefunItem was registered.");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ItemHandler handler : handlers) {
|
for (ItemHandler handler : handlers) {
|
||||||
if (itemhandlers.put(handler.getIdentifier(), handler).isPresent()) {
|
itemhandlers.put(handler.getIdentifier(), handler);
|
||||||
warn("ItemHandler \"" + handler.getIdentifier().getSimpleName() + "\" has already been assigned to this item. It was overridden.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tickers are a special case (at the moment at least)
|
// Tickers are a special case (at the moment at least)
|
||||||
if (handler instanceof BlockTicker) {
|
if (handler instanceof BlockTicker) {
|
||||||
|
@ -25,7 +25,9 @@ import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon;
|
|||||||
import io.github.thebusybiscuit.slimefun4.api.events.AsyncMachineProcessCompleteEvent;
|
import io.github.thebusybiscuit.slimefun4.api.events.AsyncMachineProcessCompleteEvent;
|
||||||
import io.github.thebusybiscuit.slimefun4.api.items.ItemState;
|
import io.github.thebusybiscuit.slimefun4.api.items.ItemState;
|
||||||
import io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetComponent;
|
import io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetComponent;
|
||||||
|
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockBreakHandler;
|
||||||
import io.github.thebusybiscuit.slimefun4.core.networks.energy.EnergyNetComponentType;
|
import io.github.thebusybiscuit.slimefun4.core.networks.energy.EnergyNetComponentType;
|
||||||
|
import io.github.thebusybiscuit.slimefun4.implementation.handlers.SimpleBlockBreakHandler;
|
||||||
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
|
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
|
||||||
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
|
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
|
||||||
import io.github.thebusybiscuit.slimefun4.utils.itemstack.ItemStackWrapper;
|
import io.github.thebusybiscuit.slimefun4.utils.itemstack.ItemStackWrapper;
|
||||||
@ -59,27 +61,35 @@ public abstract class AContainer extends SlimefunItem implements InventoryBlock,
|
|||||||
private int processingSpeed = -1;
|
private int processingSpeed = -1;
|
||||||
|
|
||||||
@ParametersAreNonnullByDefault
|
@ParametersAreNonnullByDefault
|
||||||
public AContainer(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
|
protected AContainer(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
|
||||||
super(category, item, recipeType, recipe);
|
super(category, item, recipeType, recipe);
|
||||||
|
|
||||||
createPreset(this, getInventoryTitle(), this::constructMenu);
|
createPreset(this, getInventoryTitle(), this::constructMenu);
|
||||||
|
|
||||||
registerBlockHandler(item.getItemId(), (p, b, tool, reason) -> {
|
addItemHandler(onBlockBreak());
|
||||||
BlockMenu inv = BlockStorage.getInventory(b);
|
}
|
||||||
|
|
||||||
if (inv != null) {
|
@Nonnull
|
||||||
inv.dropItems(b.getLocation(), getInputSlots());
|
protected BlockBreakHandler onBlockBreak() {
|
||||||
inv.dropItems(b.getLocation(), getOutputSlots());
|
return new SimpleBlockBreakHandler() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBlockBreak(Block b) {
|
||||||
|
BlockMenu inv = BlockStorage.getInventory(b);
|
||||||
|
|
||||||
|
if (inv != null) {
|
||||||
|
inv.dropItems(b.getLocation(), getInputSlots());
|
||||||
|
inv.dropItems(b.getLocation(), getOutputSlots());
|
||||||
|
}
|
||||||
|
|
||||||
|
progress.remove(b);
|
||||||
|
processing.remove(b);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
progress.remove(b);
|
|
||||||
processing.remove(b);
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParametersAreNonnullByDefault
|
@ParametersAreNonnullByDefault
|
||||||
public AContainer(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, ItemStack recipeOutput) {
|
protected AContainer(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, ItemStack recipeOutput) {
|
||||||
this(category, item, recipeType, recipe);
|
this(category, item, recipeType, recipe);
|
||||||
this.recipeOutput = recipeOutput;
|
this.recipeOutput = recipeOutput;
|
||||||
}
|
}
|
||||||
|
@ -21,8 +21,10 @@ import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction;
|
|||||||
import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon;
|
import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon;
|
||||||
import io.github.thebusybiscuit.slimefun4.api.events.AsyncGeneratorProcessCompleteEvent;
|
import io.github.thebusybiscuit.slimefun4.api.events.AsyncGeneratorProcessCompleteEvent;
|
||||||
import io.github.thebusybiscuit.slimefun4.api.items.ItemState;
|
import io.github.thebusybiscuit.slimefun4.api.items.ItemState;
|
||||||
|
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockBreakHandler;
|
||||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
|
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
|
||||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||||
|
import io.github.thebusybiscuit.slimefun4.implementation.handlers.SimpleBlockBreakHandler;
|
||||||
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.AbstractEnergyProvider;
|
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.AbstractEnergyProvider;
|
||||||
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
|
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
|
||||||
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
|
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
|
||||||
@ -76,22 +78,29 @@ public abstract class AGenerator extends AbstractEnergyProvider {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
registerBlockHandler(item.getItemId(), (p, b, tool, reason) -> {
|
addItemHandler(onBlockBreak());
|
||||||
BlockMenu inv = BlockStorage.getInventory(b);
|
|
||||||
|
|
||||||
if (inv != null) {
|
|
||||||
inv.dropItems(b.getLocation(), getInputSlots());
|
|
||||||
inv.dropItems(b.getLocation(), getOutputSlots());
|
|
||||||
}
|
|
||||||
|
|
||||||
progress.remove(b.getLocation());
|
|
||||||
processing.remove(b.getLocation());
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
|
|
||||||
registerDefaultFuelTypes();
|
registerDefaultFuelTypes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
protected BlockBreakHandler onBlockBreak() {
|
||||||
|
return new SimpleBlockBreakHandler() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBlockBreak(Block b) {
|
||||||
|
BlockMenu inv = BlockStorage.getInventory(b);
|
||||||
|
|
||||||
|
if (inv != null) {
|
||||||
|
inv.dropItems(b.getLocation(), getInputSlots());
|
||||||
|
inv.dropItems(b.getLocation(), getOutputSlots());
|
||||||
|
}
|
||||||
|
|
||||||
|
progress.remove(b.getLocation());
|
||||||
|
processing.remove(b.getLocation());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
private void constructMenu(BlockMenuPreset preset) {
|
private void constructMenu(BlockMenuPreset preset) {
|
||||||
for (int i : border) {
|
for (int i : border) {
|
||||||
preset.addItem(i, ChestMenuUtils.getBackground(), ChestMenuUtils.getEmptyClickHandler());
|
preset.addItem(i, ChestMenuUtils.getBackground(), ChestMenuUtils.getEmptyClickHandler());
|
||||||
|
Loading…
Reference in New Issue
Block a user