mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-24 08:06:41 +01:00
#746: Add Fluid types / tags
This commit is contained in:
parent
d5a7296002
commit
890130b460
3 changed files with 58 additions and 0 deletions
|
@ -68,6 +68,7 @@ import net.minecraft.server.Enchantments;
|
|||
import net.minecraft.server.EntityPlayer;
|
||||
import net.minecraft.server.EnumDifficulty;
|
||||
import net.minecraft.server.EnumGamemode;
|
||||
import net.minecraft.server.FluidType;
|
||||
import net.minecraft.server.GameRules;
|
||||
import net.minecraft.server.GeneratorSettings;
|
||||
import net.minecraft.server.IRecipe;
|
||||
|
@ -166,6 +167,7 @@ import org.bukkit.craftbukkit.potion.CraftPotionBrewer;
|
|||
import org.bukkit.craftbukkit.scheduler.CraftScheduler;
|
||||
import org.bukkit.craftbukkit.scoreboard.CraftScoreboardManager;
|
||||
import org.bukkit.craftbukkit.tag.CraftBlockTag;
|
||||
import org.bukkit.craftbukkit.tag.CraftFluidTag;
|
||||
import org.bukkit.craftbukkit.tag.CraftItemTag;
|
||||
import org.bukkit.craftbukkit.util.CraftChatMessage;
|
||||
import org.bukkit.craftbukkit.util.CraftIconCache;
|
||||
|
@ -1953,6 +1955,10 @@ public final class CraftServer implements Server {
|
|||
Preconditions.checkArgument(clazz == org.bukkit.Material.class, "Item namespace must have material type");
|
||||
|
||||
return (org.bukkit.Tag<T>) new CraftItemTag(console.getTagRegistry().getItemTags(), key);
|
||||
case org.bukkit.Tag.REGISTRY_FLUIDS:
|
||||
Preconditions.checkArgument(clazz == org.bukkit.Fluid.class, "Fluid namespace must have fluid type");
|
||||
|
||||
return (org.bukkit.Tag<T>) new CraftFluidTag(console.getTagRegistry().getFluidTags(), key);
|
||||
default:
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
@ -1972,6 +1978,11 @@ public final class CraftServer implements Server {
|
|||
|
||||
Tags<Item> itemTags = console.getTagRegistry().getItemTags();
|
||||
return itemTags.a().keySet().stream().map(key -> (org.bukkit.Tag<T>) new CraftItemTag(itemTags, key)).collect(ImmutableList.toImmutableList());
|
||||
case org.bukkit.Tag.REGISTRY_FLUIDS:
|
||||
Preconditions.checkArgument(clazz == org.bukkit.Material.class, "Fluid namespace must have fluid type");
|
||||
|
||||
Tags<FluidType> fluidTags = console.getTagRegistry().getFluidTags();
|
||||
return fluidTags.a().keySet().stream().map(key -> (org.bukkit.Tag<T>) new CraftFluidTag(fluidTags, key)).collect(ImmutableList.toImmutableList());
|
||||
default:
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
|
27
src/main/java/org/bukkit/craftbukkit/tag/CraftFluidTag.java
Normal file
27
src/main/java/org/bukkit/craftbukkit/tag/CraftFluidTag.java
Normal file
|
@ -0,0 +1,27 @@
|
|||
package org.bukkit.craftbukkit.tag;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import net.minecraft.server.FluidType;
|
||||
import net.minecraft.server.MinecraftKey;
|
||||
import net.minecraft.server.Tags;
|
||||
import org.bukkit.Fluid;
|
||||
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
||||
|
||||
public class CraftFluidTag extends CraftTag<FluidType, Fluid> {
|
||||
|
||||
public CraftFluidTag(Tags<FluidType> registry, MinecraftKey tag) {
|
||||
super(registry, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTagged(Fluid fluid) {
|
||||
return getHandle().isTagged(CraftMagicNumbers.getFluid(fluid));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Fluid> getValues() {
|
||||
return Collections.unmodifiableSet(getHandle().getTagged().stream().map(CraftMagicNumbers::getFluid).collect(Collectors.toSet()));
|
||||
}
|
||||
}
|
|
@ -24,6 +24,7 @@ import net.minecraft.server.ChatDeserializer;
|
|||
import net.minecraft.server.DataConverterRegistry;
|
||||
import net.minecraft.server.DataConverterTypes;
|
||||
import net.minecraft.server.DynamicOpsNBT;
|
||||
import net.minecraft.server.FluidType;
|
||||
import net.minecraft.server.IBlockData;
|
||||
import net.minecraft.server.IRegistry;
|
||||
import net.minecraft.server.Item;
|
||||
|
@ -37,8 +38,10 @@ import net.minecraft.server.NBTTagString;
|
|||
import net.minecraft.server.SavedFile;
|
||||
import net.minecraft.server.SharedConstants;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Fluid;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.UnsafeValues;
|
||||
import org.bukkit.advancement.Advancement;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
@ -83,8 +86,10 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
|||
// ========================================================================
|
||||
private static final Map<Block, Material> BLOCK_MATERIAL = new HashMap<>();
|
||||
private static final Map<Item, Material> ITEM_MATERIAL = new HashMap<>();
|
||||
private static final Map<FluidType, Fluid> FLUID_MATERIAL = new HashMap<>();
|
||||
private static final Map<Material, Item> MATERIAL_ITEM = new HashMap<>();
|
||||
private static final Map<Material, Block> MATERIAL_BLOCK = new HashMap<>();
|
||||
private static final Map<Material, FluidType> MATERIAL_FLUID = new HashMap<>();
|
||||
|
||||
static {
|
||||
for (Block block : IRegistry.BLOCK) {
|
||||
|
@ -95,6 +100,10 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
|||
ITEM_MATERIAL.put(item, Material.getMaterial(IRegistry.ITEM.getKey(item).getKey().toUpperCase(Locale.ROOT)));
|
||||
}
|
||||
|
||||
for (FluidType fluid : IRegistry.FLUID) {
|
||||
FLUID_MATERIAL.put(fluid, Registry.FLUID.get(CraftNamespacedKey.fromMinecraft(IRegistry.FLUID.getKey(fluid))));
|
||||
}
|
||||
|
||||
for (Material material : Material.values()) {
|
||||
if (material.isLegacy()) {
|
||||
continue;
|
||||
|
@ -107,6 +116,9 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
|||
IRegistry.BLOCK.getOptional(key).ifPresent((block) -> {
|
||||
MATERIAL_BLOCK.put(material, block);
|
||||
});
|
||||
IRegistry.FLUID.getOptional(key).ifPresent((fluid) -> {
|
||||
MATERIAL_FLUID.put(material, fluid);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -118,6 +130,10 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
|||
return ITEM_MATERIAL.getOrDefault(item, Material.AIR);
|
||||
}
|
||||
|
||||
public static Fluid getFluid(FluidType fluid) {
|
||||
return FLUID_MATERIAL.get(fluid);
|
||||
}
|
||||
|
||||
public static Item getItem(Material material) {
|
||||
if (material != null && material.isLegacy()) {
|
||||
material = CraftLegacy.fromLegacy(material);
|
||||
|
@ -134,6 +150,10 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
|||
return MATERIAL_BLOCK.get(material);
|
||||
}
|
||||
|
||||
public static FluidType getFluid(Fluid fluid) {
|
||||
return MATERIAL_FLUID.get(fluid);
|
||||
}
|
||||
|
||||
public static MinecraftKey key(Material mat) {
|
||||
return CraftNamespacedKey.toMinecraft(mat.getKey());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue