mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-19 19:25:48 +00:00
Massive performance improvements to Rainbow Glass Panes
This commit is contained in:
parent
06b14836dd
commit
768e4f1021
12
CHANGELOG.md
12
CHANGELOG.md
@ -41,22 +41,23 @@
|
|||||||
* Added an AoE damage effect to the Explosive Bow
|
* Added an AoE damage effect to the Explosive Bow
|
||||||
* Added runtime deprecation warnings for ItemHandlers and Attributes used by Addons
|
* Added runtime deprecation warnings for ItemHandlers and Attributes used by Addons
|
||||||
* Added a proper lag profiler
|
* Added a proper lag profiler
|
||||||
|
* Added per-plugin lag info to /sf timings
|
||||||
|
|
||||||
#### Changes
|
#### Changes
|
||||||
* Coolant Cells now last twice as long
|
* Coolant Cells now last twice as long
|
||||||
* Ticking blocks will now catch more errors caused by addons
|
* Ticking blocks will now catch more errors caused by addons
|
||||||
* Massive performance improvements to GPS/GEO machines, especially Oil Pump and GEO Miner
|
|
||||||
* Changed the texture for the Nuclear Reactor
|
* Changed the texture for the Nuclear Reactor
|
||||||
* Changed the texture for the Nether Star Reactor
|
* Changed the texture for the Nether Star Reactor
|
||||||
* Performance improvements to Rainbow Blocks
|
|
||||||
* Crafting Tin cans now produces 8 items instead of 4
|
* Crafting Tin cans now produces 8 items instead of 4
|
||||||
* Multi Tool lore now says "Crouch" instead of "Hold Shift"
|
* Multi Tool lore now says "Crouch" instead of "Hold Shift"
|
||||||
* items which cannot be distributed by a Cargo Net will be dropped on the ground now instead of getting deleted
|
* Items which cannot be distributed by a Cargo Net will be dropped on the ground now instead of getting deleted
|
||||||
* Slimefun no longer supports CraftBukkit
|
* Slimefun no longer supports CraftBukkit
|
||||||
* Item Energy is now also stored persistently via NBT
|
* Item Energy is now also stored persistently via NBT
|
||||||
* General performance improvements for ticking blocks
|
* Performance improvements to GPS/GEO machines, especially Oil Pump and GEO Miner
|
||||||
|
* Performance improvements for ticking blocks
|
||||||
* Performance improvements to the Cargo Net
|
* Performance improvements to the Cargo Net
|
||||||
* Some performance improvements to the Energy Net
|
* performance improvements to the Energy Net
|
||||||
|
* Performance improvements to Rainbow Blocks
|
||||||
|
|
||||||
#### Fixes
|
#### Fixes
|
||||||
* Fixed #2005
|
* Fixed #2005
|
||||||
@ -79,6 +80,7 @@
|
|||||||
* Fixed /sf timings reporting slightly inaccurate timings
|
* Fixed /sf timings reporting slightly inaccurate timings
|
||||||
* Fixed concurrency-related issues with the profiling
|
* Fixed concurrency-related issues with the profiling
|
||||||
* Fixed #2066
|
* Fixed #2066
|
||||||
|
* Fixed Rainbow Glass Panes not properly connecting to blocks
|
||||||
|
|
||||||
## Release Candidate 13 (16 Jun 2020)
|
## Release Candidate 13 (16 Jun 2020)
|
||||||
https://thebusybiscuit.github.io/builds/TheBusyBiscuit/Slimefun4/stable/#13
|
https://thebusybiscuit.github.io/builds/TheBusyBiscuit/Slimefun4/stable/#13
|
||||||
|
@ -2,10 +2,12 @@ package io.github.thebusybiscuit.slimefun4.core.handlers;
|
|||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.Validate;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
import org.bukkit.block.data.Waterlogged;
|
import org.bukkit.block.data.type.GlassPane;
|
||||||
|
|
||||||
import io.github.thebusybiscuit.cscorelib2.collections.LoopIterator;
|
import io.github.thebusybiscuit.cscorelib2.collections.LoopIterator;
|
||||||
import io.github.thebusybiscuit.cscorelib2.materials.MaterialCollection;
|
import io.github.thebusybiscuit.cscorelib2.materials.MaterialCollection;
|
||||||
@ -29,31 +31,33 @@ import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker;
|
|||||||
public class RainbowTickHandler extends BlockTicker {
|
public class RainbowTickHandler extends BlockTicker {
|
||||||
|
|
||||||
private final LoopIterator<Material> iterator;
|
private final LoopIterator<Material> iterator;
|
||||||
private final boolean waterlogged;
|
private final boolean glassPanes;
|
||||||
private Material material;
|
private Material material;
|
||||||
|
|
||||||
public RainbowTickHandler(Material... materials) {
|
public RainbowTickHandler(Material... materials) {
|
||||||
|
Validate.noNullElements(materials, "A RainbowTicker cannot have a Material that is null!");
|
||||||
|
|
||||||
if (materials.length == 0) {
|
if (materials.length == 0) {
|
||||||
throw new IllegalArgumentException("A RainbowTicker must have at least one Material associated with it!");
|
throw new IllegalArgumentException("A RainbowTicker must have at least one Material associated with it!");
|
||||||
}
|
}
|
||||||
|
|
||||||
waterlogged = containsWaterlogged(materials);
|
glassPanes = containsGlassPanes(materials);
|
||||||
iterator = new LoopIterator<>(Arrays.asList(materials));
|
iterator = new LoopIterator<>(Arrays.asList(materials));
|
||||||
material = iterator.next();
|
material = iterator.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method checks whether a given {@link Material} array contains any {@link Material}
|
* This method checks whether a given {@link Material} array contains any {@link Material}
|
||||||
* that would result in a {@link Waterlogged} {@link BlockData}.
|
* that would result in a {@link GlassPane} {@link BlockData}.
|
||||||
* This is done to save performance, so we don't have to validate {@link BlockData} at
|
* This is done to save performance, so we don't have to validate {@link BlockData} at
|
||||||
* runtime.
|
* runtime.
|
||||||
*
|
*
|
||||||
* @param materials
|
* @param materials
|
||||||
* The {@link Material} Array to check
|
* The {@link Material} Array to check
|
||||||
*
|
*
|
||||||
* @return Whether the array contained any {@link Waterlogged} materials
|
* @return Whether the array contained any {@link GlassPane} materials
|
||||||
*/
|
*/
|
||||||
private boolean containsWaterlogged(Material[] materials) {
|
private boolean containsGlassPanes(Material[] materials) {
|
||||||
if (SlimefunPlugin.getMinecraftVersion() == MinecraftVersion.UNIT_TEST) {
|
if (SlimefunPlugin.getMinecraftVersion() == MinecraftVersion.UNIT_TEST) {
|
||||||
// BlockData is not available to us during Unit Tests :/
|
// BlockData is not available to us during Unit Tests :/
|
||||||
return false;
|
return false;
|
||||||
@ -62,8 +66,8 @@ public class RainbowTickHandler extends BlockTicker {
|
|||||||
for (Material type : materials) {
|
for (Material type : materials) {
|
||||||
// This BlockData is purely virtual and only created on startup, it should have
|
// This BlockData is purely virtual and only created on startup, it should have
|
||||||
// no impact on performance, in fact it should save performance as it preloads
|
// no impact on performance, in fact it should save performance as it preloads
|
||||||
// the data but also saves heavy calls for non-waterlogged Materials
|
// the data but also saves heavy calls for other Materials
|
||||||
if (type.createBlockData() instanceof Waterlogged) {
|
if (type.createBlockData() instanceof GlassPane) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -83,19 +87,29 @@ public class RainbowTickHandler extends BlockTicker {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (waterlogged) {
|
if (glassPanes) {
|
||||||
BlockData blockData = b.getBlockData();
|
BlockData blockData = b.getBlockData();
|
||||||
b.setType(material, true);
|
|
||||||
|
|
||||||
if (blockData instanceof Waterlogged && ((Waterlogged) blockData).isWaterlogged()) {
|
if (blockData instanceof GlassPane) {
|
||||||
Waterlogged block = (Waterlogged) b.getBlockData();
|
BlockData block = material.createBlockData(bd -> {
|
||||||
block.setWaterlogged(true);
|
if (bd instanceof GlassPane) {
|
||||||
|
GlassPane previousData = (GlassPane) blockData;
|
||||||
|
GlassPane nextData = (GlassPane) bd;
|
||||||
|
|
||||||
|
nextData.setWaterlogged(previousData.isWaterlogged());
|
||||||
|
|
||||||
|
for (BlockFace face : previousData.getAllowedFaces()) {
|
||||||
|
nextData.setFace(face, previousData.hasFace(face));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
b.setBlockData(block);
|
b.setBlockData(block);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
b.setType(material, false);
|
b.setType(material, false);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -66,7 +66,7 @@ public final class ChatUtils {
|
|||||||
*/
|
*/
|
||||||
public static String humanize(String string) {
|
public static String humanize(String string) {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
String[] segments = string.toLowerCase(Locale.ROOT).split("_");
|
String[] segments = PatternUtils.UNDERSCORE.split(string.toLowerCase(Locale.ROOT));
|
||||||
|
|
||||||
builder.append(Character.toUpperCase(segments[0].charAt(0))).append(segments[0].substring(1));
|
builder.append(Character.toUpperCase(segments[0].charAt(0))).append(segments[0].substring(1));
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ public final class PatternUtils {
|
|||||||
public static final Pattern COMMA = Pattern.compile(",");
|
public static final Pattern COMMA = Pattern.compile(",");
|
||||||
public static final Pattern SLASH_SEPARATOR = Pattern.compile(" / ");
|
public static final Pattern SLASH_SEPARATOR = Pattern.compile(" / ");
|
||||||
public static final Pattern DASH = Pattern.compile("-");
|
public static final Pattern DASH = Pattern.compile("-");
|
||||||
|
public static final Pattern UNDERSCORE = Pattern.compile("_");
|
||||||
public static final Pattern ASCII = Pattern.compile("[A-Za-z \"_]+");
|
public static final Pattern ASCII = Pattern.compile("[A-Za-z \"_]+");
|
||||||
public static final Pattern ALPHANUMERIC = Pattern.compile("[A-Fa-f0-9]+");
|
public static final Pattern ALPHANUMERIC = Pattern.compile("[A-Fa-f0-9]+");
|
||||||
public static final Pattern NUMERIC = Pattern.compile("[0-9]+");
|
public static final Pattern NUMERIC = Pattern.compile("[0-9]+");
|
||||||
|
Loading…
Reference in New Issue
Block a user