-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(FastLeafDecay): account for datapacks changing the leaves block tag
- Loading branch information
1 parent
42e33ec
commit f22777a
Showing
9 changed files
with
322 additions
and
264 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
160 changes: 160 additions & 0 deletions
160
vanilla-tweaks-bukkit/src/main/java/me/machinemaker/vanillatweaks/tags/AbstractTag.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
/* | ||
* GNU General Public License v3 | ||
* | ||
* VanillaTweaks, a performant replacement for the VanillaTweaks datapacks. | ||
* | ||
* Copyright (C) 2021 Machine_Maker | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, version 3. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package me.machinemaker.vanillatweaks.tags; | ||
|
||
import org.bukkit.Keyed; | ||
import org.bukkit.NamespacedKey; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
import java.util.function.Predicate; | ||
|
||
abstract class AbstractTag<T extends Keyed> implements Tag<T> { | ||
|
||
private final NamespacedKey key; | ||
protected final Set<T> tagged; | ||
|
||
protected AbstractTag(NamespacedKey key, @NotNull Collection<T> values) { | ||
this.key = key; | ||
this.tagged = Set.copyOf(values); | ||
} | ||
|
||
@Override | ||
public NamespacedKey getKey() { | ||
return this.key; | ||
} | ||
|
||
@Override | ||
public boolean isTagged(T value) { | ||
return this.tagged.contains(value); | ||
} | ||
|
||
@Override | ||
public boolean test(T value) { | ||
return this.isTagged(value); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public Set<T> getValues() { | ||
return this.tagged; | ||
} | ||
|
||
static abstract class Builder<T extends Keyed, A extends AbstractTag<T>, C extends Builder<T, A, C>> { | ||
|
||
protected final NamespacedKey key; | ||
protected final Set<T> tagged; | ||
|
||
protected Builder(NamespacedKey key) { | ||
this(key, Collections.emptySet()); | ||
} | ||
|
||
protected Builder(NamespacedKey key, Set<T> tagged) { | ||
this.key = key; | ||
this.tagged = new HashSet<>(tagged); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
private C self() { | ||
return (C) this; | ||
} | ||
|
||
public final C endsWith(String suffix) { | ||
return this.add(v -> this.nameOf(v).endsWith(suffix)); | ||
} | ||
|
||
public final C startsWith(String prefix) { | ||
return this.add(v -> this.nameOf(v).startsWith(prefix)); | ||
} | ||
|
||
public final C contains(String contains) { | ||
return this.add(v -> this.nameOf(v).contains(contains)); | ||
} | ||
|
||
public final C add(Predicate<T> predicate) { | ||
return this.add(this.allValues().stream().filter(predicate).toList()); | ||
} | ||
|
||
public final C add(org.bukkit.Tag<T> tag) { | ||
return this.add(tag.getValues()); | ||
} | ||
|
||
public final C add(Tag<T> tag) { | ||
return this.add(tag.getValues()); | ||
} | ||
|
||
public final C add(Collection<T> values) { | ||
this.tagged.addAll(values); | ||
return this.self(); | ||
} | ||
|
||
@SafeVarargs | ||
public final C add(T... values) { | ||
//noinspection ManualArrayToCollectionCopy | ||
for (T value : values) { | ||
//noinspection UseBulkOperation | ||
this.tagged.add(value); | ||
} | ||
return this.self(); | ||
} | ||
|
||
public final C remove(Predicate<T> predicate) { | ||
this.tagged.removeIf(predicate); | ||
return this.self(); | ||
} | ||
|
||
public final C remove(org.bukkit.Tag<T> tag) { | ||
return this.remove(tag.getValues()); | ||
} | ||
|
||
public final C remove(Tag<T> tag) { | ||
return this.remove(tag.getValues()); | ||
} | ||
|
||
public final C remove(Collection<T> values) { | ||
this.tagged.removeAll(values); | ||
return this.self(); | ||
} | ||
|
||
@SafeVarargs | ||
public final C remove(T... values) { | ||
for (T value : values) { | ||
this.tagged.remove(value); | ||
} | ||
return this.self(); | ||
} | ||
|
||
public final C verify(int size) { | ||
if (this.tagged.size() != size) { | ||
throw new IllegalStateException(String.format("%s does not have the expected size. expected: %d, actual: %d", this.key, size, this.tagged.size())); | ||
} | ||
return this.self(); | ||
} | ||
|
||
public abstract String nameOf(T value); | ||
|
||
public abstract Collection<T> allValues(); | ||
|
||
public abstract A build(); | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
vanilla-tweaks-bukkit/src/main/java/me/machinemaker/vanillatweaks/tags/MaterialTag.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* GNU General Public License v3 | ||
* | ||
* VanillaTweaks, a performant replacement for the VanillaTweaks datapacks. | ||
* | ||
* Copyright (C) 2021 Machine_Maker | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, version 3. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package me.machinemaker.vanillatweaks.tags; | ||
|
||
import org.bukkit.Material; | ||
import org.bukkit.NamespacedKey; | ||
import org.bukkit.block.Block; | ||
import org.bukkit.entity.Item; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.Set; | ||
|
||
public final class MaterialTag extends AbstractTag<Material> { | ||
|
||
public MaterialTag(NamespacedKey key, @NotNull Collection<Material> values) { | ||
super(key, values); | ||
} | ||
|
||
public static Builder builder(NamespacedKey key) { | ||
return new Builder(key); | ||
} | ||
|
||
public boolean isTagged(Item item) { | ||
return this.isTagged(item.getItemStack()); | ||
} | ||
|
||
public boolean isTagged(ItemStack stack) { | ||
return this.isTagged(stack.getType()); | ||
} | ||
|
||
public boolean isTagged(Block block) { | ||
return this.isTagged(block.getType()); | ||
} | ||
|
||
public static final class Builder extends AbstractTag.Builder<Material, MaterialTag, Builder> { | ||
|
||
Builder(NamespacedKey key) { | ||
super(key); | ||
} | ||
|
||
@Override | ||
public String nameOf(Material value) { | ||
return value.name(); | ||
} | ||
|
||
@Override | ||
public Collection<Material> allValues() { | ||
//noinspection deprecation // for tests | ||
return Set.copyOf(Arrays.stream(Material.values()).filter(m -> !m.isLegacy()).toList()); | ||
} | ||
|
||
@Override | ||
public MaterialTag build() { | ||
return new MaterialTag(this.key, this.tagged); | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
vanilla-tweaks-bukkit/src/main/java/me/machinemaker/vanillatweaks/tags/Tag.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* GNU General Public License v3 | ||
* | ||
* VanillaTweaks, a performant replacement for the VanillaTweaks datapacks. | ||
* | ||
* Copyright (C) 2021 Machine_Maker | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, version 3. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package me.machinemaker.vanillatweaks.tags; | ||
|
||
import org.bukkit.Keyed; | ||
|
||
import java.util.function.Predicate; | ||
|
||
public interface Tag<T extends Keyed> extends org.bukkit.Tag<T>, Predicate<T> { | ||
|
||
/** | ||
* Checks if the value is a member of this tag | ||
* | ||
* @param value the value to check | ||
* @return true if value is a member of this tag | ||
*/ | ||
@Override | ||
boolean test(T value); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
vanilla-tweaks-bukkit/src/main/java/me/machinemaker/vanillatweaks/tags/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* GNU General Public License v3 | ||
* | ||
* VanillaTweaks, a performant replacement for the VanillaTweaks datapacks. | ||
* | ||
* Copyright (C) 2021 Machine_Maker | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, version 3. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
/** | ||
* Package for managing/creating value tags | ||
*/ | ||
@DefaultQualifier(NonNull.class) | ||
package me.machinemaker.vanillatweaks.tags; | ||
|
||
import org.checkerframework.checker.nullness.qual.NonNull; | ||
import org.checkerframework.framework.qual.DefaultQualifier; |
Oops, something went wrong.