trurwsuieghfdskg
This commit is contained in:
@@ -0,0 +1,148 @@
|
||||
package net.minecraft;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||
import it.unimi.dsi.fastutil.ints.IntStack;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Predicate;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
public class BlockUtil {
|
||||
public static BlockUtil.FoundRectangle getLargestRectangleAround(BlockPos p_124335_, Direction.Axis p_124336_, int p_124337_, Direction.Axis p_124338_, int p_124339_, Predicate<BlockPos> p_124340_) {
|
||||
BlockPos.MutableBlockPos blockpos$mutableblockpos = p_124335_.mutable();
|
||||
Direction direction = Direction.get(Direction.AxisDirection.NEGATIVE, p_124336_);
|
||||
Direction direction1 = direction.getOpposite();
|
||||
Direction direction2 = Direction.get(Direction.AxisDirection.NEGATIVE, p_124338_);
|
||||
Direction direction3 = direction2.getOpposite();
|
||||
int i = getLimit(p_124340_, blockpos$mutableblockpos.set(p_124335_), direction, p_124337_);
|
||||
int j = getLimit(p_124340_, blockpos$mutableblockpos.set(p_124335_), direction1, p_124337_);
|
||||
int k = i;
|
||||
BlockUtil.IntBounds[] ablockutil$intbounds = new BlockUtil.IntBounds[i + 1 + j];
|
||||
ablockutil$intbounds[i] = new BlockUtil.IntBounds(getLimit(p_124340_, blockpos$mutableblockpos.set(p_124335_), direction2, p_124339_), getLimit(p_124340_, blockpos$mutableblockpos.set(p_124335_), direction3, p_124339_));
|
||||
int l = ablockutil$intbounds[i].min;
|
||||
|
||||
for(int i1 = 1; i1 <= i; ++i1) {
|
||||
BlockUtil.IntBounds blockutil$intbounds = ablockutil$intbounds[k - (i1 - 1)];
|
||||
ablockutil$intbounds[k - i1] = new BlockUtil.IntBounds(getLimit(p_124340_, blockpos$mutableblockpos.set(p_124335_).move(direction, i1), direction2, blockutil$intbounds.min), getLimit(p_124340_, blockpos$mutableblockpos.set(p_124335_).move(direction, i1), direction3, blockutil$intbounds.max));
|
||||
}
|
||||
|
||||
for(int l2 = 1; l2 <= j; ++l2) {
|
||||
BlockUtil.IntBounds blockutil$intbounds2 = ablockutil$intbounds[k + l2 - 1];
|
||||
ablockutil$intbounds[k + l2] = new BlockUtil.IntBounds(getLimit(p_124340_, blockpos$mutableblockpos.set(p_124335_).move(direction1, l2), direction2, blockutil$intbounds2.min), getLimit(p_124340_, blockpos$mutableblockpos.set(p_124335_).move(direction1, l2), direction3, blockutil$intbounds2.max));
|
||||
}
|
||||
|
||||
int i3 = 0;
|
||||
int j3 = 0;
|
||||
int j1 = 0;
|
||||
int k1 = 0;
|
||||
int[] aint = new int[ablockutil$intbounds.length];
|
||||
|
||||
for(int l1 = l; l1 >= 0; --l1) {
|
||||
for(int i2 = 0; i2 < ablockutil$intbounds.length; ++i2) {
|
||||
BlockUtil.IntBounds blockutil$intbounds1 = ablockutil$intbounds[i2];
|
||||
int j2 = l - blockutil$intbounds1.min;
|
||||
int k2 = l + blockutil$intbounds1.max;
|
||||
aint[i2] = l1 >= j2 && l1 <= k2 ? k2 + 1 - l1 : 0;
|
||||
}
|
||||
|
||||
Pair<BlockUtil.IntBounds, Integer> pair = getMaxRectangleLocation(aint);
|
||||
BlockUtil.IntBounds blockutil$intbounds3 = pair.getFirst();
|
||||
int k3 = 1 + blockutil$intbounds3.max - blockutil$intbounds3.min;
|
||||
int l3 = pair.getSecond();
|
||||
if (k3 * l3 > j1 * k1) {
|
||||
i3 = blockutil$intbounds3.min;
|
||||
j3 = l1;
|
||||
j1 = k3;
|
||||
k1 = l3;
|
||||
}
|
||||
}
|
||||
|
||||
return new BlockUtil.FoundRectangle(p_124335_.relative(p_124336_, i3 - k).relative(p_124338_, j3 - l), j1, k1);
|
||||
}
|
||||
|
||||
private static int getLimit(Predicate<BlockPos> p_124342_, BlockPos.MutableBlockPos p_124343_, Direction p_124344_, int p_124345_) {
|
||||
int i;
|
||||
for(i = 0; i < p_124345_ && p_124342_.test(p_124343_.move(p_124344_)); ++i) {
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
static Pair<BlockUtil.IntBounds, Integer> getMaxRectangleLocation(int[] p_124347_) {
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
int k = 0;
|
||||
IntStack intstack = new IntArrayList();
|
||||
intstack.push(0);
|
||||
|
||||
for(int l = 1; l <= p_124347_.length; ++l) {
|
||||
int i1 = l == p_124347_.length ? 0 : p_124347_[l];
|
||||
|
||||
while(!intstack.isEmpty()) {
|
||||
int j1 = p_124347_[intstack.topInt()];
|
||||
if (i1 >= j1) {
|
||||
intstack.push(l);
|
||||
break;
|
||||
}
|
||||
|
||||
intstack.popInt();
|
||||
int k1 = intstack.isEmpty() ? 0 : intstack.topInt() + 1;
|
||||
if (j1 * (l - k1) > k * (j - i)) {
|
||||
j = l;
|
||||
i = k1;
|
||||
k = j1;
|
||||
}
|
||||
}
|
||||
|
||||
if (intstack.isEmpty()) {
|
||||
intstack.push(l);
|
||||
}
|
||||
}
|
||||
|
||||
return new Pair<>(new BlockUtil.IntBounds(i, j - 1), k);
|
||||
}
|
||||
|
||||
public static Optional<BlockPos> getTopConnectedBlock(BlockGetter p_177846_, BlockPos p_177847_, Block p_177848_, Direction p_177849_, Block p_177850_) {
|
||||
BlockPos.MutableBlockPos blockpos$mutableblockpos = p_177847_.mutable();
|
||||
|
||||
BlockState blockstate;
|
||||
do {
|
||||
blockpos$mutableblockpos.move(p_177849_);
|
||||
blockstate = p_177846_.getBlockState(blockpos$mutableblockpos);
|
||||
} while(blockstate.is(p_177848_));
|
||||
|
||||
return blockstate.is(p_177850_) ? Optional.of(blockpos$mutableblockpos) : Optional.empty();
|
||||
}
|
||||
|
||||
public static class FoundRectangle {
|
||||
public final BlockPos minCorner;
|
||||
public final int axis1Size;
|
||||
public final int axis2Size;
|
||||
|
||||
public FoundRectangle(BlockPos p_124352_, int p_124353_, int p_124354_) {
|
||||
this.minCorner = p_124352_;
|
||||
this.axis1Size = p_124353_;
|
||||
this.axis2Size = p_124354_;
|
||||
}
|
||||
}
|
||||
|
||||
public static class IntBounds {
|
||||
public final int min;
|
||||
public final int max;
|
||||
|
||||
public IntBounds(int p_124358_, int p_124359_) {
|
||||
this.min = p_124358_;
|
||||
this.max = p_124359_;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "IntBounds{min=" + this.min + ", max=" + this.max + "}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package net.minecraft;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface CharPredicate {
|
||||
boolean test(char p_125855_);
|
||||
|
||||
default CharPredicate and(CharPredicate p_178287_) {
|
||||
Objects.requireNonNull(p_178287_);
|
||||
return (p_178295_) -> {
|
||||
return this.test(p_178295_) && p_178287_.test(p_178295_);
|
||||
};
|
||||
}
|
||||
|
||||
default CharPredicate negate() {
|
||||
return (p_178285_) -> {
|
||||
return !this.test(p_178285_);
|
||||
};
|
||||
}
|
||||
|
||||
default CharPredicate or(CharPredicate p_178292_) {
|
||||
Objects.requireNonNull(p_178292_);
|
||||
return (p_178290_) -> {
|
||||
return this.test(p_178290_) || p_178292_.test(p_178290_);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
package net.minecraft;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.mojang.serialization.Codec;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.util.StringRepresentable;
|
||||
|
||||
public enum ChatFormatting implements StringRepresentable {
|
||||
BLACK("BLACK", '0', 0, 0),
|
||||
DARK_BLUE("DARK_BLUE", '1', 1, 170),
|
||||
DARK_GREEN("DARK_GREEN", '2', 2, 43520),
|
||||
DARK_AQUA("DARK_AQUA", '3', 3, 43690),
|
||||
DARK_RED("DARK_RED", '4', 4, 11141120),
|
||||
DARK_PURPLE("DARK_PURPLE", '5', 5, 11141290),
|
||||
GOLD("GOLD", '6', 6, 16755200),
|
||||
GRAY("GRAY", '7', 7, 11184810),
|
||||
DARK_GRAY("DARK_GRAY", '8', 8, 5592405),
|
||||
BLUE("BLUE", '9', 9, 5592575),
|
||||
GREEN("GREEN", 'a', 10, 5635925),
|
||||
AQUA("AQUA", 'b', 11, 5636095),
|
||||
RED("RED", 'c', 12, 16733525),
|
||||
LIGHT_PURPLE("LIGHT_PURPLE", 'd', 13, 16733695),
|
||||
YELLOW("YELLOW", 'e', 14, 16777045),
|
||||
WHITE("WHITE", 'f', 15, 16777215),
|
||||
OBFUSCATED("OBFUSCATED", 'k', true),
|
||||
BOLD("BOLD", 'l', true),
|
||||
STRIKETHROUGH("STRIKETHROUGH", 'm', true),
|
||||
UNDERLINE("UNDERLINE", 'n', true),
|
||||
ITALIC("ITALIC", 'o', true),
|
||||
RESET("RESET", 'r', -1, (Integer)null);
|
||||
|
||||
public static final Codec<ChatFormatting> CODEC = StringRepresentable.fromEnum(ChatFormatting::values);
|
||||
public static final char PREFIX_CODE = '\u00a7';
|
||||
private static final Map<String, ChatFormatting> FORMATTING_BY_NAME = Arrays.stream(values()).collect(Collectors.toMap((p_126660_) -> {
|
||||
return cleanName(p_126660_.name);
|
||||
}, (p_126652_) -> {
|
||||
return p_126652_;
|
||||
}));
|
||||
private static final Pattern STRIP_FORMATTING_PATTERN = Pattern.compile("(?i)\u00a7[0-9A-FK-OR]");
|
||||
private final String name;
|
||||
private final char code;
|
||||
private final boolean isFormat;
|
||||
private final String toString;
|
||||
private final int id;
|
||||
@Nullable
|
||||
private final Integer color;
|
||||
|
||||
private static String cleanName(String p_126663_) {
|
||||
return p_126663_.toLowerCase(Locale.ROOT).replaceAll("[^a-z]", "");
|
||||
}
|
||||
|
||||
private ChatFormatting(String p_126627_, char p_126628_, int p_126629_, @Nullable Integer p_126630_) {
|
||||
this(p_126627_, p_126628_, false, p_126629_, p_126630_);
|
||||
}
|
||||
|
||||
private ChatFormatting(String p_126634_, char p_126635_, boolean p_126636_) {
|
||||
this(p_126634_, p_126635_, p_126636_, -1, (Integer)null);
|
||||
}
|
||||
|
||||
private ChatFormatting(String p_126640_, char p_126641_, boolean p_126642_, int p_126643_, @Nullable Integer p_126644_) {
|
||||
this.name = p_126640_;
|
||||
this.code = p_126641_;
|
||||
this.isFormat = p_126642_;
|
||||
this.id = p_126643_;
|
||||
this.color = p_126644_;
|
||||
this.toString = "\u00a7" + p_126641_;
|
||||
}
|
||||
|
||||
public char getChar() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public boolean isFormat() {
|
||||
return this.isFormat;
|
||||
}
|
||||
|
||||
public boolean isColor() {
|
||||
return !this.isFormat && this != RESET;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Integer getColor() {
|
||||
return this.color;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.toString;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String stripFormatting(@Nullable String p_126650_) {
|
||||
return p_126650_ == null ? null : STRIP_FORMATTING_PATTERN.matcher(p_126650_).replaceAll("");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static ChatFormatting getByName(@Nullable String p_126658_) {
|
||||
return p_126658_ == null ? null : FORMATTING_BY_NAME.get(cleanName(p_126658_));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static ChatFormatting getById(int p_126648_) {
|
||||
if (p_126648_ < 0) {
|
||||
return RESET;
|
||||
} else {
|
||||
for(ChatFormatting chatformatting : values()) {
|
||||
if (chatformatting.getId() == p_126648_) {
|
||||
return chatformatting;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static ChatFormatting getByCode(char p_126646_) {
|
||||
char c0 = Character.toString(p_126646_).toLowerCase(Locale.ROOT).charAt(0);
|
||||
|
||||
for(ChatFormatting chatformatting : values()) {
|
||||
if (chatformatting.code == c0) {
|
||||
return chatformatting;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Collection<String> getNames(boolean p_126654_, boolean p_126655_) {
|
||||
List<String> list = Lists.newArrayList();
|
||||
|
||||
for(ChatFormatting chatformatting : values()) {
|
||||
if ((!chatformatting.isColor() || p_126654_) && (!chatformatting.isFormat() || p_126655_)) {
|
||||
list.add(chatformatting.getName());
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public String getSerializedName() {
|
||||
return this.getName();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,218 @@
|
||||
package net.minecraft;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.mojang.logging.LogUtils;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.CompletionException;
|
||||
import net.minecraft.util.MemoryReserve;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
public class CrashReport {
|
||||
private static final Logger LOGGER = LogUtils.getLogger();
|
||||
private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss", Locale.ROOT);
|
||||
private final String title;
|
||||
private final Throwable exception;
|
||||
private final List<CrashReportCategory> details = Lists.newArrayList();
|
||||
private File saveFile;
|
||||
private boolean trackingStackTrace = true;
|
||||
private StackTraceElement[] uncategorizedStackTrace = new StackTraceElement[0];
|
||||
private final SystemReport systemReport = new SystemReport();
|
||||
|
||||
public CrashReport(String p_127509_, Throwable p_127510_) {
|
||||
this.title = p_127509_;
|
||||
this.exception = p_127510_;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return this.title;
|
||||
}
|
||||
|
||||
public Throwable getException() {
|
||||
return this.exception;
|
||||
}
|
||||
|
||||
public String getDetails() {
|
||||
StringBuilder stringbuilder = new StringBuilder();
|
||||
this.getDetails(stringbuilder);
|
||||
return stringbuilder.toString();
|
||||
}
|
||||
|
||||
public void getDetails(StringBuilder p_127520_) {
|
||||
if ((this.uncategorizedStackTrace == null || this.uncategorizedStackTrace.length <= 0) && !this.details.isEmpty()) {
|
||||
this.uncategorizedStackTrace = ArrayUtils.subarray((StackTraceElement[])this.details.get(0).getStacktrace(), 0, 1);
|
||||
}
|
||||
|
||||
if (this.uncategorizedStackTrace != null && this.uncategorizedStackTrace.length > 0) {
|
||||
p_127520_.append("-- Head --\n");
|
||||
p_127520_.append("Thread: ").append(Thread.currentThread().getName()).append("\n");
|
||||
p_127520_.append(net.minecraftforge.logging.CrashReportAnalyser.appendSuspectedMods(this.exception, this.uncategorizedStackTrace));
|
||||
p_127520_.append("Stacktrace:");
|
||||
p_127520_.append(net.minecraftforge.logging.CrashReportExtender.generateEnhancedStackTrace(this.uncategorizedStackTrace));
|
||||
}
|
||||
|
||||
for(CrashReportCategory crashreportcategory : this.details) {
|
||||
crashreportcategory.getDetails(p_127520_);
|
||||
p_127520_.append("\n\n");
|
||||
}
|
||||
|
||||
net.minecraftforge.logging.CrashReportExtender.extendSystemReport(systemReport);
|
||||
this.systemReport.appendToCrashReportString(p_127520_);
|
||||
}
|
||||
|
||||
public String getExceptionMessage() {
|
||||
StringWriter stringwriter = null;
|
||||
PrintWriter printwriter = null;
|
||||
Throwable throwable = this.exception;
|
||||
if (throwable.getMessage() == null) {
|
||||
if (throwable instanceof NullPointerException) {
|
||||
throwable = new NullPointerException(this.title);
|
||||
} else if (throwable instanceof StackOverflowError) {
|
||||
throwable = new StackOverflowError(this.title);
|
||||
} else if (throwable instanceof OutOfMemoryError) {
|
||||
throwable = new OutOfMemoryError(this.title);
|
||||
}
|
||||
|
||||
throwable.setStackTrace(this.exception.getStackTrace());
|
||||
}
|
||||
|
||||
return net.minecraftforge.logging.CrashReportExtender.generateEnhancedStackTrace(throwable);
|
||||
}
|
||||
|
||||
public String getFriendlyReport() {
|
||||
StringBuilder stringbuilder = new StringBuilder();
|
||||
stringbuilder.append("---- Minecraft Crash Report ----\n");
|
||||
net.minecraftforge.logging.CrashReportExtender.addCrashReportHeader(stringbuilder, this);
|
||||
stringbuilder.append("// ");
|
||||
stringbuilder.append(getErrorComment());
|
||||
stringbuilder.append("\n\n");
|
||||
stringbuilder.append("Time: ");
|
||||
stringbuilder.append(DATE_TIME_FORMATTER.format(ZonedDateTime.now()));
|
||||
stringbuilder.append("\n");
|
||||
stringbuilder.append("Description: ");
|
||||
stringbuilder.append(this.title);
|
||||
stringbuilder.append("\n\n");
|
||||
stringbuilder.append(this.getExceptionMessage());
|
||||
stringbuilder.append("\n\nA detailed walkthrough of the error, its code path and all known details is as follows:\n");
|
||||
|
||||
for(int i = 0; i < 87; ++i) {
|
||||
stringbuilder.append("-");
|
||||
}
|
||||
|
||||
stringbuilder.append("\n\n");
|
||||
this.getDetails(stringbuilder);
|
||||
return stringbuilder.toString();
|
||||
}
|
||||
|
||||
public File getSaveFile() {
|
||||
return this.saveFile;
|
||||
}
|
||||
|
||||
public boolean saveToFile(File p_127513_) {
|
||||
if (this.saveFile != null) {
|
||||
return false;
|
||||
} else {
|
||||
if (p_127513_.getParentFile() != null) {
|
||||
p_127513_.getParentFile().mkdirs();
|
||||
}
|
||||
|
||||
Writer writer = null;
|
||||
|
||||
boolean flag;
|
||||
try {
|
||||
writer = new OutputStreamWriter(new FileOutputStream(p_127513_), StandardCharsets.UTF_8);
|
||||
writer.write(this.getFriendlyReport());
|
||||
this.saveFile = p_127513_;
|
||||
return true;
|
||||
} catch (Throwable throwable) {
|
||||
LOGGER.error("Could not save crash report to {}", p_127513_, throwable);
|
||||
flag = false;
|
||||
} finally {
|
||||
IOUtils.closeQuietly(writer);
|
||||
}
|
||||
|
||||
return flag;
|
||||
}
|
||||
}
|
||||
|
||||
public SystemReport getSystemReport() {
|
||||
return this.systemReport;
|
||||
}
|
||||
|
||||
public CrashReportCategory addCategory(String p_127515_) {
|
||||
return this.addCategory(p_127515_, 1);
|
||||
}
|
||||
|
||||
public CrashReportCategory addCategory(String p_127517_, int p_127518_) {
|
||||
CrashReportCategory crashreportcategory = new CrashReportCategory(p_127517_);
|
||||
if (this.trackingStackTrace) {
|
||||
int i = crashreportcategory.fillInStackTrace(p_127518_);
|
||||
StackTraceElement[] astacktraceelement = this.exception.getStackTrace();
|
||||
StackTraceElement stacktraceelement = null;
|
||||
StackTraceElement stacktraceelement1 = null;
|
||||
int j = astacktraceelement.length - i;
|
||||
if (j < 0) {
|
||||
System.out.println("Negative index in crash report handler (" + astacktraceelement.length + "/" + i + ")");
|
||||
}
|
||||
|
||||
if (astacktraceelement != null && 0 <= j && j < astacktraceelement.length) {
|
||||
stacktraceelement = astacktraceelement[j];
|
||||
if (astacktraceelement.length + 1 - i < astacktraceelement.length) {
|
||||
stacktraceelement1 = astacktraceelement[astacktraceelement.length + 1 - i];
|
||||
}
|
||||
}
|
||||
|
||||
this.trackingStackTrace = crashreportcategory.validateStackTrace(stacktraceelement, stacktraceelement1);
|
||||
if (astacktraceelement != null && astacktraceelement.length >= i && 0 <= j && j < astacktraceelement.length) {
|
||||
this.uncategorizedStackTrace = new StackTraceElement[j];
|
||||
System.arraycopy(astacktraceelement, 0, this.uncategorizedStackTrace, 0, this.uncategorizedStackTrace.length);
|
||||
} else {
|
||||
this.trackingStackTrace = false;
|
||||
}
|
||||
}
|
||||
|
||||
this.details.add(crashreportcategory);
|
||||
return crashreportcategory;
|
||||
}
|
||||
|
||||
private static String getErrorComment() {
|
||||
String[] astring = new String[]{"Who set us up the TNT?", "Everything's going to plan. No, really, that was supposed to happen.", "Uh... Did I do that?", "Oops.", "Why did you do that?", "I feel sad now :(", "My bad.", "I'm sorry, Dave.", "I let you down. Sorry :(", "On the bright side, I bought you a teddy bear!", "Daisy, daisy...", "Oh - I know what I did wrong!", "Hey, that tickles! Hehehe!", "I blame Dinnerbone.", "You should try our sister game, Minceraft!", "Don't be sad. I'll do better next time, I promise!", "Don't be sad, have a hug! <3", "I just don't know what went wrong :(", "Shall we play a game?", "Quite honestly, I wouldn't worry myself about that.", "I bet Cylons wouldn't have this problem.", "Sorry :(", "Surprise! Haha. Well, this is awkward.", "Would you like a cupcake?", "Hi. I'm Minecraft, and I'm a crashaholic.", "Ooh. Shiny.", "This doesn't make any sense!", "Why is it breaking :(", "Don't do that.", "Ouch. That hurt :(", "You're mean.", "This is a token for 1 free hug. Redeem at your nearest Mojangsta: [~~HUG~~]", "There are four lights!", "But it works on my machine."};
|
||||
|
||||
try {
|
||||
return astring[(int)(Util.getNanos() % (long)astring.length)];
|
||||
} catch (Throwable throwable) {
|
||||
return "Witty comment unavailable :(";
|
||||
}
|
||||
}
|
||||
|
||||
public static CrashReport forThrowable(Throwable p_127522_, String p_127523_) {
|
||||
while(p_127522_ instanceof CompletionException && p_127522_.getCause() != null) {
|
||||
p_127522_ = p_127522_.getCause();
|
||||
}
|
||||
|
||||
CrashReport crashreport;
|
||||
if (p_127522_ instanceof ReportedException) {
|
||||
crashreport = ((ReportedException)p_127522_).getReport();
|
||||
} else {
|
||||
crashreport = new CrashReport(p_127523_, p_127522_);
|
||||
}
|
||||
|
||||
return crashreport;
|
||||
}
|
||||
|
||||
public static void preload() {
|
||||
MemoryReserve.allocate();
|
||||
(new CrashReport("Don't panic!", new Throwable())).getFriendlyReport();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
package net.minecraft;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.SectionPos;
|
||||
import net.minecraft.world.level.LevelHeightAccessor;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
public class CrashReportCategory {
|
||||
private final String title;
|
||||
private final List<CrashReportCategory.Entry> entries = Lists.newArrayList();
|
||||
private StackTraceElement[] stackTrace = new StackTraceElement[0];
|
||||
|
||||
public CrashReportCategory(String p_178936_) {
|
||||
this.title = p_178936_;
|
||||
}
|
||||
|
||||
public static String formatLocation(LevelHeightAccessor p_178938_, double p_178939_, double p_178940_, double p_178941_) {
|
||||
return String.format(Locale.ROOT, "%.2f,%.2f,%.2f - %s", p_178939_, p_178940_, p_178941_, formatLocation(p_178938_, BlockPos.containing(p_178939_, p_178940_, p_178941_)));
|
||||
}
|
||||
|
||||
public static String formatLocation(LevelHeightAccessor p_178948_, BlockPos p_178949_) {
|
||||
return formatLocation(p_178948_, p_178949_.getX(), p_178949_.getY(), p_178949_.getZ());
|
||||
}
|
||||
|
||||
public static String formatLocation(LevelHeightAccessor p_178943_, int p_178944_, int p_178945_, int p_178946_) {
|
||||
StringBuilder stringbuilder = new StringBuilder();
|
||||
|
||||
try {
|
||||
stringbuilder.append(String.format(Locale.ROOT, "World: (%d,%d,%d)", p_178944_, p_178945_, p_178946_));
|
||||
} catch (Throwable throwable2) {
|
||||
stringbuilder.append("(Error finding world loc)");
|
||||
}
|
||||
|
||||
stringbuilder.append(", ");
|
||||
|
||||
try {
|
||||
int i = SectionPos.blockToSectionCoord(p_178944_);
|
||||
int j = SectionPos.blockToSectionCoord(p_178945_);
|
||||
int k = SectionPos.blockToSectionCoord(p_178946_);
|
||||
int l = p_178944_ & 15;
|
||||
int i1 = p_178945_ & 15;
|
||||
int j1 = p_178946_ & 15;
|
||||
int k1 = SectionPos.sectionToBlockCoord(i);
|
||||
int l1 = p_178943_.getMinBuildHeight();
|
||||
int i2 = SectionPos.sectionToBlockCoord(k);
|
||||
int j2 = SectionPos.sectionToBlockCoord(i + 1) - 1;
|
||||
int k2 = p_178943_.getMaxBuildHeight() - 1;
|
||||
int l2 = SectionPos.sectionToBlockCoord(k + 1) - 1;
|
||||
stringbuilder.append(String.format(Locale.ROOT, "Section: (at %d,%d,%d in %d,%d,%d; chunk contains blocks %d,%d,%d to %d,%d,%d)", l, i1, j1, i, j, k, k1, l1, i2, j2, k2, l2));
|
||||
} catch (Throwable throwable1) {
|
||||
stringbuilder.append("(Error finding chunk loc)");
|
||||
}
|
||||
|
||||
stringbuilder.append(", ");
|
||||
|
||||
try {
|
||||
int i3 = p_178944_ >> 9;
|
||||
int j3 = p_178946_ >> 9;
|
||||
int k3 = i3 << 5;
|
||||
int l3 = j3 << 5;
|
||||
int i4 = (i3 + 1 << 5) - 1;
|
||||
int j4 = (j3 + 1 << 5) - 1;
|
||||
int k4 = i3 << 9;
|
||||
int l4 = p_178943_.getMinBuildHeight();
|
||||
int i5 = j3 << 9;
|
||||
int j5 = (i3 + 1 << 9) - 1;
|
||||
int k5 = p_178943_.getMaxBuildHeight() - 1;
|
||||
int l5 = (j3 + 1 << 9) - 1;
|
||||
stringbuilder.append(String.format(Locale.ROOT, "Region: (%d,%d; contains chunks %d,%d to %d,%d, blocks %d,%d,%d to %d,%d,%d)", i3, j3, k3, l3, i4, j4, k4, l4, i5, j5, k5, l5));
|
||||
} catch (Throwable throwable) {
|
||||
stringbuilder.append("(Error finding world loc)");
|
||||
}
|
||||
|
||||
return stringbuilder.toString();
|
||||
}
|
||||
|
||||
public CrashReportCategory setDetail(String p_128166_, CrashReportDetail<String> p_128167_) {
|
||||
try {
|
||||
this.setDetail(p_128166_, p_128167_.call());
|
||||
} catch (Throwable throwable) {
|
||||
this.setDetailError(p_128166_, throwable);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public CrashReportCategory setDetail(String p_128160_, Object p_128161_) {
|
||||
this.entries.add(new CrashReportCategory.Entry(p_128160_, p_128161_));
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setDetailError(String p_128163_, Throwable p_128164_) {
|
||||
this.setDetail(p_128163_, p_128164_);
|
||||
}
|
||||
|
||||
public int fillInStackTrace(int p_128149_) {
|
||||
StackTraceElement[] astacktraceelement = Thread.currentThread().getStackTrace();
|
||||
if (astacktraceelement.length <= 0) {
|
||||
return 0;
|
||||
} else {
|
||||
int len = astacktraceelement.length - 3 - p_128149_;
|
||||
if (len <= 0) len = astacktraceelement.length;
|
||||
this.stackTrace = new StackTraceElement[len];
|
||||
System.arraycopy(astacktraceelement, astacktraceelement.length - len, this.stackTrace, 0, this.stackTrace.length);
|
||||
return this.stackTrace.length;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean validateStackTrace(StackTraceElement p_128157_, StackTraceElement p_128158_) {
|
||||
if (this.stackTrace.length != 0 && p_128157_ != null) {
|
||||
StackTraceElement stacktraceelement = this.stackTrace[0];
|
||||
if (stacktraceelement.isNativeMethod() == p_128157_.isNativeMethod() && stacktraceelement.getClassName().equals(p_128157_.getClassName()) && stacktraceelement.getFileName().equals(p_128157_.getFileName()) && stacktraceelement.getMethodName().equals(p_128157_.getMethodName())) {
|
||||
if (p_128158_ != null != this.stackTrace.length > 1) {
|
||||
return false;
|
||||
} else if (p_128158_ != null && !this.stackTrace[1].equals(p_128158_)) {
|
||||
return false;
|
||||
} else {
|
||||
this.stackTrace[0] = p_128157_;
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void trimStacktrace(int p_128175_) {
|
||||
StackTraceElement[] astacktraceelement = new StackTraceElement[this.stackTrace.length - p_128175_];
|
||||
System.arraycopy(this.stackTrace, 0, astacktraceelement, 0, astacktraceelement.length);
|
||||
this.stackTrace = astacktraceelement;
|
||||
}
|
||||
|
||||
public void getDetails(StringBuilder p_128169_) {
|
||||
p_128169_.append("-- ").append(this.title).append(" --\n");
|
||||
p_128169_.append("Details:");
|
||||
|
||||
for(CrashReportCategory.Entry crashreportcategory$entry : this.entries) {
|
||||
p_128169_.append("\n\t");
|
||||
p_128169_.append(crashreportcategory$entry.getKey());
|
||||
p_128169_.append(": ");
|
||||
p_128169_.append(crashreportcategory$entry.getValue());
|
||||
}
|
||||
|
||||
if (this.stackTrace != null && this.stackTrace.length > 0) {
|
||||
p_128169_.append("\nStacktrace:");
|
||||
p_128169_.append(net.minecraftforge.logging.CrashReportExtender.generateEnhancedStackTrace(this.stackTrace));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public StackTraceElement[] getStacktrace() {
|
||||
return this.stackTrace;
|
||||
}
|
||||
|
||||
public void applyStackTrace(Throwable t) {
|
||||
this.stackTrace = t.getStackTrace();
|
||||
}
|
||||
|
||||
public static void populateBlockDetails(CrashReportCategory p_178951_, LevelHeightAccessor p_178952_, BlockPos p_178953_, @Nullable BlockState p_178954_) {
|
||||
if (p_178954_ != null) {
|
||||
p_178951_.setDetail("Block", p_178954_::toString);
|
||||
}
|
||||
|
||||
p_178951_.setDetail("Block location", () -> {
|
||||
return formatLocation(p_178952_, p_178953_);
|
||||
});
|
||||
}
|
||||
|
||||
static class Entry {
|
||||
private final String key;
|
||||
private final String value;
|
||||
|
||||
public Entry(String p_128181_, @Nullable Object p_128182_) {
|
||||
this.key = p_128181_;
|
||||
if (p_128182_ == null) {
|
||||
this.value = "~~NULL~~";
|
||||
} else if (p_128182_ instanceof Throwable) {
|
||||
Throwable throwable = (Throwable)p_128182_;
|
||||
this.value = "~~ERROR~~ " + throwable.getClass().getSimpleName() + ": " + throwable.getMessage();
|
||||
} else {
|
||||
this.value = p_128182_.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return this.key;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return this.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package net.minecraft;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
public interface CrashReportDetail<V> extends Callable<V> {
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package net.minecraft;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
|
||||
public class DefaultUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler {
|
||||
private final Logger logger;
|
||||
|
||||
public DefaultUncaughtExceptionHandler(Logger p_202576_) {
|
||||
this.logger = p_202576_;
|
||||
}
|
||||
|
||||
public void uncaughtException(Thread p_131079_, Throwable p_131080_) {
|
||||
this.logger.error("Caught previously unhandled exception :", p_131080_);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package net.minecraft;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
|
||||
public class DefaultUncaughtExceptionHandlerWithName implements Thread.UncaughtExceptionHandler {
|
||||
private final Logger logger;
|
||||
|
||||
public DefaultUncaughtExceptionHandlerWithName(Logger p_202578_) {
|
||||
this.logger = p_202578_;
|
||||
}
|
||||
|
||||
public void uncaughtException(Thread p_131803_, Throwable p_131804_) {
|
||||
this.logger.error("Caught previously unhandled exception :");
|
||||
this.logger.error(p_131803_.getName(), p_131804_);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
package net.minecraft;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.mojang.logging.LogUtils;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
import net.minecraft.server.packs.PackType;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
import net.minecraft.world.level.storage.DataVersion;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
public class DetectedVersion implements WorldVersion {
|
||||
private static final Logger LOGGER = LogUtils.getLogger();
|
||||
public static final WorldVersion BUILT_IN = new DetectedVersion();
|
||||
private final String id;
|
||||
private final String name;
|
||||
private final boolean stable;
|
||||
private final DataVersion worldVersion;
|
||||
private final int protocolVersion;
|
||||
private final int resourcePackVersion;
|
||||
private final int dataPackVersion;
|
||||
private final Date buildTime;
|
||||
|
||||
private DetectedVersion() {
|
||||
this.id = UUID.randomUUID().toString().replaceAll("-", "");
|
||||
this.name = "1.20.1";
|
||||
this.stable = true;
|
||||
this.worldVersion = new DataVersion(3465, "main");
|
||||
this.protocolVersion = SharedConstants.getProtocolVersion();
|
||||
this.resourcePackVersion = 15;
|
||||
this.dataPackVersion = 15;
|
||||
this.buildTime = new Date();
|
||||
}
|
||||
|
||||
private DetectedVersion(JsonObject p_132489_) {
|
||||
this.id = GsonHelper.getAsString(p_132489_, "id");
|
||||
this.name = GsonHelper.getAsString(p_132489_, "name");
|
||||
this.stable = GsonHelper.getAsBoolean(p_132489_, "stable");
|
||||
this.worldVersion = new DataVersion(GsonHelper.getAsInt(p_132489_, "world_version"), GsonHelper.getAsString(p_132489_, "series_id", DataVersion.MAIN_SERIES));
|
||||
this.protocolVersion = GsonHelper.getAsInt(p_132489_, "protocol_version");
|
||||
JsonObject jsonobject = GsonHelper.getAsJsonObject(p_132489_, "pack_version");
|
||||
this.resourcePackVersion = GsonHelper.getAsInt(jsonobject, "resource");
|
||||
this.dataPackVersion = GsonHelper.getAsInt(jsonobject, "data");
|
||||
this.buildTime = Date.from(ZonedDateTime.parse(GsonHelper.getAsString(p_132489_, "build_time")).toInstant());
|
||||
}
|
||||
|
||||
public static WorldVersion tryDetectVersion() {
|
||||
try (InputStream inputstream = DetectedVersion.class.getResourceAsStream("/version.json")) {
|
||||
if (inputstream == null) {
|
||||
LOGGER.warn("Missing version information!");
|
||||
return BUILT_IN;
|
||||
} else {
|
||||
try (InputStreamReader inputstreamreader = new InputStreamReader(inputstream)) {
|
||||
return new DetectedVersion(GsonHelper.parse(inputstreamreader));
|
||||
}
|
||||
}
|
||||
} catch (JsonParseException | IOException ioexception) {
|
||||
throw new IllegalStateException("Game version information is corrupt", ioexception);
|
||||
}
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public DataVersion getDataVersion() {
|
||||
return this.worldVersion;
|
||||
}
|
||||
|
||||
public int getProtocolVersion() {
|
||||
return this.protocolVersion;
|
||||
}
|
||||
|
||||
public int getPackVersion(PackType p_265454_) {
|
||||
return p_265454_ == PackType.SERVER_DATA ? this.dataPackVersion : this.resourcePackVersion;
|
||||
}
|
||||
|
||||
public Date getBuildTime() {
|
||||
return this.buildTime;
|
||||
}
|
||||
|
||||
public boolean isStable() {
|
||||
return this.stable;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package net.minecraft;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.meta.TypeQualifierDefault;
|
||||
|
||||
@Nonnull
|
||||
@TypeQualifierDefault({ElementType.FIELD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface FieldsAreNonnullByDefault {
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
package net.minecraft;
|
||||
|
||||
import com.mojang.serialization.DataResult;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.FileAlreadyExistsException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.InvalidPathException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
|
||||
public class FileUtil {
|
||||
private static final Pattern COPY_COUNTER_PATTERN = Pattern.compile("(<name>.*) \\((<count>\\d*)\\)", 66);
|
||||
private static final int MAX_FILE_NAME = 255;
|
||||
private static final Pattern RESERVED_WINDOWS_FILENAMES = Pattern.compile(".*\\.|(?:COM|CLOCK\\$|CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])(?:\\..*)?", 2);
|
||||
private static final Pattern STRICT_PATH_SEGMENT_CHECK = Pattern.compile("[-._a-z0-9]+");
|
||||
|
||||
public static String findAvailableName(Path p_133731_, String p_133732_, String p_133733_) throws IOException {
|
||||
for(char c0 : SharedConstants.ILLEGAL_FILE_CHARACTERS) {
|
||||
p_133732_ = p_133732_.replace(c0, '_');
|
||||
}
|
||||
|
||||
p_133732_ = p_133732_.replaceAll("[./\"]", "_");
|
||||
if (RESERVED_WINDOWS_FILENAMES.matcher(p_133732_).matches()) {
|
||||
p_133732_ = "_" + p_133732_ + "_";
|
||||
}
|
||||
|
||||
Matcher matcher = COPY_COUNTER_PATTERN.matcher(p_133732_);
|
||||
int j = 0;
|
||||
if (matcher.matches()) {
|
||||
p_133732_ = matcher.group("name");
|
||||
j = Integer.parseInt(matcher.group("count"));
|
||||
}
|
||||
|
||||
if (p_133732_.length() > 255 - p_133733_.length()) {
|
||||
p_133732_ = p_133732_.substring(0, 255 - p_133733_.length());
|
||||
}
|
||||
|
||||
while(true) {
|
||||
String s = p_133732_;
|
||||
if (j != 0) {
|
||||
String s1 = " (" + j + ")";
|
||||
int i = 255 - s1.length();
|
||||
if (p_133732_.length() > i) {
|
||||
s = p_133732_.substring(0, i);
|
||||
}
|
||||
|
||||
s = s + s1;
|
||||
}
|
||||
|
||||
s = s + p_133733_;
|
||||
Path path = p_133731_.resolve(s);
|
||||
|
||||
try {
|
||||
Path path1 = Files.createDirectory(path);
|
||||
Files.deleteIfExists(path1);
|
||||
return p_133731_.relativize(path1).toString();
|
||||
} catch (FileAlreadyExistsException filealreadyexistsexception) {
|
||||
++j;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isPathNormalized(Path p_133729_) {
|
||||
Path path = p_133729_.normalize();
|
||||
return path.equals(p_133729_);
|
||||
}
|
||||
|
||||
public static boolean isPathPortable(Path p_133735_) {
|
||||
for(Path path : p_133735_) {
|
||||
if (RESERVED_WINDOWS_FILENAMES.matcher(path.toString()).matches()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static Path createPathToResource(Path p_133737_, String p_133738_, String p_133739_) {
|
||||
String s = p_133738_ + p_133739_;
|
||||
Path path = Paths.get(s);
|
||||
if (path.endsWith(p_133739_)) {
|
||||
throw new InvalidPathException(s, "empty resource name");
|
||||
} else {
|
||||
return p_133737_.resolve(path);
|
||||
}
|
||||
}
|
||||
|
||||
public static String getFullResourcePath(String p_179923_) {
|
||||
return FilenameUtils.getFullPath(p_179923_).replace(File.separator, "/");
|
||||
}
|
||||
|
||||
public static String normalizeResourcePath(String p_179925_) {
|
||||
return FilenameUtils.normalize(p_179925_).replace(File.separator, "/");
|
||||
}
|
||||
|
||||
public static DataResult<List<String>> decomposePath(String p_248866_) {
|
||||
int i = p_248866_.indexOf(47);
|
||||
if (i == -1) {
|
||||
DataResult dataresult;
|
||||
switch (p_248866_) {
|
||||
case "":
|
||||
case ".":
|
||||
case "..":
|
||||
dataresult = DataResult.error(() -> {
|
||||
return "Invalid path '" + p_248866_ + "'";
|
||||
});
|
||||
break;
|
||||
default:
|
||||
dataresult = !isValidStrictPathSegment(p_248866_) ? DataResult.error(() -> {
|
||||
return "Invalid path '" + p_248866_ + "'";
|
||||
}) : DataResult.success(List.of(p_248866_));
|
||||
}
|
||||
|
||||
return dataresult;
|
||||
} else {
|
||||
List<String> list = new ArrayList<>();
|
||||
int j = 0;
|
||||
boolean flag = false;
|
||||
|
||||
while(true) {
|
||||
String s = p_248866_.substring(j, i);
|
||||
switch (p_248866_.substring(j, i)) {
|
||||
case "":
|
||||
case ".":
|
||||
case "..":
|
||||
return DataResult.error(() -> {
|
||||
return "Invalid segment '" + s + "' in path '" + p_248866_ + "'";
|
||||
});
|
||||
}
|
||||
|
||||
if (!isValidStrictPathSegment(s)) {
|
||||
return DataResult.error(() -> {
|
||||
return "Invalid segment '" + s + "' in path '" + p_248866_ + "'";
|
||||
});
|
||||
}
|
||||
|
||||
list.add(s);
|
||||
if (flag) {
|
||||
return DataResult.success(list);
|
||||
}
|
||||
|
||||
j = i + 1;
|
||||
i = p_248866_.indexOf(47, j);
|
||||
if (i == -1) {
|
||||
i = p_248866_.length();
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Path resolvePath(Path p_251522_, List<String> p_251495_) {
|
||||
int i = p_251495_.size();
|
||||
Path path;
|
||||
switch (i) {
|
||||
case 0:
|
||||
path = p_251522_;
|
||||
break;
|
||||
case 1:
|
||||
path = p_251522_.resolve(p_251495_.get(0));
|
||||
break;
|
||||
default:
|
||||
String[] astring = new String[i - 1];
|
||||
|
||||
for(int j = 1; j < i; ++j) {
|
||||
astring[j - 1] = p_251495_.get(j);
|
||||
}
|
||||
|
||||
path = p_251522_.resolve(p_251522_.getFileSystem().getPath(p_251495_.get(0), astring));
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
public static boolean isValidStrictPathSegment(String p_249814_) {
|
||||
return STRICT_PATH_SEGMENT_CHECK.matcher(p_249814_).matches();
|
||||
}
|
||||
|
||||
public static void validatePath(String... p_249502_) {
|
||||
if (p_249502_.length == 0) {
|
||||
throw new IllegalArgumentException("Path must have at least one element");
|
||||
} else {
|
||||
for(String s : p_249502_) {
|
||||
if (s.equals("..") || s.equals(".") || !isValidStrictPathSegment(s)) {
|
||||
throw new IllegalArgumentException("Illegal segment " + s + " in path " + Arrays.toString((Object[])p_249502_));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static void createDirectoriesSafe(Path p_259902_) throws IOException {
|
||||
Files.createDirectories(Files.exists(p_259902_) ? p_259902_.toRealPath() : p_259902_);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package net.minecraft;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.meta.TypeQualifierDefault;
|
||||
|
||||
@Nonnull
|
||||
@TypeQualifierDefault({ElementType.METHOD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface MethodsReturnNonnullByDefault {
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package net.minecraft;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class Optionull {
|
||||
@Nullable
|
||||
public static <T, R> R map(@Nullable T p_270441_, Function<T, R> p_270332_) {
|
||||
return (R)(p_270441_ == null ? null : p_270332_.apply(p_270441_));
|
||||
}
|
||||
|
||||
public static <T, R> R mapOrDefault(@Nullable T p_270215_, Function<T, R> p_270557_, R p_270839_) {
|
||||
return (R)(p_270215_ == null ? p_270839_ : p_270557_.apply(p_270215_));
|
||||
}
|
||||
|
||||
public static <T, R> R mapOrElse(@Nullable T p_270820_, Function<T, R> p_270536_, Supplier<R> p_270756_) {
|
||||
return (R)(p_270820_ == null ? p_270756_.get() : p_270536_.apply(p_270820_));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static <T> T first(Collection<T> p_270346_) {
|
||||
Iterator<T> iterator = p_270346_.iterator();
|
||||
return (T)(iterator.hasNext() ? iterator.next() : null);
|
||||
}
|
||||
|
||||
public static <T> T firstOrDefault(Collection<T> p_270625_, T p_270960_) {
|
||||
Iterator<T> iterator = p_270625_.iterator();
|
||||
return (T)(iterator.hasNext() ? iterator.next() : p_270960_);
|
||||
}
|
||||
|
||||
public static <T> T firstOrElse(Collection<T> p_270529_, Supplier<T> p_270239_) {
|
||||
Iterator<T> iterator = p_270529_.iterator();
|
||||
return (T)(iterator.hasNext() ? iterator.next() : p_270239_.get());
|
||||
}
|
||||
|
||||
public static <T> boolean isNullOrEmpty(@Nullable T[] p_270794_) {
|
||||
return p_270794_ == null || p_270794_.length == 0;
|
||||
}
|
||||
|
||||
public static boolean isNullOrEmpty(@Nullable boolean[] p_270403_) {
|
||||
return p_270403_ == null || p_270403_.length == 0;
|
||||
}
|
||||
|
||||
public static boolean isNullOrEmpty(@Nullable byte[] p_270775_) {
|
||||
return p_270775_ == null || p_270775_.length == 0;
|
||||
}
|
||||
|
||||
public static boolean isNullOrEmpty(@Nullable char[] p_270512_) {
|
||||
return p_270512_ == null || p_270512_.length == 0;
|
||||
}
|
||||
|
||||
public static boolean isNullOrEmpty(@Nullable short[] p_270712_) {
|
||||
return p_270712_ == null || p_270712_.length == 0;
|
||||
}
|
||||
|
||||
public static boolean isNullOrEmpty(@Nullable int[] p_270127_) {
|
||||
return p_270127_ == null || p_270127_.length == 0;
|
||||
}
|
||||
|
||||
public static boolean isNullOrEmpty(@Nullable long[] p_270148_) {
|
||||
return p_270148_ == null || p_270148_.length == 0;
|
||||
}
|
||||
|
||||
public static boolean isNullOrEmpty(@Nullable float[] p_270428_) {
|
||||
return p_270428_ == null || p_270428_.length == 0;
|
||||
}
|
||||
|
||||
public static boolean isNullOrEmpty(@Nullable double[] p_270373_) {
|
||||
return p_270373_ == null || p_270373_.length == 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package net.minecraft;
|
||||
|
||||
public class ReportedException extends RuntimeException {
|
||||
private final CrashReport report;
|
||||
|
||||
public ReportedException(CrashReport p_134760_) {
|
||||
this.report = p_134760_;
|
||||
}
|
||||
|
||||
public CrashReport getReport() {
|
||||
return this.report;
|
||||
}
|
||||
|
||||
public Throwable getCause() {
|
||||
return this.report.getException();
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return this.report.getTitle();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package net.minecraft;
|
||||
|
||||
import org.apache.commons.lang3.StringEscapeUtils;
|
||||
|
||||
public class ResourceLocationException extends RuntimeException {
|
||||
public ResourceLocationException(String p_135421_) {
|
||||
super(StringEscapeUtils.escapeJava(p_135421_));
|
||||
}
|
||||
|
||||
public ResourceLocationException(String p_135423_, Throwable p_135424_) {
|
||||
super(StringEscapeUtils.escapeJava(p_135423_), p_135424_);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,218 @@
|
||||
package net.minecraft;
|
||||
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.datafixers.DSL;
|
||||
import io.netty.util.ResourceLeakDetector;
|
||||
import io.netty.util.ResourceLeakDetector.Level;
|
||||
import java.time.Duration;
|
||||
import java.util.Set;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.commands.BrigadierExceptions;
|
||||
import net.minecraft.util.datafix.DataFixTypes;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
|
||||
public class SharedConstants {
|
||||
/** @deprecated */
|
||||
@Deprecated
|
||||
public static final boolean SNAPSHOT = false;
|
||||
/** @deprecated */
|
||||
@Deprecated
|
||||
public static final int WORLD_VERSION = 3465;
|
||||
/** @deprecated */
|
||||
@Deprecated
|
||||
public static final String SERIES = "main";
|
||||
/** @deprecated */
|
||||
@Deprecated
|
||||
public static final String VERSION_STRING = "1.20.1";
|
||||
/** @deprecated */
|
||||
@Deprecated
|
||||
public static final int RELEASE_NETWORK_PROTOCOL_VERSION = 763;
|
||||
/** @deprecated */
|
||||
@Deprecated
|
||||
public static final int SNAPSHOT_NETWORK_PROTOCOL_VERSION = 142;
|
||||
public static final int SNBT_NAG_VERSION = 3437;
|
||||
private static final int SNAPSHOT_PROTOCOL_BIT = 30;
|
||||
public static final boolean THROW_ON_TASK_FAILURE = false;
|
||||
/** @deprecated */
|
||||
@Deprecated
|
||||
public static final int RESOURCE_PACK_FORMAT = 15;
|
||||
/** @deprecated */
|
||||
@Deprecated
|
||||
public static final int DATA_PACK_FORMAT = 15;
|
||||
/** @deprecated */
|
||||
@Deprecated
|
||||
public static final int LANGUAGE_FORMAT = 1;
|
||||
public static final int REPORT_FORMAT_VERSION = 1;
|
||||
public static final String DATA_VERSION_TAG = "DataVersion";
|
||||
public static final boolean USE_NEW_RENDERSYSTEM = false;
|
||||
public static final boolean MULTITHREADED_RENDERING = false;
|
||||
public static final boolean FIX_TNT_DUPE = false;
|
||||
public static final boolean FIX_SAND_DUPE = false;
|
||||
public static final boolean USE_DEBUG_FEATURES = false;
|
||||
public static final boolean DEBUG_OPEN_INCOMPATIBLE_WORLDS = false;
|
||||
public static final boolean DEBUG_ALLOW_LOW_SIM_DISTANCE = false;
|
||||
public static final boolean DEBUG_HOTKEYS = false;
|
||||
public static final boolean DEBUG_UI_NARRATION = false;
|
||||
public static final boolean DEBUG_RENDER = false;
|
||||
public static final boolean DEBUG_PATHFINDING = false;
|
||||
public static final boolean DEBUG_WATER = false;
|
||||
public static final boolean DEBUG_HEIGHTMAP = false;
|
||||
public static final boolean DEBUG_COLLISION = false;
|
||||
public static final boolean DEBUG_SUPPORT_BLOCKS = false;
|
||||
public static final boolean DEBUG_SHAPES = false;
|
||||
public static final boolean DEBUG_NEIGHBORSUPDATE = false;
|
||||
public static final boolean DEBUG_STRUCTURES = false;
|
||||
public static final boolean DEBUG_LIGHT = false;
|
||||
public static final boolean DEBUG_SKY_LIGHT_SECTIONS = false;
|
||||
public static final boolean DEBUG_WORLDGENATTEMPT = false;
|
||||
public static final boolean DEBUG_SOLID_FACE = false;
|
||||
public static final boolean DEBUG_CHUNKS = false;
|
||||
public static final boolean DEBUG_GAME_EVENT_LISTENERS = false;
|
||||
public static final boolean DEBUG_DUMP_TEXTURE_ATLAS = false;
|
||||
public static final boolean DEBUG_DUMP_INTERPOLATED_TEXTURE_FRAMES = false;
|
||||
public static final boolean DEBUG_STRUCTURE_EDIT_MODE = false;
|
||||
public static final boolean DEBUG_SAVE_STRUCTURES_AS_SNBT = false;
|
||||
public static final boolean DEBUG_SYNCHRONOUS_GL_LOGS = false;
|
||||
public static final boolean DEBUG_VERBOSE_SERVER_EVENTS = false;
|
||||
public static final boolean DEBUG_NAMED_RUNNABLES = false;
|
||||
public static final boolean DEBUG_GOAL_SELECTOR = false;
|
||||
public static final boolean DEBUG_VILLAGE_SECTIONS = false;
|
||||
public static final boolean DEBUG_BRAIN = false;
|
||||
public static final boolean DEBUG_BEES = false;
|
||||
public static final boolean DEBUG_RAIDS = false;
|
||||
public static final boolean DEBUG_BLOCK_BREAK = false;
|
||||
public static final boolean DEBUG_RESOURCE_LOAD_TIMES = false;
|
||||
public static final boolean DEBUG_MONITOR_TICK_TIMES = false;
|
||||
public static final boolean DEBUG_KEEP_JIGSAW_BLOCKS_DURING_STRUCTURE_GEN = false;
|
||||
public static final boolean DEBUG_DONT_SAVE_WORLD = false;
|
||||
public static final boolean DEBUG_LARGE_DRIPSTONE = false;
|
||||
public static final boolean DEBUG_PACKET_SERIALIZATION = false;
|
||||
public static final boolean DEBUG_CARVERS = false;
|
||||
public static final boolean DEBUG_ORE_VEINS = false;
|
||||
public static final boolean DEBUG_SCULK_CATALYST = false;
|
||||
public static final boolean DEBUG_BYPASS_REALMS_VERSION_CHECK = false;
|
||||
public static final boolean DEBUG_SOCIAL_INTERACTIONS = false;
|
||||
public static final boolean DEBUG_VALIDATE_RESOURCE_PATH_CASE = false;
|
||||
public static final boolean DEBUG_IGNORE_LOCAL_MOB_CAP = false;
|
||||
public static final boolean DEBUG_SMALL_SPAWN = false;
|
||||
public static final boolean DEBUG_DISABLE_LIQUID_SPREADING = false;
|
||||
public static final boolean DEBUG_AQUIFERS = false;
|
||||
public static final boolean DEBUG_JFR_PROFILING_ENABLE_LEVEL_LOADING = false;
|
||||
public static boolean debugGenerateSquareTerrainWithoutNoise = false;
|
||||
public static boolean debugGenerateStripedTerrainWithoutNoise = false;
|
||||
public static final boolean DEBUG_ONLY_GENERATE_HALF_THE_WORLD = false;
|
||||
public static final boolean DEBUG_DISABLE_FLUID_GENERATION = false;
|
||||
public static final boolean DEBUG_DISABLE_AQUIFERS = false;
|
||||
public static final boolean DEBUG_DISABLE_SURFACE = false;
|
||||
public static final boolean DEBUG_DISABLE_CARVERS = false;
|
||||
public static final boolean DEBUG_DISABLE_STRUCTURES = false;
|
||||
public static final boolean DEBUG_DISABLE_FEATURES = false;
|
||||
public static final boolean DEBUG_DISABLE_ORE_VEINS = false;
|
||||
public static final boolean DEBUG_DISABLE_BLENDING = false;
|
||||
public static final boolean DEBUG_DISABLE_BELOW_ZERO_RETROGENERATION = false;
|
||||
public static final int DEFAULT_MINECRAFT_PORT = 25565;
|
||||
public static final boolean INGAME_DEBUG_OUTPUT = false;
|
||||
public static final boolean DEBUG_SUBTITLES = false;
|
||||
public static final int FAKE_MS_LATENCY = 0;
|
||||
public static final int FAKE_MS_JITTER = 0;
|
||||
public static final ResourceLeakDetector.Level NETTY_LEAK_DETECTION = Level.DISABLED;
|
||||
public static final boolean COMMAND_STACK_TRACES = false;
|
||||
public static final boolean DEBUG_WORLD_RECREATE = false;
|
||||
public static final boolean DEBUG_SHOW_SERVER_DEBUG_VALUES = false;
|
||||
public static final boolean DEBUG_STORE_CHUNK_STACKTRACES = false;
|
||||
public static final boolean DEBUG_FEATURE_COUNT = false;
|
||||
public static final boolean DEBUG_RESOURCE_GENERATION_OVERRIDE = false;
|
||||
public static final boolean DEBUG_FORCE_TELEMETRY = false;
|
||||
public static final boolean DEBUG_DONT_SEND_TELEMETRY_TO_BACKEND = false;
|
||||
public static final long MAXIMUM_TICK_TIME_NANOS = Duration.ofMillis(300L).toNanos();
|
||||
public static final boolean USE_WORKFLOWS_HOOKS = false;
|
||||
public static boolean CHECK_DATA_FIXER_SCHEMA = true;
|
||||
public static boolean IS_RUNNING_IN_IDE;
|
||||
public static Set<DSL.TypeReference> DATA_FIX_TYPES_TO_OPTIMIZE = Set.of();
|
||||
public static final int WORLD_RESOLUTION = 16;
|
||||
public static final int MAX_CHAT_LENGTH = 256;
|
||||
public static final int MAX_COMMAND_LENGTH = 32500;
|
||||
public static final int MAX_CHAINED_NEIGHBOR_UPDATES = 1000000;
|
||||
public static final int MAX_RENDER_DISTANCE = 32;
|
||||
public static final char[] ILLEGAL_FILE_CHARACTERS = new char[]{'/', '\n', '\r', '\t', '\u0000', '\f', '`', '?', '*', '\\', '<', '>', '|', '"', ':'};
|
||||
public static final int TICKS_PER_SECOND = 20;
|
||||
public static final int TICKS_PER_MINUTE = 1200;
|
||||
public static final int TICKS_PER_GAME_DAY = 24000;
|
||||
public static final float AVERAGE_GAME_TICKS_PER_RANDOM_TICK_PER_BLOCK = 1365.3334F;
|
||||
public static final float AVERAGE_RANDOM_TICKS_PER_BLOCK_PER_MINUTE = 0.87890625F;
|
||||
public static final float AVERAGE_RANDOM_TICKS_PER_BLOCK_PER_GAME_DAY = 17.578125F;
|
||||
public static final int WORLD_ICON_SIZE = 64;
|
||||
@Nullable
|
||||
private static WorldVersion CURRENT_VERSION;
|
||||
|
||||
public static boolean isAllowedChatCharacter(char p_136189_) {
|
||||
return p_136189_ != 167 && p_136189_ >= ' ' && p_136189_ != 127;
|
||||
}
|
||||
|
||||
public static String filterText(String p_136191_) {
|
||||
return filterText(p_136191_, false);
|
||||
}
|
||||
|
||||
public static String filterText(String p_239658_, boolean p_239659_) {
|
||||
StringBuilder stringbuilder = new StringBuilder();
|
||||
|
||||
for(char c0 : p_239658_.toCharArray()) {
|
||||
if (isAllowedChatCharacter(c0)) {
|
||||
stringbuilder.append(c0);
|
||||
} else if (p_239659_ && c0 == '\n') {
|
||||
stringbuilder.append(c0);
|
||||
}
|
||||
}
|
||||
|
||||
return stringbuilder.toString();
|
||||
}
|
||||
|
||||
public static void setVersion(WorldVersion p_183706_) {
|
||||
if (CURRENT_VERSION == null) {
|
||||
CURRENT_VERSION = p_183706_;
|
||||
} else if (p_183706_ != CURRENT_VERSION) {
|
||||
throw new IllegalStateException("Cannot override the current game version!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void tryDetectVersion() {
|
||||
if (CURRENT_VERSION == null) {
|
||||
CURRENT_VERSION = DetectedVersion.tryDetectVersion();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static WorldVersion getCurrentVersion() {
|
||||
if (CURRENT_VERSION == null) {
|
||||
throw new IllegalStateException("Game version not set");
|
||||
} else {
|
||||
return CURRENT_VERSION;
|
||||
}
|
||||
}
|
||||
|
||||
public static int getProtocolVersion() {
|
||||
return 763;
|
||||
}
|
||||
|
||||
public static boolean debugVoidTerrain(ChunkPos p_183708_) {
|
||||
int i = p_183708_.getMinBlockX();
|
||||
int j = p_183708_.getMinBlockZ();
|
||||
if (!debugGenerateSquareTerrainWithoutNoise) {
|
||||
return false;
|
||||
} else {
|
||||
return i > 8192 || i < 0 || j > 1024 || j < 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static void enableDataFixerOptimizations() {
|
||||
DATA_FIX_TYPES_TO_OPTIMIZE = DataFixTypes.TYPES_FOR_LEVEL_LIST;
|
||||
}
|
||||
|
||||
static {
|
||||
if (System.getProperty("io.netty.leakDetection.level") == null) // Forge: allow level to be manually specified
|
||||
ResourceLeakDetector.setLevel(NETTY_LEAK_DETECTION);
|
||||
CommandSyntaxException.ENABLE_COMMAND_STACK_TRACES = false;
|
||||
CommandSyntaxException.BUILT_IN_EXCEPTIONS = new BrigadierExceptions();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
package net.minecraft;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.mojang.logging.LogUtils;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
import org.slf4j.Logger;
|
||||
import oshi.SystemInfo;
|
||||
import oshi.hardware.CentralProcessor;
|
||||
import oshi.hardware.GlobalMemory;
|
||||
import oshi.hardware.GraphicsCard;
|
||||
import oshi.hardware.HardwareAbstractionLayer;
|
||||
import oshi.hardware.PhysicalMemory;
|
||||
import oshi.hardware.VirtualMemory;
|
||||
|
||||
public class SystemReport {
|
||||
public static final long BYTES_PER_MEBIBYTE = 1048576L;
|
||||
private static final long ONE_GIGA = 1000000000L;
|
||||
private static final Logger LOGGER = LogUtils.getLogger();
|
||||
private static final String OPERATING_SYSTEM = System.getProperty("os.name") + " (" + System.getProperty("os.arch") + ") version " + System.getProperty("os.version");
|
||||
private static final String JAVA_VERSION = System.getProperty("java.version") + ", " + System.getProperty("java.vendor");
|
||||
private static final String JAVA_VM_VERSION = System.getProperty("java.vm.name") + " (" + System.getProperty("java.vm.info") + "), " + System.getProperty("java.vm.vendor");
|
||||
private final Map<String, String> entries = Maps.newLinkedHashMap();
|
||||
|
||||
public SystemReport() {
|
||||
this.setDetail("Minecraft Version", SharedConstants.getCurrentVersion().getName());
|
||||
this.setDetail("Minecraft Version ID", SharedConstants.getCurrentVersion().getId());
|
||||
this.setDetail("Operating System", OPERATING_SYSTEM);
|
||||
this.setDetail("Java Version", JAVA_VERSION);
|
||||
this.setDetail("Java VM Version", JAVA_VM_VERSION);
|
||||
this.setDetail("Memory", () -> {
|
||||
Runtime runtime = Runtime.getRuntime();
|
||||
long i = runtime.maxMemory();
|
||||
long j = runtime.totalMemory();
|
||||
long k = runtime.freeMemory();
|
||||
long l = i / 1048576L;
|
||||
long i1 = j / 1048576L;
|
||||
long j1 = k / 1048576L;
|
||||
return k + " bytes (" + j1 + " MiB) / " + j + " bytes (" + i1 + " MiB) up to " + i + " bytes (" + l + " MiB)";
|
||||
});
|
||||
this.setDetail("CPUs", () -> {
|
||||
return String.valueOf(Runtime.getRuntime().availableProcessors());
|
||||
});
|
||||
this.ignoreErrors("hardware", () -> {
|
||||
this.putHardware(new SystemInfo());
|
||||
});
|
||||
this.setDetail("JVM Flags", () -> {
|
||||
List<String> list = Util.getVmArguments().collect(Collectors.toList());
|
||||
return String.format(Locale.ROOT, "%d total; %s", list.size(), String.join(" ", list));
|
||||
});
|
||||
}
|
||||
|
||||
public void setDetail(String p_143520_, String p_143521_) {
|
||||
this.entries.put(p_143520_, p_143521_);
|
||||
}
|
||||
|
||||
public void setDetail(String p_143523_, Supplier<String> p_143524_) {
|
||||
try {
|
||||
this.setDetail(p_143523_, p_143524_.get());
|
||||
} catch (Exception exception) {
|
||||
LOGGER.warn("Failed to get system info for {}", p_143523_, exception);
|
||||
this.setDetail(p_143523_, "ERR");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void putHardware(SystemInfo p_143536_) {
|
||||
HardwareAbstractionLayer hardwareabstractionlayer = p_143536_.getHardware();
|
||||
this.ignoreErrors("processor", () -> {
|
||||
this.putProcessor(hardwareabstractionlayer.getProcessor());
|
||||
});
|
||||
this.ignoreErrors("graphics", () -> {
|
||||
this.putGraphics(hardwareabstractionlayer.getGraphicsCards());
|
||||
});
|
||||
this.ignoreErrors("memory", () -> {
|
||||
this.putMemory(hardwareabstractionlayer.getMemory());
|
||||
});
|
||||
}
|
||||
|
||||
private void ignoreErrors(String p_143517_, Runnable p_143518_) {
|
||||
try {
|
||||
p_143518_.run();
|
||||
} catch (Throwable throwable) {
|
||||
LOGGER.warn("Failed retrieving info for group {}", p_143517_, throwable);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void putPhysicalMemory(List<PhysicalMemory> p_143532_) {
|
||||
int i = 0;
|
||||
|
||||
for(PhysicalMemory physicalmemory : p_143532_) {
|
||||
String s = String.format(Locale.ROOT, "Memory slot #%d ", i++);
|
||||
this.setDetail(s + "capacity (MB)", () -> {
|
||||
return String.format(Locale.ROOT, "%.2f", (float)physicalmemory.getCapacity() / 1048576.0F);
|
||||
});
|
||||
this.setDetail(s + "clockSpeed (GHz)", () -> {
|
||||
return String.format(Locale.ROOT, "%.2f", (float)physicalmemory.getClockSpeed() / 1.0E9F);
|
||||
});
|
||||
this.setDetail(s + "type", physicalmemory::getMemoryType);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void putVirtualMemory(VirtualMemory p_143550_) {
|
||||
this.setDetail("Virtual memory max (MB)", () -> {
|
||||
return String.format(Locale.ROOT, "%.2f", (float)p_143550_.getVirtualMax() / 1048576.0F);
|
||||
});
|
||||
this.setDetail("Virtual memory used (MB)", () -> {
|
||||
return String.format(Locale.ROOT, "%.2f", (float)p_143550_.getVirtualInUse() / 1048576.0F);
|
||||
});
|
||||
this.setDetail("Swap memory total (MB)", () -> {
|
||||
return String.format(Locale.ROOT, "%.2f", (float)p_143550_.getSwapTotal() / 1048576.0F);
|
||||
});
|
||||
this.setDetail("Swap memory used (MB)", () -> {
|
||||
return String.format(Locale.ROOT, "%.2f", (float)p_143550_.getSwapUsed() / 1048576.0F);
|
||||
});
|
||||
}
|
||||
|
||||
private void putMemory(GlobalMemory p_143542_) {
|
||||
this.ignoreErrors("physical memory", () -> {
|
||||
this.putPhysicalMemory(p_143542_.getPhysicalMemory());
|
||||
});
|
||||
this.ignoreErrors("virtual memory", () -> {
|
||||
this.putVirtualMemory(p_143542_.getVirtualMemory());
|
||||
});
|
||||
}
|
||||
|
||||
private void putGraphics(List<GraphicsCard> p_143553_) {
|
||||
int i = 0;
|
||||
|
||||
for(GraphicsCard graphicscard : p_143553_) {
|
||||
String s = String.format(Locale.ROOT, "Graphics card #%d ", i++);
|
||||
this.setDetail(s + "name", graphicscard::getName);
|
||||
this.setDetail(s + "vendor", graphicscard::getVendor);
|
||||
this.setDetail(s + "VRAM (MB)", () -> {
|
||||
return String.format(Locale.ROOT, "%.2f", (float)graphicscard.getVRam() / 1048576.0F);
|
||||
});
|
||||
this.setDetail(s + "deviceId", graphicscard::getDeviceId);
|
||||
this.setDetail(s + "versionInfo", graphicscard::getVersionInfo);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void putProcessor(CentralProcessor p_143540_) {
|
||||
CentralProcessor.ProcessorIdentifier processoridentifier = p_143540_.getProcessorIdentifier();
|
||||
this.setDetail("Processor Vendor", processoridentifier::getVendor);
|
||||
this.setDetail("Processor Name", processoridentifier::getName);
|
||||
this.setDetail("Identifier", processoridentifier::getIdentifier);
|
||||
this.setDetail("Microarchitecture", processoridentifier::getMicroarchitecture);
|
||||
this.setDetail("Frequency (GHz)", () -> {
|
||||
return String.format(Locale.ROOT, "%.2f", (float)processoridentifier.getVendorFreq() / 1.0E9F);
|
||||
});
|
||||
this.setDetail("Number of physical packages", () -> {
|
||||
return String.valueOf(p_143540_.getPhysicalPackageCount());
|
||||
});
|
||||
this.setDetail("Number of physical CPUs", () -> {
|
||||
return String.valueOf(p_143540_.getPhysicalProcessorCount());
|
||||
});
|
||||
this.setDetail("Number of logical CPUs", () -> {
|
||||
return String.valueOf(p_143540_.getLogicalProcessorCount());
|
||||
});
|
||||
}
|
||||
|
||||
public void appendToCrashReportString(StringBuilder p_143526_) {
|
||||
p_143526_.append("-- ").append("System Details").append(" --\n");
|
||||
p_143526_.append("Details:");
|
||||
this.entries.forEach((p_143529_, p_143530_) -> {
|
||||
p_143526_.append("\n\t");
|
||||
p_143526_.append(p_143529_);
|
||||
p_143526_.append(": ");
|
||||
p_143526_.append(p_143530_);
|
||||
});
|
||||
}
|
||||
|
||||
public String toLineSeparatedString() {
|
||||
return this.entries.entrySet().stream().map((p_143534_) -> {
|
||||
return (String)p_143534_.getKey() + ": " + (String)p_143534_.getValue();
|
||||
}).collect(Collectors.joining(System.lineSeparator()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,917 @@
|
||||
package net.minecraft;
|
||||
|
||||
import com.google.common.base.Ticker;
|
||||
import com.google.common.collect.Iterators;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.util.concurrent.MoreExecutors;
|
||||
import com.mojang.datafixers.DSL;
|
||||
import com.mojang.datafixers.DataFixUtils;
|
||||
import com.mojang.datafixers.types.Type;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import com.mojang.logging.LogUtils;
|
||||
import com.mojang.serialization.DataResult;
|
||||
import it.unimi.dsi.fastutil.Hash;
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.RuntimeMXBean;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.spi.FileSystemProvider;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedActionException;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CompletionException;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ForkJoinPool;
|
||||
import java.util.concurrent.ForkJoinWorkerThread;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.BooleanSupplier;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.IntFunction;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.function.ToIntFunction;
|
||||
import java.util.stream.Collector;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.LongStream;
|
||||
import java.util.stream.Stream;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.Bootstrap;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.util.SingleKeyCache;
|
||||
import net.minecraft.util.TimeSource;
|
||||
import net.minecraft.util.datafix.DataFixers;
|
||||
import net.minecraft.world.level.block.state.properties.Property;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
public class Util {
|
||||
static final Logger LOGGER = LogUtils.getLogger();
|
||||
private static final int DEFAULT_MAX_THREADS = 255;
|
||||
private static final String MAX_THREADS_SYSTEM_PROPERTY = "max.bg.threads";
|
||||
private static final AtomicInteger WORKER_COUNT = new AtomicInteger(1);
|
||||
private static final ExecutorService BACKGROUND_EXECUTOR = makeExecutor("Main");
|
||||
private static final ExecutorService IO_POOL = makeIoExecutor();
|
||||
private static final DateTimeFormatter FILENAME_DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd_HH.mm.ss", Locale.ROOT);
|
||||
public static TimeSource.NanoTimeSource timeSource = System::nanoTime;
|
||||
public static final Ticker TICKER = new Ticker() {
|
||||
public long read() {
|
||||
return Util.timeSource.getAsLong();
|
||||
}
|
||||
};
|
||||
public static final UUID NIL_UUID = new UUID(0L, 0L);
|
||||
public static final FileSystemProvider ZIP_FILE_SYSTEM_PROVIDER = FileSystemProvider.installedProviders().stream().filter((p_201865_) -> {
|
||||
return p_201865_.getScheme().equalsIgnoreCase("jar");
|
||||
}).findFirst().orElseThrow(() -> {
|
||||
return new IllegalStateException("No jar file system provider found");
|
||||
});
|
||||
private static Consumer<String> thePauser = (p_201905_) -> {
|
||||
};
|
||||
|
||||
public static <K, V> Collector<Map.Entry<? extends K, ? extends V>, ?, Map<K, V>> toMap() {
|
||||
return Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue);
|
||||
}
|
||||
|
||||
public static <T extends Comparable<T>> String getPropertyName(Property<T> p_137454_, Object p_137455_) {
|
||||
return p_137454_.getName((T)(p_137455_));
|
||||
}
|
||||
|
||||
public static String makeDescriptionId(String p_137493_, @Nullable ResourceLocation p_137494_) {
|
||||
return p_137494_ == null ? p_137493_ + ".unregistered_sadface" : p_137493_ + "." + p_137494_.getNamespace() + "." + p_137494_.getPath().replace('/', '.');
|
||||
}
|
||||
|
||||
public static long getMillis() {
|
||||
return getNanos() / 1000000L;
|
||||
}
|
||||
|
||||
public static long getNanos() {
|
||||
return timeSource.getAsLong();
|
||||
}
|
||||
|
||||
public static long getEpochMillis() {
|
||||
return Instant.now().toEpochMilli();
|
||||
}
|
||||
|
||||
public static String getFilenameFormattedDateTime() {
|
||||
return FILENAME_DATE_TIME_FORMATTER.format(ZonedDateTime.now());
|
||||
}
|
||||
|
||||
private static ExecutorService makeExecutor(String p_137478_) {
|
||||
int i = Mth.clamp(Runtime.getRuntime().availableProcessors() - 1, 1, getMaxThreads());
|
||||
ExecutorService executorservice;
|
||||
if (i <= 0) {
|
||||
executorservice = MoreExecutors.newDirectExecutorService();
|
||||
} else {
|
||||
executorservice = new ForkJoinPool(i, (p_201863_) -> {
|
||||
ForkJoinWorkerThread forkjoinworkerthread = new ForkJoinWorkerThread(p_201863_) {
|
||||
protected void onTermination(Throwable p_211561_) {
|
||||
if (p_211561_ != null) {
|
||||
Util.LOGGER.warn("{} died", this.getName(), p_211561_);
|
||||
} else {
|
||||
Util.LOGGER.debug("{} shutdown", (Object)this.getName());
|
||||
}
|
||||
|
||||
super.onTermination(p_211561_);
|
||||
}
|
||||
};
|
||||
forkjoinworkerthread.setName("Worker-" + p_137478_ + "-" + WORKER_COUNT.getAndIncrement());
|
||||
return forkjoinworkerthread;
|
||||
}, Util::onThreadException, true);
|
||||
}
|
||||
|
||||
return executorservice;
|
||||
}
|
||||
|
||||
private static int getMaxThreads() {
|
||||
String s = System.getProperty("max.bg.threads");
|
||||
if (s != null) {
|
||||
try {
|
||||
int i = Integer.parseInt(s);
|
||||
if (i >= 1 && i <= 255) {
|
||||
return i;
|
||||
}
|
||||
|
||||
LOGGER.error("Wrong {} property value '{}'. Should be an integer value between 1 and {}.", "max.bg.threads", s, 255);
|
||||
} catch (NumberFormatException numberformatexception) {
|
||||
LOGGER.error("Could not parse {} property value '{}'. Should be an integer value between 1 and {}.", "max.bg.threads", s, 255);
|
||||
}
|
||||
}
|
||||
|
||||
return 255;
|
||||
}
|
||||
|
||||
// We add these inner classes to compensate for Mojang's missing inner classes and shift the anonymous class index.
|
||||
// This allows us to obfuscate subsequent anonymous inner classes correctly.
|
||||
@SuppressWarnings("unused") private static java.util.function.LongSupplier INNER_CLASS_SHIFT1 = new java.util.function.LongSupplier() { public long getAsLong() { return 0; } };
|
||||
@SuppressWarnings("unused") private static java.util.function.LongSupplier INNER_CLASS_SHIFT2 = new java.util.function.LongSupplier() { public long getAsLong() { return 0; } };
|
||||
|
||||
public static ExecutorService backgroundExecutor() {
|
||||
return BACKGROUND_EXECUTOR;
|
||||
}
|
||||
|
||||
public static ExecutorService ioPool() {
|
||||
return IO_POOL;
|
||||
}
|
||||
|
||||
public static void shutdownExecutors() {
|
||||
shutdownExecutor(BACKGROUND_EXECUTOR);
|
||||
shutdownExecutor(IO_POOL);
|
||||
}
|
||||
|
||||
private static void shutdownExecutor(ExecutorService p_137532_) {
|
||||
p_137532_.shutdown();
|
||||
|
||||
boolean flag;
|
||||
try {
|
||||
flag = p_137532_.awaitTermination(3L, TimeUnit.SECONDS);
|
||||
} catch (InterruptedException interruptedexception) {
|
||||
flag = false;
|
||||
}
|
||||
|
||||
if (!flag) {
|
||||
p_137532_.shutdownNow();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static ExecutorService makeIoExecutor() {
|
||||
return Executors.newCachedThreadPool((p_201860_) -> {
|
||||
Thread thread = new Thread(p_201860_);
|
||||
thread.setName("IO-Worker-" + WORKER_COUNT.getAndIncrement());
|
||||
thread.setUncaughtExceptionHandler(Util::onThreadException);
|
||||
return thread;
|
||||
});
|
||||
}
|
||||
|
||||
public static void throwAsRuntime(Throwable p_137560_) {
|
||||
throw p_137560_ instanceof RuntimeException ? (RuntimeException)p_137560_ : new RuntimeException(p_137560_);
|
||||
}
|
||||
|
||||
private static void onThreadException(Thread p_137496_, Throwable p_137497_) {
|
||||
pauseInIde(p_137497_);
|
||||
if (p_137497_ instanceof CompletionException) {
|
||||
p_137497_ = p_137497_.getCause();
|
||||
}
|
||||
|
||||
if (p_137497_ instanceof ReportedException) {
|
||||
Bootstrap.realStdoutPrintln(((ReportedException)p_137497_).getReport().getFriendlyReport());
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
LOGGER.error(String.format(Locale.ROOT, "Caught exception in thread %s", p_137496_), p_137497_);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Type<?> fetchChoiceType(DSL.TypeReference p_137457_, String p_137458_) {
|
||||
return !SharedConstants.CHECK_DATA_FIXER_SCHEMA ? null : doFetchChoiceType(p_137457_, p_137458_);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static Type<?> doFetchChoiceType(DSL.TypeReference p_137552_, String p_137553_) {
|
||||
Type<?> type = null;
|
||||
|
||||
try {
|
||||
type = DataFixers.getDataFixer().getSchema(DataFixUtils.makeKey(SharedConstants.getCurrentVersion().getDataVersion().getVersion())).getChoiceType(p_137552_, p_137553_);
|
||||
} catch (IllegalArgumentException illegalargumentexception) {
|
||||
LOGGER.debug("No data fixer registered for {}", (Object)p_137553_);
|
||||
if (SharedConstants.IS_RUNNING_IN_IDE) {
|
||||
throw illegalargumentexception;
|
||||
}
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
public static Runnable wrapThreadWithTaskName(String p_143788_, Runnable p_143789_) {
|
||||
return SharedConstants.IS_RUNNING_IN_IDE ? () -> {
|
||||
Thread thread = Thread.currentThread();
|
||||
String s = thread.getName();
|
||||
thread.setName(p_143788_);
|
||||
|
||||
try {
|
||||
p_143789_.run();
|
||||
} finally {
|
||||
thread.setName(s);
|
||||
}
|
||||
|
||||
} : p_143789_;
|
||||
}
|
||||
|
||||
public static <V> Supplier<V> wrapThreadWithTaskName(String p_183947_, Supplier<V> p_183948_) {
|
||||
return SharedConstants.IS_RUNNING_IN_IDE ? () -> {
|
||||
Thread thread = Thread.currentThread();
|
||||
String s = thread.getName();
|
||||
thread.setName(p_183947_);
|
||||
|
||||
Object object;
|
||||
try {
|
||||
object = p_183948_.get();
|
||||
} finally {
|
||||
thread.setName(s);
|
||||
}
|
||||
|
||||
return (V)object;
|
||||
} : p_183948_;
|
||||
}
|
||||
|
||||
public static Util.OS getPlatform() {
|
||||
String s = System.getProperty("os.name").toLowerCase(Locale.ROOT);
|
||||
if (s.contains("win")) {
|
||||
return Util.OS.WINDOWS;
|
||||
} else if (s.contains("mac")) {
|
||||
return Util.OS.OSX;
|
||||
} else if (s.contains("solaris")) {
|
||||
return Util.OS.SOLARIS;
|
||||
} else if (s.contains("sunos")) {
|
||||
return Util.OS.SOLARIS;
|
||||
} else if (s.contains("linux")) {
|
||||
return Util.OS.LINUX;
|
||||
} else {
|
||||
return s.contains("unix") ? Util.OS.LINUX : Util.OS.UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
public static Stream<String> getVmArguments() {
|
||||
RuntimeMXBean runtimemxbean = ManagementFactory.getRuntimeMXBean();
|
||||
return runtimemxbean.getInputArguments().stream().filter((p_201903_) -> {
|
||||
return p_201903_.startsWith("-X");
|
||||
});
|
||||
}
|
||||
|
||||
public static <T> T lastOf(List<T> p_137510_) {
|
||||
return p_137510_.get(p_137510_.size() - 1);
|
||||
}
|
||||
|
||||
public static <T> T findNextInIterable(Iterable<T> p_137467_, @Nullable T p_137468_) {
|
||||
Iterator<T> iterator = p_137467_.iterator();
|
||||
T t = iterator.next();
|
||||
if (p_137468_ != null) {
|
||||
T t1 = t;
|
||||
|
||||
while(t1 != p_137468_) {
|
||||
if (iterator.hasNext()) {
|
||||
t1 = iterator.next();
|
||||
}
|
||||
}
|
||||
|
||||
if (iterator.hasNext()) {
|
||||
return iterator.next();
|
||||
}
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
public static <T> T findPreviousInIterable(Iterable<T> p_137555_, @Nullable T p_137556_) {
|
||||
Iterator<T> iterator = p_137555_.iterator();
|
||||
|
||||
T t;
|
||||
T t1;
|
||||
for(t = null; iterator.hasNext(); t = t1) {
|
||||
t1 = iterator.next();
|
||||
if (t1 == p_137556_) {
|
||||
if (t == null) {
|
||||
t = (T)(iterator.hasNext() ? Iterators.getLast(iterator) : p_137556_);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
public static <T> T make(Supplier<T> p_137538_) {
|
||||
return p_137538_.get();
|
||||
}
|
||||
|
||||
public static <T> T make(T p_137470_, Consumer<T> p_137471_) {
|
||||
p_137471_.accept(p_137470_);
|
||||
return p_137470_;
|
||||
}
|
||||
|
||||
public static <K> Hash.Strategy<K> identityStrategy() {
|
||||
return (Hash.Strategy<K>) Util.IdentityStrategy.INSTANCE;
|
||||
}
|
||||
|
||||
public static <V> CompletableFuture<List<V>> sequence(List<? extends CompletableFuture<V>> p_137568_) {
|
||||
if (p_137568_.isEmpty()) {
|
||||
return CompletableFuture.completedFuture(List.of());
|
||||
} else if (p_137568_.size() == 1) {
|
||||
return p_137568_.get(0).thenApply(List::of);
|
||||
} else {
|
||||
CompletableFuture<Void> completablefuture = CompletableFuture.allOf(p_137568_.toArray(new CompletableFuture[0]));
|
||||
return completablefuture.thenApply((p_203746_) -> {
|
||||
return p_137568_.stream().map(CompletableFuture::join).toList();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static <V> CompletableFuture<List<V>> sequenceFailFast(List<? extends CompletableFuture<? extends V>> p_143841_) {
|
||||
CompletableFuture<List<V>> completablefuture = new CompletableFuture<>();
|
||||
return fallibleSequence(p_143841_, completablefuture::completeExceptionally).applyToEither(completablefuture, Function.identity());
|
||||
}
|
||||
|
||||
public static <V> CompletableFuture<List<V>> sequenceFailFastAndCancel(List<? extends CompletableFuture<? extends V>> p_214685_) {
|
||||
CompletableFuture<List<V>> completablefuture = new CompletableFuture<>();
|
||||
return fallibleSequence(p_214685_, (p_274642_) -> {
|
||||
if (completablefuture.completeExceptionally(p_274642_)) {
|
||||
for(CompletableFuture<? extends V> completablefuture1 : p_214685_) {
|
||||
completablefuture1.cancel(true);
|
||||
}
|
||||
}
|
||||
|
||||
}).applyToEither(completablefuture, Function.identity());
|
||||
}
|
||||
|
||||
private static <V> CompletableFuture<List<V>> fallibleSequence(List<? extends CompletableFuture<? extends V>> p_214632_, Consumer<Throwable> p_214633_) {
|
||||
List<V> list = Lists.newArrayListWithCapacity(p_214632_.size());
|
||||
CompletableFuture<?>[] completablefuture = new CompletableFuture[p_214632_.size()];
|
||||
p_214632_.forEach((p_214641_) -> {
|
||||
int i = list.size();
|
||||
list.add((V)null);
|
||||
completablefuture[i] = p_214641_.whenComplete((p_214650_, p_214651_) -> {
|
||||
if (p_214651_ != null) {
|
||||
p_214633_.accept(p_214651_);
|
||||
} else {
|
||||
list.set(i, p_214650_);
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
return CompletableFuture.allOf(completablefuture).thenApply((p_214626_) -> {
|
||||
return list;
|
||||
});
|
||||
}
|
||||
|
||||
public static <T> Optional<T> ifElse(Optional<T> p_137522_, Consumer<T> p_137523_, Runnable p_137524_) {
|
||||
if (p_137522_.isPresent()) {
|
||||
p_137523_.accept(p_137522_.get());
|
||||
} else {
|
||||
p_137524_.run();
|
||||
}
|
||||
|
||||
return p_137522_;
|
||||
}
|
||||
|
||||
public static <T> Supplier<T> name(Supplier<T> p_214656_, Supplier<String> p_214657_) {
|
||||
return p_214656_;
|
||||
}
|
||||
|
||||
public static Runnable name(Runnable p_137475_, Supplier<String> p_137476_) {
|
||||
return p_137475_;
|
||||
}
|
||||
|
||||
public static void logAndPauseIfInIde(String p_143786_) {
|
||||
LOGGER.error(p_143786_);
|
||||
if (SharedConstants.IS_RUNNING_IN_IDE) {
|
||||
doPause(p_143786_);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void logAndPauseIfInIde(String p_200891_, Throwable p_200892_) {
|
||||
LOGGER.error(p_200891_, p_200892_);
|
||||
if (SharedConstants.IS_RUNNING_IN_IDE) {
|
||||
doPause(p_200891_);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static <T extends Throwable> T pauseInIde(T p_137571_) {
|
||||
if (SharedConstants.IS_RUNNING_IN_IDE) {
|
||||
LOGGER.error("Trying to throw a fatal exception, pausing in IDE", p_137571_);
|
||||
doPause(p_137571_.getMessage());
|
||||
}
|
||||
|
||||
return p_137571_;
|
||||
}
|
||||
|
||||
public static void setPause(Consumer<String> p_183970_) {
|
||||
thePauser = p_183970_;
|
||||
}
|
||||
|
||||
private static void doPause(String p_183985_) {
|
||||
Instant instant = Instant.now();
|
||||
LOGGER.warn("Did you remember to set a breakpoint here?");
|
||||
boolean flag = Duration.between(instant, Instant.now()).toMillis() > 500L;
|
||||
if (!flag) {
|
||||
thePauser.accept(p_183985_);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static String describeError(Throwable p_137576_) {
|
||||
if (p_137576_.getCause() != null) {
|
||||
return describeError(p_137576_.getCause());
|
||||
} else {
|
||||
return p_137576_.getMessage() != null ? p_137576_.getMessage() : p_137576_.toString();
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T getRandom(T[] p_214671_, RandomSource p_214672_) {
|
||||
return p_214671_[p_214672_.nextInt(p_214671_.length)];
|
||||
}
|
||||
|
||||
public static int getRandom(int[] p_214668_, RandomSource p_214669_) {
|
||||
return p_214668_[p_214669_.nextInt(p_214668_.length)];
|
||||
}
|
||||
|
||||
public static <T> T getRandom(List<T> p_214622_, RandomSource p_214623_) {
|
||||
return p_214622_.get(p_214623_.nextInt(p_214622_.size()));
|
||||
}
|
||||
|
||||
public static <T> Optional<T> getRandomSafe(List<T> p_214677_, RandomSource p_214678_) {
|
||||
return p_214677_.isEmpty() ? Optional.empty() : Optional.of(getRandom(p_214677_, p_214678_));
|
||||
}
|
||||
|
||||
private static BooleanSupplier createRenamer(final Path p_137503_, final Path p_137504_) {
|
||||
return new BooleanSupplier() {
|
||||
public boolean getAsBoolean() {
|
||||
try {
|
||||
Files.move(p_137503_, p_137504_);
|
||||
return true;
|
||||
} catch (IOException ioexception) {
|
||||
Util.LOGGER.error("Failed to rename", (Throwable)ioexception);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "rename " + p_137503_ + " to " + p_137504_;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static BooleanSupplier createDeleter(final Path p_137501_) {
|
||||
return new BooleanSupplier() {
|
||||
public boolean getAsBoolean() {
|
||||
try {
|
||||
Files.deleteIfExists(p_137501_);
|
||||
return true;
|
||||
} catch (IOException ioexception) {
|
||||
Util.LOGGER.warn("Failed to delete", (Throwable)ioexception);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "delete old " + p_137501_;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static BooleanSupplier createFileDeletedCheck(final Path p_137562_) {
|
||||
return new BooleanSupplier() {
|
||||
public boolean getAsBoolean() {
|
||||
return !Files.exists(p_137562_);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "verify that " + p_137562_ + " is deleted";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static BooleanSupplier createFileCreatedCheck(final Path p_137573_) {
|
||||
return new BooleanSupplier() {
|
||||
public boolean getAsBoolean() {
|
||||
return Files.isRegularFile(p_137573_);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "verify that " + p_137573_ + " is present";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static boolean executeInSequence(BooleanSupplier... p_137549_) {
|
||||
for(BooleanSupplier booleansupplier : p_137549_) {
|
||||
if (!booleansupplier.getAsBoolean()) {
|
||||
LOGGER.warn("Failed to execute {}", (Object)booleansupplier);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean runWithRetries(int p_137450_, String p_137451_, BooleanSupplier... p_137452_) {
|
||||
for(int i = 0; i < p_137450_; ++i) {
|
||||
if (executeInSequence(p_137452_)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
LOGGER.error("Failed to {}, retrying {}/{}", p_137451_, i, p_137450_);
|
||||
}
|
||||
|
||||
LOGGER.error("Failed to {}, aborting, progress might be lost", (Object)p_137451_);
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void safeReplaceFile(File p_137463_, File p_137464_, File p_137465_) {
|
||||
safeReplaceFile(p_137463_.toPath(), p_137464_.toPath(), p_137465_.toPath());
|
||||
}
|
||||
|
||||
public static void safeReplaceFile(Path p_137506_, Path p_137507_, Path p_137508_) {
|
||||
safeReplaceOrMoveFile(p_137506_, p_137507_, p_137508_, false);
|
||||
}
|
||||
|
||||
public static void safeReplaceOrMoveFile(File p_212225_, File p_212226_, File p_212227_, boolean p_212228_) {
|
||||
safeReplaceOrMoveFile(p_212225_.toPath(), p_212226_.toPath(), p_212227_.toPath(), p_212228_);
|
||||
}
|
||||
|
||||
public static void safeReplaceOrMoveFile(Path p_212230_, Path p_212231_, Path p_212232_, boolean p_212233_) {
|
||||
int i = 10;
|
||||
if (!Files.exists(p_212230_) || runWithRetries(10, "create backup " + p_212232_, createDeleter(p_212232_), createRenamer(p_212230_, p_212232_), createFileCreatedCheck(p_212232_))) {
|
||||
if (runWithRetries(10, "remove old " + p_212230_, createDeleter(p_212230_), createFileDeletedCheck(p_212230_))) {
|
||||
if (!runWithRetries(10, "replace " + p_212230_ + " with " + p_212231_, createRenamer(p_212231_, p_212230_), createFileCreatedCheck(p_212230_)) && !p_212233_) {
|
||||
runWithRetries(10, "restore " + p_212230_ + " from " + p_212232_, createRenamer(p_212232_, p_212230_), createFileCreatedCheck(p_212230_));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static int offsetByCodepoints(String p_137480_, int p_137481_, int p_137482_) {
|
||||
int i = p_137480_.length();
|
||||
if (p_137482_ >= 0) {
|
||||
for(int j = 0; p_137481_ < i && j < p_137482_; ++j) {
|
||||
if (Character.isHighSurrogate(p_137480_.charAt(p_137481_++)) && p_137481_ < i && Character.isLowSurrogate(p_137480_.charAt(p_137481_))) {
|
||||
++p_137481_;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for(int k = p_137482_; p_137481_ > 0 && k < 0; ++k) {
|
||||
--p_137481_;
|
||||
if (Character.isLowSurrogate(p_137480_.charAt(p_137481_)) && p_137481_ > 0 && Character.isHighSurrogate(p_137480_.charAt(p_137481_ - 1))) {
|
||||
--p_137481_;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return p_137481_;
|
||||
}
|
||||
|
||||
public static Consumer<String> prefix(String p_137490_, Consumer<String> p_137491_) {
|
||||
return (p_214645_) -> {
|
||||
p_137491_.accept(p_137490_ + p_214645_);
|
||||
};
|
||||
}
|
||||
|
||||
public static DataResult<int[]> fixedSize(IntStream p_137540_, int p_137541_) {
|
||||
int[] aint = p_137540_.limit((long)(p_137541_ + 1)).toArray();
|
||||
if (aint.length != p_137541_) {
|
||||
Supplier<String> supplier = () -> {
|
||||
return "Input is not a list of " + p_137541_ + " ints";
|
||||
};
|
||||
return aint.length >= p_137541_ ? DataResult.error(supplier, Arrays.copyOf(aint, p_137541_)) : DataResult.error(supplier);
|
||||
} else {
|
||||
return DataResult.success(aint);
|
||||
}
|
||||
}
|
||||
|
||||
public static DataResult<long[]> fixedSize(LongStream p_287579_, int p_287631_) {
|
||||
long[] along = p_287579_.limit((long)(p_287631_ + 1)).toArray();
|
||||
if (along.length != p_287631_) {
|
||||
Supplier<String> supplier = () -> {
|
||||
return "Input is not a list of " + p_287631_ + " longs";
|
||||
};
|
||||
return along.length >= p_287631_ ? DataResult.error(supplier, Arrays.copyOf(along, p_287631_)) : DataResult.error(supplier);
|
||||
} else {
|
||||
return DataResult.success(along);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> DataResult<List<T>> fixedSize(List<T> p_143796_, int p_143797_) {
|
||||
if (p_143796_.size() != p_143797_) {
|
||||
Supplier<String> supplier = () -> {
|
||||
return "Input is not a list of " + p_143797_ + " elements";
|
||||
};
|
||||
return p_143796_.size() >= p_143797_ ? DataResult.error(supplier, p_143796_.subList(0, p_143797_)) : DataResult.error(supplier);
|
||||
} else {
|
||||
return DataResult.success(p_143796_);
|
||||
}
|
||||
}
|
||||
|
||||
public static void startTimerHackThread() {
|
||||
Thread thread = new Thread("Timer hack thread") {
|
||||
public void run() {
|
||||
while(true) {
|
||||
try {
|
||||
Thread.sleep(2147483647L);
|
||||
} catch (InterruptedException interruptedexception) {
|
||||
Util.LOGGER.warn("Timer hack thread interrupted, that really should not happen");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
thread.setDaemon(true);
|
||||
thread.setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler(LOGGER));
|
||||
thread.start();
|
||||
}
|
||||
|
||||
public static void copyBetweenDirs(Path p_137564_, Path p_137565_, Path p_137566_) throws IOException {
|
||||
Path path = p_137564_.relativize(p_137566_);
|
||||
Path path1 = p_137565_.resolve(path);
|
||||
Files.copy(p_137566_, path1);
|
||||
}
|
||||
|
||||
public static String sanitizeName(String p_137484_, CharPredicate p_137485_) {
|
||||
return p_137484_.toLowerCase(Locale.ROOT).chars().mapToObj((p_214666_) -> {
|
||||
return p_137485_.test((char)p_214666_) ? Character.toString((char)p_214666_) : "_";
|
||||
}).collect(Collectors.joining());
|
||||
}
|
||||
|
||||
public static <K, V> SingleKeyCache<K, V> singleKeyCache(Function<K, V> p_270326_) {
|
||||
return new SingleKeyCache<>(p_270326_);
|
||||
}
|
||||
|
||||
public static <T, R> Function<T, R> memoize(final Function<T, R> p_143828_) {
|
||||
return new Function<T, R>() {
|
||||
private final Map<T, R> cache = new ConcurrentHashMap<>();
|
||||
|
||||
public R apply(T p_214691_) {
|
||||
return this.cache.computeIfAbsent(p_214691_, p_143828_);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "memoize/1[function=" + p_143828_ + ", size=" + this.cache.size() + "]";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static <T, U, R> BiFunction<T, U, R> memoize(final BiFunction<T, U, R> p_143822_) {
|
||||
return new BiFunction<T, U, R>() {
|
||||
private final Map<Pair<T, U>, R> cache = new ConcurrentHashMap<>();
|
||||
|
||||
public R apply(T p_214700_, U p_214701_) {
|
||||
return this.cache.computeIfAbsent(Pair.of(p_214700_, p_214701_), (p_214698_) -> {
|
||||
return p_143822_.apply(p_214698_.getFirst(), p_214698_.getSecond());
|
||||
});
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "memoize/2[function=" + p_143822_ + ", size=" + this.cache.size() + "]";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static <T> List<T> toShuffledList(Stream<T> p_214662_, RandomSource p_214663_) {
|
||||
ObjectArrayList<T> objectarraylist = p_214662_.collect(ObjectArrayList.toList());
|
||||
shuffle(objectarraylist, p_214663_);
|
||||
return objectarraylist;
|
||||
}
|
||||
|
||||
public static IntArrayList toShuffledList(IntStream p_214659_, RandomSource p_214660_) {
|
||||
IntArrayList intarraylist = IntArrayList.wrap(p_214659_.toArray());
|
||||
int i = intarraylist.size();
|
||||
|
||||
for(int j = i; j > 1; --j) {
|
||||
int k = p_214660_.nextInt(j);
|
||||
intarraylist.set(j - 1, intarraylist.set(k, intarraylist.getInt(j - 1)));
|
||||
}
|
||||
|
||||
return intarraylist;
|
||||
}
|
||||
|
||||
public static <T> List<T> shuffledCopy(T[] p_214682_, RandomSource p_214683_) {
|
||||
ObjectArrayList<T> objectarraylist = new ObjectArrayList<>(p_214682_);
|
||||
shuffle(objectarraylist, p_214683_);
|
||||
return objectarraylist;
|
||||
}
|
||||
|
||||
public static <T> List<T> shuffledCopy(ObjectArrayList<T> p_214612_, RandomSource p_214613_) {
|
||||
ObjectArrayList<T> objectarraylist = new ObjectArrayList<>(p_214612_);
|
||||
shuffle(objectarraylist, p_214613_);
|
||||
return objectarraylist;
|
||||
}
|
||||
|
||||
public static <T> void shuffle(ObjectArrayList<T> p_214674_, RandomSource p_214675_) {
|
||||
int i = p_214674_.size();
|
||||
|
||||
for(int j = i; j > 1; --j) {
|
||||
int k = p_214675_.nextInt(j);
|
||||
p_214674_.set(j - 1, p_214674_.set(k, p_214674_.get(j - 1)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static <T> CompletableFuture<T> blockUntilDone(Function<Executor, CompletableFuture<T>> p_214680_) {
|
||||
return blockUntilDone(p_214680_, CompletableFuture::isDone);
|
||||
}
|
||||
|
||||
public static <T> T blockUntilDone(Function<Executor, T> p_214653_, Predicate<T> p_214654_) {
|
||||
BlockingQueue<Runnable> blockingqueue = new LinkedBlockingQueue<>();
|
||||
T t = p_214653_.apply(blockingqueue::add);
|
||||
|
||||
while(!p_214654_.test(t)) {
|
||||
try {
|
||||
Runnable runnable = blockingqueue.poll(100L, TimeUnit.MILLISECONDS);
|
||||
if (runnable != null) {
|
||||
runnable.run();
|
||||
}
|
||||
} catch (InterruptedException interruptedexception) {
|
||||
LOGGER.warn("Interrupted wait");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int i = blockingqueue.size();
|
||||
if (i > 0) {
|
||||
LOGGER.warn("Tasks left in queue: {}", (int)i);
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
public static <T> ToIntFunction<T> createIndexLookup(List<T> p_214687_) {
|
||||
return createIndexLookup(p_214687_, Object2IntOpenHashMap::new);
|
||||
}
|
||||
|
||||
public static <T> ToIntFunction<T> createIndexLookup(List<T> p_214635_, IntFunction<Object2IntMap<T>> p_214636_) {
|
||||
Object2IntMap<T> object2intmap = p_214636_.apply(p_214635_.size());
|
||||
|
||||
for(int i = 0; i < p_214635_.size(); ++i) {
|
||||
object2intmap.put(p_214635_.get(i), i);
|
||||
}
|
||||
|
||||
return object2intmap;
|
||||
}
|
||||
|
||||
public static <T, E extends Exception> T getOrThrow(DataResult<T> p_261812_, Function<String, E> p_261468_) throws E {
|
||||
Optional<DataResult.PartialResult<T>> optional = p_261812_.error();
|
||||
if (optional.isPresent()) {
|
||||
throw p_261468_.apply(optional.get().message());
|
||||
} else {
|
||||
return p_261812_.result().orElseThrow();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isWhitespace(int p_289004_) {
|
||||
return Character.isWhitespace(p_289004_) || Character.isSpaceChar(p_289004_);
|
||||
}
|
||||
|
||||
public static boolean isBlank(@Nullable String p_288983_) {
|
||||
return p_288983_ != null && p_288983_.length() != 0 ? p_288983_.chars().allMatch(Util::isWhitespace) : true;
|
||||
}
|
||||
|
||||
static enum IdentityStrategy implements Hash.Strategy<Object> {
|
||||
INSTANCE;
|
||||
|
||||
public int hashCode(Object p_137626_) {
|
||||
return System.identityHashCode(p_137626_);
|
||||
}
|
||||
|
||||
public boolean equals(Object p_137623_, Object p_137624_) {
|
||||
return p_137623_ == p_137624_;
|
||||
}
|
||||
}
|
||||
|
||||
public static enum OS {
|
||||
LINUX("linux"),
|
||||
SOLARIS("solaris"),
|
||||
WINDOWS("windows") {
|
||||
protected String[] getOpenUrlArguments(URL p_137662_) {
|
||||
return new String[]{"rundll32", "url.dll,FileProtocolHandler", p_137662_.toString()};
|
||||
}
|
||||
},
|
||||
OSX("mac") {
|
||||
protected String[] getOpenUrlArguments(URL p_137667_) {
|
||||
return new String[]{"open", p_137667_.toString()};
|
||||
}
|
||||
},
|
||||
UNKNOWN("unknown");
|
||||
|
||||
private final String telemetryName;
|
||||
|
||||
OS(String p_183998_) {
|
||||
this.telemetryName = p_183998_;
|
||||
}
|
||||
|
||||
public void openUrl(URL p_137651_) {
|
||||
try {
|
||||
Process process = AccessController.doPrivileged((PrivilegedExceptionAction<Process>)(() -> {
|
||||
return Runtime.getRuntime().exec(this.getOpenUrlArguments(p_137651_));
|
||||
}));
|
||||
process.getInputStream().close();
|
||||
process.getErrorStream().close();
|
||||
process.getOutputStream().close();
|
||||
} catch (IOException | PrivilegedActionException privilegedactionexception) {
|
||||
Util.LOGGER.error("Couldn't open url '{}'", p_137651_, privilegedactionexception);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void openUri(URI p_137649_) {
|
||||
try {
|
||||
this.openUrl(p_137649_.toURL());
|
||||
} catch (MalformedURLException malformedurlexception) {
|
||||
Util.LOGGER.error("Couldn't open uri '{}'", p_137649_, malformedurlexception);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void openFile(File p_137645_) {
|
||||
try {
|
||||
this.openUrl(p_137645_.toURI().toURL());
|
||||
} catch (MalformedURLException malformedurlexception) {
|
||||
Util.LOGGER.error("Couldn't open file '{}'", p_137645_, malformedurlexception);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected String[] getOpenUrlArguments(URL p_137652_) {
|
||||
String s = p_137652_.toString();
|
||||
if ("file".equals(p_137652_.getProtocol())) {
|
||||
s = s.replace("file:", "file://");
|
||||
}
|
||||
|
||||
return new String[]{"xdg-open", s};
|
||||
}
|
||||
|
||||
public void openUri(String p_137647_) {
|
||||
try {
|
||||
this.openUrl((new URI(p_137647_)).toURL());
|
||||
} catch (MalformedURLException | IllegalArgumentException | URISyntaxException urisyntaxexception) {
|
||||
Util.LOGGER.error("Couldn't open uri '{}'", p_137647_, urisyntaxexception);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public String telemetryName() {
|
||||
return this.telemetryName;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package net.minecraft;
|
||||
|
||||
import java.util.Date;
|
||||
import net.minecraft.server.packs.PackType;
|
||||
import net.minecraft.world.level.storage.DataVersion;
|
||||
|
||||
public interface WorldVersion {
|
||||
DataVersion getDataVersion();
|
||||
|
||||
String getId();
|
||||
|
||||
String getName();
|
||||
|
||||
int getProtocolVersion();
|
||||
|
||||
int getPackVersion(PackType p_265245_);
|
||||
|
||||
Date getBuildTime();
|
||||
|
||||
boolean isStable();
|
||||
}
|
||||
@@ -0,0 +1,433 @@
|
||||
package net.minecraft.advancements;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.advancements.critereon.DeserializationContext;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.ComponentUtils;
|
||||
import net.minecraft.network.chat.HoverEvent;
|
||||
import net.minecraft.network.chat.Style;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
public class Advancement {
|
||||
@Nullable
|
||||
private final Advancement parent;
|
||||
@Nullable
|
||||
private final DisplayInfo display;
|
||||
private final AdvancementRewards rewards;
|
||||
private final ResourceLocation id;
|
||||
private final Map<String, Criterion> criteria;
|
||||
private final String[][] requirements;
|
||||
private final Set<Advancement> children = Sets.newLinkedHashSet();
|
||||
private final Component chatComponent;
|
||||
private final boolean sendsTelemetryEvent;
|
||||
|
||||
public Advancement(ResourceLocation p_286878_, @Nullable Advancement p_286496_, @Nullable DisplayInfo p_286499_, AdvancementRewards p_286389_, Map<String, Criterion> p_286635_, String[][] p_286882_, boolean p_286478_) {
|
||||
this.id = p_286878_;
|
||||
this.display = p_286499_;
|
||||
this.criteria = ImmutableMap.copyOf(p_286635_);
|
||||
this.parent = p_286496_;
|
||||
this.rewards = p_286389_;
|
||||
this.requirements = p_286882_;
|
||||
this.sendsTelemetryEvent = p_286478_;
|
||||
if (p_286496_ != null) {
|
||||
p_286496_.addChild(this);
|
||||
}
|
||||
|
||||
if (p_286499_ == null) {
|
||||
this.chatComponent = Component.literal(p_286878_.toString());
|
||||
} else {
|
||||
Component component = p_286499_.getTitle();
|
||||
ChatFormatting chatformatting = p_286499_.getFrame().getChatColor();
|
||||
Component component1 = ComponentUtils.mergeStyles(component.copy(), Style.EMPTY.withColor(chatformatting)).append("\n").append(p_286499_.getDescription());
|
||||
Component component2 = component.copy().withStyle((p_138316_) -> {
|
||||
return p_138316_.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, component1));
|
||||
});
|
||||
this.chatComponent = ComponentUtils.wrapInSquareBrackets(component2).withStyle(chatformatting);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Advancement.Builder deconstruct() {
|
||||
return new Advancement.Builder(this.parent == null ? null : this.parent.getId(), this.display, this.rewards, this.criteria, this.requirements, this.sendsTelemetryEvent);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Advancement getParent() {
|
||||
return this.parent;
|
||||
}
|
||||
|
||||
public Advancement getRoot() {
|
||||
return getRoot(this);
|
||||
}
|
||||
|
||||
public static Advancement getRoot(Advancement p_265545_) {
|
||||
Advancement advancement = p_265545_;
|
||||
|
||||
while(true) {
|
||||
Advancement advancement1 = advancement.getParent();
|
||||
if (advancement1 == null) {
|
||||
return advancement;
|
||||
}
|
||||
|
||||
advancement = advancement1;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public DisplayInfo getDisplay() {
|
||||
return this.display;
|
||||
}
|
||||
|
||||
public boolean sendsTelemetryEvent() {
|
||||
return this.sendsTelemetryEvent;
|
||||
}
|
||||
|
||||
public AdvancementRewards getRewards() {
|
||||
return this.rewards;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "SimpleAdvancement{id=" + this.getId() + ", parent=" + (this.parent == null ? "null" : this.parent.getId()) + ", display=" + this.display + ", rewards=" + this.rewards + ", criteria=" + this.criteria + ", requirements=" + Arrays.deepToString(this.requirements) + ", sendsTelemetryEvent=" + this.sendsTelemetryEvent + "}";
|
||||
}
|
||||
|
||||
public Iterable<Advancement> getChildren() {
|
||||
return this.children;
|
||||
}
|
||||
|
||||
public Map<String, Criterion> getCriteria() {
|
||||
return this.criteria;
|
||||
}
|
||||
|
||||
public int getMaxCriteraRequired() {
|
||||
return this.requirements.length;
|
||||
}
|
||||
|
||||
public void addChild(Advancement p_138318_) {
|
||||
this.children.add(p_138318_);
|
||||
}
|
||||
|
||||
public ResourceLocation getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public boolean equals(Object p_138324_) {
|
||||
if (this == p_138324_) {
|
||||
return true;
|
||||
} else if (!(p_138324_ instanceof Advancement)) {
|
||||
return false;
|
||||
} else {
|
||||
Advancement advancement = (Advancement)p_138324_;
|
||||
return this.id.equals(advancement.id);
|
||||
}
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return this.id.hashCode();
|
||||
}
|
||||
|
||||
public String[][] getRequirements() {
|
||||
return this.requirements;
|
||||
}
|
||||
|
||||
public Component getChatComponent() {
|
||||
return this.chatComponent;
|
||||
}
|
||||
|
||||
public static class Builder implements net.minecraftforge.common.extensions.IForgeAdvancementBuilder {
|
||||
@Nullable
|
||||
private ResourceLocation parentId;
|
||||
@Nullable
|
||||
private Advancement parent;
|
||||
@Nullable
|
||||
private DisplayInfo display;
|
||||
private AdvancementRewards rewards = AdvancementRewards.EMPTY;
|
||||
private Map<String, Criterion> criteria = Maps.newLinkedHashMap();
|
||||
@Nullable
|
||||
private String[][] requirements;
|
||||
private RequirementsStrategy requirementsStrategy = RequirementsStrategy.AND;
|
||||
private final boolean sendsTelemetryEvent;
|
||||
|
||||
Builder(@Nullable ResourceLocation p_286422_, @Nullable DisplayInfo p_286485_, AdvancementRewards p_286364_, Map<String, Criterion> p_286544_, String[][] p_286283_, boolean p_286626_) {
|
||||
this.parentId = p_286422_;
|
||||
this.display = p_286485_;
|
||||
this.rewards = p_286364_;
|
||||
this.criteria = p_286544_;
|
||||
this.requirements = p_286283_;
|
||||
this.sendsTelemetryEvent = p_286626_;
|
||||
}
|
||||
|
||||
private Builder(boolean p_286780_) {
|
||||
this.sendsTelemetryEvent = p_286780_;
|
||||
}
|
||||
|
||||
public static Advancement.Builder advancement() {
|
||||
return new Advancement.Builder(true);
|
||||
}
|
||||
|
||||
public static Advancement.Builder recipeAdvancement() {
|
||||
return new Advancement.Builder(false);
|
||||
}
|
||||
|
||||
public Advancement.Builder parent(Advancement p_138399_) {
|
||||
this.parent = p_138399_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Advancement.Builder parent(ResourceLocation p_138397_) {
|
||||
this.parentId = p_138397_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Advancement.Builder display(ItemStack p_138363_, Component p_138364_, Component p_138365_, @Nullable ResourceLocation p_138366_, FrameType p_138367_, boolean p_138368_, boolean p_138369_, boolean p_138370_) {
|
||||
return this.display(new DisplayInfo(p_138363_, p_138364_, p_138365_, p_138366_, p_138367_, p_138368_, p_138369_, p_138370_));
|
||||
}
|
||||
|
||||
public Advancement.Builder display(ItemLike p_138372_, Component p_138373_, Component p_138374_, @Nullable ResourceLocation p_138375_, FrameType p_138376_, boolean p_138377_, boolean p_138378_, boolean p_138379_) {
|
||||
return this.display(new DisplayInfo(new ItemStack(p_138372_.asItem()), p_138373_, p_138374_, p_138375_, p_138376_, p_138377_, p_138378_, p_138379_));
|
||||
}
|
||||
|
||||
public Advancement.Builder display(DisplayInfo p_138359_) {
|
||||
this.display = p_138359_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Advancement.Builder rewards(AdvancementRewards.Builder p_138355_) {
|
||||
return this.rewards(p_138355_.build());
|
||||
}
|
||||
|
||||
public Advancement.Builder rewards(AdvancementRewards p_138357_) {
|
||||
this.rewards = p_138357_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Advancement.Builder addCriterion(String p_138387_, CriterionTriggerInstance p_138388_) {
|
||||
return this.addCriterion(p_138387_, new Criterion(p_138388_));
|
||||
}
|
||||
|
||||
public Advancement.Builder addCriterion(String p_138384_, Criterion p_138385_) {
|
||||
if (this.criteria.containsKey(p_138384_)) {
|
||||
throw new IllegalArgumentException("Duplicate criterion " + p_138384_);
|
||||
} else {
|
||||
this.criteria.put(p_138384_, p_138385_);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public Advancement.Builder requirements(RequirementsStrategy p_138361_) {
|
||||
this.requirementsStrategy = p_138361_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Advancement.Builder requirements(String[][] p_143952_) {
|
||||
this.requirements = p_143952_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean canBuild(Function<ResourceLocation, Advancement> p_138393_) {
|
||||
if (this.parentId == null) {
|
||||
return true;
|
||||
} else {
|
||||
if (this.parent == null) {
|
||||
this.parent = p_138393_.apply(this.parentId);
|
||||
}
|
||||
|
||||
return this.parent != null;
|
||||
}
|
||||
}
|
||||
|
||||
public Advancement build(ResourceLocation p_138404_) {
|
||||
if (!this.canBuild((p_138407_) -> {
|
||||
return null;
|
||||
})) {
|
||||
throw new IllegalStateException("Tried to build incomplete advancement!");
|
||||
} else {
|
||||
if (this.requirements == null) {
|
||||
this.requirements = this.requirementsStrategy.createRequirements(this.criteria.keySet());
|
||||
}
|
||||
|
||||
return new Advancement(p_138404_, this.parent, this.display, this.rewards, this.criteria, this.requirements, this.sendsTelemetryEvent);
|
||||
}
|
||||
}
|
||||
|
||||
public Advancement save(Consumer<Advancement> p_138390_, String p_138391_) {
|
||||
Advancement advancement = this.build(new ResourceLocation(p_138391_));
|
||||
p_138390_.accept(advancement);
|
||||
return advancement;
|
||||
}
|
||||
|
||||
public JsonObject serializeToJson() {
|
||||
if (this.requirements == null) {
|
||||
this.requirements = this.requirementsStrategy.createRequirements(this.criteria.keySet());
|
||||
}
|
||||
|
||||
JsonObject jsonobject = new JsonObject();
|
||||
if (this.parent != null) {
|
||||
jsonobject.addProperty("parent", this.parent.getId().toString());
|
||||
} else if (this.parentId != null) {
|
||||
jsonobject.addProperty("parent", this.parentId.toString());
|
||||
}
|
||||
|
||||
if (this.display != null) {
|
||||
jsonobject.add("display", this.display.serializeToJson());
|
||||
}
|
||||
|
||||
jsonobject.add("rewards", this.rewards.serializeToJson());
|
||||
JsonObject jsonobject1 = new JsonObject();
|
||||
|
||||
for(Map.Entry<String, Criterion> entry : this.criteria.entrySet()) {
|
||||
jsonobject1.add(entry.getKey(), entry.getValue().serializeToJson());
|
||||
}
|
||||
|
||||
jsonobject.add("criteria", jsonobject1);
|
||||
JsonArray jsonarray1 = new JsonArray();
|
||||
|
||||
for(String[] astring : this.requirements) {
|
||||
JsonArray jsonarray = new JsonArray();
|
||||
|
||||
for(String s : astring) {
|
||||
jsonarray.add(s);
|
||||
}
|
||||
|
||||
jsonarray1.add(jsonarray);
|
||||
}
|
||||
|
||||
jsonobject.add("requirements", jsonarray1);
|
||||
jsonobject.addProperty("sends_telemetry_event", this.sendsTelemetryEvent);
|
||||
return jsonobject;
|
||||
}
|
||||
|
||||
public void serializeToNetwork(FriendlyByteBuf p_138395_) {
|
||||
if (this.requirements == null) {
|
||||
this.requirements = this.requirementsStrategy.createRequirements(this.criteria.keySet());
|
||||
}
|
||||
|
||||
p_138395_.writeNullable(this.parentId, FriendlyByteBuf::writeResourceLocation);
|
||||
p_138395_.writeNullable(this.display, (p_214831_, p_214832_) -> {
|
||||
p_214832_.serializeToNetwork(p_214831_);
|
||||
});
|
||||
Criterion.serializeToNetwork(this.criteria, p_138395_);
|
||||
p_138395_.writeVarInt(this.requirements.length);
|
||||
|
||||
for(String[] astring : this.requirements) {
|
||||
p_138395_.writeVarInt(astring.length);
|
||||
|
||||
for(String s : astring) {
|
||||
p_138395_.writeUtf(s);
|
||||
}
|
||||
}
|
||||
|
||||
p_138395_.writeBoolean(this.sendsTelemetryEvent);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Task Advancement{parentId=" + this.parentId + ", display=" + this.display + ", rewards=" + this.rewards + ", criteria=" + this.criteria + ", requirements=" + Arrays.deepToString(this.requirements) + ", sends_telemetry_event=" + this.sendsTelemetryEvent + "}";
|
||||
}
|
||||
|
||||
/** @deprecated Forge: use {@linkplain #fromJson(JsonObject, DeserializationContext, net.minecraftforge.common.crafting.conditions.ICondition.IContext) overload with context}. */
|
||||
@Deprecated
|
||||
public static Advancement.Builder fromJson(JsonObject p_138381_, DeserializationContext p_138382_) {
|
||||
return fromJson(p_138381_, p_138382_, net.minecraftforge.common.crafting.conditions.ICondition.IContext.EMPTY);
|
||||
}
|
||||
|
||||
public static Advancement.Builder fromJson(JsonObject p_138381_, DeserializationContext p_138382_, net.minecraftforge.common.crafting.conditions.ICondition.IContext context) {
|
||||
if ((p_138381_ = net.minecraftforge.common.crafting.ConditionalAdvancement.processConditional(p_138381_, context)) == null) return null;
|
||||
ResourceLocation resourcelocation = p_138381_.has("parent") ? new ResourceLocation(GsonHelper.getAsString(p_138381_, "parent")) : null;
|
||||
DisplayInfo displayinfo = p_138381_.has("display") ? DisplayInfo.fromJson(GsonHelper.getAsJsonObject(p_138381_, "display")) : null;
|
||||
AdvancementRewards advancementrewards = p_138381_.has("rewards") ? AdvancementRewards.deserialize(GsonHelper.getAsJsonObject(p_138381_, "rewards")) : AdvancementRewards.EMPTY;
|
||||
Map<String, Criterion> map = Criterion.criteriaFromJson(GsonHelper.getAsJsonObject(p_138381_, "criteria"), p_138382_);
|
||||
if (map.isEmpty()) {
|
||||
throw new JsonSyntaxException("Advancement criteria cannot be empty");
|
||||
} else {
|
||||
JsonArray jsonarray = GsonHelper.getAsJsonArray(p_138381_, "requirements", new JsonArray());
|
||||
String[][] astring = new String[jsonarray.size()][];
|
||||
|
||||
for(int i = 0; i < jsonarray.size(); ++i) {
|
||||
JsonArray jsonarray1 = GsonHelper.convertToJsonArray(jsonarray.get(i), "requirements[" + i + "]");
|
||||
astring[i] = new String[jsonarray1.size()];
|
||||
|
||||
for(int j = 0; j < jsonarray1.size(); ++j) {
|
||||
astring[i][j] = GsonHelper.convertToString(jsonarray1.get(j), "requirements[" + i + "][" + j + "]");
|
||||
}
|
||||
}
|
||||
|
||||
if (astring.length == 0) {
|
||||
astring = new String[map.size()][];
|
||||
int k = 0;
|
||||
|
||||
for(String s2 : map.keySet()) {
|
||||
astring[k++] = new String[]{s2};
|
||||
}
|
||||
}
|
||||
|
||||
for(String[] astring1 : astring) {
|
||||
if (astring1.length == 0 && map.isEmpty()) {
|
||||
throw new JsonSyntaxException("Requirement entry cannot be empty");
|
||||
}
|
||||
|
||||
for(String s : astring1) {
|
||||
if (!map.containsKey(s)) {
|
||||
throw new JsonSyntaxException("Unknown required criterion '" + s + "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(String s1 : map.keySet()) {
|
||||
boolean flag1 = false;
|
||||
|
||||
for(String[] astring2 : astring) {
|
||||
if (ArrayUtils.contains(astring2, s1)) {
|
||||
flag1 = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!flag1) {
|
||||
throw new JsonSyntaxException("Criterion '" + s1 + "' isn't a requirement for completion. This isn't supported behaviour, all criteria must be required.");
|
||||
}
|
||||
}
|
||||
|
||||
boolean flag = GsonHelper.getAsBoolean(p_138381_, "sends_telemetry_event", false);
|
||||
return new Advancement.Builder(resourcelocation, displayinfo, advancementrewards, map, astring, flag);
|
||||
}
|
||||
}
|
||||
|
||||
public static Advancement.Builder fromNetwork(FriendlyByteBuf p_138402_) {
|
||||
ResourceLocation resourcelocation = p_138402_.readNullable(FriendlyByteBuf::readResourceLocation);
|
||||
DisplayInfo displayinfo = p_138402_.readNullable(DisplayInfo::fromNetwork);
|
||||
Map<String, Criterion> map = Criterion.criteriaFromNetwork(p_138402_);
|
||||
String[][] astring = new String[p_138402_.readVarInt()][];
|
||||
|
||||
for(int i = 0; i < astring.length; ++i) {
|
||||
astring[i] = new String[p_138402_.readVarInt()];
|
||||
|
||||
for(int j = 0; j < astring[i].length; ++j) {
|
||||
astring[i][j] = p_138402_.readUtf();
|
||||
}
|
||||
}
|
||||
|
||||
boolean flag = p_138402_.readBoolean();
|
||||
return new Advancement.Builder(resourcelocation, displayinfo, AdvancementRewards.EMPTY, map, astring, flag);
|
||||
}
|
||||
|
||||
public Map<String, Criterion> getCriteria() {
|
||||
return this.criteria;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
package net.minecraft.advancements;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.mojang.logging.LogUtils;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
public class AdvancementList {
|
||||
private static final Logger LOGGER = LogUtils.getLogger();
|
||||
private final Map<ResourceLocation, Advancement> advancements = Maps.newHashMap();
|
||||
private final Set<Advancement> roots = Sets.newLinkedHashSet();
|
||||
private final Set<Advancement> tasks = Sets.newLinkedHashSet();
|
||||
@Nullable
|
||||
private AdvancementList.Listener listener;
|
||||
|
||||
private void remove(Advancement p_139340_) {
|
||||
for(Advancement advancement : p_139340_.getChildren()) {
|
||||
this.remove(advancement);
|
||||
}
|
||||
|
||||
LOGGER.info("Forgot about advancement {}", (Object)p_139340_.getId());
|
||||
this.advancements.remove(p_139340_.getId());
|
||||
if (p_139340_.getParent() == null) {
|
||||
this.roots.remove(p_139340_);
|
||||
if (this.listener != null) {
|
||||
this.listener.onRemoveAdvancementRoot(p_139340_);
|
||||
}
|
||||
} else {
|
||||
this.tasks.remove(p_139340_);
|
||||
if (this.listener != null) {
|
||||
this.listener.onRemoveAdvancementTask(p_139340_);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void remove(Set<ResourceLocation> p_139336_) {
|
||||
for(ResourceLocation resourcelocation : p_139336_) {
|
||||
Advancement advancement = this.advancements.get(resourcelocation);
|
||||
if (advancement == null) {
|
||||
LOGGER.warn("Told to remove advancement {} but I don't know what that is", (Object)resourcelocation);
|
||||
} else {
|
||||
this.remove(advancement);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void add(Map<ResourceLocation, Advancement.Builder> p_139334_) {
|
||||
Map<ResourceLocation, Advancement.Builder> map = Maps.newHashMap(p_139334_);
|
||||
|
||||
while(!map.isEmpty()) {
|
||||
boolean flag = false;
|
||||
Iterator<Map.Entry<ResourceLocation, Advancement.Builder>> iterator = map.entrySet().iterator();
|
||||
|
||||
while(iterator.hasNext()) {
|
||||
Map.Entry<ResourceLocation, Advancement.Builder> entry = iterator.next();
|
||||
ResourceLocation resourcelocation = entry.getKey();
|
||||
Advancement.Builder advancement$builder = entry.getValue();
|
||||
if (advancement$builder.canBuild(this.advancements::get)) {
|
||||
Advancement advancement = advancement$builder.build(resourcelocation);
|
||||
this.advancements.put(resourcelocation, advancement);
|
||||
flag = true;
|
||||
iterator.remove();
|
||||
if (advancement.getParent() == null) {
|
||||
this.roots.add(advancement);
|
||||
if (this.listener != null) {
|
||||
this.listener.onAddAdvancementRoot(advancement);
|
||||
}
|
||||
} else {
|
||||
this.tasks.add(advancement);
|
||||
if (this.listener != null) {
|
||||
this.listener.onAddAdvancementTask(advancement);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!flag) {
|
||||
for(Map.Entry<ResourceLocation, Advancement.Builder> entry1 : map.entrySet()) {
|
||||
LOGGER.error("Couldn't load advancement {}: {}", entry1.getKey(), entry1.getValue());
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
LOGGER.info("Loaded {} advancements", (int)this.advancements.size());
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
this.advancements.clear();
|
||||
this.roots.clear();
|
||||
this.tasks.clear();
|
||||
if (this.listener != null) {
|
||||
this.listener.onAdvancementsCleared();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Iterable<Advancement> getRoots() {
|
||||
return this.roots;
|
||||
}
|
||||
|
||||
public Collection<Advancement> getAllAdvancements() {
|
||||
return this.advancements.values();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Advancement get(ResourceLocation p_139338_) {
|
||||
return this.advancements.get(p_139338_);
|
||||
}
|
||||
|
||||
public void setListener(@Nullable AdvancementList.Listener p_139342_) {
|
||||
this.listener = p_139342_;
|
||||
if (p_139342_ != null) {
|
||||
for(Advancement advancement : this.roots) {
|
||||
p_139342_.onAddAdvancementRoot(advancement);
|
||||
}
|
||||
|
||||
for(Advancement advancement1 : this.tasks) {
|
||||
p_139342_.onAddAdvancementTask(advancement1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public interface Listener {
|
||||
void onAddAdvancementRoot(Advancement p_139345_);
|
||||
|
||||
void onRemoveAdvancementRoot(Advancement p_139346_);
|
||||
|
||||
void onAddAdvancementTask(Advancement p_139347_);
|
||||
|
||||
void onRemoveAdvancementTask(Advancement p_139348_);
|
||||
|
||||
void onAdvancementsCleared();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,252 @@
|
||||
package net.minecraft.advancements;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
|
||||
public class AdvancementProgress implements Comparable<AdvancementProgress> {
|
||||
final Map<String, CriterionProgress> criteria;
|
||||
private String[][] requirements = new String[0][];
|
||||
|
||||
private AdvancementProgress(Map<String, CriterionProgress> p_144358_) {
|
||||
this.criteria = p_144358_;
|
||||
}
|
||||
|
||||
public AdvancementProgress() {
|
||||
this.criteria = Maps.newHashMap();
|
||||
}
|
||||
|
||||
public void update(Map<String, Criterion> p_8199_, String[][] p_8200_) {
|
||||
Set<String> set = p_8199_.keySet();
|
||||
this.criteria.entrySet().removeIf((p_8203_) -> {
|
||||
return !set.contains(p_8203_.getKey());
|
||||
});
|
||||
|
||||
for(String s : set) {
|
||||
if (!this.criteria.containsKey(s)) {
|
||||
this.criteria.put(s, new CriterionProgress());
|
||||
}
|
||||
}
|
||||
|
||||
this.requirements = p_8200_;
|
||||
}
|
||||
|
||||
public boolean isDone() {
|
||||
if (this.requirements.length == 0) {
|
||||
return false;
|
||||
} else {
|
||||
for(String[] astring : this.requirements) {
|
||||
boolean flag = false;
|
||||
|
||||
for(String s : astring) {
|
||||
CriterionProgress criterionprogress = this.getCriterion(s);
|
||||
if (criterionprogress != null && criterionprogress.isDone()) {
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!flag) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasProgress() {
|
||||
for(CriterionProgress criterionprogress : this.criteria.values()) {
|
||||
if (criterionprogress.isDone()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean grantProgress(String p_8197_) {
|
||||
CriterionProgress criterionprogress = this.criteria.get(p_8197_);
|
||||
if (criterionprogress != null && !criterionprogress.isDone()) {
|
||||
criterionprogress.grant();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean revokeProgress(String p_8210_) {
|
||||
CriterionProgress criterionprogress = this.criteria.get(p_8210_);
|
||||
if (criterionprogress != null && criterionprogress.isDone()) {
|
||||
criterionprogress.revoke();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "AdvancementProgress{criteria=" + this.criteria + ", requirements=" + Arrays.deepToString(this.requirements) + "}";
|
||||
}
|
||||
|
||||
public void serializeToNetwork(FriendlyByteBuf p_8205_) {
|
||||
p_8205_.writeMap(this.criteria, FriendlyByteBuf::writeUtf, (p_144360_, p_144361_) -> {
|
||||
p_144361_.serializeToNetwork(p_144360_);
|
||||
});
|
||||
}
|
||||
|
||||
public static AdvancementProgress fromNetwork(FriendlyByteBuf p_8212_) {
|
||||
Map<String, CriterionProgress> map = p_8212_.readMap(FriendlyByteBuf::readUtf, CriterionProgress::fromNetwork);
|
||||
return new AdvancementProgress(map);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public CriterionProgress getCriterion(String p_8215_) {
|
||||
return this.criteria.get(p_8215_);
|
||||
}
|
||||
|
||||
public float getPercent() {
|
||||
if (this.criteria.isEmpty()) {
|
||||
return 0.0F;
|
||||
} else {
|
||||
float f = (float)this.requirements.length;
|
||||
float f1 = (float)this.countCompletedRequirements();
|
||||
return f1 / f;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getProgressText() {
|
||||
if (this.criteria.isEmpty()) {
|
||||
return null;
|
||||
} else {
|
||||
int i = this.requirements.length;
|
||||
if (i <= 1) {
|
||||
return null;
|
||||
} else {
|
||||
int j = this.countCompletedRequirements();
|
||||
return j + "/" + i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int countCompletedRequirements() {
|
||||
int i = 0;
|
||||
|
||||
for(String[] astring : this.requirements) {
|
||||
boolean flag = false;
|
||||
|
||||
for(String s : astring) {
|
||||
CriterionProgress criterionprogress = this.getCriterion(s);
|
||||
if (criterionprogress != null && criterionprogress.isDone()) {
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (flag) {
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
public Iterable<String> getRemainingCriteria() {
|
||||
List<String> list = Lists.newArrayList();
|
||||
|
||||
for(Map.Entry<String, CriterionProgress> entry : this.criteria.entrySet()) {
|
||||
if (!entry.getValue().isDone()) {
|
||||
list.add(entry.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public Iterable<String> getCompletedCriteria() {
|
||||
List<String> list = Lists.newArrayList();
|
||||
|
||||
for(Map.Entry<String, CriterionProgress> entry : this.criteria.entrySet()) {
|
||||
if (entry.getValue().isDone()) {
|
||||
list.add(entry.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Date getFirstProgressDate() {
|
||||
Date date = null;
|
||||
|
||||
for(CriterionProgress criterionprogress : this.criteria.values()) {
|
||||
if (criterionprogress.isDone() && (date == null || criterionprogress.getObtained().before(date))) {
|
||||
date = criterionprogress.getObtained();
|
||||
}
|
||||
}
|
||||
|
||||
return date;
|
||||
}
|
||||
|
||||
public int compareTo(AdvancementProgress p_8195_) {
|
||||
Date date = this.getFirstProgressDate();
|
||||
Date date1 = p_8195_.getFirstProgressDate();
|
||||
if (date == null && date1 != null) {
|
||||
return 1;
|
||||
} else if (date != null && date1 == null) {
|
||||
return -1;
|
||||
} else {
|
||||
return date == null && date1 == null ? 0 : date.compareTo(date1);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Serializer implements JsonDeserializer<AdvancementProgress>, JsonSerializer<AdvancementProgress> {
|
||||
public JsonElement serialize(AdvancementProgress p_8226_, Type p_8227_, JsonSerializationContext p_8228_) {
|
||||
JsonObject jsonobject = new JsonObject();
|
||||
JsonObject jsonobject1 = new JsonObject();
|
||||
|
||||
for(Map.Entry<String, CriterionProgress> entry : p_8226_.criteria.entrySet()) {
|
||||
CriterionProgress criterionprogress = entry.getValue();
|
||||
if (criterionprogress.isDone()) {
|
||||
jsonobject1.add(entry.getKey(), criterionprogress.serializeToJson());
|
||||
}
|
||||
}
|
||||
|
||||
if (!jsonobject1.entrySet().isEmpty()) {
|
||||
jsonobject.add("criteria", jsonobject1);
|
||||
}
|
||||
|
||||
jsonobject.addProperty("done", p_8226_.isDone());
|
||||
return jsonobject;
|
||||
}
|
||||
|
||||
public AdvancementProgress deserialize(JsonElement p_8230_, Type p_8231_, JsonDeserializationContext p_8232_) throws JsonParseException {
|
||||
JsonObject jsonobject = GsonHelper.convertToJsonObject(p_8230_, "advancement");
|
||||
JsonObject jsonobject1 = GsonHelper.getAsJsonObject(jsonobject, "criteria", new JsonObject());
|
||||
AdvancementProgress advancementprogress = new AdvancementProgress();
|
||||
|
||||
for(Map.Entry<String, JsonElement> entry : jsonobject1.entrySet()) {
|
||||
String s = entry.getKey();
|
||||
advancementprogress.criteria.put(s, CriterionProgress.fromJson(GsonHelper.convertToString(entry.getValue(), s)));
|
||||
}
|
||||
|
||||
return advancementprogress;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,192 @@
|
||||
package net.minecraft.advancements;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonNull;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.commands.CommandFunction;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.storage.loot.LootParams;
|
||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets;
|
||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
|
||||
|
||||
public class AdvancementRewards {
|
||||
public static final AdvancementRewards EMPTY = new AdvancementRewards(0, new ResourceLocation[0], new ResourceLocation[0], CommandFunction.CacheableFunction.NONE);
|
||||
private final int experience;
|
||||
private final ResourceLocation[] loot;
|
||||
private final ResourceLocation[] recipes;
|
||||
private final CommandFunction.CacheableFunction function;
|
||||
|
||||
public AdvancementRewards(int p_9985_, ResourceLocation[] p_9986_, ResourceLocation[] p_9987_, CommandFunction.CacheableFunction p_9988_) {
|
||||
this.experience = p_9985_;
|
||||
this.loot = p_9986_;
|
||||
this.recipes = p_9987_;
|
||||
this.function = p_9988_;
|
||||
}
|
||||
|
||||
public ResourceLocation[] getRecipes() {
|
||||
return this.recipes;
|
||||
}
|
||||
|
||||
public void grant(ServerPlayer p_9990_) {
|
||||
p_9990_.giveExperiencePoints(this.experience);
|
||||
LootParams lootparams = (new LootParams.Builder(p_9990_.serverLevel())).withParameter(LootContextParams.THIS_ENTITY, p_9990_).withParameter(LootContextParams.ORIGIN, p_9990_.position()).withLuck(p_9990_.getLuck()).create(LootContextParamSets.ADVANCEMENT_REWARD); // Forge: Add luck to LootContext
|
||||
boolean flag = false;
|
||||
|
||||
for(ResourceLocation resourcelocation : this.loot) {
|
||||
for(ItemStack itemstack : p_9990_.server.getLootData().getLootTable(resourcelocation).getRandomItems(lootparams)) {
|
||||
if (p_9990_.addItem(itemstack)) {
|
||||
p_9990_.level().playSound((Player)null, p_9990_.getX(), p_9990_.getY(), p_9990_.getZ(), SoundEvents.ITEM_PICKUP, SoundSource.PLAYERS, 0.2F, ((p_9990_.getRandom().nextFloat() - p_9990_.getRandom().nextFloat()) * 0.7F + 1.0F) * 2.0F);
|
||||
flag = true;
|
||||
} else {
|
||||
ItemEntity itementity = p_9990_.drop(itemstack, false);
|
||||
if (itementity != null) {
|
||||
itementity.setNoPickUpDelay();
|
||||
itementity.setTarget(p_9990_.getUUID());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (flag) {
|
||||
p_9990_.containerMenu.broadcastChanges();
|
||||
}
|
||||
|
||||
if (this.recipes.length > 0) {
|
||||
p_9990_.awardRecipesByKey(this.recipes);
|
||||
}
|
||||
|
||||
MinecraftServer minecraftserver = p_9990_.server;
|
||||
this.function.get(minecraftserver.getFunctions()).ifPresent((p_289236_) -> {
|
||||
minecraftserver.getFunctions().execute(p_289236_, p_9990_.createCommandSourceStack().withSuppressedOutput().withPermission(2));
|
||||
});
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "AdvancementRewards{experience=" + this.experience + ", loot=" + Arrays.toString((Object[])this.loot) + ", recipes=" + Arrays.toString((Object[])this.recipes) + ", function=" + this.function + "}";
|
||||
}
|
||||
|
||||
public JsonElement serializeToJson() {
|
||||
if (this == EMPTY) {
|
||||
return JsonNull.INSTANCE;
|
||||
} else {
|
||||
JsonObject jsonobject = new JsonObject();
|
||||
if (this.experience != 0) {
|
||||
jsonobject.addProperty("experience", this.experience);
|
||||
}
|
||||
|
||||
if (this.loot.length > 0) {
|
||||
JsonArray jsonarray = new JsonArray();
|
||||
|
||||
for(ResourceLocation resourcelocation : this.loot) {
|
||||
jsonarray.add(resourcelocation.toString());
|
||||
}
|
||||
|
||||
jsonobject.add("loot", jsonarray);
|
||||
}
|
||||
|
||||
if (this.recipes.length > 0) {
|
||||
JsonArray jsonarray1 = new JsonArray();
|
||||
|
||||
for(ResourceLocation resourcelocation1 : this.recipes) {
|
||||
jsonarray1.add(resourcelocation1.toString());
|
||||
}
|
||||
|
||||
jsonobject.add("recipes", jsonarray1);
|
||||
}
|
||||
|
||||
if (this.function.getId() != null) {
|
||||
jsonobject.addProperty("function", this.function.getId().toString());
|
||||
}
|
||||
|
||||
return jsonobject;
|
||||
}
|
||||
}
|
||||
|
||||
public static AdvancementRewards deserialize(JsonObject p_9992_) throws JsonParseException {
|
||||
int i = GsonHelper.getAsInt(p_9992_, "experience", 0);
|
||||
JsonArray jsonarray = GsonHelper.getAsJsonArray(p_9992_, "loot", new JsonArray());
|
||||
ResourceLocation[] aresourcelocation = new ResourceLocation[jsonarray.size()];
|
||||
|
||||
for(int j = 0; j < aresourcelocation.length; ++j) {
|
||||
aresourcelocation[j] = new ResourceLocation(GsonHelper.convertToString(jsonarray.get(j), "loot[" + j + "]"));
|
||||
}
|
||||
|
||||
JsonArray jsonarray1 = GsonHelper.getAsJsonArray(p_9992_, "recipes", new JsonArray());
|
||||
ResourceLocation[] aresourcelocation1 = new ResourceLocation[jsonarray1.size()];
|
||||
|
||||
for(int k = 0; k < aresourcelocation1.length; ++k) {
|
||||
aresourcelocation1[k] = new ResourceLocation(GsonHelper.convertToString(jsonarray1.get(k), "recipes[" + k + "]"));
|
||||
}
|
||||
|
||||
CommandFunction.CacheableFunction commandfunction$cacheablefunction;
|
||||
if (p_9992_.has("function")) {
|
||||
commandfunction$cacheablefunction = new CommandFunction.CacheableFunction(new ResourceLocation(GsonHelper.getAsString(p_9992_, "function")));
|
||||
} else {
|
||||
commandfunction$cacheablefunction = CommandFunction.CacheableFunction.NONE;
|
||||
}
|
||||
|
||||
return new AdvancementRewards(i, aresourcelocation, aresourcelocation1, commandfunction$cacheablefunction);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private int experience;
|
||||
private final List<ResourceLocation> loot = Lists.newArrayList();
|
||||
private final List<ResourceLocation> recipes = Lists.newArrayList();
|
||||
@Nullable
|
||||
private ResourceLocation function;
|
||||
|
||||
public static AdvancementRewards.Builder experience(int p_10006_) {
|
||||
return (new AdvancementRewards.Builder()).addExperience(p_10006_);
|
||||
}
|
||||
|
||||
public AdvancementRewards.Builder addExperience(int p_10008_) {
|
||||
this.experience += p_10008_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public static AdvancementRewards.Builder loot(ResourceLocation p_144823_) {
|
||||
return (new AdvancementRewards.Builder()).addLootTable(p_144823_);
|
||||
}
|
||||
|
||||
public AdvancementRewards.Builder addLootTable(ResourceLocation p_144825_) {
|
||||
this.loot.add(p_144825_);
|
||||
return this;
|
||||
}
|
||||
|
||||
public static AdvancementRewards.Builder recipe(ResourceLocation p_10010_) {
|
||||
return (new AdvancementRewards.Builder()).addRecipe(p_10010_);
|
||||
}
|
||||
|
||||
public AdvancementRewards.Builder addRecipe(ResourceLocation p_10012_) {
|
||||
this.recipes.add(p_10012_);
|
||||
return this;
|
||||
}
|
||||
|
||||
public static AdvancementRewards.Builder function(ResourceLocation p_144827_) {
|
||||
return (new AdvancementRewards.Builder()).runs(p_144827_);
|
||||
}
|
||||
|
||||
public AdvancementRewards.Builder runs(ResourceLocation p_144829_) {
|
||||
this.function = p_144829_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AdvancementRewards build() {
|
||||
return new AdvancementRewards(this.experience, this.loot.toArray(new ResourceLocation[0]), this.recipes.toArray(new ResourceLocation[0]), this.function == null ? CommandFunction.CacheableFunction.NONE : new CommandFunction.CacheableFunction(this.function));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
package net.minecraft.advancements;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import java.util.Map;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.advancements.critereon.BeeNestDestroyedTrigger;
|
||||
import net.minecraft.advancements.critereon.BredAnimalsTrigger;
|
||||
import net.minecraft.advancements.critereon.BrewedPotionTrigger;
|
||||
import net.minecraft.advancements.critereon.ChangeDimensionTrigger;
|
||||
import net.minecraft.advancements.critereon.ChanneledLightningTrigger;
|
||||
import net.minecraft.advancements.critereon.ConstructBeaconTrigger;
|
||||
import net.minecraft.advancements.critereon.ConsumeItemTrigger;
|
||||
import net.minecraft.advancements.critereon.CuredZombieVillagerTrigger;
|
||||
import net.minecraft.advancements.critereon.DistanceTrigger;
|
||||
import net.minecraft.advancements.critereon.EffectsChangedTrigger;
|
||||
import net.minecraft.advancements.critereon.EnchantedItemTrigger;
|
||||
import net.minecraft.advancements.critereon.EnterBlockTrigger;
|
||||
import net.minecraft.advancements.critereon.EntityHurtPlayerTrigger;
|
||||
import net.minecraft.advancements.critereon.FilledBucketTrigger;
|
||||
import net.minecraft.advancements.critereon.FishingRodHookedTrigger;
|
||||
import net.minecraft.advancements.critereon.ImpossibleTrigger;
|
||||
import net.minecraft.advancements.critereon.InventoryChangeTrigger;
|
||||
import net.minecraft.advancements.critereon.ItemDurabilityTrigger;
|
||||
import net.minecraft.advancements.critereon.ItemUsedOnLocationTrigger;
|
||||
import net.minecraft.advancements.critereon.KilledByCrossbowTrigger;
|
||||
import net.minecraft.advancements.critereon.KilledTrigger;
|
||||
import net.minecraft.advancements.critereon.LevitationTrigger;
|
||||
import net.minecraft.advancements.critereon.LightningStrikeTrigger;
|
||||
import net.minecraft.advancements.critereon.LootTableTrigger;
|
||||
import net.minecraft.advancements.critereon.PickedUpItemTrigger;
|
||||
import net.minecraft.advancements.critereon.PlayerHurtEntityTrigger;
|
||||
import net.minecraft.advancements.critereon.PlayerInteractTrigger;
|
||||
import net.minecraft.advancements.critereon.PlayerTrigger;
|
||||
import net.minecraft.advancements.critereon.RecipeCraftedTrigger;
|
||||
import net.minecraft.advancements.critereon.RecipeUnlockedTrigger;
|
||||
import net.minecraft.advancements.critereon.ShotCrossbowTrigger;
|
||||
import net.minecraft.advancements.critereon.SlideDownBlockTrigger;
|
||||
import net.minecraft.advancements.critereon.StartRidingTrigger;
|
||||
import net.minecraft.advancements.critereon.SummonedEntityTrigger;
|
||||
import net.minecraft.advancements.critereon.TameAnimalTrigger;
|
||||
import net.minecraft.advancements.critereon.TargetBlockTrigger;
|
||||
import net.minecraft.advancements.critereon.TradeTrigger;
|
||||
import net.minecraft.advancements.critereon.UsedEnderEyeTrigger;
|
||||
import net.minecraft.advancements.critereon.UsedTotemTrigger;
|
||||
import net.minecraft.advancements.critereon.UsingItemTrigger;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
public class CriteriaTriggers {
|
||||
private static final Map<ResourceLocation, CriterionTrigger<?>> CRITERIA = Maps.newHashMap();
|
||||
public static final ImpossibleTrigger IMPOSSIBLE = register(new ImpossibleTrigger());
|
||||
public static final KilledTrigger PLAYER_KILLED_ENTITY = register(new KilledTrigger(new ResourceLocation("player_killed_entity")));
|
||||
public static final KilledTrigger ENTITY_KILLED_PLAYER = register(new KilledTrigger(new ResourceLocation("entity_killed_player")));
|
||||
public static final EnterBlockTrigger ENTER_BLOCK = register(new EnterBlockTrigger());
|
||||
public static final InventoryChangeTrigger INVENTORY_CHANGED = register(new InventoryChangeTrigger());
|
||||
public static final RecipeUnlockedTrigger RECIPE_UNLOCKED = register(new RecipeUnlockedTrigger());
|
||||
public static final PlayerHurtEntityTrigger PLAYER_HURT_ENTITY = register(new PlayerHurtEntityTrigger());
|
||||
public static final EntityHurtPlayerTrigger ENTITY_HURT_PLAYER = register(new EntityHurtPlayerTrigger());
|
||||
public static final EnchantedItemTrigger ENCHANTED_ITEM = register(new EnchantedItemTrigger());
|
||||
public static final FilledBucketTrigger FILLED_BUCKET = register(new FilledBucketTrigger());
|
||||
public static final BrewedPotionTrigger BREWED_POTION = register(new BrewedPotionTrigger());
|
||||
public static final ConstructBeaconTrigger CONSTRUCT_BEACON = register(new ConstructBeaconTrigger());
|
||||
public static final UsedEnderEyeTrigger USED_ENDER_EYE = register(new UsedEnderEyeTrigger());
|
||||
public static final SummonedEntityTrigger SUMMONED_ENTITY = register(new SummonedEntityTrigger());
|
||||
public static final BredAnimalsTrigger BRED_ANIMALS = register(new BredAnimalsTrigger());
|
||||
public static final PlayerTrigger LOCATION = register(new PlayerTrigger(new ResourceLocation("location")));
|
||||
public static final PlayerTrigger SLEPT_IN_BED = register(new PlayerTrigger(new ResourceLocation("slept_in_bed")));
|
||||
public static final CuredZombieVillagerTrigger CURED_ZOMBIE_VILLAGER = register(new CuredZombieVillagerTrigger());
|
||||
public static final TradeTrigger TRADE = register(new TradeTrigger());
|
||||
public static final ItemDurabilityTrigger ITEM_DURABILITY_CHANGED = register(new ItemDurabilityTrigger());
|
||||
public static final LevitationTrigger LEVITATION = register(new LevitationTrigger());
|
||||
public static final ChangeDimensionTrigger CHANGED_DIMENSION = register(new ChangeDimensionTrigger());
|
||||
public static final PlayerTrigger TICK = register(new PlayerTrigger(new ResourceLocation("tick")));
|
||||
public static final TameAnimalTrigger TAME_ANIMAL = register(new TameAnimalTrigger());
|
||||
public static final ItemUsedOnLocationTrigger PLACED_BLOCK = register(new ItemUsedOnLocationTrigger(new ResourceLocation("placed_block")));
|
||||
public static final ConsumeItemTrigger CONSUME_ITEM = register(new ConsumeItemTrigger());
|
||||
public static final EffectsChangedTrigger EFFECTS_CHANGED = register(new EffectsChangedTrigger());
|
||||
public static final UsedTotemTrigger USED_TOTEM = register(new UsedTotemTrigger());
|
||||
public static final DistanceTrigger NETHER_TRAVEL = register(new DistanceTrigger(new ResourceLocation("nether_travel")));
|
||||
public static final FishingRodHookedTrigger FISHING_ROD_HOOKED = register(new FishingRodHookedTrigger());
|
||||
public static final ChanneledLightningTrigger CHANNELED_LIGHTNING = register(new ChanneledLightningTrigger());
|
||||
public static final ShotCrossbowTrigger SHOT_CROSSBOW = register(new ShotCrossbowTrigger());
|
||||
public static final KilledByCrossbowTrigger KILLED_BY_CROSSBOW = register(new KilledByCrossbowTrigger());
|
||||
public static final PlayerTrigger RAID_WIN = register(new PlayerTrigger(new ResourceLocation("hero_of_the_village")));
|
||||
public static final PlayerTrigger BAD_OMEN = register(new PlayerTrigger(new ResourceLocation("voluntary_exile")));
|
||||
public static final SlideDownBlockTrigger HONEY_BLOCK_SLIDE = register(new SlideDownBlockTrigger());
|
||||
public static final BeeNestDestroyedTrigger BEE_NEST_DESTROYED = register(new BeeNestDestroyedTrigger());
|
||||
public static final TargetBlockTrigger TARGET_BLOCK_HIT = register(new TargetBlockTrigger());
|
||||
public static final ItemUsedOnLocationTrigger ITEM_USED_ON_BLOCK = register(new ItemUsedOnLocationTrigger(new ResourceLocation("item_used_on_block")));
|
||||
public static final LootTableTrigger GENERATE_LOOT = register(new LootTableTrigger());
|
||||
public static final PickedUpItemTrigger THROWN_ITEM_PICKED_UP_BY_ENTITY = register(new PickedUpItemTrigger(new ResourceLocation("thrown_item_picked_up_by_entity")));
|
||||
public static final PickedUpItemTrigger THROWN_ITEM_PICKED_UP_BY_PLAYER = register(new PickedUpItemTrigger(new ResourceLocation("thrown_item_picked_up_by_player")));
|
||||
public static final PlayerInteractTrigger PLAYER_INTERACTED_WITH_ENTITY = register(new PlayerInteractTrigger());
|
||||
public static final StartRidingTrigger START_RIDING_TRIGGER = register(new StartRidingTrigger());
|
||||
public static final LightningStrikeTrigger LIGHTNING_STRIKE = register(new LightningStrikeTrigger());
|
||||
public static final UsingItemTrigger USING_ITEM = register(new UsingItemTrigger());
|
||||
public static final DistanceTrigger FALL_FROM_HEIGHT = register(new DistanceTrigger(new ResourceLocation("fall_from_height")));
|
||||
public static final DistanceTrigger RIDE_ENTITY_IN_LAVA_TRIGGER = register(new DistanceTrigger(new ResourceLocation("ride_entity_in_lava")));
|
||||
public static final KilledTrigger KILL_MOB_NEAR_SCULK_CATALYST = register(new KilledTrigger(new ResourceLocation("kill_mob_near_sculk_catalyst")));
|
||||
public static final ItemUsedOnLocationTrigger ALLAY_DROP_ITEM_ON_BLOCK = register(new ItemUsedOnLocationTrigger(new ResourceLocation("allay_drop_item_on_block")));
|
||||
public static final PlayerTrigger AVOID_VIBRATION = register(new PlayerTrigger(new ResourceLocation("avoid_vibration")));
|
||||
public static final RecipeCraftedTrigger RECIPE_CRAFTED = register(new RecipeCraftedTrigger());
|
||||
|
||||
public static <T extends CriterionTrigger<?>> T register(T p_10596_) {
|
||||
if (CRITERIA.containsKey(p_10596_.getId())) {
|
||||
throw new IllegalArgumentException("Duplicate criterion id " + p_10596_.getId());
|
||||
} else {
|
||||
CRITERIA.put(p_10596_.getId(), p_10596_);
|
||||
return p_10596_;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static <T extends CriterionTriggerInstance> CriterionTrigger<T> getCriterion(ResourceLocation p_10598_) {
|
||||
return (CriterionTrigger<T>)CRITERIA.get(p_10598_);
|
||||
}
|
||||
|
||||
public static Iterable<? extends CriterionTrigger<?>> all() {
|
||||
return CRITERIA.values();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package net.minecraft.advancements;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import java.util.Map;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.advancements.critereon.DeserializationContext;
|
||||
import net.minecraft.advancements.critereon.SerializationContext;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
|
||||
public class Criterion {
|
||||
@Nullable
|
||||
private final CriterionTriggerInstance trigger;
|
||||
|
||||
public Criterion(CriterionTriggerInstance p_11415_) {
|
||||
this.trigger = p_11415_;
|
||||
}
|
||||
|
||||
public Criterion() {
|
||||
this.trigger = null;
|
||||
}
|
||||
|
||||
public void serializeToNetwork(FriendlyByteBuf p_11424_) {
|
||||
}
|
||||
|
||||
public static Criterion criterionFromJson(JsonObject p_11418_, DeserializationContext p_11419_) {
|
||||
ResourceLocation resourcelocation = new ResourceLocation(GsonHelper.getAsString(p_11418_, "trigger"));
|
||||
CriterionTrigger<?> criteriontrigger = CriteriaTriggers.getCriterion(resourcelocation);
|
||||
if (criteriontrigger == null) {
|
||||
throw new JsonSyntaxException("Invalid criterion trigger: " + resourcelocation);
|
||||
} else {
|
||||
CriterionTriggerInstance criteriontriggerinstance = criteriontrigger.createInstance(GsonHelper.getAsJsonObject(p_11418_, "conditions", new JsonObject()), p_11419_);
|
||||
return new Criterion(criteriontriggerinstance);
|
||||
}
|
||||
}
|
||||
|
||||
public static Criterion criterionFromNetwork(FriendlyByteBuf p_11430_) {
|
||||
return new Criterion();
|
||||
}
|
||||
|
||||
public static Map<String, Criterion> criteriaFromJson(JsonObject p_11427_, DeserializationContext p_11428_) {
|
||||
Map<String, Criterion> map = Maps.newHashMap();
|
||||
|
||||
for(Map.Entry<String, JsonElement> entry : p_11427_.entrySet()) {
|
||||
map.put(entry.getKey(), criterionFromJson(GsonHelper.convertToJsonObject(entry.getValue(), "criterion"), p_11428_));
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
public static Map<String, Criterion> criteriaFromNetwork(FriendlyByteBuf p_11432_) {
|
||||
return p_11432_.readMap(FriendlyByteBuf::readUtf, Criterion::criterionFromNetwork);
|
||||
}
|
||||
|
||||
public static void serializeToNetwork(Map<String, Criterion> p_11421_, FriendlyByteBuf p_11422_) {
|
||||
p_11422_.writeMap(p_11421_, FriendlyByteBuf::writeUtf, (p_145258_, p_145259_) -> {
|
||||
p_145259_.serializeToNetwork(p_145258_);
|
||||
});
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public CriterionTriggerInstance getTrigger() {
|
||||
return this.trigger;
|
||||
}
|
||||
|
||||
public JsonElement serializeToJson() {
|
||||
if (this.trigger == null) {
|
||||
throw new JsonSyntaxException("Missing trigger");
|
||||
} else {
|
||||
JsonObject jsonobject = new JsonObject();
|
||||
jsonobject.addProperty("trigger", this.trigger.getCriterion().toString());
|
||||
JsonObject jsonobject1 = this.trigger.serializeToJson(SerializationContext.INSTANCE);
|
||||
if (jsonobject1.size() != 0) {
|
||||
jsonobject.add("conditions", jsonobject1);
|
||||
}
|
||||
|
||||
return jsonobject;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package net.minecraft.advancements;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonNull;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
|
||||
public class CriterionProgress {
|
||||
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z", Locale.ROOT);
|
||||
@Nullable
|
||||
private Date obtained;
|
||||
|
||||
public boolean isDone() {
|
||||
return this.obtained != null;
|
||||
}
|
||||
|
||||
public void grant() {
|
||||
this.obtained = new Date();
|
||||
}
|
||||
|
||||
public void revoke() {
|
||||
this.obtained = null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Date getObtained() {
|
||||
return this.obtained;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "CriterionProgress{obtained=" + (this.obtained == null ? "false" : this.obtained) + "}";
|
||||
}
|
||||
|
||||
public void serializeToNetwork(FriendlyByteBuf p_12915_) {
|
||||
p_12915_.writeNullable(this.obtained, FriendlyByteBuf::writeDate);
|
||||
}
|
||||
|
||||
public JsonElement serializeToJson() {
|
||||
return (JsonElement)(this.obtained != null ? new JsonPrimitive(DATE_FORMAT.format(this.obtained)) : JsonNull.INSTANCE);
|
||||
}
|
||||
|
||||
public static CriterionProgress fromNetwork(FriendlyByteBuf p_12918_) {
|
||||
CriterionProgress criterionprogress = new CriterionProgress();
|
||||
criterionprogress.obtained = p_12918_.readNullable(FriendlyByteBuf::readDate);
|
||||
return criterionprogress;
|
||||
}
|
||||
|
||||
public static CriterionProgress fromJson(String p_12913_) {
|
||||
CriterionProgress criterionprogress = new CriterionProgress();
|
||||
|
||||
try {
|
||||
criterionprogress.obtained = DATE_FORMAT.parse(p_12913_);
|
||||
return criterionprogress;
|
||||
} catch (ParseException parseexception) {
|
||||
throw new JsonSyntaxException("Invalid datetime: " + p_12913_, parseexception);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package net.minecraft.advancements;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.advancements.critereon.DeserializationContext;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.PlayerAdvancements;
|
||||
|
||||
public interface CriterionTrigger<T extends CriterionTriggerInstance> {
|
||||
ResourceLocation getId();
|
||||
|
||||
void addPlayerListener(PlayerAdvancements p_13674_, CriterionTrigger.Listener<T> p_13675_);
|
||||
|
||||
void removePlayerListener(PlayerAdvancements p_13676_, CriterionTrigger.Listener<T> p_13677_);
|
||||
|
||||
void removePlayerListeners(PlayerAdvancements p_13673_);
|
||||
|
||||
T createInstance(JsonObject p_13671_, DeserializationContext p_13672_);
|
||||
|
||||
public static class Listener<T extends CriterionTriggerInstance> {
|
||||
private final T trigger;
|
||||
private final Advancement advancement;
|
||||
private final String criterion;
|
||||
|
||||
public Listener(T p_13682_, Advancement p_13683_, String p_13684_) {
|
||||
this.trigger = p_13682_;
|
||||
this.advancement = p_13683_;
|
||||
this.criterion = p_13684_;
|
||||
}
|
||||
|
||||
public T getTriggerInstance() {
|
||||
return this.trigger;
|
||||
}
|
||||
|
||||
public void run(PlayerAdvancements p_13687_) {
|
||||
p_13687_.award(this.advancement, this.criterion);
|
||||
}
|
||||
|
||||
public boolean equals(Object p_13689_) {
|
||||
if (this == p_13689_) {
|
||||
return true;
|
||||
} else if (p_13689_ != null && this.getClass() == p_13689_.getClass()) {
|
||||
CriterionTrigger.Listener<?> listener = (CriterionTrigger.Listener)p_13689_;
|
||||
if (!this.trigger.equals(listener.trigger)) {
|
||||
return false;
|
||||
} else {
|
||||
return !this.advancement.equals(listener.advancement) ? false : this.criterion.equals(listener.criterion);
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int i = this.trigger.hashCode();
|
||||
i = 31 * i + this.advancement.hashCode();
|
||||
return 31 * i + this.criterion.hashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package net.minecraft.advancements;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.advancements.critereon.SerializationContext;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
public interface CriterionTriggerInstance {
|
||||
ResourceLocation getCriterion();
|
||||
|
||||
JsonObject serializeToJson(SerializationContext p_14485_);
|
||||
}
|
||||
@@ -0,0 +1,194 @@
|
||||
package net.minecraft.advancements;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.TagParser;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
public class DisplayInfo {
|
||||
private final Component title;
|
||||
private final Component description;
|
||||
private final ItemStack icon;
|
||||
@Nullable
|
||||
private final ResourceLocation background;
|
||||
private final FrameType frame;
|
||||
private final boolean showToast;
|
||||
private final boolean announceChat;
|
||||
private final boolean hidden;
|
||||
private float x;
|
||||
private float y;
|
||||
|
||||
public DisplayInfo(ItemStack p_14969_, Component p_14970_, Component p_14971_, @Nullable ResourceLocation p_14972_, FrameType p_14973_, boolean p_14974_, boolean p_14975_, boolean p_14976_) {
|
||||
this.title = p_14970_;
|
||||
this.description = p_14971_;
|
||||
this.icon = p_14969_;
|
||||
this.background = p_14972_;
|
||||
this.frame = p_14973_;
|
||||
this.showToast = p_14974_;
|
||||
this.announceChat = p_14975_;
|
||||
this.hidden = p_14976_;
|
||||
}
|
||||
|
||||
public void setLocation(float p_14979_, float p_14980_) {
|
||||
this.x = p_14979_;
|
||||
this.y = p_14980_;
|
||||
}
|
||||
|
||||
public Component getTitle() {
|
||||
return this.title;
|
||||
}
|
||||
|
||||
public Component getDescription() {
|
||||
return this.description;
|
||||
}
|
||||
|
||||
public ItemStack getIcon() {
|
||||
return this.icon;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ResourceLocation getBackground() {
|
||||
return this.background;
|
||||
}
|
||||
|
||||
public FrameType getFrame() {
|
||||
return this.frame;
|
||||
}
|
||||
|
||||
public float getX() {
|
||||
return this.x;
|
||||
}
|
||||
|
||||
public float getY() {
|
||||
return this.y;
|
||||
}
|
||||
|
||||
public boolean shouldShowToast() {
|
||||
return this.showToast;
|
||||
}
|
||||
|
||||
public boolean shouldAnnounceChat() {
|
||||
return this.announceChat;
|
||||
}
|
||||
|
||||
public boolean isHidden() {
|
||||
return this.hidden;
|
||||
}
|
||||
|
||||
public static DisplayInfo fromJson(JsonObject p_14982_) {
|
||||
Component component = Component.Serializer.fromJson(p_14982_.get("title"));
|
||||
Component component1 = Component.Serializer.fromJson(p_14982_.get("description"));
|
||||
if (component != null && component1 != null) {
|
||||
ItemStack itemstack = getIcon(GsonHelper.getAsJsonObject(p_14982_, "icon"));
|
||||
ResourceLocation resourcelocation = p_14982_.has("background") ? new ResourceLocation(GsonHelper.getAsString(p_14982_, "background")) : null;
|
||||
FrameType frametype = p_14982_.has("frame") ? FrameType.byName(GsonHelper.getAsString(p_14982_, "frame")) : FrameType.TASK;
|
||||
boolean flag = GsonHelper.getAsBoolean(p_14982_, "show_toast", true);
|
||||
boolean flag1 = GsonHelper.getAsBoolean(p_14982_, "announce_to_chat", true);
|
||||
boolean flag2 = GsonHelper.getAsBoolean(p_14982_, "hidden", false);
|
||||
return new DisplayInfo(itemstack, component, component1, resourcelocation, frametype, flag, flag1, flag2);
|
||||
} else {
|
||||
throw new JsonSyntaxException("Both title and description must be set");
|
||||
}
|
||||
}
|
||||
|
||||
private static ItemStack getIcon(JsonObject p_14987_) {
|
||||
if (!p_14987_.has("item")) {
|
||||
throw new JsonSyntaxException("Unsupported icon type, currently only items are supported (add 'item' key)");
|
||||
} else {
|
||||
Item item = GsonHelper.getAsItem(p_14987_, "item");
|
||||
if (p_14987_.has("data")) {
|
||||
throw new JsonParseException("Disallowed data tag found");
|
||||
} else {
|
||||
ItemStack itemstack = new ItemStack(item);
|
||||
if (p_14987_.has("nbt")) {
|
||||
try {
|
||||
CompoundTag compoundtag = TagParser.parseTag(GsonHelper.convertToString(p_14987_.get("nbt"), "nbt"));
|
||||
itemstack.setTag(compoundtag);
|
||||
} catch (CommandSyntaxException commandsyntaxexception) {
|
||||
throw new JsonSyntaxException("Invalid nbt tag: " + commandsyntaxexception.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void serializeToNetwork(FriendlyByteBuf p_14984_) {
|
||||
p_14984_.writeComponent(this.title);
|
||||
p_14984_.writeComponent(this.description);
|
||||
p_14984_.writeItem(this.icon);
|
||||
p_14984_.writeEnum(this.frame);
|
||||
int i = 0;
|
||||
if (this.background != null) {
|
||||
i |= 1;
|
||||
}
|
||||
|
||||
if (this.showToast) {
|
||||
i |= 2;
|
||||
}
|
||||
|
||||
if (this.hidden) {
|
||||
i |= 4;
|
||||
}
|
||||
|
||||
p_14984_.writeInt(i);
|
||||
if (this.background != null) {
|
||||
p_14984_.writeResourceLocation(this.background);
|
||||
}
|
||||
|
||||
p_14984_.writeFloat(this.x);
|
||||
p_14984_.writeFloat(this.y);
|
||||
}
|
||||
|
||||
public static DisplayInfo fromNetwork(FriendlyByteBuf p_14989_) {
|
||||
Component component = p_14989_.readComponent();
|
||||
Component component1 = p_14989_.readComponent();
|
||||
ItemStack itemstack = p_14989_.readItem();
|
||||
FrameType frametype = p_14989_.readEnum(FrameType.class);
|
||||
int i = p_14989_.readInt();
|
||||
ResourceLocation resourcelocation = (i & 1) != 0 ? p_14989_.readResourceLocation() : null;
|
||||
boolean flag = (i & 2) != 0;
|
||||
boolean flag1 = (i & 4) != 0;
|
||||
DisplayInfo displayinfo = new DisplayInfo(itemstack, component, component1, resourcelocation, frametype, flag, false, flag1);
|
||||
displayinfo.setLocation(p_14989_.readFloat(), p_14989_.readFloat());
|
||||
return displayinfo;
|
||||
}
|
||||
|
||||
public JsonElement serializeToJson() {
|
||||
JsonObject jsonobject = new JsonObject();
|
||||
jsonobject.add("icon", this.serializeIcon());
|
||||
jsonobject.add("title", Component.Serializer.toJsonTree(this.title));
|
||||
jsonobject.add("description", Component.Serializer.toJsonTree(this.description));
|
||||
jsonobject.addProperty("frame", this.frame.getName());
|
||||
jsonobject.addProperty("show_toast", this.showToast);
|
||||
jsonobject.addProperty("announce_to_chat", this.announceChat);
|
||||
jsonobject.addProperty("hidden", this.hidden);
|
||||
if (this.background != null) {
|
||||
jsonobject.addProperty("background", this.background.toString());
|
||||
}
|
||||
|
||||
return jsonobject;
|
||||
}
|
||||
|
||||
private JsonObject serializeIcon() {
|
||||
JsonObject jsonobject = new JsonObject();
|
||||
jsonobject.addProperty("item", BuiltInRegistries.ITEM.getKey(this.icon.getItem()).toString());
|
||||
if (this.icon.hasTag()) {
|
||||
jsonobject.addProperty("nbt", this.icon.getTag().toString());
|
||||
}
|
||||
|
||||
return jsonobject;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package net.minecraft.advancements;
|
||||
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
||||
public enum FrameType {
|
||||
TASK("task", 0, ChatFormatting.GREEN),
|
||||
CHALLENGE("challenge", 26, ChatFormatting.DARK_PURPLE),
|
||||
GOAL("goal", 52, ChatFormatting.GREEN);
|
||||
|
||||
private final String name;
|
||||
private final int texture;
|
||||
private final ChatFormatting chatColor;
|
||||
private final Component displayName;
|
||||
|
||||
private FrameType(String p_15545_, int p_15546_, ChatFormatting p_15547_) {
|
||||
this.name = p_15545_;
|
||||
this.texture = p_15546_;
|
||||
this.chatColor = p_15547_;
|
||||
this.displayName = Component.translatable("advancements.toast." + p_15545_);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public int getTexture() {
|
||||
return this.texture;
|
||||
}
|
||||
|
||||
public static FrameType byName(String p_15550_) {
|
||||
for(FrameType frametype : values()) {
|
||||
if (frametype.name.equals(p_15550_)) {
|
||||
return frametype;
|
||||
}
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("Unknown frame type '" + p_15550_ + "'");
|
||||
}
|
||||
|
||||
public ChatFormatting getChatColor() {
|
||||
return this.chatColor;
|
||||
}
|
||||
|
||||
public Component getDisplayName() {
|
||||
return this.displayName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package net.minecraft.advancements;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public interface RequirementsStrategy {
|
||||
RequirementsStrategy AND = (p_15984_) -> {
|
||||
String[][] astring = new String[p_15984_.size()][];
|
||||
int i = 0;
|
||||
|
||||
for(String s : p_15984_) {
|
||||
astring[i++] = new String[]{s};
|
||||
}
|
||||
|
||||
return astring;
|
||||
};
|
||||
RequirementsStrategy OR = (p_15982_) -> {
|
||||
return new String[][]{p_15982_.toArray(new String[0])};
|
||||
};
|
||||
|
||||
String[][] createRequirements(Collection<String> p_15986_);
|
||||
}
|
||||
@@ -0,0 +1,231 @@
|
||||
package net.minecraft.advancements;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class TreeNodePosition {
|
||||
private final Advancement advancement;
|
||||
@Nullable
|
||||
private final TreeNodePosition parent;
|
||||
@Nullable
|
||||
private final TreeNodePosition previousSibling;
|
||||
private final int childIndex;
|
||||
private final List<TreeNodePosition> children = Lists.newArrayList();
|
||||
private TreeNodePosition ancestor;
|
||||
@Nullable
|
||||
private TreeNodePosition thread;
|
||||
private int x;
|
||||
private float y;
|
||||
private float mod;
|
||||
private float change;
|
||||
private float shift;
|
||||
|
||||
public TreeNodePosition(Advancement p_16567_, @Nullable TreeNodePosition p_16568_, @Nullable TreeNodePosition p_16569_, int p_16570_, int p_16571_) {
|
||||
if (p_16567_.getDisplay() == null) {
|
||||
throw new IllegalArgumentException("Can't position an invisible advancement!");
|
||||
} else {
|
||||
this.advancement = p_16567_;
|
||||
this.parent = p_16568_;
|
||||
this.previousSibling = p_16569_;
|
||||
this.childIndex = p_16570_;
|
||||
this.ancestor = this;
|
||||
this.x = p_16571_;
|
||||
this.y = -1.0F;
|
||||
TreeNodePosition treenodeposition = null;
|
||||
|
||||
for(Advancement advancement : p_16567_.getChildren()) {
|
||||
treenodeposition = this.addChild(advancement, treenodeposition);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private TreeNodePosition addChild(Advancement p_16590_, @Nullable TreeNodePosition p_16591_) {
|
||||
if (p_16590_.getDisplay() != null) {
|
||||
p_16591_ = new TreeNodePosition(p_16590_, this, p_16591_, this.children.size() + 1, this.x + 1);
|
||||
this.children.add(p_16591_);
|
||||
} else {
|
||||
for(Advancement advancement : p_16590_.getChildren()) {
|
||||
p_16591_ = this.addChild(advancement, p_16591_);
|
||||
}
|
||||
}
|
||||
|
||||
return p_16591_;
|
||||
}
|
||||
|
||||
private void firstWalk() {
|
||||
if (this.children.isEmpty()) {
|
||||
if (this.previousSibling != null) {
|
||||
this.y = this.previousSibling.y + 1.0F;
|
||||
} else {
|
||||
this.y = 0.0F;
|
||||
}
|
||||
|
||||
} else {
|
||||
TreeNodePosition treenodeposition = null;
|
||||
|
||||
for(TreeNodePosition treenodeposition1 : this.children) {
|
||||
treenodeposition1.firstWalk();
|
||||
treenodeposition = treenodeposition1.apportion(treenodeposition == null ? treenodeposition1 : treenodeposition);
|
||||
}
|
||||
|
||||
this.executeShifts();
|
||||
float f = ((this.children.get(0)).y + (this.children.get(this.children.size() - 1)).y) / 2.0F;
|
||||
if (this.previousSibling != null) {
|
||||
this.y = this.previousSibling.y + 1.0F;
|
||||
this.mod = this.y - f;
|
||||
} else {
|
||||
this.y = f;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private float secondWalk(float p_16576_, int p_16577_, float p_16578_) {
|
||||
this.y += p_16576_;
|
||||
this.x = p_16577_;
|
||||
if (this.y < p_16578_) {
|
||||
p_16578_ = this.y;
|
||||
}
|
||||
|
||||
for(TreeNodePosition treenodeposition : this.children) {
|
||||
p_16578_ = treenodeposition.secondWalk(p_16576_ + this.mod, p_16577_ + 1, p_16578_);
|
||||
}
|
||||
|
||||
return p_16578_;
|
||||
}
|
||||
|
||||
private void thirdWalk(float p_16574_) {
|
||||
this.y += p_16574_;
|
||||
|
||||
for(TreeNodePosition treenodeposition : this.children) {
|
||||
treenodeposition.thirdWalk(p_16574_);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void executeShifts() {
|
||||
float f = 0.0F;
|
||||
float f1 = 0.0F;
|
||||
|
||||
for(int i = this.children.size() - 1; i >= 0; --i) {
|
||||
TreeNodePosition treenodeposition = this.children.get(i);
|
||||
treenodeposition.y += f;
|
||||
treenodeposition.mod += f;
|
||||
f1 += treenodeposition.change;
|
||||
f += treenodeposition.shift + f1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private TreeNodePosition previousOrThread() {
|
||||
if (this.thread != null) {
|
||||
return this.thread;
|
||||
} else {
|
||||
return !this.children.isEmpty() ? this.children.get(0) : null;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private TreeNodePosition nextOrThread() {
|
||||
if (this.thread != null) {
|
||||
return this.thread;
|
||||
} else {
|
||||
return !this.children.isEmpty() ? this.children.get(this.children.size() - 1) : null;
|
||||
}
|
||||
}
|
||||
|
||||
private TreeNodePosition apportion(TreeNodePosition p_16580_) {
|
||||
if (this.previousSibling == null) {
|
||||
return p_16580_;
|
||||
} else {
|
||||
TreeNodePosition treenodeposition = this;
|
||||
TreeNodePosition treenodeposition1 = this;
|
||||
TreeNodePosition treenodeposition2 = this.previousSibling;
|
||||
TreeNodePosition treenodeposition3 = this.parent.children.get(0);
|
||||
float f = this.mod;
|
||||
float f1 = this.mod;
|
||||
float f2 = treenodeposition2.mod;
|
||||
|
||||
float f3;
|
||||
for(f3 = treenodeposition3.mod; treenodeposition2.nextOrThread() != null && treenodeposition.previousOrThread() != null; f1 += treenodeposition1.mod) {
|
||||
treenodeposition2 = treenodeposition2.nextOrThread();
|
||||
treenodeposition = treenodeposition.previousOrThread();
|
||||
treenodeposition3 = treenodeposition3.previousOrThread();
|
||||
treenodeposition1 = treenodeposition1.nextOrThread();
|
||||
treenodeposition1.ancestor = this;
|
||||
float f4 = treenodeposition2.y + f2 - (treenodeposition.y + f) + 1.0F;
|
||||
if (f4 > 0.0F) {
|
||||
treenodeposition2.getAncestor(this, p_16580_).moveSubtree(this, f4);
|
||||
f += f4;
|
||||
f1 += f4;
|
||||
}
|
||||
|
||||
f2 += treenodeposition2.mod;
|
||||
f += treenodeposition.mod;
|
||||
f3 += treenodeposition3.mod;
|
||||
}
|
||||
|
||||
if (treenodeposition2.nextOrThread() != null && treenodeposition1.nextOrThread() == null) {
|
||||
treenodeposition1.thread = treenodeposition2.nextOrThread();
|
||||
treenodeposition1.mod += f2 - f1;
|
||||
} else {
|
||||
if (treenodeposition.previousOrThread() != null && treenodeposition3.previousOrThread() == null) {
|
||||
treenodeposition3.thread = treenodeposition.previousOrThread();
|
||||
treenodeposition3.mod += f - f3;
|
||||
}
|
||||
|
||||
p_16580_ = this;
|
||||
}
|
||||
|
||||
return p_16580_;
|
||||
}
|
||||
}
|
||||
|
||||
private void moveSubtree(TreeNodePosition p_16582_, float p_16583_) {
|
||||
float f = (float)(p_16582_.childIndex - this.childIndex);
|
||||
if (f != 0.0F) {
|
||||
p_16582_.change -= p_16583_ / f;
|
||||
this.change += p_16583_ / f;
|
||||
}
|
||||
|
||||
p_16582_.shift += p_16583_;
|
||||
p_16582_.y += p_16583_;
|
||||
p_16582_.mod += p_16583_;
|
||||
}
|
||||
|
||||
private TreeNodePosition getAncestor(TreeNodePosition p_16585_, TreeNodePosition p_16586_) {
|
||||
return this.ancestor != null && p_16585_.parent.children.contains(this.ancestor) ? this.ancestor : p_16586_;
|
||||
}
|
||||
|
||||
private void finalizePosition() {
|
||||
if (this.advancement.getDisplay() != null) {
|
||||
this.advancement.getDisplay().setLocation((float)this.x, this.y);
|
||||
}
|
||||
|
||||
if (!this.children.isEmpty()) {
|
||||
for(TreeNodePosition treenodeposition : this.children) {
|
||||
treenodeposition.finalizePosition();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void run(Advancement p_16588_) {
|
||||
if (p_16588_.getDisplay() == null) {
|
||||
throw new IllegalArgumentException("Can't position children of an invisible root!");
|
||||
} else {
|
||||
TreeNodePosition treenodeposition = new TreeNodePosition(p_16588_, (TreeNodePosition)null, (TreeNodePosition)null, 1, 0);
|
||||
treenodeposition.firstWalk();
|
||||
float f = treenodeposition.secondWalk(0.0F, 0, treenodeposition.y);
|
||||
if (f < 0.0F) {
|
||||
treenodeposition.thirdWalk(-f);
|
||||
}
|
||||
|
||||
treenodeposition.finalizePosition();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.advancements.CriterionTriggerInstance;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
public abstract class AbstractCriterionTriggerInstance implements CriterionTriggerInstance {
|
||||
private final ResourceLocation criterion;
|
||||
private final ContextAwarePredicate player;
|
||||
|
||||
public AbstractCriterionTriggerInstance(ResourceLocation p_286357_, ContextAwarePredicate p_286466_) {
|
||||
this.criterion = p_286357_;
|
||||
this.player = p_286466_;
|
||||
}
|
||||
|
||||
public ResourceLocation getCriterion() {
|
||||
return this.criterion;
|
||||
}
|
||||
|
||||
protected ContextAwarePredicate getPlayerPredicate() {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
public JsonObject serializeToJson(SerializationContext p_16979_) {
|
||||
JsonObject jsonobject = new JsonObject();
|
||||
jsonobject.add("player", this.player.toJson(p_16979_));
|
||||
return jsonobject;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "AbstractCriterionInstance{criterion=" + this.criterion + "}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
public class BeeNestDestroyedTrigger extends SimpleCriterionTrigger<BeeNestDestroyedTrigger.TriggerInstance> {
|
||||
static final ResourceLocation ID = new ResourceLocation("bee_nest_destroyed");
|
||||
|
||||
public ResourceLocation getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
public BeeNestDestroyedTrigger.TriggerInstance createInstance(JsonObject p_286717_, ContextAwarePredicate p_286621_, DeserializationContext p_286840_) {
|
||||
Block block = deserializeBlock(p_286717_);
|
||||
ItemPredicate itempredicate = ItemPredicate.fromJson(p_286717_.get("item"));
|
||||
MinMaxBounds.Ints minmaxbounds$ints = MinMaxBounds.Ints.fromJson(p_286717_.get("num_bees_inside"));
|
||||
return new BeeNestDestroyedTrigger.TriggerInstance(p_286621_, block, itempredicate, minmaxbounds$ints);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static Block deserializeBlock(JsonObject p_17488_) {
|
||||
if (p_17488_.has("block")) {
|
||||
ResourceLocation resourcelocation = new ResourceLocation(GsonHelper.getAsString(p_17488_, "block"));
|
||||
return BuiltInRegistries.BLOCK.getOptional(resourcelocation).orElseThrow(() -> {
|
||||
return new JsonSyntaxException("Unknown block type '" + resourcelocation + "'");
|
||||
});
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void trigger(ServerPlayer p_146652_, BlockState p_146653_, ItemStack p_146654_, int p_146655_) {
|
||||
this.trigger(p_146652_, (p_146660_) -> {
|
||||
return p_146660_.matches(p_146653_, p_146654_, p_146655_);
|
||||
});
|
||||
}
|
||||
|
||||
public static class TriggerInstance extends AbstractCriterionTriggerInstance {
|
||||
@Nullable
|
||||
private final Block block;
|
||||
private final ItemPredicate item;
|
||||
private final MinMaxBounds.Ints numBees;
|
||||
|
||||
public TriggerInstance(ContextAwarePredicate p_286609_, @Nullable Block p_286264_, ItemPredicate p_286572_, MinMaxBounds.Ints p_286574_) {
|
||||
super(BeeNestDestroyedTrigger.ID, p_286609_);
|
||||
this.block = p_286264_;
|
||||
this.item = p_286572_;
|
||||
this.numBees = p_286574_;
|
||||
}
|
||||
|
||||
public static BeeNestDestroyedTrigger.TriggerInstance destroyedBeeNest(Block p_17513_, ItemPredicate.Builder p_17514_, MinMaxBounds.Ints p_17515_) {
|
||||
return new BeeNestDestroyedTrigger.TriggerInstance(ContextAwarePredicate.ANY, p_17513_, p_17514_.build(), p_17515_);
|
||||
}
|
||||
|
||||
public boolean matches(BlockState p_146662_, ItemStack p_146663_, int p_146664_) {
|
||||
if (this.block != null && !p_146662_.is(this.block)) {
|
||||
return false;
|
||||
} else {
|
||||
return !this.item.matches(p_146663_) ? false : this.numBees.matches(p_146664_);
|
||||
}
|
||||
}
|
||||
|
||||
public JsonObject serializeToJson(SerializationContext p_17517_) {
|
||||
JsonObject jsonobject = super.serializeToJson(p_17517_);
|
||||
if (this.block != null) {
|
||||
jsonobject.addProperty("block", BuiltInRegistries.BLOCK.getKey(this.block).toString());
|
||||
}
|
||||
|
||||
jsonobject.add("item", this.item.serializeToJson());
|
||||
jsonobject.add("num_bees_inside", this.numBees.serializeToJson());
|
||||
return jsonobject;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonNull;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import java.util.Set;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
public class BlockPredicate {
|
||||
public static final BlockPredicate ANY = new BlockPredicate((TagKey<Block>)null, (Set<Block>)null, StatePropertiesPredicate.ANY, NbtPredicate.ANY);
|
||||
@Nullable
|
||||
private final TagKey<Block> tag;
|
||||
@Nullable
|
||||
private final Set<Block> blocks;
|
||||
private final StatePropertiesPredicate properties;
|
||||
private final NbtPredicate nbt;
|
||||
|
||||
public BlockPredicate(@Nullable TagKey<Block> p_204023_, @Nullable Set<Block> p_204024_, StatePropertiesPredicate p_204025_, NbtPredicate p_204026_) {
|
||||
this.tag = p_204023_;
|
||||
this.blocks = p_204024_;
|
||||
this.properties = p_204025_;
|
||||
this.nbt = p_204026_;
|
||||
}
|
||||
|
||||
public boolean matches(ServerLevel p_17915_, BlockPos p_17916_) {
|
||||
if (this == ANY) {
|
||||
return true;
|
||||
} else if (!p_17915_.isLoaded(p_17916_)) {
|
||||
return false;
|
||||
} else {
|
||||
BlockState blockstate = p_17915_.getBlockState(p_17916_);
|
||||
if (this.tag != null && !blockstate.is(this.tag)) {
|
||||
return false;
|
||||
} else if (this.blocks != null && !this.blocks.contains(blockstate.getBlock())) {
|
||||
return false;
|
||||
} else if (!this.properties.matches(blockstate)) {
|
||||
return false;
|
||||
} else {
|
||||
if (this.nbt != NbtPredicate.ANY) {
|
||||
BlockEntity blockentity = p_17915_.getBlockEntity(p_17916_);
|
||||
if (blockentity == null || !this.nbt.matches(blockentity.saveWithFullMetadata())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static BlockPredicate fromJson(@Nullable JsonElement p_17918_) {
|
||||
if (p_17918_ != null && !p_17918_.isJsonNull()) {
|
||||
JsonObject jsonobject = GsonHelper.convertToJsonObject(p_17918_, "block");
|
||||
NbtPredicate nbtpredicate = NbtPredicate.fromJson(jsonobject.get("nbt"));
|
||||
Set<Block> set = null;
|
||||
JsonArray jsonarray = GsonHelper.getAsJsonArray(jsonobject, "blocks", (JsonArray)null);
|
||||
if (jsonarray != null) {
|
||||
ImmutableSet.Builder<Block> builder = ImmutableSet.builder();
|
||||
|
||||
for(JsonElement jsonelement : jsonarray) {
|
||||
ResourceLocation resourcelocation = new ResourceLocation(GsonHelper.convertToString(jsonelement, "block"));
|
||||
builder.add(BuiltInRegistries.BLOCK.getOptional(resourcelocation).orElseThrow(() -> {
|
||||
return new JsonSyntaxException("Unknown block id '" + resourcelocation + "'");
|
||||
}));
|
||||
}
|
||||
|
||||
set = builder.build();
|
||||
}
|
||||
|
||||
TagKey<Block> tagkey = null;
|
||||
if (jsonobject.has("tag")) {
|
||||
ResourceLocation resourcelocation1 = new ResourceLocation(GsonHelper.getAsString(jsonobject, "tag"));
|
||||
tagkey = TagKey.create(Registries.BLOCK, resourcelocation1);
|
||||
}
|
||||
|
||||
StatePropertiesPredicate statepropertiespredicate = StatePropertiesPredicate.fromJson(jsonobject.get("state"));
|
||||
return new BlockPredicate(tagkey, set, statepropertiespredicate, nbtpredicate);
|
||||
} else {
|
||||
return ANY;
|
||||
}
|
||||
}
|
||||
|
||||
public JsonElement serializeToJson() {
|
||||
if (this == ANY) {
|
||||
return JsonNull.INSTANCE;
|
||||
} else {
|
||||
JsonObject jsonobject = new JsonObject();
|
||||
if (this.blocks != null) {
|
||||
JsonArray jsonarray = new JsonArray();
|
||||
|
||||
for(Block block : this.blocks) {
|
||||
jsonarray.add(BuiltInRegistries.BLOCK.getKey(block).toString());
|
||||
}
|
||||
|
||||
jsonobject.add("blocks", jsonarray);
|
||||
}
|
||||
|
||||
if (this.tag != null) {
|
||||
jsonobject.addProperty("tag", this.tag.location().toString());
|
||||
}
|
||||
|
||||
jsonobject.add("nbt", this.nbt.serializeToJson());
|
||||
jsonobject.add("state", this.properties.serializeToJson());
|
||||
return jsonobject;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
@Nullable
|
||||
private Set<Block> blocks;
|
||||
@Nullable
|
||||
private TagKey<Block> tag;
|
||||
private StatePropertiesPredicate properties = StatePropertiesPredicate.ANY;
|
||||
private NbtPredicate nbt = NbtPredicate.ANY;
|
||||
|
||||
private Builder() {
|
||||
}
|
||||
|
||||
public static BlockPredicate.Builder block() {
|
||||
return new BlockPredicate.Builder();
|
||||
}
|
||||
|
||||
public BlockPredicate.Builder of(Block... p_146727_) {
|
||||
this.blocks = ImmutableSet.copyOf(p_146727_);
|
||||
return this;
|
||||
}
|
||||
|
||||
public BlockPredicate.Builder of(Iterable<Block> p_146723_) {
|
||||
this.blocks = ImmutableSet.copyOf(p_146723_);
|
||||
return this;
|
||||
}
|
||||
|
||||
public BlockPredicate.Builder of(TagKey<Block> p_204028_) {
|
||||
this.tag = p_204028_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BlockPredicate.Builder hasNbt(CompoundTag p_146725_) {
|
||||
this.nbt = new NbtPredicate(p_146725_);
|
||||
return this;
|
||||
}
|
||||
|
||||
public BlockPredicate.Builder setProperties(StatePropertiesPredicate p_17930_) {
|
||||
this.properties = p_17930_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BlockPredicate build() {
|
||||
return new BlockPredicate(this.tag, this.blocks, this.properties, this.nbt);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.AgeableMob;
|
||||
import net.minecraft.world.entity.animal.Animal;
|
||||
import net.minecraft.world.level.storage.loot.LootContext;
|
||||
|
||||
public class BredAnimalsTrigger extends SimpleCriterionTrigger<BredAnimalsTrigger.TriggerInstance> {
|
||||
static final ResourceLocation ID = new ResourceLocation("bred_animals");
|
||||
|
||||
public ResourceLocation getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
public BredAnimalsTrigger.TriggerInstance createInstance(JsonObject p_286457_, ContextAwarePredicate p_286507_, DeserializationContext p_286849_) {
|
||||
ContextAwarePredicate contextawarepredicate = EntityPredicate.fromJson(p_286457_, "parent", p_286849_);
|
||||
ContextAwarePredicate contextawarepredicate1 = EntityPredicate.fromJson(p_286457_, "partner", p_286849_);
|
||||
ContextAwarePredicate contextawarepredicate2 = EntityPredicate.fromJson(p_286457_, "child", p_286849_);
|
||||
return new BredAnimalsTrigger.TriggerInstance(p_286507_, contextawarepredicate, contextawarepredicate1, contextawarepredicate2);
|
||||
}
|
||||
|
||||
public void trigger(ServerPlayer p_147279_, Animal p_147280_, Animal p_147281_, @Nullable AgeableMob p_147282_) {
|
||||
LootContext lootcontext = EntityPredicate.createContext(p_147279_, p_147280_);
|
||||
LootContext lootcontext1 = EntityPredicate.createContext(p_147279_, p_147281_);
|
||||
LootContext lootcontext2 = p_147282_ != null ? EntityPredicate.createContext(p_147279_, p_147282_) : null;
|
||||
this.trigger(p_147279_, (p_18653_) -> {
|
||||
return p_18653_.matches(lootcontext, lootcontext1, lootcontext2);
|
||||
});
|
||||
}
|
||||
|
||||
public static class TriggerInstance extends AbstractCriterionTriggerInstance {
|
||||
private final ContextAwarePredicate parent;
|
||||
private final ContextAwarePredicate partner;
|
||||
private final ContextAwarePredicate child;
|
||||
|
||||
public TriggerInstance(ContextAwarePredicate p_286459_, ContextAwarePredicate p_286695_, ContextAwarePredicate p_286476_, ContextAwarePredicate p_286433_) {
|
||||
super(BredAnimalsTrigger.ID, p_286459_);
|
||||
this.parent = p_286695_;
|
||||
this.partner = p_286476_;
|
||||
this.child = p_286433_;
|
||||
}
|
||||
|
||||
public static BredAnimalsTrigger.TriggerInstance bredAnimals() {
|
||||
return new BredAnimalsTrigger.TriggerInstance(ContextAwarePredicate.ANY, ContextAwarePredicate.ANY, ContextAwarePredicate.ANY, ContextAwarePredicate.ANY);
|
||||
}
|
||||
|
||||
public static BredAnimalsTrigger.TriggerInstance bredAnimals(EntityPredicate.Builder p_18668_) {
|
||||
return new BredAnimalsTrigger.TriggerInstance(ContextAwarePredicate.ANY, ContextAwarePredicate.ANY, ContextAwarePredicate.ANY, EntityPredicate.wrap(p_18668_.build()));
|
||||
}
|
||||
|
||||
public static BredAnimalsTrigger.TriggerInstance bredAnimals(EntityPredicate p_18670_, EntityPredicate p_18671_, EntityPredicate p_18672_) {
|
||||
return new BredAnimalsTrigger.TriggerInstance(ContextAwarePredicate.ANY, EntityPredicate.wrap(p_18670_), EntityPredicate.wrap(p_18671_), EntityPredicate.wrap(p_18672_));
|
||||
}
|
||||
|
||||
public boolean matches(LootContext p_18676_, LootContext p_18677_, @Nullable LootContext p_18678_) {
|
||||
if (this.child == ContextAwarePredicate.ANY || p_18678_ != null && this.child.matches(p_18678_)) {
|
||||
return this.parent.matches(p_18676_) && this.partner.matches(p_18677_) || this.parent.matches(p_18677_) && this.partner.matches(p_18676_);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public JsonObject serializeToJson(SerializationContext p_18674_) {
|
||||
JsonObject jsonobject = super.serializeToJson(p_18674_);
|
||||
jsonobject.add("parent", this.parent.toJson(p_18674_));
|
||||
jsonobject.add("partner", this.partner.toJson(p_18674_));
|
||||
jsonobject.add("child", this.child.toJson(p_18674_));
|
||||
return jsonobject;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
import net.minecraft.world.item.alchemy.Potion;
|
||||
|
||||
public class BrewedPotionTrigger extends SimpleCriterionTrigger<BrewedPotionTrigger.TriggerInstance> {
|
||||
static final ResourceLocation ID = new ResourceLocation("brewed_potion");
|
||||
|
||||
public ResourceLocation getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
public BrewedPotionTrigger.TriggerInstance createInstance(JsonObject p_286606_, ContextAwarePredicate p_286420_, DeserializationContext p_286605_) {
|
||||
Potion potion = null;
|
||||
if (p_286606_.has("potion")) {
|
||||
ResourceLocation resourcelocation = new ResourceLocation(GsonHelper.getAsString(p_286606_, "potion"));
|
||||
potion = BuiltInRegistries.POTION.getOptional(resourcelocation).orElseThrow(() -> {
|
||||
return new JsonSyntaxException("Unknown potion '" + resourcelocation + "'");
|
||||
});
|
||||
}
|
||||
|
||||
return new BrewedPotionTrigger.TriggerInstance(p_286420_, potion);
|
||||
}
|
||||
|
||||
public void trigger(ServerPlayer p_19121_, Potion p_19122_) {
|
||||
this.trigger(p_19121_, (p_19125_) -> {
|
||||
return p_19125_.matches(p_19122_);
|
||||
});
|
||||
}
|
||||
|
||||
public static class TriggerInstance extends AbstractCriterionTriggerInstance {
|
||||
@Nullable
|
||||
private final Potion potion;
|
||||
|
||||
public TriggerInstance(ContextAwarePredicate p_286312_, @Nullable Potion p_286830_) {
|
||||
super(BrewedPotionTrigger.ID, p_286312_);
|
||||
this.potion = p_286830_;
|
||||
}
|
||||
|
||||
public static BrewedPotionTrigger.TriggerInstance brewedPotion() {
|
||||
return new BrewedPotionTrigger.TriggerInstance(ContextAwarePredicate.ANY, (Potion)null);
|
||||
}
|
||||
|
||||
public boolean matches(Potion p_19142_) {
|
||||
return this.potion == null || this.potion == p_19142_;
|
||||
}
|
||||
|
||||
public JsonObject serializeToJson(SerializationContext p_19144_) {
|
||||
JsonObject jsonobject = super.serializeToJson(p_19144_);
|
||||
if (this.potion != null) {
|
||||
jsonobject.addProperty("potion", BuiltInRegistries.POTION.getKey(this.potion).toString());
|
||||
}
|
||||
|
||||
return jsonobject;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
public class ChangeDimensionTrigger extends SimpleCriterionTrigger<ChangeDimensionTrigger.TriggerInstance> {
|
||||
static final ResourceLocation ID = new ResourceLocation("changed_dimension");
|
||||
|
||||
public ResourceLocation getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
public ChangeDimensionTrigger.TriggerInstance createInstance(JsonObject p_19762_, ContextAwarePredicate p_286295_, DeserializationContext p_19764_) {
|
||||
ResourceKey<Level> resourcekey = p_19762_.has("from") ? ResourceKey.create(Registries.DIMENSION, new ResourceLocation(GsonHelper.getAsString(p_19762_, "from"))) : null;
|
||||
ResourceKey<Level> resourcekey1 = p_19762_.has("to") ? ResourceKey.create(Registries.DIMENSION, new ResourceLocation(GsonHelper.getAsString(p_19762_, "to"))) : null;
|
||||
return new ChangeDimensionTrigger.TriggerInstance(p_286295_, resourcekey, resourcekey1);
|
||||
}
|
||||
|
||||
public void trigger(ServerPlayer p_19758_, ResourceKey<Level> p_19759_, ResourceKey<Level> p_19760_) {
|
||||
this.trigger(p_19758_, (p_19768_) -> {
|
||||
return p_19768_.matches(p_19759_, p_19760_);
|
||||
});
|
||||
}
|
||||
|
||||
public static class TriggerInstance extends AbstractCriterionTriggerInstance {
|
||||
@Nullable
|
||||
private final ResourceKey<Level> from;
|
||||
@Nullable
|
||||
private final ResourceKey<Level> to;
|
||||
|
||||
public TriggerInstance(ContextAwarePredicate p_286423_, @Nullable ResourceKey<Level> p_286585_, @Nullable ResourceKey<Level> p_286666_) {
|
||||
super(ChangeDimensionTrigger.ID, p_286423_);
|
||||
this.from = p_286585_;
|
||||
this.to = p_286666_;
|
||||
}
|
||||
|
||||
public static ChangeDimensionTrigger.TriggerInstance changedDimension() {
|
||||
return new ChangeDimensionTrigger.TriggerInstance(ContextAwarePredicate.ANY, (ResourceKey<Level>)null, (ResourceKey<Level>)null);
|
||||
}
|
||||
|
||||
public static ChangeDimensionTrigger.TriggerInstance changedDimension(ResourceKey<Level> p_147561_, ResourceKey<Level> p_147562_) {
|
||||
return new ChangeDimensionTrigger.TriggerInstance(ContextAwarePredicate.ANY, p_147561_, p_147562_);
|
||||
}
|
||||
|
||||
public static ChangeDimensionTrigger.TriggerInstance changedDimensionTo(ResourceKey<Level> p_19783_) {
|
||||
return new ChangeDimensionTrigger.TriggerInstance(ContextAwarePredicate.ANY, (ResourceKey<Level>)null, p_19783_);
|
||||
}
|
||||
|
||||
public static ChangeDimensionTrigger.TriggerInstance changedDimensionFrom(ResourceKey<Level> p_147564_) {
|
||||
return new ChangeDimensionTrigger.TriggerInstance(ContextAwarePredicate.ANY, p_147564_, (ResourceKey<Level>)null);
|
||||
}
|
||||
|
||||
public boolean matches(ResourceKey<Level> p_19785_, ResourceKey<Level> p_19786_) {
|
||||
if (this.from != null && this.from != p_19785_) {
|
||||
return false;
|
||||
} else {
|
||||
return this.to == null || this.to == p_19786_;
|
||||
}
|
||||
}
|
||||
|
||||
public JsonObject serializeToJson(SerializationContext p_19781_) {
|
||||
JsonObject jsonobject = super.serializeToJson(p_19781_);
|
||||
if (this.from != null) {
|
||||
jsonobject.addProperty("from", this.from.location().toString());
|
||||
}
|
||||
|
||||
if (this.to != null) {
|
||||
jsonobject.addProperty("to", this.to.location().toString());
|
||||
}
|
||||
|
||||
return jsonobject;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.storage.loot.LootContext;
|
||||
|
||||
public class ChanneledLightningTrigger extends SimpleCriterionTrigger<ChanneledLightningTrigger.TriggerInstance> {
|
||||
static final ResourceLocation ID = new ResourceLocation("channeled_lightning");
|
||||
|
||||
public ResourceLocation getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
public ChanneledLightningTrigger.TriggerInstance createInstance(JsonObject p_286858_, ContextAwarePredicate p_286240_, DeserializationContext p_286562_) {
|
||||
ContextAwarePredicate[] acontextawarepredicate = EntityPredicate.fromJsonArray(p_286858_, "victims", p_286562_);
|
||||
return new ChanneledLightningTrigger.TriggerInstance(p_286240_, acontextawarepredicate);
|
||||
}
|
||||
|
||||
public void trigger(ServerPlayer p_21722_, Collection<? extends Entity> p_21723_) {
|
||||
List<LootContext> list = p_21723_.stream().map((p_21720_) -> {
|
||||
return EntityPredicate.createContext(p_21722_, p_21720_);
|
||||
}).collect(Collectors.toList());
|
||||
this.trigger(p_21722_, (p_21730_) -> {
|
||||
return p_21730_.matches(list);
|
||||
});
|
||||
}
|
||||
|
||||
public static class TriggerInstance extends AbstractCriterionTriggerInstance {
|
||||
private final ContextAwarePredicate[] victims;
|
||||
|
||||
public TriggerInstance(ContextAwarePredicate p_286697_, ContextAwarePredicate[] p_286366_) {
|
||||
super(ChanneledLightningTrigger.ID, p_286697_);
|
||||
this.victims = p_286366_;
|
||||
}
|
||||
|
||||
public static ChanneledLightningTrigger.TriggerInstance channeledLightning(EntityPredicate... p_21747_) {
|
||||
return new ChanneledLightningTrigger.TriggerInstance(ContextAwarePredicate.ANY, Stream.of(p_21747_).map(EntityPredicate::wrap).toArray((p_286116_) -> {
|
||||
return new ContextAwarePredicate[p_286116_];
|
||||
}));
|
||||
}
|
||||
|
||||
public boolean matches(Collection<? extends LootContext> p_21745_) {
|
||||
for(ContextAwarePredicate contextawarepredicate : this.victims) {
|
||||
boolean flag = false;
|
||||
|
||||
for(LootContext lootcontext : p_21745_) {
|
||||
if (contextawarepredicate.matches(lootcontext)) {
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!flag) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public JsonObject serializeToJson(SerializationContext p_21743_) {
|
||||
JsonObject jsonobject = super.serializeToJson(p_21743_);
|
||||
jsonobject.add("victims", ContextAwarePredicate.toJson(this.victims, p_21743_));
|
||||
return jsonobject;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
public class ConstructBeaconTrigger extends SimpleCriterionTrigger<ConstructBeaconTrigger.TriggerInstance> {
|
||||
static final ResourceLocation ID = new ResourceLocation("construct_beacon");
|
||||
|
||||
public ResourceLocation getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
public ConstructBeaconTrigger.TriggerInstance createInstance(JsonObject p_286465_, ContextAwarePredicate p_286914_, DeserializationContext p_286803_) {
|
||||
MinMaxBounds.Ints minmaxbounds$ints = MinMaxBounds.Ints.fromJson(p_286465_.get("level"));
|
||||
return new ConstructBeaconTrigger.TriggerInstance(p_286914_, minmaxbounds$ints);
|
||||
}
|
||||
|
||||
public void trigger(ServerPlayer p_148030_, int p_148031_) {
|
||||
this.trigger(p_148030_, (p_148028_) -> {
|
||||
return p_148028_.matches(p_148031_);
|
||||
});
|
||||
}
|
||||
|
||||
public static class TriggerInstance extends AbstractCriterionTriggerInstance {
|
||||
private final MinMaxBounds.Ints level;
|
||||
|
||||
public TriggerInstance(ContextAwarePredicate p_286868_, MinMaxBounds.Ints p_286272_) {
|
||||
super(ConstructBeaconTrigger.ID, p_286868_);
|
||||
this.level = p_286272_;
|
||||
}
|
||||
|
||||
public static ConstructBeaconTrigger.TriggerInstance constructedBeacon() {
|
||||
return new ConstructBeaconTrigger.TriggerInstance(ContextAwarePredicate.ANY, MinMaxBounds.Ints.ANY);
|
||||
}
|
||||
|
||||
public static ConstructBeaconTrigger.TriggerInstance constructedBeacon(MinMaxBounds.Ints p_22766_) {
|
||||
return new ConstructBeaconTrigger.TriggerInstance(ContextAwarePredicate.ANY, p_22766_);
|
||||
}
|
||||
|
||||
public boolean matches(int p_148033_) {
|
||||
return this.level.matches(p_148033_);
|
||||
}
|
||||
|
||||
public JsonObject serializeToJson(SerializationContext p_22770_) {
|
||||
JsonObject jsonobject = super.serializeToJson(p_22770_);
|
||||
jsonobject.add("level", this.level.serializeToJson());
|
||||
return jsonobject;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.alchemy.Potion;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
|
||||
public class ConsumeItemTrigger extends SimpleCriterionTrigger<ConsumeItemTrigger.TriggerInstance> {
|
||||
static final ResourceLocation ID = new ResourceLocation("consume_item");
|
||||
|
||||
public ResourceLocation getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
public ConsumeItemTrigger.TriggerInstance createInstance(JsonObject p_286724_, ContextAwarePredicate p_286492_, DeserializationContext p_286887_) {
|
||||
return new ConsumeItemTrigger.TriggerInstance(p_286492_, ItemPredicate.fromJson(p_286724_.get("item")));
|
||||
}
|
||||
|
||||
public void trigger(ServerPlayer p_23683_, ItemStack p_23684_) {
|
||||
this.trigger(p_23683_, (p_23687_) -> {
|
||||
return p_23687_.matches(p_23684_);
|
||||
});
|
||||
}
|
||||
|
||||
public static class TriggerInstance extends AbstractCriterionTriggerInstance {
|
||||
private final ItemPredicate item;
|
||||
|
||||
public TriggerInstance(ContextAwarePredicate p_286663_, ItemPredicate p_286533_) {
|
||||
super(ConsumeItemTrigger.ID, p_286663_);
|
||||
this.item = p_286533_;
|
||||
}
|
||||
|
||||
public static ConsumeItemTrigger.TriggerInstance usedItem() {
|
||||
return new ConsumeItemTrigger.TriggerInstance(ContextAwarePredicate.ANY, ItemPredicate.ANY);
|
||||
}
|
||||
|
||||
public static ConsumeItemTrigger.TriggerInstance usedItem(ItemPredicate p_148082_) {
|
||||
return new ConsumeItemTrigger.TriggerInstance(ContextAwarePredicate.ANY, p_148082_);
|
||||
}
|
||||
|
||||
public static ConsumeItemTrigger.TriggerInstance usedItem(ItemLike p_23704_) {
|
||||
return new ConsumeItemTrigger.TriggerInstance(ContextAwarePredicate.ANY, new ItemPredicate((TagKey<Item>)null, ImmutableSet.of(p_23704_.asItem()), MinMaxBounds.Ints.ANY, MinMaxBounds.Ints.ANY, EnchantmentPredicate.NONE, EnchantmentPredicate.NONE, (Potion)null, NbtPredicate.ANY));
|
||||
}
|
||||
|
||||
public boolean matches(ItemStack p_23702_) {
|
||||
return this.item.matches(p_23702_);
|
||||
}
|
||||
|
||||
public JsonObject serializeToJson(SerializationContext p_23706_) {
|
||||
JsonObject jsonobject = super.serializeToJson(p_23706_);
|
||||
jsonobject.add("item", this.item.serializeToJson());
|
||||
return jsonobject;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonNull;
|
||||
import java.util.function.Predicate;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.world.level.storage.loot.LootContext;
|
||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSet;
|
||||
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;
|
||||
import net.minecraft.world.level.storage.loot.predicates.LootItemConditions;
|
||||
|
||||
public class ContextAwarePredicate {
|
||||
public static final ContextAwarePredicate ANY = new ContextAwarePredicate(new LootItemCondition[0]);
|
||||
private final LootItemCondition[] conditions;
|
||||
private final Predicate<LootContext> compositePredicates;
|
||||
|
||||
ContextAwarePredicate(LootItemCondition[] p_286308_) {
|
||||
this.conditions = p_286308_;
|
||||
this.compositePredicates = LootItemConditions.andConditions(p_286308_);
|
||||
}
|
||||
|
||||
public static ContextAwarePredicate create(LootItemCondition... p_286844_) {
|
||||
return new ContextAwarePredicate(p_286844_);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static ContextAwarePredicate fromElement(String p_286647_, DeserializationContext p_286323_, @Nullable JsonElement p_286520_, LootContextParamSet p_286912_) {
|
||||
if (p_286520_ != null && p_286520_.isJsonArray()) {
|
||||
LootItemCondition[] alootitemcondition = p_286323_.deserializeConditions(p_286520_.getAsJsonArray(), p_286323_.getAdvancementId() + "/" + p_286647_, p_286912_);
|
||||
return new ContextAwarePredicate(alootitemcondition);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean matches(LootContext p_286260_) {
|
||||
return this.compositePredicates.test(p_286260_);
|
||||
}
|
||||
|
||||
public JsonElement toJson(SerializationContext p_286222_) {
|
||||
return (JsonElement)(this.conditions.length == 0 ? JsonNull.INSTANCE : p_286222_.serializeConditions(this.conditions));
|
||||
}
|
||||
|
||||
public static JsonElement toJson(ContextAwarePredicate[] p_286611_, SerializationContext p_286638_) {
|
||||
if (p_286611_.length == 0) {
|
||||
return JsonNull.INSTANCE;
|
||||
} else {
|
||||
JsonArray jsonarray = new JsonArray();
|
||||
|
||||
for(ContextAwarePredicate contextawarepredicate : p_286611_) {
|
||||
jsonarray.add(contextawarepredicate.toJson(p_286638_));
|
||||
}
|
||||
|
||||
return jsonarray;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.monster.Zombie;
|
||||
import net.minecraft.world.entity.npc.Villager;
|
||||
import net.minecraft.world.level.storage.loot.LootContext;
|
||||
|
||||
public class CuredZombieVillagerTrigger extends SimpleCriterionTrigger<CuredZombieVillagerTrigger.TriggerInstance> {
|
||||
static final ResourceLocation ID = new ResourceLocation("cured_zombie_villager");
|
||||
|
||||
public ResourceLocation getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
public CuredZombieVillagerTrigger.TriggerInstance createInstance(JsonObject p_286832_, ContextAwarePredicate p_286917_, DeserializationContext p_286335_) {
|
||||
ContextAwarePredicate contextawarepredicate = EntityPredicate.fromJson(p_286832_, "zombie", p_286335_);
|
||||
ContextAwarePredicate contextawarepredicate1 = EntityPredicate.fromJson(p_286832_, "villager", p_286335_);
|
||||
return new CuredZombieVillagerTrigger.TriggerInstance(p_286917_, contextawarepredicate, contextawarepredicate1);
|
||||
}
|
||||
|
||||
public void trigger(ServerPlayer p_24275_, Zombie p_24276_, Villager p_24277_) {
|
||||
LootContext lootcontext = EntityPredicate.createContext(p_24275_, p_24276_);
|
||||
LootContext lootcontext1 = EntityPredicate.createContext(p_24275_, p_24277_);
|
||||
this.trigger(p_24275_, (p_24285_) -> {
|
||||
return p_24285_.matches(lootcontext, lootcontext1);
|
||||
});
|
||||
}
|
||||
|
||||
public static class TriggerInstance extends AbstractCriterionTriggerInstance {
|
||||
private final ContextAwarePredicate zombie;
|
||||
private final ContextAwarePredicate villager;
|
||||
|
||||
public TriggerInstance(ContextAwarePredicate p_286338_, ContextAwarePredicate p_286686_, ContextAwarePredicate p_286773_) {
|
||||
super(CuredZombieVillagerTrigger.ID, p_286338_);
|
||||
this.zombie = p_286686_;
|
||||
this.villager = p_286773_;
|
||||
}
|
||||
|
||||
public static CuredZombieVillagerTrigger.TriggerInstance curedZombieVillager() {
|
||||
return new CuredZombieVillagerTrigger.TriggerInstance(ContextAwarePredicate.ANY, ContextAwarePredicate.ANY, ContextAwarePredicate.ANY);
|
||||
}
|
||||
|
||||
public boolean matches(LootContext p_24300_, LootContext p_24301_) {
|
||||
if (!this.zombie.matches(p_24300_)) {
|
||||
return false;
|
||||
} else {
|
||||
return this.villager.matches(p_24301_);
|
||||
}
|
||||
}
|
||||
|
||||
public JsonObject serializeToJson(SerializationContext p_24298_) {
|
||||
JsonObject jsonobject = super.serializeToJson(p_24298_);
|
||||
jsonobject.add("zombie", this.zombie.toJson(p_24298_));
|
||||
jsonobject.add("villager", this.villager.toJson(p_24298_));
|
||||
return jsonobject;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonNull;
|
||||
import com.google.gson.JsonObject;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
|
||||
public class DamagePredicate {
|
||||
public static final DamagePredicate ANY = DamagePredicate.Builder.damageInstance().build();
|
||||
private final MinMaxBounds.Doubles dealtDamage;
|
||||
private final MinMaxBounds.Doubles takenDamage;
|
||||
private final EntityPredicate sourceEntity;
|
||||
@Nullable
|
||||
private final Boolean blocked;
|
||||
private final DamageSourcePredicate type;
|
||||
|
||||
public DamagePredicate() {
|
||||
this.dealtDamage = MinMaxBounds.Doubles.ANY;
|
||||
this.takenDamage = MinMaxBounds.Doubles.ANY;
|
||||
this.sourceEntity = EntityPredicate.ANY;
|
||||
this.blocked = null;
|
||||
this.type = DamageSourcePredicate.ANY;
|
||||
}
|
||||
|
||||
public DamagePredicate(MinMaxBounds.Doubles p_24911_, MinMaxBounds.Doubles p_24912_, EntityPredicate p_24913_, @Nullable Boolean p_24914_, DamageSourcePredicate p_24915_) {
|
||||
this.dealtDamage = p_24911_;
|
||||
this.takenDamage = p_24912_;
|
||||
this.sourceEntity = p_24913_;
|
||||
this.blocked = p_24914_;
|
||||
this.type = p_24915_;
|
||||
}
|
||||
|
||||
public boolean matches(ServerPlayer p_24918_, DamageSource p_24919_, float p_24920_, float p_24921_, boolean p_24922_) {
|
||||
if (this == ANY) {
|
||||
return true;
|
||||
} else if (!this.dealtDamage.matches((double)p_24920_)) {
|
||||
return false;
|
||||
} else if (!this.takenDamage.matches((double)p_24921_)) {
|
||||
return false;
|
||||
} else if (!this.sourceEntity.matches(p_24918_, p_24919_.getEntity())) {
|
||||
return false;
|
||||
} else if (this.blocked != null && this.blocked != p_24922_) {
|
||||
return false;
|
||||
} else {
|
||||
return this.type.matches(p_24918_, p_24919_);
|
||||
}
|
||||
}
|
||||
|
||||
public static DamagePredicate fromJson(@Nullable JsonElement p_24924_) {
|
||||
if (p_24924_ != null && !p_24924_.isJsonNull()) {
|
||||
JsonObject jsonobject = GsonHelper.convertToJsonObject(p_24924_, "damage");
|
||||
MinMaxBounds.Doubles minmaxbounds$doubles = MinMaxBounds.Doubles.fromJson(jsonobject.get("dealt"));
|
||||
MinMaxBounds.Doubles minmaxbounds$doubles1 = MinMaxBounds.Doubles.fromJson(jsonobject.get("taken"));
|
||||
Boolean obool = jsonobject.has("blocked") ? GsonHelper.getAsBoolean(jsonobject, "blocked") : null;
|
||||
EntityPredicate entitypredicate = EntityPredicate.fromJson(jsonobject.get("source_entity"));
|
||||
DamageSourcePredicate damagesourcepredicate = DamageSourcePredicate.fromJson(jsonobject.get("type"));
|
||||
return new DamagePredicate(minmaxbounds$doubles, minmaxbounds$doubles1, entitypredicate, obool, damagesourcepredicate);
|
||||
} else {
|
||||
return ANY;
|
||||
}
|
||||
}
|
||||
|
||||
public JsonElement serializeToJson() {
|
||||
if (this == ANY) {
|
||||
return JsonNull.INSTANCE;
|
||||
} else {
|
||||
JsonObject jsonobject = new JsonObject();
|
||||
jsonobject.add("dealt", this.dealtDamage.serializeToJson());
|
||||
jsonobject.add("taken", this.takenDamage.serializeToJson());
|
||||
jsonobject.add("source_entity", this.sourceEntity.serializeToJson());
|
||||
jsonobject.add("type", this.type.serializeToJson());
|
||||
if (this.blocked != null) {
|
||||
jsonobject.addProperty("blocked", this.blocked);
|
||||
}
|
||||
|
||||
return jsonobject;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private MinMaxBounds.Doubles dealtDamage = MinMaxBounds.Doubles.ANY;
|
||||
private MinMaxBounds.Doubles takenDamage = MinMaxBounds.Doubles.ANY;
|
||||
private EntityPredicate sourceEntity = EntityPredicate.ANY;
|
||||
@Nullable
|
||||
private Boolean blocked;
|
||||
private DamageSourcePredicate type = DamageSourcePredicate.ANY;
|
||||
|
||||
public static DamagePredicate.Builder damageInstance() {
|
||||
return new DamagePredicate.Builder();
|
||||
}
|
||||
|
||||
public DamagePredicate.Builder dealtDamage(MinMaxBounds.Doubles p_148146_) {
|
||||
this.dealtDamage = p_148146_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DamagePredicate.Builder takenDamage(MinMaxBounds.Doubles p_148148_) {
|
||||
this.takenDamage = p_148148_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DamagePredicate.Builder sourceEntity(EntityPredicate p_148144_) {
|
||||
this.sourceEntity = p_148144_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DamagePredicate.Builder blocked(Boolean p_24935_) {
|
||||
this.blocked = p_24935_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DamagePredicate.Builder type(DamageSourcePredicate p_148142_) {
|
||||
this.type = p_148142_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DamagePredicate.Builder type(DamageSourcePredicate.Builder p_24933_) {
|
||||
this.type = p_24933_.build();
|
||||
return this;
|
||||
}
|
||||
|
||||
public DamagePredicate build() {
|
||||
return new DamagePredicate(this.dealtDamage, this.takenDamage, this.sourceEntity, this.blocked, this.type);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonNull;
|
||||
import com.google.gson.JsonObject;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.damagesource.DamageType;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
public class DamageSourcePredicate {
|
||||
public static final DamageSourcePredicate ANY = DamageSourcePredicate.Builder.damageType().build();
|
||||
private final List<TagPredicate<DamageType>> tags;
|
||||
private final EntityPredicate directEntity;
|
||||
private final EntityPredicate sourceEntity;
|
||||
|
||||
public DamageSourcePredicate(List<TagPredicate<DamageType>> p_270233_, EntityPredicate p_270167_, EntityPredicate p_270429_) {
|
||||
this.tags = p_270233_;
|
||||
this.directEntity = p_270167_;
|
||||
this.sourceEntity = p_270429_;
|
||||
}
|
||||
|
||||
public boolean matches(ServerPlayer p_25449_, DamageSource p_25450_) {
|
||||
return this.matches(p_25449_.serverLevel(), p_25449_.position(), p_25450_);
|
||||
}
|
||||
|
||||
public boolean matches(ServerLevel p_25445_, Vec3 p_25446_, DamageSource p_25447_) {
|
||||
if (this == ANY) {
|
||||
return true;
|
||||
} else {
|
||||
for(TagPredicate<DamageType> tagpredicate : this.tags) {
|
||||
if (!tagpredicate.matches(p_25447_.typeHolder())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.directEntity.matches(p_25445_, p_25446_, p_25447_.getDirectEntity())) {
|
||||
return false;
|
||||
} else {
|
||||
return this.sourceEntity.matches(p_25445_, p_25446_, p_25447_.getEntity());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static DamageSourcePredicate fromJson(@Nullable JsonElement p_25452_) {
|
||||
if (p_25452_ != null && !p_25452_.isJsonNull()) {
|
||||
JsonObject jsonobject = GsonHelper.convertToJsonObject(p_25452_, "damage type");
|
||||
JsonArray jsonarray = GsonHelper.getAsJsonArray(jsonobject, "tags", (JsonArray)null);
|
||||
List<TagPredicate<DamageType>> list;
|
||||
if (jsonarray != null) {
|
||||
list = new ArrayList<>(jsonarray.size());
|
||||
|
||||
for(JsonElement jsonelement : jsonarray) {
|
||||
list.add(TagPredicate.fromJson(jsonelement, Registries.DAMAGE_TYPE));
|
||||
}
|
||||
} else {
|
||||
list = List.of();
|
||||
}
|
||||
|
||||
EntityPredicate entitypredicate = EntityPredicate.fromJson(jsonobject.get("direct_entity"));
|
||||
EntityPredicate entitypredicate1 = EntityPredicate.fromJson(jsonobject.get("source_entity"));
|
||||
return new DamageSourcePredicate(list, entitypredicate, entitypredicate1);
|
||||
} else {
|
||||
return ANY;
|
||||
}
|
||||
}
|
||||
|
||||
public JsonElement serializeToJson() {
|
||||
if (this == ANY) {
|
||||
return JsonNull.INSTANCE;
|
||||
} else {
|
||||
JsonObject jsonobject = new JsonObject();
|
||||
if (!this.tags.isEmpty()) {
|
||||
JsonArray jsonarray = new JsonArray(this.tags.size());
|
||||
|
||||
for(int i = 0; i < this.tags.size(); ++i) {
|
||||
jsonarray.add(this.tags.get(i).serializeToJson());
|
||||
}
|
||||
|
||||
jsonobject.add("tags", jsonarray);
|
||||
}
|
||||
|
||||
jsonobject.add("direct_entity", this.directEntity.serializeToJson());
|
||||
jsonobject.add("source_entity", this.sourceEntity.serializeToJson());
|
||||
return jsonobject;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private final ImmutableList.Builder<TagPredicate<DamageType>> tags = ImmutableList.builder();
|
||||
private EntityPredicate directEntity = EntityPredicate.ANY;
|
||||
private EntityPredicate sourceEntity = EntityPredicate.ANY;
|
||||
|
||||
public static DamageSourcePredicate.Builder damageType() {
|
||||
return new DamageSourcePredicate.Builder();
|
||||
}
|
||||
|
||||
public DamageSourcePredicate.Builder tag(TagPredicate<DamageType> p_270455_) {
|
||||
this.tags.add(p_270455_);
|
||||
return this;
|
||||
}
|
||||
|
||||
public DamageSourcePredicate.Builder direct(EntityPredicate p_148230_) {
|
||||
this.directEntity = p_148230_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DamageSourcePredicate.Builder direct(EntityPredicate.Builder p_25473_) {
|
||||
this.directEntity = p_25473_.build();
|
||||
return this;
|
||||
}
|
||||
|
||||
public DamageSourcePredicate.Builder source(EntityPredicate p_148234_) {
|
||||
this.sourceEntity = p_148234_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DamageSourcePredicate.Builder source(EntityPredicate.Builder p_148232_) {
|
||||
this.sourceEntity = p_148232_.build();
|
||||
return this;
|
||||
}
|
||||
|
||||
public DamageSourcePredicate build() {
|
||||
return new DamageSourcePredicate(this.tags.build(), this.directEntity, this.sourceEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.mojang.logging.LogUtils;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.storage.loot.Deserializers;
|
||||
import net.minecraft.world.level.storage.loot.LootDataManager;
|
||||
import net.minecraft.world.level.storage.loot.ValidationContext;
|
||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSet;
|
||||
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
public class DeserializationContext {
|
||||
private static final Logger LOGGER = LogUtils.getLogger();
|
||||
private final ResourceLocation id;
|
||||
private final LootDataManager lootData;
|
||||
private final Gson predicateGson = Deserializers.createConditionSerializer().create();
|
||||
|
||||
public DeserializationContext(ResourceLocation p_279318_, LootDataManager p_279364_) {
|
||||
this.id = p_279318_;
|
||||
this.lootData = p_279364_;
|
||||
}
|
||||
|
||||
public final LootItemCondition[] deserializeConditions(JsonArray p_25875_, String p_25876_, LootContextParamSet p_25877_) {
|
||||
LootItemCondition[] alootitemcondition = this.predicateGson.fromJson(p_25875_, LootItemCondition[].class);
|
||||
ValidationContext validationcontext = new ValidationContext(p_25877_, this.lootData);
|
||||
|
||||
for(LootItemCondition lootitemcondition : alootitemcondition) {
|
||||
lootitemcondition.validate(validationcontext);
|
||||
validationcontext.getProblems().forEach((p_25880_, p_25881_) -> {
|
||||
LOGGER.warn("Found validation problem in advancement trigger {}/{}: {}", p_25876_, p_25880_, p_25881_);
|
||||
});
|
||||
}
|
||||
|
||||
return alootitemcondition;
|
||||
}
|
||||
|
||||
public ResourceLocation getAdvancementId() {
|
||||
return this.id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonNull;
|
||||
import com.google.gson.JsonObject;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
import net.minecraft.util.Mth;
|
||||
|
||||
public class DistancePredicate {
|
||||
public static final DistancePredicate ANY = new DistancePredicate(MinMaxBounds.Doubles.ANY, MinMaxBounds.Doubles.ANY, MinMaxBounds.Doubles.ANY, MinMaxBounds.Doubles.ANY, MinMaxBounds.Doubles.ANY);
|
||||
private final MinMaxBounds.Doubles x;
|
||||
private final MinMaxBounds.Doubles y;
|
||||
private final MinMaxBounds.Doubles z;
|
||||
private final MinMaxBounds.Doubles horizontal;
|
||||
private final MinMaxBounds.Doubles absolute;
|
||||
|
||||
public DistancePredicate(MinMaxBounds.Doubles p_26249_, MinMaxBounds.Doubles p_26250_, MinMaxBounds.Doubles p_26251_, MinMaxBounds.Doubles p_26252_, MinMaxBounds.Doubles p_26253_) {
|
||||
this.x = p_26249_;
|
||||
this.y = p_26250_;
|
||||
this.z = p_26251_;
|
||||
this.horizontal = p_26252_;
|
||||
this.absolute = p_26253_;
|
||||
}
|
||||
|
||||
public static DistancePredicate horizontal(MinMaxBounds.Doubles p_148837_) {
|
||||
return new DistancePredicate(MinMaxBounds.Doubles.ANY, MinMaxBounds.Doubles.ANY, MinMaxBounds.Doubles.ANY, p_148837_, MinMaxBounds.Doubles.ANY);
|
||||
}
|
||||
|
||||
public static DistancePredicate vertical(MinMaxBounds.Doubles p_148839_) {
|
||||
return new DistancePredicate(MinMaxBounds.Doubles.ANY, p_148839_, MinMaxBounds.Doubles.ANY, MinMaxBounds.Doubles.ANY, MinMaxBounds.Doubles.ANY);
|
||||
}
|
||||
|
||||
public static DistancePredicate absolute(MinMaxBounds.Doubles p_148841_) {
|
||||
return new DistancePredicate(MinMaxBounds.Doubles.ANY, MinMaxBounds.Doubles.ANY, MinMaxBounds.Doubles.ANY, MinMaxBounds.Doubles.ANY, p_148841_);
|
||||
}
|
||||
|
||||
public boolean matches(double p_26256_, double p_26257_, double p_26258_, double p_26259_, double p_26260_, double p_26261_) {
|
||||
float f = (float)(p_26256_ - p_26259_);
|
||||
float f1 = (float)(p_26257_ - p_26260_);
|
||||
float f2 = (float)(p_26258_ - p_26261_);
|
||||
if (this.x.matches((double)Mth.abs(f)) && this.y.matches((double)Mth.abs(f1)) && this.z.matches((double)Mth.abs(f2))) {
|
||||
if (!this.horizontal.matchesSqr((double)(f * f + f2 * f2))) {
|
||||
return false;
|
||||
} else {
|
||||
return this.absolute.matchesSqr((double)(f * f + f1 * f1 + f2 * f2));
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static DistancePredicate fromJson(@Nullable JsonElement p_26265_) {
|
||||
if (p_26265_ != null && !p_26265_.isJsonNull()) {
|
||||
JsonObject jsonobject = GsonHelper.convertToJsonObject(p_26265_, "distance");
|
||||
MinMaxBounds.Doubles minmaxbounds$doubles = MinMaxBounds.Doubles.fromJson(jsonobject.get("x"));
|
||||
MinMaxBounds.Doubles minmaxbounds$doubles1 = MinMaxBounds.Doubles.fromJson(jsonobject.get("y"));
|
||||
MinMaxBounds.Doubles minmaxbounds$doubles2 = MinMaxBounds.Doubles.fromJson(jsonobject.get("z"));
|
||||
MinMaxBounds.Doubles minmaxbounds$doubles3 = MinMaxBounds.Doubles.fromJson(jsonobject.get("horizontal"));
|
||||
MinMaxBounds.Doubles minmaxbounds$doubles4 = MinMaxBounds.Doubles.fromJson(jsonobject.get("absolute"));
|
||||
return new DistancePredicate(minmaxbounds$doubles, minmaxbounds$doubles1, minmaxbounds$doubles2, minmaxbounds$doubles3, minmaxbounds$doubles4);
|
||||
} else {
|
||||
return ANY;
|
||||
}
|
||||
}
|
||||
|
||||
public JsonElement serializeToJson() {
|
||||
if (this == ANY) {
|
||||
return JsonNull.INSTANCE;
|
||||
} else {
|
||||
JsonObject jsonobject = new JsonObject();
|
||||
jsonobject.add("x", this.x.serializeToJson());
|
||||
jsonobject.add("y", this.y.serializeToJson());
|
||||
jsonobject.add("z", this.z.serializeToJson());
|
||||
jsonobject.add("horizontal", this.horizontal.serializeToJson());
|
||||
jsonobject.add("absolute", this.absolute.serializeToJson());
|
||||
return jsonobject;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.advancements.CriteriaTriggers;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
public class DistanceTrigger extends SimpleCriterionTrigger<DistanceTrigger.TriggerInstance> {
|
||||
final ResourceLocation id;
|
||||
|
||||
public DistanceTrigger(ResourceLocation p_186163_) {
|
||||
this.id = p_186163_;
|
||||
}
|
||||
|
||||
public ResourceLocation getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public DistanceTrigger.TriggerInstance createInstance(JsonObject p_286540_, ContextAwarePredicate p_286753_, DeserializationContext p_286709_) {
|
||||
LocationPredicate locationpredicate = LocationPredicate.fromJson(p_286540_.get("start_position"));
|
||||
DistancePredicate distancepredicate = DistancePredicate.fromJson(p_286540_.get("distance"));
|
||||
return new DistanceTrigger.TriggerInstance(this.id, p_286753_, locationpredicate, distancepredicate);
|
||||
}
|
||||
|
||||
public void trigger(ServerPlayer p_186166_, Vec3 p_186167_) {
|
||||
Vec3 vec3 = p_186166_.position();
|
||||
this.trigger(p_186166_, (p_284572_) -> {
|
||||
return p_284572_.matches(p_186166_.serverLevel(), p_186167_, vec3);
|
||||
});
|
||||
}
|
||||
|
||||
public static class TriggerInstance extends AbstractCriterionTriggerInstance {
|
||||
private final LocationPredicate startPosition;
|
||||
private final DistancePredicate distance;
|
||||
|
||||
public TriggerInstance(ResourceLocation p_286369_, ContextAwarePredicate p_286587_, LocationPredicate p_286563_, DistancePredicate p_286818_) {
|
||||
super(p_286369_, p_286587_);
|
||||
this.startPosition = p_286563_;
|
||||
this.distance = p_286818_;
|
||||
}
|
||||
|
||||
public static DistanceTrigger.TriggerInstance fallFromHeight(EntityPredicate.Builder p_186198_, DistancePredicate p_186199_, LocationPredicate p_186200_) {
|
||||
return new DistanceTrigger.TriggerInstance(CriteriaTriggers.FALL_FROM_HEIGHT.id, EntityPredicate.wrap(p_186198_.build()), p_186200_, p_186199_);
|
||||
}
|
||||
|
||||
public static DistanceTrigger.TriggerInstance rideEntityInLava(EntityPredicate.Builder p_186195_, DistancePredicate p_186196_) {
|
||||
return new DistanceTrigger.TriggerInstance(CriteriaTriggers.RIDE_ENTITY_IN_LAVA_TRIGGER.id, EntityPredicate.wrap(p_186195_.build()), LocationPredicate.ANY, p_186196_);
|
||||
}
|
||||
|
||||
public static DistanceTrigger.TriggerInstance travelledThroughNether(DistancePredicate p_186193_) {
|
||||
return new DistanceTrigger.TriggerInstance(CriteriaTriggers.NETHER_TRAVEL.id, ContextAwarePredicate.ANY, LocationPredicate.ANY, p_186193_);
|
||||
}
|
||||
|
||||
public JsonObject serializeToJson(SerializationContext p_186202_) {
|
||||
JsonObject jsonobject = super.serializeToJson(p_186202_);
|
||||
jsonobject.add("start_position", this.startPosition.serializeToJson());
|
||||
jsonobject.add("distance", this.distance.serializeToJson());
|
||||
return jsonobject;
|
||||
}
|
||||
|
||||
public boolean matches(ServerLevel p_186189_, Vec3 p_186190_, Vec3 p_186191_) {
|
||||
if (!this.startPosition.matches(p_186189_, p_186190_.x, p_186190_.y, p_186190_.z)) {
|
||||
return false;
|
||||
} else {
|
||||
return this.distance.matches(p_186190_.x, p_186190_.y, p_186190_.z, p_186191_.x, p_186191_.y, p_186191_.z);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.storage.loot.LootContext;
|
||||
|
||||
public class EffectsChangedTrigger extends SimpleCriterionTrigger<EffectsChangedTrigger.TriggerInstance> {
|
||||
static final ResourceLocation ID = new ResourceLocation("effects_changed");
|
||||
|
||||
public ResourceLocation getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
public EffectsChangedTrigger.TriggerInstance createInstance(JsonObject p_286892_, ContextAwarePredicate p_286547_, DeserializationContext p_286271_) {
|
||||
MobEffectsPredicate mobeffectspredicate = MobEffectsPredicate.fromJson(p_286892_.get("effects"));
|
||||
ContextAwarePredicate contextawarepredicate = EntityPredicate.fromJson(p_286892_, "source", p_286271_);
|
||||
return new EffectsChangedTrigger.TriggerInstance(p_286547_, mobeffectspredicate, contextawarepredicate);
|
||||
}
|
||||
|
||||
public void trigger(ServerPlayer p_149263_, @Nullable Entity p_149264_) {
|
||||
LootContext lootcontext = p_149264_ != null ? EntityPredicate.createContext(p_149263_, p_149264_) : null;
|
||||
this.trigger(p_149263_, (p_149268_) -> {
|
||||
return p_149268_.matches(p_149263_, lootcontext);
|
||||
});
|
||||
}
|
||||
|
||||
public static class TriggerInstance extends AbstractCriterionTriggerInstance {
|
||||
private final MobEffectsPredicate effects;
|
||||
private final ContextAwarePredicate source;
|
||||
|
||||
public TriggerInstance(ContextAwarePredicate p_286580_, MobEffectsPredicate p_286820_, ContextAwarePredicate p_286703_) {
|
||||
super(EffectsChangedTrigger.ID, p_286580_);
|
||||
this.effects = p_286820_;
|
||||
this.source = p_286703_;
|
||||
}
|
||||
|
||||
public static EffectsChangedTrigger.TriggerInstance hasEffects(MobEffectsPredicate p_26781_) {
|
||||
return new EffectsChangedTrigger.TriggerInstance(ContextAwarePredicate.ANY, p_26781_, ContextAwarePredicate.ANY);
|
||||
}
|
||||
|
||||
public static EffectsChangedTrigger.TriggerInstance gotEffectsFrom(EntityPredicate p_149278_) {
|
||||
return new EffectsChangedTrigger.TriggerInstance(ContextAwarePredicate.ANY, MobEffectsPredicate.ANY, EntityPredicate.wrap(p_149278_));
|
||||
}
|
||||
|
||||
public boolean matches(ServerPlayer p_149275_, @Nullable LootContext p_149276_) {
|
||||
if (!this.effects.matches(p_149275_)) {
|
||||
return false;
|
||||
} else {
|
||||
return this.source == ContextAwarePredicate.ANY || p_149276_ != null && this.source.matches(p_149276_);
|
||||
}
|
||||
}
|
||||
|
||||
public JsonObject serializeToJson(SerializationContext p_26783_) {
|
||||
JsonObject jsonobject = super.serializeToJson(p_26783_);
|
||||
jsonobject.add("effects", this.effects.serializeToJson());
|
||||
jsonobject.add("source", this.source.toJson(p_26783_));
|
||||
return jsonobject;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
public class EnchantedItemTrigger extends SimpleCriterionTrigger<EnchantedItemTrigger.TriggerInstance> {
|
||||
static final ResourceLocation ID = new ResourceLocation("enchanted_item");
|
||||
|
||||
public ResourceLocation getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
public EnchantedItemTrigger.TriggerInstance createInstance(JsonObject p_286526_, ContextAwarePredicate p_286279_, DeserializationContext p_286881_) {
|
||||
ItemPredicate itempredicate = ItemPredicate.fromJson(p_286526_.get("item"));
|
||||
MinMaxBounds.Ints minmaxbounds$ints = MinMaxBounds.Ints.fromJson(p_286526_.get("levels"));
|
||||
return new EnchantedItemTrigger.TriggerInstance(p_286279_, itempredicate, minmaxbounds$ints);
|
||||
}
|
||||
|
||||
public void trigger(ServerPlayer p_27669_, ItemStack p_27670_, int p_27671_) {
|
||||
this.trigger(p_27669_, (p_27675_) -> {
|
||||
return p_27675_.matches(p_27670_, p_27671_);
|
||||
});
|
||||
}
|
||||
|
||||
public static class TriggerInstance extends AbstractCriterionTriggerInstance {
|
||||
private final ItemPredicate item;
|
||||
private final MinMaxBounds.Ints levels;
|
||||
|
||||
public TriggerInstance(ContextAwarePredicate p_286871_, ItemPredicate p_286640_, MinMaxBounds.Ints p_286367_) {
|
||||
super(EnchantedItemTrigger.ID, p_286871_);
|
||||
this.item = p_286640_;
|
||||
this.levels = p_286367_;
|
||||
}
|
||||
|
||||
public static EnchantedItemTrigger.TriggerInstance enchantedItem() {
|
||||
return new EnchantedItemTrigger.TriggerInstance(ContextAwarePredicate.ANY, ItemPredicate.ANY, MinMaxBounds.Ints.ANY);
|
||||
}
|
||||
|
||||
public boolean matches(ItemStack p_27692_, int p_27693_) {
|
||||
if (!this.item.matches(p_27692_)) {
|
||||
return false;
|
||||
} else {
|
||||
return this.levels.matches(p_27693_);
|
||||
}
|
||||
}
|
||||
|
||||
public JsonObject serializeToJson(SerializationContext p_27695_) {
|
||||
JsonObject jsonobject = super.serializeToJson(p_27695_);
|
||||
jsonobject.add("item", this.item.serializeToJson());
|
||||
jsonobject.add("levels", this.levels.serializeToJson());
|
||||
return jsonobject;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonNull;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import java.util.Map;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
import net.minecraft.world.item.enchantment.Enchantment;
|
||||
|
||||
public class EnchantmentPredicate {
|
||||
public static final EnchantmentPredicate ANY = new EnchantmentPredicate();
|
||||
public static final EnchantmentPredicate[] NONE = new EnchantmentPredicate[0];
|
||||
@Nullable
|
||||
private final Enchantment enchantment;
|
||||
private final MinMaxBounds.Ints level;
|
||||
|
||||
public EnchantmentPredicate() {
|
||||
this.enchantment = null;
|
||||
this.level = MinMaxBounds.Ints.ANY;
|
||||
}
|
||||
|
||||
public EnchantmentPredicate(@Nullable Enchantment p_30471_, MinMaxBounds.Ints p_30472_) {
|
||||
this.enchantment = p_30471_;
|
||||
this.level = p_30472_;
|
||||
}
|
||||
|
||||
public boolean containedIn(Map<Enchantment, Integer> p_30477_) {
|
||||
if (this.enchantment != null) {
|
||||
if (!p_30477_.containsKey(this.enchantment)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int i = p_30477_.get(this.enchantment);
|
||||
if (this.level != MinMaxBounds.Ints.ANY && !this.level.matches(i)) {
|
||||
return false;
|
||||
}
|
||||
} else if (this.level != MinMaxBounds.Ints.ANY) {
|
||||
for(Integer integer : p_30477_.values()) {
|
||||
if (this.level.matches(integer)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public JsonElement serializeToJson() {
|
||||
if (this == ANY) {
|
||||
return JsonNull.INSTANCE;
|
||||
} else {
|
||||
JsonObject jsonobject = new JsonObject();
|
||||
if (this.enchantment != null) {
|
||||
jsonobject.addProperty("enchantment", BuiltInRegistries.ENCHANTMENT.getKey(this.enchantment).toString());
|
||||
}
|
||||
|
||||
jsonobject.add("levels", this.level.serializeToJson());
|
||||
return jsonobject;
|
||||
}
|
||||
}
|
||||
|
||||
public static EnchantmentPredicate fromJson(@Nullable JsonElement p_30475_) {
|
||||
if (p_30475_ != null && !p_30475_.isJsonNull()) {
|
||||
JsonObject jsonobject = GsonHelper.convertToJsonObject(p_30475_, "enchantment");
|
||||
Enchantment enchantment = null;
|
||||
if (jsonobject.has("enchantment")) {
|
||||
ResourceLocation resourcelocation = new ResourceLocation(GsonHelper.getAsString(jsonobject, "enchantment"));
|
||||
enchantment = BuiltInRegistries.ENCHANTMENT.getOptional(resourcelocation).orElseThrow(() -> {
|
||||
return new JsonSyntaxException("Unknown enchantment '" + resourcelocation + "'");
|
||||
});
|
||||
}
|
||||
|
||||
MinMaxBounds.Ints minmaxbounds$ints = MinMaxBounds.Ints.fromJson(jsonobject.get("levels"));
|
||||
return new EnchantmentPredicate(enchantment, minmaxbounds$ints);
|
||||
} else {
|
||||
return ANY;
|
||||
}
|
||||
}
|
||||
|
||||
public static EnchantmentPredicate[] fromJsonArray(@Nullable JsonElement p_30481_) {
|
||||
if (p_30481_ != null && !p_30481_.isJsonNull()) {
|
||||
JsonArray jsonarray = GsonHelper.convertToJsonArray(p_30481_, "enchantments");
|
||||
EnchantmentPredicate[] aenchantmentpredicate = new EnchantmentPredicate[jsonarray.size()];
|
||||
|
||||
for(int i = 0; i < aenchantmentpredicate.length; ++i) {
|
||||
aenchantmentpredicate[i] = fromJson(jsonarray.get(i));
|
||||
}
|
||||
|
||||
return aenchantmentpredicate;
|
||||
} else {
|
||||
return NONE;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
public class EnterBlockTrigger extends SimpleCriterionTrigger<EnterBlockTrigger.TriggerInstance> {
|
||||
static final ResourceLocation ID = new ResourceLocation("enter_block");
|
||||
|
||||
public ResourceLocation getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
public EnterBlockTrigger.TriggerInstance createInstance(JsonObject p_286490_, ContextAwarePredicate p_286595_, DeserializationContext p_286764_) {
|
||||
Block block = deserializeBlock(p_286490_);
|
||||
StatePropertiesPredicate statepropertiespredicate = StatePropertiesPredicate.fromJson(p_286490_.get("state"));
|
||||
if (block != null) {
|
||||
statepropertiespredicate.checkState(block.getStateDefinition(), (p_31274_) -> {
|
||||
throw new JsonSyntaxException("Block " + block + " has no property " + p_31274_);
|
||||
});
|
||||
}
|
||||
|
||||
return new EnterBlockTrigger.TriggerInstance(p_286595_, block, statepropertiespredicate);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static Block deserializeBlock(JsonObject p_31279_) {
|
||||
if (p_31279_.has("block")) {
|
||||
ResourceLocation resourcelocation = new ResourceLocation(GsonHelper.getAsString(p_31279_, "block"));
|
||||
return BuiltInRegistries.BLOCK.getOptional(resourcelocation).orElseThrow(() -> {
|
||||
return new JsonSyntaxException("Unknown block type '" + resourcelocation + "'");
|
||||
});
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void trigger(ServerPlayer p_31270_, BlockState p_31271_) {
|
||||
this.trigger(p_31270_, (p_31277_) -> {
|
||||
return p_31277_.matches(p_31271_);
|
||||
});
|
||||
}
|
||||
|
||||
public static class TriggerInstance extends AbstractCriterionTriggerInstance {
|
||||
@Nullable
|
||||
private final Block block;
|
||||
private final StatePropertiesPredicate state;
|
||||
|
||||
public TriggerInstance(ContextAwarePredicate p_286269_, @Nullable Block p_286517_, StatePropertiesPredicate p_286864_) {
|
||||
super(EnterBlockTrigger.ID, p_286269_);
|
||||
this.block = p_286517_;
|
||||
this.state = p_286864_;
|
||||
}
|
||||
|
||||
public static EnterBlockTrigger.TriggerInstance entersBlock(Block p_31298_) {
|
||||
return new EnterBlockTrigger.TriggerInstance(ContextAwarePredicate.ANY, p_31298_, StatePropertiesPredicate.ANY);
|
||||
}
|
||||
|
||||
public JsonObject serializeToJson(SerializationContext p_31302_) {
|
||||
JsonObject jsonobject = super.serializeToJson(p_31302_);
|
||||
if (this.block != null) {
|
||||
jsonobject.addProperty("block", BuiltInRegistries.BLOCK.getKey(this.block).toString());
|
||||
}
|
||||
|
||||
jsonobject.add("state", this.state.serializeToJson());
|
||||
return jsonobject;
|
||||
}
|
||||
|
||||
public boolean matches(BlockState p_31300_) {
|
||||
if (this.block != null && !p_31300_.is(this.block)) {
|
||||
return false;
|
||||
} else {
|
||||
return this.state.matches(p_31300_);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonNull;
|
||||
import com.google.gson.JsonObject;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.raid.Raid;
|
||||
import net.minecraft.world.item.Items;
|
||||
|
||||
public class EntityEquipmentPredicate {
|
||||
public static final EntityEquipmentPredicate ANY = new EntityEquipmentPredicate(ItemPredicate.ANY, ItemPredicate.ANY, ItemPredicate.ANY, ItemPredicate.ANY, ItemPredicate.ANY, ItemPredicate.ANY);
|
||||
public static final EntityEquipmentPredicate CAPTAIN = new EntityEquipmentPredicate(ItemPredicate.Builder.item().of(Items.WHITE_BANNER).hasNbt(Raid.getLeaderBannerInstance().getTag()).build(), ItemPredicate.ANY, ItemPredicate.ANY, ItemPredicate.ANY, ItemPredicate.ANY, ItemPredicate.ANY);
|
||||
private final ItemPredicate head;
|
||||
private final ItemPredicate chest;
|
||||
private final ItemPredicate legs;
|
||||
private final ItemPredicate feet;
|
||||
private final ItemPredicate mainhand;
|
||||
private final ItemPredicate offhand;
|
||||
|
||||
public EntityEquipmentPredicate(ItemPredicate p_32186_, ItemPredicate p_32187_, ItemPredicate p_32188_, ItemPredicate p_32189_, ItemPredicate p_32190_, ItemPredicate p_32191_) {
|
||||
this.head = p_32186_;
|
||||
this.chest = p_32187_;
|
||||
this.legs = p_32188_;
|
||||
this.feet = p_32189_;
|
||||
this.mainhand = p_32190_;
|
||||
this.offhand = p_32191_;
|
||||
}
|
||||
|
||||
public boolean matches(@Nullable Entity p_32194_) {
|
||||
if (this == ANY) {
|
||||
return true;
|
||||
} else if (!(p_32194_ instanceof LivingEntity)) {
|
||||
return false;
|
||||
} else {
|
||||
LivingEntity livingentity = (LivingEntity)p_32194_;
|
||||
if (!this.head.matches(livingentity.getItemBySlot(EquipmentSlot.HEAD))) {
|
||||
return false;
|
||||
} else if (!this.chest.matches(livingentity.getItemBySlot(EquipmentSlot.CHEST))) {
|
||||
return false;
|
||||
} else if (!this.legs.matches(livingentity.getItemBySlot(EquipmentSlot.LEGS))) {
|
||||
return false;
|
||||
} else if (!this.feet.matches(livingentity.getItemBySlot(EquipmentSlot.FEET))) {
|
||||
return false;
|
||||
} else if (!this.mainhand.matches(livingentity.getItemBySlot(EquipmentSlot.MAINHAND))) {
|
||||
return false;
|
||||
} else {
|
||||
return this.offhand.matches(livingentity.getItemBySlot(EquipmentSlot.OFFHAND));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static EntityEquipmentPredicate fromJson(@Nullable JsonElement p_32196_) {
|
||||
if (p_32196_ != null && !p_32196_.isJsonNull()) {
|
||||
JsonObject jsonobject = GsonHelper.convertToJsonObject(p_32196_, "equipment");
|
||||
ItemPredicate itempredicate = ItemPredicate.fromJson(jsonobject.get("head"));
|
||||
ItemPredicate itempredicate1 = ItemPredicate.fromJson(jsonobject.get("chest"));
|
||||
ItemPredicate itempredicate2 = ItemPredicate.fromJson(jsonobject.get("legs"));
|
||||
ItemPredicate itempredicate3 = ItemPredicate.fromJson(jsonobject.get("feet"));
|
||||
ItemPredicate itempredicate4 = ItemPredicate.fromJson(jsonobject.get("mainhand"));
|
||||
ItemPredicate itempredicate5 = ItemPredicate.fromJson(jsonobject.get("offhand"));
|
||||
return new EntityEquipmentPredicate(itempredicate, itempredicate1, itempredicate2, itempredicate3, itempredicate4, itempredicate5);
|
||||
} else {
|
||||
return ANY;
|
||||
}
|
||||
}
|
||||
|
||||
public JsonElement serializeToJson() {
|
||||
if (this == ANY) {
|
||||
return JsonNull.INSTANCE;
|
||||
} else {
|
||||
JsonObject jsonobject = new JsonObject();
|
||||
jsonobject.add("head", this.head.serializeToJson());
|
||||
jsonobject.add("chest", this.chest.serializeToJson());
|
||||
jsonobject.add("legs", this.legs.serializeToJson());
|
||||
jsonobject.add("feet", this.feet.serializeToJson());
|
||||
jsonobject.add("mainhand", this.mainhand.serializeToJson());
|
||||
jsonobject.add("offhand", this.offhand.serializeToJson());
|
||||
return jsonobject;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private ItemPredicate head = ItemPredicate.ANY;
|
||||
private ItemPredicate chest = ItemPredicate.ANY;
|
||||
private ItemPredicate legs = ItemPredicate.ANY;
|
||||
private ItemPredicate feet = ItemPredicate.ANY;
|
||||
private ItemPredicate mainhand = ItemPredicate.ANY;
|
||||
private ItemPredicate offhand = ItemPredicate.ANY;
|
||||
|
||||
public static EntityEquipmentPredicate.Builder equipment() {
|
||||
return new EntityEquipmentPredicate.Builder();
|
||||
}
|
||||
|
||||
public EntityEquipmentPredicate.Builder head(ItemPredicate p_32206_) {
|
||||
this.head = p_32206_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EntityEquipmentPredicate.Builder chest(ItemPredicate p_32209_) {
|
||||
this.chest = p_32209_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EntityEquipmentPredicate.Builder legs(ItemPredicate p_32211_) {
|
||||
this.legs = p_32211_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EntityEquipmentPredicate.Builder feet(ItemPredicate p_32213_) {
|
||||
this.feet = p_32213_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EntityEquipmentPredicate.Builder mainhand(ItemPredicate p_149929_) {
|
||||
this.mainhand = p_149929_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EntityEquipmentPredicate.Builder offhand(ItemPredicate p_149931_) {
|
||||
this.offhand = p_149931_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EntityEquipmentPredicate build() {
|
||||
return new EntityEquipmentPredicate(this.head, this.chest, this.legs, this.feet, this.mainhand, this.offhand);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonNull;
|
||||
import com.google.gson.JsonObject;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
|
||||
public class EntityFlagsPredicate {
|
||||
public static final EntityFlagsPredicate ANY = (new EntityFlagsPredicate.Builder()).build();
|
||||
@Nullable
|
||||
private final Boolean isOnFire;
|
||||
@Nullable
|
||||
private final Boolean isCrouching;
|
||||
@Nullable
|
||||
private final Boolean isSprinting;
|
||||
@Nullable
|
||||
private final Boolean isSwimming;
|
||||
@Nullable
|
||||
private final Boolean isBaby;
|
||||
|
||||
public EntityFlagsPredicate(@Nullable Boolean p_33690_, @Nullable Boolean p_33691_, @Nullable Boolean p_33692_, @Nullable Boolean p_33693_, @Nullable Boolean p_33694_) {
|
||||
this.isOnFire = p_33690_;
|
||||
this.isCrouching = p_33691_;
|
||||
this.isSprinting = p_33692_;
|
||||
this.isSwimming = p_33693_;
|
||||
this.isBaby = p_33694_;
|
||||
}
|
||||
|
||||
public boolean matches(Entity p_33697_) {
|
||||
if (this.isOnFire != null && p_33697_.isOnFire() != this.isOnFire) {
|
||||
return false;
|
||||
} else if (this.isCrouching != null && p_33697_.isCrouching() != this.isCrouching) {
|
||||
return false;
|
||||
} else if (this.isSprinting != null && p_33697_.isSprinting() != this.isSprinting) {
|
||||
return false;
|
||||
} else if (this.isSwimming != null && p_33697_.isSwimming() != this.isSwimming) {
|
||||
return false;
|
||||
} else {
|
||||
return this.isBaby == null || !(p_33697_ instanceof LivingEntity) || ((LivingEntity)p_33697_).isBaby() == this.isBaby;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static Boolean getOptionalBoolean(JsonObject p_33701_, String p_33702_) {
|
||||
return p_33701_.has(p_33702_) ? GsonHelper.getAsBoolean(p_33701_, p_33702_) : null;
|
||||
}
|
||||
|
||||
public static EntityFlagsPredicate fromJson(@Nullable JsonElement p_33699_) {
|
||||
if (p_33699_ != null && !p_33699_.isJsonNull()) {
|
||||
JsonObject jsonobject = GsonHelper.convertToJsonObject(p_33699_, "entity flags");
|
||||
Boolean obool = getOptionalBoolean(jsonobject, "is_on_fire");
|
||||
Boolean obool1 = getOptionalBoolean(jsonobject, "is_sneaking");
|
||||
Boolean obool2 = getOptionalBoolean(jsonobject, "is_sprinting");
|
||||
Boolean obool3 = getOptionalBoolean(jsonobject, "is_swimming");
|
||||
Boolean obool4 = getOptionalBoolean(jsonobject, "is_baby");
|
||||
return new EntityFlagsPredicate(obool, obool1, obool2, obool3, obool4);
|
||||
} else {
|
||||
return ANY;
|
||||
}
|
||||
}
|
||||
|
||||
private void addOptionalBoolean(JsonObject p_33704_, String p_33705_, @Nullable Boolean p_33706_) {
|
||||
if (p_33706_ != null) {
|
||||
p_33704_.addProperty(p_33705_, p_33706_);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public JsonElement serializeToJson() {
|
||||
if (this == ANY) {
|
||||
return JsonNull.INSTANCE;
|
||||
} else {
|
||||
JsonObject jsonobject = new JsonObject();
|
||||
this.addOptionalBoolean(jsonobject, "is_on_fire", this.isOnFire);
|
||||
this.addOptionalBoolean(jsonobject, "is_sneaking", this.isCrouching);
|
||||
this.addOptionalBoolean(jsonobject, "is_sprinting", this.isSprinting);
|
||||
this.addOptionalBoolean(jsonobject, "is_swimming", this.isSwimming);
|
||||
this.addOptionalBoolean(jsonobject, "is_baby", this.isBaby);
|
||||
return jsonobject;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
@Nullable
|
||||
private Boolean isOnFire;
|
||||
@Nullable
|
||||
private Boolean isCrouching;
|
||||
@Nullable
|
||||
private Boolean isSprinting;
|
||||
@Nullable
|
||||
private Boolean isSwimming;
|
||||
@Nullable
|
||||
private Boolean isBaby;
|
||||
|
||||
public static EntityFlagsPredicate.Builder flags() {
|
||||
return new EntityFlagsPredicate.Builder();
|
||||
}
|
||||
|
||||
public EntityFlagsPredicate.Builder setOnFire(@Nullable Boolean p_33715_) {
|
||||
this.isOnFire = p_33715_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EntityFlagsPredicate.Builder setCrouching(@Nullable Boolean p_150058_) {
|
||||
this.isCrouching = p_150058_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EntityFlagsPredicate.Builder setSprinting(@Nullable Boolean p_150060_) {
|
||||
this.isSprinting = p_150060_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EntityFlagsPredicate.Builder setSwimming(@Nullable Boolean p_150062_) {
|
||||
this.isSwimming = p_150062_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EntityFlagsPredicate.Builder setIsBaby(@Nullable Boolean p_33718_) {
|
||||
this.isBaby = p_33718_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EntityFlagsPredicate build() {
|
||||
return new EntityFlagsPredicate(this.isOnFire, this.isCrouching, this.isSprinting, this.isSwimming, this.isBaby);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
|
||||
public class EntityHurtPlayerTrigger extends SimpleCriterionTrigger<EntityHurtPlayerTrigger.TriggerInstance> {
|
||||
static final ResourceLocation ID = new ResourceLocation("entity_hurt_player");
|
||||
|
||||
public ResourceLocation getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
public EntityHurtPlayerTrigger.TriggerInstance createInstance(JsonObject p_286446_, ContextAwarePredicate p_286687_, DeserializationContext p_286799_) {
|
||||
DamagePredicate damagepredicate = DamagePredicate.fromJson(p_286446_.get("damage"));
|
||||
return new EntityHurtPlayerTrigger.TriggerInstance(p_286687_, damagepredicate);
|
||||
}
|
||||
|
||||
public void trigger(ServerPlayer p_35175_, DamageSource p_35176_, float p_35177_, float p_35178_, boolean p_35179_) {
|
||||
this.trigger(p_35175_, (p_35186_) -> {
|
||||
return p_35186_.matches(p_35175_, p_35176_, p_35177_, p_35178_, p_35179_);
|
||||
});
|
||||
}
|
||||
|
||||
public static class TriggerInstance extends AbstractCriterionTriggerInstance {
|
||||
private final DamagePredicate damage;
|
||||
|
||||
public TriggerInstance(ContextAwarePredicate p_286419_, DamagePredicate p_286408_) {
|
||||
super(EntityHurtPlayerTrigger.ID, p_286419_);
|
||||
this.damage = p_286408_;
|
||||
}
|
||||
|
||||
public static EntityHurtPlayerTrigger.TriggerInstance entityHurtPlayer() {
|
||||
return new EntityHurtPlayerTrigger.TriggerInstance(ContextAwarePredicate.ANY, DamagePredicate.ANY);
|
||||
}
|
||||
|
||||
public static EntityHurtPlayerTrigger.TriggerInstance entityHurtPlayer(DamagePredicate p_150188_) {
|
||||
return new EntityHurtPlayerTrigger.TriggerInstance(ContextAwarePredicate.ANY, p_150188_);
|
||||
}
|
||||
|
||||
public static EntityHurtPlayerTrigger.TriggerInstance entityHurtPlayer(DamagePredicate.Builder p_35207_) {
|
||||
return new EntityHurtPlayerTrigger.TriggerInstance(ContextAwarePredicate.ANY, p_35207_.build());
|
||||
}
|
||||
|
||||
public boolean matches(ServerPlayer p_35201_, DamageSource p_35202_, float p_35203_, float p_35204_, boolean p_35205_) {
|
||||
return this.damage.matches(p_35201_, p_35202_, p_35203_, p_35204_, p_35205_);
|
||||
}
|
||||
|
||||
public JsonObject serializeToJson(SerializationContext p_35209_) {
|
||||
JsonObject jsonobject = super.serializeToJson(p_35209_);
|
||||
jsonobject.add("damage", this.damage.serializeToJson());
|
||||
return jsonobject;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,324 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonNull;
|
||||
import com.google.gson.JsonObject;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.Mob;
|
||||
import net.minecraft.world.level.storage.loot.LootContext;
|
||||
import net.minecraft.world.level.storage.loot.LootParams;
|
||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets;
|
||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
|
||||
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;
|
||||
import net.minecraft.world.level.storage.loot.predicates.LootItemEntityPropertyCondition;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraft.world.scores.Team;
|
||||
|
||||
public class EntityPredicate {
|
||||
public static final EntityPredicate ANY = new EntityPredicate(EntityTypePredicate.ANY, DistancePredicate.ANY, LocationPredicate.ANY, LocationPredicate.ANY, MobEffectsPredicate.ANY, NbtPredicate.ANY, EntityFlagsPredicate.ANY, EntityEquipmentPredicate.ANY, EntitySubPredicate.ANY, (String)null);
|
||||
private final EntityTypePredicate entityType;
|
||||
private final DistancePredicate distanceToPlayer;
|
||||
private final LocationPredicate location;
|
||||
private final LocationPredicate steppingOnLocation;
|
||||
private final MobEffectsPredicate effects;
|
||||
private final NbtPredicate nbt;
|
||||
private final EntityFlagsPredicate flags;
|
||||
private final EntityEquipmentPredicate equipment;
|
||||
private final EntitySubPredicate subPredicate;
|
||||
private final EntityPredicate vehicle;
|
||||
private final EntityPredicate passenger;
|
||||
private final EntityPredicate targetedEntity;
|
||||
@Nullable
|
||||
private final String team;
|
||||
|
||||
private EntityPredicate(EntityTypePredicate p_218789_, DistancePredicate p_218790_, LocationPredicate p_218791_, LocationPredicate p_218792_, MobEffectsPredicate p_218793_, NbtPredicate p_218794_, EntityFlagsPredicate p_218795_, EntityEquipmentPredicate p_218796_, EntitySubPredicate p_218797_, @Nullable String p_218798_) {
|
||||
this.entityType = p_218789_;
|
||||
this.distanceToPlayer = p_218790_;
|
||||
this.location = p_218791_;
|
||||
this.steppingOnLocation = p_218792_;
|
||||
this.effects = p_218793_;
|
||||
this.nbt = p_218794_;
|
||||
this.flags = p_218795_;
|
||||
this.equipment = p_218796_;
|
||||
this.subPredicate = p_218797_;
|
||||
this.passenger = this;
|
||||
this.vehicle = this;
|
||||
this.targetedEntity = this;
|
||||
this.team = p_218798_;
|
||||
}
|
||||
|
||||
EntityPredicate(EntityTypePredicate p_218775_, DistancePredicate p_218776_, LocationPredicate p_218777_, LocationPredicate p_218778_, MobEffectsPredicate p_218779_, NbtPredicate p_218780_, EntityFlagsPredicate p_218781_, EntityEquipmentPredicate p_218782_, EntitySubPredicate p_218783_, EntityPredicate p_218784_, EntityPredicate p_218785_, EntityPredicate p_218786_, @Nullable String p_218787_) {
|
||||
this.entityType = p_218775_;
|
||||
this.distanceToPlayer = p_218776_;
|
||||
this.location = p_218777_;
|
||||
this.steppingOnLocation = p_218778_;
|
||||
this.effects = p_218779_;
|
||||
this.nbt = p_218780_;
|
||||
this.flags = p_218781_;
|
||||
this.equipment = p_218782_;
|
||||
this.subPredicate = p_218783_;
|
||||
this.vehicle = p_218784_;
|
||||
this.passenger = p_218785_;
|
||||
this.targetedEntity = p_218786_;
|
||||
this.team = p_218787_;
|
||||
}
|
||||
|
||||
public static ContextAwarePredicate fromJson(JsonObject p_286877_, String p_286245_, DeserializationContext p_286427_) {
|
||||
JsonElement jsonelement = p_286877_.get(p_286245_);
|
||||
return fromElement(p_286245_, p_286427_, jsonelement);
|
||||
}
|
||||
|
||||
public static ContextAwarePredicate[] fromJsonArray(JsonObject p_286850_, String p_286682_, DeserializationContext p_286876_) {
|
||||
JsonElement jsonelement = p_286850_.get(p_286682_);
|
||||
if (jsonelement != null && !jsonelement.isJsonNull()) {
|
||||
JsonArray jsonarray = GsonHelper.convertToJsonArray(jsonelement, p_286682_);
|
||||
ContextAwarePredicate[] acontextawarepredicate = new ContextAwarePredicate[jsonarray.size()];
|
||||
|
||||
for(int i = 0; i < jsonarray.size(); ++i) {
|
||||
acontextawarepredicate[i] = fromElement(p_286682_ + "[" + i + "]", p_286876_, jsonarray.get(i));
|
||||
}
|
||||
|
||||
return acontextawarepredicate;
|
||||
} else {
|
||||
return new ContextAwarePredicate[0];
|
||||
}
|
||||
}
|
||||
|
||||
private static ContextAwarePredicate fromElement(String p_286569_, DeserializationContext p_286821_, @Nullable JsonElement p_286582_) {
|
||||
ContextAwarePredicate contextawarepredicate = ContextAwarePredicate.fromElement(p_286569_, p_286821_, p_286582_, LootContextParamSets.ADVANCEMENT_ENTITY);
|
||||
if (contextawarepredicate != null) {
|
||||
return contextawarepredicate;
|
||||
} else {
|
||||
EntityPredicate entitypredicate = fromJson(p_286582_);
|
||||
return wrap(entitypredicate);
|
||||
}
|
||||
}
|
||||
|
||||
public static ContextAwarePredicate wrap(EntityPredicate p_286570_) {
|
||||
if (p_286570_ == ANY) {
|
||||
return ContextAwarePredicate.ANY;
|
||||
} else {
|
||||
LootItemCondition lootitemcondition = LootItemEntityPropertyCondition.hasProperties(LootContext.EntityTarget.THIS, p_286570_).build();
|
||||
return new ContextAwarePredicate(new LootItemCondition[]{lootitemcondition});
|
||||
}
|
||||
}
|
||||
|
||||
public boolean matches(ServerPlayer p_36612_, @Nullable Entity p_36613_) {
|
||||
return this.matches(p_36612_.serverLevel(), p_36612_.position(), p_36613_);
|
||||
}
|
||||
|
||||
public boolean matches(ServerLevel p_36608_, @Nullable Vec3 p_36609_, @Nullable Entity p_36610_) {
|
||||
if (this == ANY) {
|
||||
return true;
|
||||
} else if (p_36610_ == null) {
|
||||
return false;
|
||||
} else if (!this.entityType.matches(p_36610_.getType())) {
|
||||
return false;
|
||||
} else {
|
||||
if (p_36609_ == null) {
|
||||
if (this.distanceToPlayer != DistancePredicate.ANY) {
|
||||
return false;
|
||||
}
|
||||
} else if (!this.distanceToPlayer.matches(p_36609_.x, p_36609_.y, p_36609_.z, p_36610_.getX(), p_36610_.getY(), p_36610_.getZ())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this.location.matches(p_36608_, p_36610_.getX(), p_36610_.getY(), p_36610_.getZ())) {
|
||||
return false;
|
||||
} else {
|
||||
if (this.steppingOnLocation != LocationPredicate.ANY) {
|
||||
Vec3 vec3 = Vec3.atCenterOf(p_36610_.getOnPos());
|
||||
if (!this.steppingOnLocation.matches(p_36608_, vec3.x(), vec3.y(), vec3.z())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.effects.matches(p_36610_)) {
|
||||
return false;
|
||||
} else if (!this.nbt.matches(p_36610_)) {
|
||||
return false;
|
||||
} else if (!this.flags.matches(p_36610_)) {
|
||||
return false;
|
||||
} else if (!this.equipment.matches(p_36610_)) {
|
||||
return false;
|
||||
} else if (!this.subPredicate.matches(p_36610_, p_36608_, p_36609_)) {
|
||||
return false;
|
||||
} else if (!this.vehicle.matches(p_36608_, p_36609_, p_36610_.getVehicle())) {
|
||||
return false;
|
||||
} else if (this.passenger != ANY && p_36610_.getPassengers().stream().noneMatch((p_150322_) -> {
|
||||
return this.passenger.matches(p_36608_, p_36609_, p_150322_);
|
||||
})) {
|
||||
return false;
|
||||
} else if (!this.targetedEntity.matches(p_36608_, p_36609_, p_36610_ instanceof Mob ? ((Mob)p_36610_).getTarget() : null)) {
|
||||
return false;
|
||||
} else {
|
||||
if (this.team != null) {
|
||||
Team team = p_36610_.getTeam();
|
||||
if (team == null || !this.team.equals(team.getName())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static EntityPredicate fromJson(@Nullable JsonElement p_36615_) {
|
||||
if (p_36615_ != null && !p_36615_.isJsonNull()) {
|
||||
JsonObject jsonobject = GsonHelper.convertToJsonObject(p_36615_, "entity");
|
||||
EntityTypePredicate entitytypepredicate = EntityTypePredicate.fromJson(jsonobject.get("type"));
|
||||
DistancePredicate distancepredicate = DistancePredicate.fromJson(jsonobject.get("distance"));
|
||||
LocationPredicate locationpredicate = LocationPredicate.fromJson(jsonobject.get("location"));
|
||||
LocationPredicate locationpredicate1 = LocationPredicate.fromJson(jsonobject.get("stepping_on"));
|
||||
MobEffectsPredicate mobeffectspredicate = MobEffectsPredicate.fromJson(jsonobject.get("effects"));
|
||||
NbtPredicate nbtpredicate = NbtPredicate.fromJson(jsonobject.get("nbt"));
|
||||
EntityFlagsPredicate entityflagspredicate = EntityFlagsPredicate.fromJson(jsonobject.get("flags"));
|
||||
EntityEquipmentPredicate entityequipmentpredicate = EntityEquipmentPredicate.fromJson(jsonobject.get("equipment"));
|
||||
EntitySubPredicate entitysubpredicate = EntitySubPredicate.fromJson(jsonobject.get("type_specific"));
|
||||
EntityPredicate entitypredicate = fromJson(jsonobject.get("vehicle"));
|
||||
EntityPredicate entitypredicate1 = fromJson(jsonobject.get("passenger"));
|
||||
EntityPredicate entitypredicate2 = fromJson(jsonobject.get("targeted_entity"));
|
||||
String s = GsonHelper.getAsString(jsonobject, "team", (String)null);
|
||||
return (new EntityPredicate.Builder()).entityType(entitytypepredicate).distance(distancepredicate).located(locationpredicate).steppingOn(locationpredicate1).effects(mobeffectspredicate).nbt(nbtpredicate).flags(entityflagspredicate).equipment(entityequipmentpredicate).subPredicate(entitysubpredicate).team(s).vehicle(entitypredicate).passenger(entitypredicate1).targetedEntity(entitypredicate2).build();
|
||||
} else {
|
||||
return ANY;
|
||||
}
|
||||
}
|
||||
|
||||
public JsonElement serializeToJson() {
|
||||
if (this == ANY) {
|
||||
return JsonNull.INSTANCE;
|
||||
} else {
|
||||
JsonObject jsonobject = new JsonObject();
|
||||
jsonobject.add("type", this.entityType.serializeToJson());
|
||||
jsonobject.add("distance", this.distanceToPlayer.serializeToJson());
|
||||
jsonobject.add("location", this.location.serializeToJson());
|
||||
jsonobject.add("stepping_on", this.steppingOnLocation.serializeToJson());
|
||||
jsonobject.add("effects", this.effects.serializeToJson());
|
||||
jsonobject.add("nbt", this.nbt.serializeToJson());
|
||||
jsonobject.add("flags", this.flags.serializeToJson());
|
||||
jsonobject.add("equipment", this.equipment.serializeToJson());
|
||||
jsonobject.add("type_specific", this.subPredicate.serialize());
|
||||
jsonobject.add("vehicle", this.vehicle.serializeToJson());
|
||||
jsonobject.add("passenger", this.passenger.serializeToJson());
|
||||
jsonobject.add("targeted_entity", this.targetedEntity.serializeToJson());
|
||||
jsonobject.addProperty("team", this.team);
|
||||
return jsonobject;
|
||||
}
|
||||
}
|
||||
|
||||
public static LootContext createContext(ServerPlayer p_36617_, Entity p_36618_) {
|
||||
LootParams lootparams = (new LootParams.Builder(p_36617_.serverLevel())).withParameter(LootContextParams.THIS_ENTITY, p_36618_).withParameter(LootContextParams.ORIGIN, p_36617_.position()).create(LootContextParamSets.ADVANCEMENT_ENTITY);
|
||||
return (new LootContext.Builder(lootparams)).create((ResourceLocation)null);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private EntityTypePredicate entityType = EntityTypePredicate.ANY;
|
||||
private DistancePredicate distanceToPlayer = DistancePredicate.ANY;
|
||||
private LocationPredicate location = LocationPredicate.ANY;
|
||||
private LocationPredicate steppingOnLocation = LocationPredicate.ANY;
|
||||
private MobEffectsPredicate effects = MobEffectsPredicate.ANY;
|
||||
private NbtPredicate nbt = NbtPredicate.ANY;
|
||||
private EntityFlagsPredicate flags = EntityFlagsPredicate.ANY;
|
||||
private EntityEquipmentPredicate equipment = EntityEquipmentPredicate.ANY;
|
||||
private EntitySubPredicate subPredicate = EntitySubPredicate.ANY;
|
||||
private EntityPredicate vehicle = EntityPredicate.ANY;
|
||||
private EntityPredicate passenger = EntityPredicate.ANY;
|
||||
private EntityPredicate targetedEntity = EntityPredicate.ANY;
|
||||
@Nullable
|
||||
private String team;
|
||||
|
||||
public static EntityPredicate.Builder entity() {
|
||||
return new EntityPredicate.Builder();
|
||||
}
|
||||
|
||||
public EntityPredicate.Builder of(EntityType<?> p_36637_) {
|
||||
this.entityType = EntityTypePredicate.of(p_36637_);
|
||||
return this;
|
||||
}
|
||||
|
||||
public EntityPredicate.Builder of(TagKey<EntityType<?>> p_204078_) {
|
||||
this.entityType = EntityTypePredicate.of(p_204078_);
|
||||
return this;
|
||||
}
|
||||
|
||||
public EntityPredicate.Builder entityType(EntityTypePredicate p_36647_) {
|
||||
this.entityType = p_36647_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EntityPredicate.Builder distance(DistancePredicate p_36639_) {
|
||||
this.distanceToPlayer = p_36639_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EntityPredicate.Builder located(LocationPredicate p_36651_) {
|
||||
this.location = p_36651_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EntityPredicate.Builder steppingOn(LocationPredicate p_150331_) {
|
||||
this.steppingOnLocation = p_150331_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EntityPredicate.Builder effects(MobEffectsPredicate p_36653_) {
|
||||
this.effects = p_36653_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EntityPredicate.Builder nbt(NbtPredicate p_36655_) {
|
||||
this.nbt = p_36655_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EntityPredicate.Builder flags(EntityFlagsPredicate p_36643_) {
|
||||
this.flags = p_36643_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EntityPredicate.Builder equipment(EntityEquipmentPredicate p_36641_) {
|
||||
this.equipment = p_36641_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EntityPredicate.Builder subPredicate(EntitySubPredicate p_218801_) {
|
||||
this.subPredicate = p_218801_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EntityPredicate.Builder vehicle(EntityPredicate p_36645_) {
|
||||
this.vehicle = p_36645_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EntityPredicate.Builder passenger(EntityPredicate p_150329_) {
|
||||
this.passenger = p_150329_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EntityPredicate.Builder targetedEntity(EntityPredicate p_36664_) {
|
||||
this.targetedEntity = p_36664_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EntityPredicate.Builder team(@Nullable String p_36659_) {
|
||||
this.team = p_36659_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EntityPredicate build() {
|
||||
return new EntityPredicate(this.entityType, this.distanceToPlayer, this.location, this.steppingOnLocation, this.effects, this.nbt, this.flags, this.equipment, this.subPredicate, this.vehicle, this.passenger, this.targetedEntity, this.team);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,239 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.ImmutableBiMap;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonNull;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import java.util.Optional;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.animal.Cat;
|
||||
import net.minecraft.world.entity.animal.CatVariant;
|
||||
import net.minecraft.world.entity.animal.Fox;
|
||||
import net.minecraft.world.entity.animal.FrogVariant;
|
||||
import net.minecraft.world.entity.animal.MushroomCow;
|
||||
import net.minecraft.world.entity.animal.Parrot;
|
||||
import net.minecraft.world.entity.animal.Rabbit;
|
||||
import net.minecraft.world.entity.animal.TropicalFish;
|
||||
import net.minecraft.world.entity.animal.axolotl.Axolotl;
|
||||
import net.minecraft.world.entity.animal.frog.Frog;
|
||||
import net.minecraft.world.entity.animal.horse.Horse;
|
||||
import net.minecraft.world.entity.animal.horse.Llama;
|
||||
import net.minecraft.world.entity.animal.horse.Variant;
|
||||
import net.minecraft.world.entity.decoration.Painting;
|
||||
import net.minecraft.world.entity.decoration.PaintingVariant;
|
||||
import net.minecraft.world.entity.npc.VillagerDataHolder;
|
||||
import net.minecraft.world.entity.npc.VillagerType;
|
||||
import net.minecraft.world.entity.vehicle.Boat;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
public interface EntitySubPredicate {
|
||||
EntitySubPredicate ANY = new EntitySubPredicate() {
|
||||
public boolean matches(Entity p_218841_, ServerLevel p_218842_, @Nullable Vec3 p_218843_) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public JsonObject serializeCustomData() {
|
||||
return new JsonObject();
|
||||
}
|
||||
|
||||
public EntitySubPredicate.Type type() {
|
||||
return EntitySubPredicate.Types.ANY;
|
||||
}
|
||||
};
|
||||
|
||||
static EntitySubPredicate fromJson(@Nullable JsonElement p_218836_) {
|
||||
if (p_218836_ != null && !p_218836_.isJsonNull()) {
|
||||
JsonObject jsonobject = GsonHelper.convertToJsonObject(p_218836_, "type_specific");
|
||||
String s = GsonHelper.getAsString(jsonobject, "type", (String)null);
|
||||
if (s == null) {
|
||||
return ANY;
|
||||
} else {
|
||||
EntitySubPredicate.Type entitysubpredicate$type = EntitySubPredicate.Types.TYPES.get(s);
|
||||
if (entitysubpredicate$type == null) {
|
||||
throw new JsonSyntaxException("Unknown sub-predicate type: " + s);
|
||||
} else {
|
||||
return entitysubpredicate$type.deserialize(jsonobject);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return ANY;
|
||||
}
|
||||
}
|
||||
|
||||
boolean matches(Entity p_218828_, ServerLevel p_218829_, @Nullable Vec3 p_218830_);
|
||||
|
||||
JsonObject serializeCustomData();
|
||||
|
||||
default JsonElement serialize() {
|
||||
if (this.type() == EntitySubPredicate.Types.ANY) {
|
||||
return JsonNull.INSTANCE;
|
||||
} else {
|
||||
JsonObject jsonobject = this.serializeCustomData();
|
||||
String s = EntitySubPredicate.Types.TYPES.inverse().get(this.type());
|
||||
jsonobject.addProperty("type", s);
|
||||
return jsonobject;
|
||||
}
|
||||
}
|
||||
|
||||
EntitySubPredicate.Type type();
|
||||
|
||||
static EntitySubPredicate variant(CatVariant p_218832_) {
|
||||
return EntitySubPredicate.Types.CAT.createPredicate(p_218832_);
|
||||
}
|
||||
|
||||
static EntitySubPredicate variant(FrogVariant p_218834_) {
|
||||
return EntitySubPredicate.Types.FROG.createPredicate(p_218834_);
|
||||
}
|
||||
|
||||
public interface Type {
|
||||
EntitySubPredicate deserialize(JsonObject p_218846_);
|
||||
}
|
||||
|
||||
public static final class Types {
|
||||
public static final EntitySubPredicate.Type ANY = (p_218860_) -> {
|
||||
return EntitySubPredicate.ANY;
|
||||
};
|
||||
public static final EntitySubPredicate.Type LIGHTNING = LighthingBoltPredicate::fromJson;
|
||||
public static final EntitySubPredicate.Type FISHING_HOOK = FishingHookPredicate::fromJson;
|
||||
public static final EntitySubPredicate.Type PLAYER = PlayerPredicate::fromJson;
|
||||
public static final EntitySubPredicate.Type SLIME = SlimePredicate::fromJson;
|
||||
public static final EntityVariantPredicate<CatVariant> CAT = EntityVariantPredicate.create(BuiltInRegistries.CAT_VARIANT, (p_218862_) -> {
|
||||
Optional optional;
|
||||
if (p_218862_ instanceof Cat cat) {
|
||||
optional = Optional.of(cat.getVariant());
|
||||
} else {
|
||||
optional = Optional.empty();
|
||||
}
|
||||
|
||||
return optional;
|
||||
});
|
||||
public static final EntityVariantPredicate<FrogVariant> FROG = EntityVariantPredicate.create(BuiltInRegistries.FROG_VARIANT, (p_218858_) -> {
|
||||
Optional optional;
|
||||
if (p_218858_ instanceof Frog frog) {
|
||||
optional = Optional.of(frog.getVariant());
|
||||
} else {
|
||||
optional = Optional.empty();
|
||||
}
|
||||
|
||||
return optional;
|
||||
});
|
||||
public static final EntityVariantPredicate<Axolotl.Variant> AXOLOTL = EntityVariantPredicate.create(Axolotl.Variant.CODEC, (p_262508_) -> {
|
||||
Optional optional;
|
||||
if (p_262508_ instanceof Axolotl axolotl) {
|
||||
optional = Optional.of(axolotl.getVariant());
|
||||
} else {
|
||||
optional = Optional.empty();
|
||||
}
|
||||
|
||||
return optional;
|
||||
});
|
||||
public static final EntityVariantPredicate<Boat.Type> BOAT = EntityVariantPredicate.create(Boat.Type.CODEC, (p_262507_) -> {
|
||||
Optional optional;
|
||||
if (p_262507_ instanceof Boat boat) {
|
||||
optional = Optional.of(boat.getVariant());
|
||||
} else {
|
||||
optional = Optional.empty();
|
||||
}
|
||||
|
||||
return optional;
|
||||
});
|
||||
public static final EntityVariantPredicate<Fox.Type> FOX = EntityVariantPredicate.create(Fox.Type.CODEC, (p_262510_) -> {
|
||||
Optional optional;
|
||||
if (p_262510_ instanceof Fox fox) {
|
||||
optional = Optional.of(fox.getVariant());
|
||||
} else {
|
||||
optional = Optional.empty();
|
||||
}
|
||||
|
||||
return optional;
|
||||
});
|
||||
public static final EntityVariantPredicate<MushroomCow.MushroomType> MOOSHROOM = EntityVariantPredicate.create(MushroomCow.MushroomType.CODEC, (p_262513_) -> {
|
||||
Optional optional;
|
||||
if (p_262513_ instanceof MushroomCow mushroomcow) {
|
||||
optional = Optional.of(mushroomcow.getVariant());
|
||||
} else {
|
||||
optional = Optional.empty();
|
||||
}
|
||||
|
||||
return optional;
|
||||
});
|
||||
public static final EntityVariantPredicate<Holder<PaintingVariant>> PAINTING = EntityVariantPredicate.create(BuiltInRegistries.PAINTING_VARIANT.holderByNameCodec(), (p_262509_) -> {
|
||||
Optional optional;
|
||||
if (p_262509_ instanceof Painting painting) {
|
||||
optional = Optional.of(painting.getVariant());
|
||||
} else {
|
||||
optional = Optional.empty();
|
||||
}
|
||||
|
||||
return optional;
|
||||
});
|
||||
public static final EntityVariantPredicate<Rabbit.Variant> RABBIT = EntityVariantPredicate.create(Rabbit.Variant.CODEC, (p_262511_) -> {
|
||||
Optional optional;
|
||||
if (p_262511_ instanceof Rabbit rabbit) {
|
||||
optional = Optional.of(rabbit.getVariant());
|
||||
} else {
|
||||
optional = Optional.empty();
|
||||
}
|
||||
|
||||
return optional;
|
||||
});
|
||||
public static final EntityVariantPredicate<Variant> HORSE = EntityVariantPredicate.create(Variant.CODEC, (p_262516_) -> {
|
||||
Optional optional;
|
||||
if (p_262516_ instanceof Horse horse) {
|
||||
optional = Optional.of(horse.getVariant());
|
||||
} else {
|
||||
optional = Optional.empty();
|
||||
}
|
||||
|
||||
return optional;
|
||||
});
|
||||
public static final EntityVariantPredicate<Llama.Variant> LLAMA = EntityVariantPredicate.create(Llama.Variant.CODEC, (p_262515_) -> {
|
||||
Optional optional;
|
||||
if (p_262515_ instanceof Llama llama) {
|
||||
optional = Optional.of(llama.getVariant());
|
||||
} else {
|
||||
optional = Optional.empty();
|
||||
}
|
||||
|
||||
return optional;
|
||||
});
|
||||
public static final EntityVariantPredicate<VillagerType> VILLAGER = EntityVariantPredicate.create(BuiltInRegistries.VILLAGER_TYPE.byNameCodec(), (p_262512_) -> {
|
||||
Optional optional;
|
||||
if (p_262512_ instanceof VillagerDataHolder villagerdataholder) {
|
||||
optional = Optional.of(villagerdataholder.getVariant());
|
||||
} else {
|
||||
optional = Optional.empty();
|
||||
}
|
||||
|
||||
return optional;
|
||||
});
|
||||
public static final EntityVariantPredicate<Parrot.Variant> PARROT = EntityVariantPredicate.create(Parrot.Variant.CODEC, (p_262506_) -> {
|
||||
Optional optional;
|
||||
if (p_262506_ instanceof Parrot parrot) {
|
||||
optional = Optional.of(parrot.getVariant());
|
||||
} else {
|
||||
optional = Optional.empty();
|
||||
}
|
||||
|
||||
return optional;
|
||||
});
|
||||
public static final EntityVariantPredicate<TropicalFish.Pattern> TROPICAL_FISH = EntityVariantPredicate.create(TropicalFish.Pattern.CODEC, (p_262517_) -> {
|
||||
Optional optional;
|
||||
if (p_262517_ instanceof TropicalFish tropicalfish) {
|
||||
optional = Optional.of(tropicalfish.getVariant());
|
||||
} else {
|
||||
optional = Optional.empty();
|
||||
}
|
||||
|
||||
return optional;
|
||||
});
|
||||
public static final BiMap<String, EntitySubPredicate.Type> TYPES = ImmutableBiMap.<String, EntitySubPredicate.Type>builder().put("any", ANY).put("lightning", LIGHTNING).put("fishing_hook", FISHING_HOOK).put("player", PLAYER).put("slime", SLIME).put("cat", CAT.type()).put("frog", FROG.type()).put("axolotl", AXOLOTL.type()).put("boat", BOAT.type()).put("fox", FOX.type()).put("mooshroom", MOOSHROOM.type()).put("painting", PAINTING.type()).put("rabbit", RABBIT.type()).put("horse", HORSE.type()).put("llama", LLAMA.type()).put("villager", VILLAGER.type()).put("parrot", PARROT.type()).put("tropical_fish", TROPICAL_FISH.type()).buildOrThrow();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonNull;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
|
||||
public abstract class EntityTypePredicate {
|
||||
public static final EntityTypePredicate ANY = new EntityTypePredicate() {
|
||||
public boolean matches(EntityType<?> p_37652_) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public JsonElement serializeToJson() {
|
||||
return JsonNull.INSTANCE;
|
||||
}
|
||||
};
|
||||
private static final Joiner COMMA_JOINER = Joiner.on(", ");
|
||||
|
||||
public abstract boolean matches(EntityType<?> p_37642_);
|
||||
|
||||
public abstract JsonElement serializeToJson();
|
||||
|
||||
public static EntityTypePredicate fromJson(@Nullable JsonElement p_37644_) {
|
||||
if (p_37644_ != null && !p_37644_.isJsonNull()) {
|
||||
String s = GsonHelper.convertToString(p_37644_, "type");
|
||||
if (s.startsWith("#")) {
|
||||
ResourceLocation resourcelocation1 = new ResourceLocation(s.substring(1));
|
||||
return new EntityTypePredicate.TagPredicate(TagKey.create(Registries.ENTITY_TYPE, resourcelocation1));
|
||||
} else {
|
||||
ResourceLocation resourcelocation = new ResourceLocation(s);
|
||||
EntityType<?> entitytype = BuiltInRegistries.ENTITY_TYPE.getOptional(resourcelocation).orElseThrow(() -> {
|
||||
return new JsonSyntaxException("Unknown entity type '" + resourcelocation + "', valid types are: " + COMMA_JOINER.join(BuiltInRegistries.ENTITY_TYPE.keySet()));
|
||||
});
|
||||
return new EntityTypePredicate.TypePredicate(entitytype);
|
||||
}
|
||||
} else {
|
||||
return ANY;
|
||||
}
|
||||
}
|
||||
|
||||
public static EntityTypePredicate of(EntityType<?> p_37648_) {
|
||||
return new EntityTypePredicate.TypePredicate(p_37648_);
|
||||
}
|
||||
|
||||
public static EntityTypePredicate of(TagKey<EntityType<?>> p_204082_) {
|
||||
return new EntityTypePredicate.TagPredicate(p_204082_);
|
||||
}
|
||||
|
||||
static class TagPredicate extends EntityTypePredicate {
|
||||
private final TagKey<EntityType<?>> tag;
|
||||
|
||||
public TagPredicate(TagKey<EntityType<?>> p_204084_) {
|
||||
this.tag = p_204084_;
|
||||
}
|
||||
|
||||
public boolean matches(EntityType<?> p_37658_) {
|
||||
return p_37658_.is(this.tag);
|
||||
}
|
||||
|
||||
public JsonElement serializeToJson() {
|
||||
return new JsonPrimitive("#" + this.tag.location());
|
||||
}
|
||||
}
|
||||
|
||||
static class TypePredicate extends EntityTypePredicate {
|
||||
private final EntityType<?> type;
|
||||
|
||||
public TypePredicate(EntityType<?> p_37661_) {
|
||||
this.type = p_37661_;
|
||||
}
|
||||
|
||||
public boolean matches(EntityType<?> p_37664_) {
|
||||
return this.type == p_37664_;
|
||||
}
|
||||
|
||||
public JsonElement serializeToJson() {
|
||||
return new JsonPrimitive(BuiltInRegistries.ENTITY_TYPE.getKey(this.type).toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.Dynamic;
|
||||
import com.mojang.serialization.JsonOps;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
public class EntityVariantPredicate<V> {
|
||||
private static final String VARIANT_KEY = "variant";
|
||||
final Codec<V> variantCodec;
|
||||
final Function<Entity, Optional<V>> getter;
|
||||
final EntitySubPredicate.Type type;
|
||||
|
||||
public static <V> EntityVariantPredicate<V> create(Registry<V> p_219094_, Function<Entity, Optional<V>> p_219095_) {
|
||||
return new EntityVariantPredicate<>(p_219094_.byNameCodec(), p_219095_);
|
||||
}
|
||||
|
||||
public static <V> EntityVariantPredicate<V> create(Codec<V> p_262671_, Function<Entity, Optional<V>> p_262652_) {
|
||||
return new EntityVariantPredicate<>(p_262671_, p_262652_);
|
||||
}
|
||||
|
||||
private EntityVariantPredicate(Codec<V> p_262574_, Function<Entity, Optional<V>> p_262610_) {
|
||||
this.variantCodec = p_262574_;
|
||||
this.getter = p_262610_;
|
||||
this.type = (p_262519_) -> {
|
||||
JsonElement jsonelement = p_262519_.get("variant");
|
||||
if (jsonelement == null) {
|
||||
throw new JsonParseException("Missing variant field");
|
||||
} else {
|
||||
V v = Util.getOrThrow(p_262574_.decode(new Dynamic<>(JsonOps.INSTANCE, jsonelement)), JsonParseException::new).getFirst();
|
||||
return this.createPredicate(v);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public EntitySubPredicate.Type type() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public EntitySubPredicate createPredicate(final V p_219097_) {
|
||||
return new EntitySubPredicate() {
|
||||
public boolean matches(Entity p_219105_, ServerLevel p_219106_, @Nullable Vec3 p_219107_) {
|
||||
return EntityVariantPredicate.this.getter.apply(p_219105_).filter((p_219110_) -> {
|
||||
return p_219110_.equals(p_219097_);
|
||||
}).isPresent();
|
||||
}
|
||||
|
||||
public JsonObject serializeCustomData() {
|
||||
JsonObject jsonobject = new JsonObject();
|
||||
jsonobject.add("variant", Util.getOrThrow(EntityVariantPredicate.this.variantCodec.encodeStart(JsonOps.INSTANCE, p_219097_), (p_262521_) -> {
|
||||
return new JsonParseException("Can't serialize variant " + p_219097_ + ", message " + p_262521_);
|
||||
}));
|
||||
return jsonobject;
|
||||
}
|
||||
|
||||
public EntitySubPredicate.Type type() {
|
||||
return EntityVariantPredicate.this.type;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
public class FilledBucketTrigger extends SimpleCriterionTrigger<FilledBucketTrigger.TriggerInstance> {
|
||||
static final ResourceLocation ID = new ResourceLocation("filled_bucket");
|
||||
|
||||
public ResourceLocation getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
public FilledBucketTrigger.TriggerInstance createInstance(JsonObject p_286783_, ContextAwarePredicate p_286776_, DeserializationContext p_286812_) {
|
||||
ItemPredicate itempredicate = ItemPredicate.fromJson(p_286783_.get("item"));
|
||||
return new FilledBucketTrigger.TriggerInstance(p_286776_, itempredicate);
|
||||
}
|
||||
|
||||
public void trigger(ServerPlayer p_38773_, ItemStack p_38774_) {
|
||||
this.trigger(p_38773_, (p_38777_) -> {
|
||||
return p_38777_.matches(p_38774_);
|
||||
});
|
||||
}
|
||||
|
||||
public static class TriggerInstance extends AbstractCriterionTriggerInstance {
|
||||
private final ItemPredicate item;
|
||||
|
||||
public TriggerInstance(ContextAwarePredicate p_286231_, ItemPredicate p_286845_) {
|
||||
super(FilledBucketTrigger.ID, p_286231_);
|
||||
this.item = p_286845_;
|
||||
}
|
||||
|
||||
public static FilledBucketTrigger.TriggerInstance filledBucket(ItemPredicate p_38794_) {
|
||||
return new FilledBucketTrigger.TriggerInstance(ContextAwarePredicate.ANY, p_38794_);
|
||||
}
|
||||
|
||||
public boolean matches(ItemStack p_38792_) {
|
||||
return this.item.matches(p_38792_);
|
||||
}
|
||||
|
||||
public JsonObject serializeToJson(SerializationContext p_38796_) {
|
||||
JsonObject jsonobject = super.serializeToJson(p_38796_);
|
||||
jsonobject.add("item", this.item.serializeToJson());
|
||||
return jsonobject;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.projectile.FishingHook;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
public class FishingHookPredicate implements EntitySubPredicate {
|
||||
public static final FishingHookPredicate ANY = new FishingHookPredicate(false);
|
||||
private static final String IN_OPEN_WATER_KEY = "in_open_water";
|
||||
private final boolean inOpenWater;
|
||||
|
||||
private FishingHookPredicate(boolean p_39760_) {
|
||||
this.inOpenWater = p_39760_;
|
||||
}
|
||||
|
||||
public static FishingHookPredicate inOpenWater(boolean p_39767_) {
|
||||
return new FishingHookPredicate(p_39767_);
|
||||
}
|
||||
|
||||
public static FishingHookPredicate fromJson(JsonObject p_219720_) {
|
||||
JsonElement jsonelement = p_219720_.get("in_open_water");
|
||||
return jsonelement != null ? new FishingHookPredicate(GsonHelper.convertToBoolean(jsonelement, "in_open_water")) : ANY;
|
||||
}
|
||||
|
||||
public JsonObject serializeCustomData() {
|
||||
if (this == ANY) {
|
||||
return new JsonObject();
|
||||
} else {
|
||||
JsonObject jsonobject = new JsonObject();
|
||||
jsonobject.add("in_open_water", new JsonPrimitive(this.inOpenWater));
|
||||
return jsonobject;
|
||||
}
|
||||
}
|
||||
|
||||
public EntitySubPredicate.Type type() {
|
||||
return EntitySubPredicate.Types.FISHING_HOOK;
|
||||
}
|
||||
|
||||
public boolean matches(Entity p_219716_, ServerLevel p_219717_, @Nullable Vec3 p_219718_) {
|
||||
if (this == ANY) {
|
||||
return true;
|
||||
} else if (!(p_219716_ instanceof FishingHook)) {
|
||||
return false;
|
||||
} else {
|
||||
FishingHook fishinghook = (FishingHook)p_219716_;
|
||||
return this.inOpenWater == fishinghook.isOpenWaterFishing();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import java.util.Collection;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.entity.projectile.FishingHook;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.storage.loot.LootContext;
|
||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
|
||||
|
||||
public class FishingRodHookedTrigger extends SimpleCriterionTrigger<FishingRodHookedTrigger.TriggerInstance> {
|
||||
static final ResourceLocation ID = new ResourceLocation("fishing_rod_hooked");
|
||||
|
||||
public ResourceLocation getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
public FishingRodHookedTrigger.TriggerInstance createInstance(JsonObject p_286350_, ContextAwarePredicate p_286888_, DeserializationContext p_286756_) {
|
||||
ItemPredicate itempredicate = ItemPredicate.fromJson(p_286350_.get("rod"));
|
||||
ContextAwarePredicate contextawarepredicate = EntityPredicate.fromJson(p_286350_, "entity", p_286756_);
|
||||
ItemPredicate itempredicate1 = ItemPredicate.fromJson(p_286350_.get("item"));
|
||||
return new FishingRodHookedTrigger.TriggerInstance(p_286888_, itempredicate, contextawarepredicate, itempredicate1);
|
||||
}
|
||||
|
||||
public void trigger(ServerPlayer p_40417_, ItemStack p_40418_, FishingHook p_40419_, Collection<ItemStack> p_40420_) {
|
||||
LootContext lootcontext = EntityPredicate.createContext(p_40417_, (Entity)(p_40419_.getHookedIn() != null ? p_40419_.getHookedIn() : p_40419_));
|
||||
this.trigger(p_40417_, (p_40425_) -> {
|
||||
return p_40425_.matches(p_40418_, lootcontext, p_40420_);
|
||||
});
|
||||
}
|
||||
|
||||
public static class TriggerInstance extends AbstractCriterionTriggerInstance {
|
||||
private final ItemPredicate rod;
|
||||
private final ContextAwarePredicate entity;
|
||||
private final ItemPredicate item;
|
||||
|
||||
public TriggerInstance(ContextAwarePredicate p_286346_, ItemPredicate p_286539_, ContextAwarePredicate p_286253_, ItemPredicate p_286372_) {
|
||||
super(FishingRodHookedTrigger.ID, p_286346_);
|
||||
this.rod = p_286539_;
|
||||
this.entity = p_286253_;
|
||||
this.item = p_286372_;
|
||||
}
|
||||
|
||||
public static FishingRodHookedTrigger.TriggerInstance fishedItem(ItemPredicate p_40448_, EntityPredicate p_40449_, ItemPredicate p_40450_) {
|
||||
return new FishingRodHookedTrigger.TriggerInstance(ContextAwarePredicate.ANY, p_40448_, EntityPredicate.wrap(p_40449_), p_40450_);
|
||||
}
|
||||
|
||||
public boolean matches(ItemStack p_40444_, LootContext p_40445_, Collection<ItemStack> p_40446_) {
|
||||
if (!this.rod.matches(p_40444_)) {
|
||||
return false;
|
||||
} else if (!this.entity.matches(p_40445_)) {
|
||||
return false;
|
||||
} else {
|
||||
if (this.item != ItemPredicate.ANY) {
|
||||
boolean flag = false;
|
||||
Entity entity = p_40445_.getParamOrNull(LootContextParams.THIS_ENTITY);
|
||||
if (entity instanceof ItemEntity) {
|
||||
ItemEntity itementity = (ItemEntity)entity;
|
||||
if (this.item.matches(itementity.getItem())) {
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
|
||||
for(ItemStack itemstack : p_40446_) {
|
||||
if (this.item.matches(itemstack)) {
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!flag) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public JsonObject serializeToJson(SerializationContext p_40452_) {
|
||||
JsonObject jsonobject = super.serializeToJson(p_40452_);
|
||||
jsonobject.add("rod", this.rod.serializeToJson());
|
||||
jsonobject.add("entity", this.entity.toJson(p_40452_));
|
||||
jsonobject.add("item", this.item.serializeToJson());
|
||||
return jsonobject;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonNull;
|
||||
import com.google.gson.JsonObject;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
import net.minecraft.world.level.material.Fluid;
|
||||
import net.minecraft.world.level.material.FluidState;
|
||||
|
||||
public class FluidPredicate {
|
||||
public static final FluidPredicate ANY = new FluidPredicate((TagKey<Fluid>)null, (Fluid)null, StatePropertiesPredicate.ANY);
|
||||
@Nullable
|
||||
private final TagKey<Fluid> tag;
|
||||
@Nullable
|
||||
private final Fluid fluid;
|
||||
private final StatePropertiesPredicate properties;
|
||||
|
||||
public FluidPredicate(@Nullable TagKey<Fluid> p_204102_, @Nullable Fluid p_204103_, StatePropertiesPredicate p_204104_) {
|
||||
this.tag = p_204102_;
|
||||
this.fluid = p_204103_;
|
||||
this.properties = p_204104_;
|
||||
}
|
||||
|
||||
public boolean matches(ServerLevel p_41105_, BlockPos p_41106_) {
|
||||
if (this == ANY) {
|
||||
return true;
|
||||
} else if (!p_41105_.isLoaded(p_41106_)) {
|
||||
return false;
|
||||
} else {
|
||||
FluidState fluidstate = p_41105_.getFluidState(p_41106_);
|
||||
if (this.tag != null && !fluidstate.is(this.tag)) {
|
||||
return false;
|
||||
} else if (this.fluid != null && !fluidstate.is(this.fluid)) {
|
||||
return false;
|
||||
} else {
|
||||
return this.properties.matches(fluidstate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static FluidPredicate fromJson(@Nullable JsonElement p_41108_) {
|
||||
if (p_41108_ != null && !p_41108_.isJsonNull()) {
|
||||
JsonObject jsonobject = GsonHelper.convertToJsonObject(p_41108_, "fluid");
|
||||
Fluid fluid = null;
|
||||
if (jsonobject.has("fluid")) {
|
||||
ResourceLocation resourcelocation = new ResourceLocation(GsonHelper.getAsString(jsonobject, "fluid"));
|
||||
fluid = BuiltInRegistries.FLUID.get(resourcelocation);
|
||||
}
|
||||
|
||||
TagKey<Fluid> tagkey = null;
|
||||
if (jsonobject.has("tag")) {
|
||||
ResourceLocation resourcelocation1 = new ResourceLocation(GsonHelper.getAsString(jsonobject, "tag"));
|
||||
tagkey = TagKey.create(Registries.FLUID, resourcelocation1);
|
||||
}
|
||||
|
||||
StatePropertiesPredicate statepropertiespredicate = StatePropertiesPredicate.fromJson(jsonobject.get("state"));
|
||||
return new FluidPredicate(tagkey, fluid, statepropertiespredicate);
|
||||
} else {
|
||||
return ANY;
|
||||
}
|
||||
}
|
||||
|
||||
public JsonElement serializeToJson() {
|
||||
if (this == ANY) {
|
||||
return JsonNull.INSTANCE;
|
||||
} else {
|
||||
JsonObject jsonobject = new JsonObject();
|
||||
if (this.fluid != null) {
|
||||
jsonobject.addProperty("fluid", BuiltInRegistries.FLUID.getKey(this.fluid).toString());
|
||||
}
|
||||
|
||||
if (this.tag != null) {
|
||||
jsonobject.addProperty("tag", this.tag.location().toString());
|
||||
}
|
||||
|
||||
jsonobject.add("state", this.properties.serializeToJson());
|
||||
return jsonobject;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
@Nullable
|
||||
private Fluid fluid;
|
||||
@Nullable
|
||||
private TagKey<Fluid> fluids;
|
||||
private StatePropertiesPredicate properties = StatePropertiesPredicate.ANY;
|
||||
|
||||
private Builder() {
|
||||
}
|
||||
|
||||
public static FluidPredicate.Builder fluid() {
|
||||
return new FluidPredicate.Builder();
|
||||
}
|
||||
|
||||
public FluidPredicate.Builder of(Fluid p_151172_) {
|
||||
this.fluid = p_151172_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public FluidPredicate.Builder of(TagKey<Fluid> p_204106_) {
|
||||
this.fluids = p_204106_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public FluidPredicate.Builder setProperties(StatePropertiesPredicate p_151170_) {
|
||||
this.properties = p_151170_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public FluidPredicate build() {
|
||||
return new FluidPredicate(this.fluids, this.fluid, this.properties);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.advancements.CriterionTrigger;
|
||||
import net.minecraft.advancements.CriterionTriggerInstance;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.PlayerAdvancements;
|
||||
|
||||
public class ImpossibleTrigger implements CriterionTrigger<ImpossibleTrigger.TriggerInstance> {
|
||||
static final ResourceLocation ID = new ResourceLocation("impossible");
|
||||
|
||||
public ResourceLocation getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
public void addPlayerListener(PlayerAdvancements p_41565_, CriterionTrigger.Listener<ImpossibleTrigger.TriggerInstance> p_41566_) {
|
||||
}
|
||||
|
||||
public void removePlayerListener(PlayerAdvancements p_41572_, CriterionTrigger.Listener<ImpossibleTrigger.TriggerInstance> p_41573_) {
|
||||
}
|
||||
|
||||
public void removePlayerListeners(PlayerAdvancements p_41563_) {
|
||||
}
|
||||
|
||||
public ImpossibleTrigger.TriggerInstance createInstance(JsonObject p_41569_, DeserializationContext p_41570_) {
|
||||
return new ImpossibleTrigger.TriggerInstance();
|
||||
}
|
||||
|
||||
public static class TriggerInstance implements CriterionTriggerInstance {
|
||||
public ResourceLocation getCriterion() {
|
||||
return ImpossibleTrigger.ID;
|
||||
}
|
||||
|
||||
public JsonObject serializeToJson(SerializationContext p_41577_) {
|
||||
return new JsonObject();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import java.util.List;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.alchemy.Potion;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
|
||||
public class InventoryChangeTrigger extends SimpleCriterionTrigger<InventoryChangeTrigger.TriggerInstance> {
|
||||
static final ResourceLocation ID = new ResourceLocation("inventory_changed");
|
||||
|
||||
public ResourceLocation getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
public InventoryChangeTrigger.TriggerInstance createInstance(JsonObject p_286555_, ContextAwarePredicate p_286704_, DeserializationContext p_286270_) {
|
||||
JsonObject jsonobject = GsonHelper.getAsJsonObject(p_286555_, "slots", new JsonObject());
|
||||
MinMaxBounds.Ints minmaxbounds$ints = MinMaxBounds.Ints.fromJson(jsonobject.get("occupied"));
|
||||
MinMaxBounds.Ints minmaxbounds$ints1 = MinMaxBounds.Ints.fromJson(jsonobject.get("full"));
|
||||
MinMaxBounds.Ints minmaxbounds$ints2 = MinMaxBounds.Ints.fromJson(jsonobject.get("empty"));
|
||||
ItemPredicate[] aitempredicate = ItemPredicate.fromJsonArray(p_286555_.get("items"));
|
||||
return new InventoryChangeTrigger.TriggerInstance(p_286704_, minmaxbounds$ints, minmaxbounds$ints1, minmaxbounds$ints2, aitempredicate);
|
||||
}
|
||||
|
||||
public void trigger(ServerPlayer p_43150_, Inventory p_43151_, ItemStack p_43152_) {
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
int k = 0;
|
||||
|
||||
for(int l = 0; l < p_43151_.getContainerSize(); ++l) {
|
||||
ItemStack itemstack = p_43151_.getItem(l);
|
||||
if (itemstack.isEmpty()) {
|
||||
++j;
|
||||
} else {
|
||||
++k;
|
||||
if (itemstack.getCount() >= itemstack.getMaxStackSize()) {
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.trigger(p_43150_, p_43151_, p_43152_, i, j, k);
|
||||
}
|
||||
|
||||
private void trigger(ServerPlayer p_43154_, Inventory p_43155_, ItemStack p_43156_, int p_43157_, int p_43158_, int p_43159_) {
|
||||
this.trigger(p_43154_, (p_43166_) -> {
|
||||
return p_43166_.matches(p_43155_, p_43156_, p_43157_, p_43158_, p_43159_);
|
||||
});
|
||||
}
|
||||
|
||||
public static class TriggerInstance extends AbstractCriterionTriggerInstance {
|
||||
private final MinMaxBounds.Ints slotsOccupied;
|
||||
private final MinMaxBounds.Ints slotsFull;
|
||||
private final MinMaxBounds.Ints slotsEmpty;
|
||||
private final ItemPredicate[] predicates;
|
||||
|
||||
public TriggerInstance(ContextAwarePredicate p_286286_, MinMaxBounds.Ints p_286313_, MinMaxBounds.Ints p_286767_, MinMaxBounds.Ints p_286601_, ItemPredicate[] p_286380_) {
|
||||
super(InventoryChangeTrigger.ID, p_286286_);
|
||||
this.slotsOccupied = p_286313_;
|
||||
this.slotsFull = p_286767_;
|
||||
this.slotsEmpty = p_286601_;
|
||||
this.predicates = p_286380_;
|
||||
}
|
||||
|
||||
public static InventoryChangeTrigger.TriggerInstance hasItems(ItemPredicate... p_43198_) {
|
||||
return new InventoryChangeTrigger.TriggerInstance(ContextAwarePredicate.ANY, MinMaxBounds.Ints.ANY, MinMaxBounds.Ints.ANY, MinMaxBounds.Ints.ANY, p_43198_);
|
||||
}
|
||||
|
||||
public static InventoryChangeTrigger.TriggerInstance hasItems(ItemLike... p_43200_) {
|
||||
ItemPredicate[] aitempredicate = new ItemPredicate[p_43200_.length];
|
||||
|
||||
for(int i = 0; i < p_43200_.length; ++i) {
|
||||
aitempredicate[i] = new ItemPredicate((TagKey<Item>)null, ImmutableSet.of(p_43200_[i].asItem()), MinMaxBounds.Ints.ANY, MinMaxBounds.Ints.ANY, EnchantmentPredicate.NONE, EnchantmentPredicate.NONE, (Potion)null, NbtPredicate.ANY);
|
||||
}
|
||||
|
||||
return hasItems(aitempredicate);
|
||||
}
|
||||
|
||||
public JsonObject serializeToJson(SerializationContext p_43196_) {
|
||||
JsonObject jsonobject = super.serializeToJson(p_43196_);
|
||||
if (!this.slotsOccupied.isAny() || !this.slotsFull.isAny() || !this.slotsEmpty.isAny()) {
|
||||
JsonObject jsonobject1 = new JsonObject();
|
||||
jsonobject1.add("occupied", this.slotsOccupied.serializeToJson());
|
||||
jsonobject1.add("full", this.slotsFull.serializeToJson());
|
||||
jsonobject1.add("empty", this.slotsEmpty.serializeToJson());
|
||||
jsonobject.add("slots", jsonobject1);
|
||||
}
|
||||
|
||||
if (this.predicates.length > 0) {
|
||||
JsonArray jsonarray = new JsonArray();
|
||||
|
||||
for(ItemPredicate itempredicate : this.predicates) {
|
||||
jsonarray.add(itempredicate.serializeToJson());
|
||||
}
|
||||
|
||||
jsonobject.add("items", jsonarray);
|
||||
}
|
||||
|
||||
return jsonobject;
|
||||
}
|
||||
|
||||
public boolean matches(Inventory p_43187_, ItemStack p_43188_, int p_43189_, int p_43190_, int p_43191_) {
|
||||
if (!this.slotsFull.matches(p_43189_)) {
|
||||
return false;
|
||||
} else if (!this.slotsEmpty.matches(p_43190_)) {
|
||||
return false;
|
||||
} else if (!this.slotsOccupied.matches(p_43191_)) {
|
||||
return false;
|
||||
} else {
|
||||
int i = this.predicates.length;
|
||||
if (i == 0) {
|
||||
return true;
|
||||
} else if (i != 1) {
|
||||
List<ItemPredicate> list = new ObjectArrayList<>(this.predicates);
|
||||
int j = p_43187_.getContainerSize();
|
||||
|
||||
for(int k = 0; k < j; ++k) {
|
||||
if (list.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
ItemStack itemstack = p_43187_.getItem(k);
|
||||
if (!itemstack.isEmpty()) {
|
||||
list.removeIf((p_43194_) -> {
|
||||
return p_43194_.matches(itemstack);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return list.isEmpty();
|
||||
} else {
|
||||
return !p_43188_.isEmpty() && this.predicates[0].matches(p_43188_);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
public class ItemDurabilityTrigger extends SimpleCriterionTrigger<ItemDurabilityTrigger.TriggerInstance> {
|
||||
static final ResourceLocation ID = new ResourceLocation("item_durability_changed");
|
||||
|
||||
public ResourceLocation getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
public ItemDurabilityTrigger.TriggerInstance createInstance(JsonObject p_286693_, ContextAwarePredicate p_286383_, DeserializationContext p_286352_) {
|
||||
ItemPredicate itempredicate = ItemPredicate.fromJson(p_286693_.get("item"));
|
||||
MinMaxBounds.Ints minmaxbounds$ints = MinMaxBounds.Ints.fromJson(p_286693_.get("durability"));
|
||||
MinMaxBounds.Ints minmaxbounds$ints1 = MinMaxBounds.Ints.fromJson(p_286693_.get("delta"));
|
||||
return new ItemDurabilityTrigger.TriggerInstance(p_286383_, itempredicate, minmaxbounds$ints, minmaxbounds$ints1);
|
||||
}
|
||||
|
||||
public void trigger(ServerPlayer p_43670_, ItemStack p_43671_, int p_43672_) {
|
||||
this.trigger(p_43670_, (p_43676_) -> {
|
||||
return p_43676_.matches(p_43671_, p_43672_);
|
||||
});
|
||||
}
|
||||
|
||||
public static class TriggerInstance extends AbstractCriterionTriggerInstance {
|
||||
private final ItemPredicate item;
|
||||
private final MinMaxBounds.Ints durability;
|
||||
private final MinMaxBounds.Ints delta;
|
||||
|
||||
public TriggerInstance(ContextAwarePredicate p_286731_, ItemPredicate p_286447_, MinMaxBounds.Ints p_286431_, MinMaxBounds.Ints p_286460_) {
|
||||
super(ItemDurabilityTrigger.ID, p_286731_);
|
||||
this.item = p_286447_;
|
||||
this.durability = p_286431_;
|
||||
this.delta = p_286460_;
|
||||
}
|
||||
|
||||
public static ItemDurabilityTrigger.TriggerInstance changedDurability(ItemPredicate p_151287_, MinMaxBounds.Ints p_151288_) {
|
||||
return changedDurability(ContextAwarePredicate.ANY, p_151287_, p_151288_);
|
||||
}
|
||||
|
||||
public static ItemDurabilityTrigger.TriggerInstance changedDurability(ContextAwarePredicate p_286720_, ItemPredicate p_286288_, MinMaxBounds.Ints p_286730_) {
|
||||
return new ItemDurabilityTrigger.TriggerInstance(p_286720_, p_286288_, p_286730_, MinMaxBounds.Ints.ANY);
|
||||
}
|
||||
|
||||
public boolean matches(ItemStack p_43699_, int p_43700_) {
|
||||
if (!this.item.matches(p_43699_)) {
|
||||
return false;
|
||||
} else if (!this.durability.matches(p_43699_.getMaxDamage() - p_43700_)) {
|
||||
return false;
|
||||
} else {
|
||||
return this.delta.matches(p_43699_.getDamageValue() - p_43700_);
|
||||
}
|
||||
}
|
||||
|
||||
public JsonObject serializeToJson(SerializationContext p_43702_) {
|
||||
JsonObject jsonobject = super.serializeToJson(p_43702_);
|
||||
jsonobject.add("item", this.item.serializeToJson());
|
||||
jsonobject.add("durability", this.durability.serializeToJson());
|
||||
jsonobject.add("delta", this.delta.serializeToJson());
|
||||
return jsonobject;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,299 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonNull;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
import net.minecraft.world.item.EnchantedBookItem;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.alchemy.Potion;
|
||||
import net.minecraft.world.item.alchemy.PotionUtils;
|
||||
import net.minecraft.world.item.enchantment.Enchantment;
|
||||
import net.minecraft.world.item.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
|
||||
public class ItemPredicate {
|
||||
private static final Map<ResourceLocation, java.util.function.Function<JsonObject, ItemPredicate>> custom_predicates = new java.util.HashMap<>();
|
||||
private static final Map<ResourceLocation, java.util.function.Function<JsonObject, ItemPredicate>> unmod_predicates = java.util.Collections.unmodifiableMap(custom_predicates);
|
||||
public static final ItemPredicate ANY = new ItemPredicate();
|
||||
@Nullable
|
||||
private final TagKey<Item> tag;
|
||||
@Nullable
|
||||
private final Set<Item> items;
|
||||
private final MinMaxBounds.Ints count;
|
||||
private final MinMaxBounds.Ints durability;
|
||||
private final EnchantmentPredicate[] enchantments;
|
||||
private final EnchantmentPredicate[] storedEnchantments;
|
||||
@Nullable
|
||||
private final Potion potion;
|
||||
private final NbtPredicate nbt;
|
||||
|
||||
public ItemPredicate() {
|
||||
this.tag = null;
|
||||
this.items = null;
|
||||
this.potion = null;
|
||||
this.count = MinMaxBounds.Ints.ANY;
|
||||
this.durability = MinMaxBounds.Ints.ANY;
|
||||
this.enchantments = EnchantmentPredicate.NONE;
|
||||
this.storedEnchantments = EnchantmentPredicate.NONE;
|
||||
this.nbt = NbtPredicate.ANY;
|
||||
}
|
||||
|
||||
public ItemPredicate(@Nullable TagKey<Item> p_204137_, @Nullable Set<Item> p_204138_, MinMaxBounds.Ints p_204139_, MinMaxBounds.Ints p_204140_, EnchantmentPredicate[] p_204141_, EnchantmentPredicate[] p_204142_, @Nullable Potion p_204143_, NbtPredicate p_204144_) {
|
||||
this.tag = p_204137_;
|
||||
this.items = p_204138_;
|
||||
this.count = p_204139_;
|
||||
this.durability = p_204140_;
|
||||
this.enchantments = p_204141_;
|
||||
this.storedEnchantments = p_204142_;
|
||||
this.potion = p_204143_;
|
||||
this.nbt = p_204144_;
|
||||
}
|
||||
|
||||
public boolean matches(ItemStack p_45050_) {
|
||||
if (this == ANY) {
|
||||
return true;
|
||||
} else if (this.tag != null && !p_45050_.is(this.tag)) {
|
||||
return false;
|
||||
} else if (this.items != null && !this.items.contains(p_45050_.getItem())) {
|
||||
return false;
|
||||
} else if (!this.count.matches(p_45050_.getCount())) {
|
||||
return false;
|
||||
} else if (!this.durability.isAny() && !p_45050_.isDamageableItem()) {
|
||||
return false;
|
||||
} else if (!this.durability.matches(p_45050_.getMaxDamage() - p_45050_.getDamageValue())) {
|
||||
return false;
|
||||
} else if (!this.nbt.matches(p_45050_)) {
|
||||
return false;
|
||||
} else {
|
||||
if (this.enchantments.length > 0) {
|
||||
Map<Enchantment, Integer> map = p_45050_.getAllEnchantments();
|
||||
|
||||
for(EnchantmentPredicate enchantmentpredicate : this.enchantments) {
|
||||
if (!enchantmentpredicate.containedIn(map)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.storedEnchantments.length > 0) {
|
||||
Map<Enchantment, Integer> map1 = EnchantmentHelper.deserializeEnchantments(EnchantedBookItem.getEnchantments(p_45050_));
|
||||
|
||||
for(EnchantmentPredicate enchantmentpredicate1 : this.storedEnchantments) {
|
||||
if (!enchantmentpredicate1.containedIn(map1)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Potion potion = PotionUtils.getPotion(p_45050_);
|
||||
return this.potion == null || this.potion == potion;
|
||||
}
|
||||
}
|
||||
|
||||
public static ItemPredicate fromJson(@Nullable JsonElement p_45052_) {
|
||||
if (p_45052_ != null && !p_45052_.isJsonNull()) {
|
||||
JsonObject jsonobject = GsonHelper.convertToJsonObject(p_45052_, "item");
|
||||
if (jsonobject.has("type")) {
|
||||
final ResourceLocation rl = new ResourceLocation(GsonHelper.getAsString(jsonobject, "type"));
|
||||
if (custom_predicates.containsKey(rl)) return custom_predicates.get(rl).apply(jsonobject);
|
||||
else throw new JsonSyntaxException("There is no ItemPredicate of type "+rl);
|
||||
}
|
||||
MinMaxBounds.Ints minmaxbounds$ints = MinMaxBounds.Ints.fromJson(jsonobject.get("count"));
|
||||
MinMaxBounds.Ints minmaxbounds$ints1 = MinMaxBounds.Ints.fromJson(jsonobject.get("durability"));
|
||||
if (jsonobject.has("data")) {
|
||||
throw new JsonParseException("Disallowed data tag found");
|
||||
} else {
|
||||
NbtPredicate nbtpredicate = NbtPredicate.fromJson(jsonobject.get("nbt"));
|
||||
Set<Item> set = null;
|
||||
JsonArray jsonarray = GsonHelper.getAsJsonArray(jsonobject, "items", (JsonArray)null);
|
||||
if (jsonarray != null) {
|
||||
ImmutableSet.Builder<Item> builder = ImmutableSet.builder();
|
||||
|
||||
for(JsonElement jsonelement : jsonarray) {
|
||||
ResourceLocation resourcelocation = new ResourceLocation(GsonHelper.convertToString(jsonelement, "item"));
|
||||
builder.add(BuiltInRegistries.ITEM.getOptional(resourcelocation).orElseThrow(() -> {
|
||||
return new JsonSyntaxException("Unknown item id '" + resourcelocation + "'");
|
||||
}));
|
||||
}
|
||||
|
||||
set = builder.build();
|
||||
}
|
||||
|
||||
TagKey<Item> tagkey = null;
|
||||
if (jsonobject.has("tag")) {
|
||||
ResourceLocation resourcelocation1 = new ResourceLocation(GsonHelper.getAsString(jsonobject, "tag"));
|
||||
tagkey = TagKey.create(Registries.ITEM, resourcelocation1);
|
||||
}
|
||||
|
||||
Potion potion = null;
|
||||
if (jsonobject.has("potion")) {
|
||||
ResourceLocation resourcelocation2 = new ResourceLocation(GsonHelper.getAsString(jsonobject, "potion"));
|
||||
potion = BuiltInRegistries.POTION.getOptional(resourcelocation2).orElseThrow(() -> {
|
||||
return new JsonSyntaxException("Unknown potion '" + resourcelocation2 + "'");
|
||||
});
|
||||
}
|
||||
|
||||
EnchantmentPredicate[] aenchantmentpredicate = EnchantmentPredicate.fromJsonArray(jsonobject.get("enchantments"));
|
||||
EnchantmentPredicate[] aenchantmentpredicate1 = EnchantmentPredicate.fromJsonArray(jsonobject.get("stored_enchantments"));
|
||||
return new ItemPredicate(tagkey, set, minmaxbounds$ints, minmaxbounds$ints1, aenchantmentpredicate, aenchantmentpredicate1, potion, nbtpredicate);
|
||||
}
|
||||
} else {
|
||||
return ANY;
|
||||
}
|
||||
}
|
||||
|
||||
public JsonElement serializeToJson() {
|
||||
if (this == ANY) {
|
||||
return JsonNull.INSTANCE;
|
||||
} else {
|
||||
JsonObject jsonobject = new JsonObject();
|
||||
if (this.items != null) {
|
||||
JsonArray jsonarray = new JsonArray();
|
||||
|
||||
for(Item item : this.items) {
|
||||
jsonarray.add(BuiltInRegistries.ITEM.getKey(item).toString());
|
||||
}
|
||||
|
||||
jsonobject.add("items", jsonarray);
|
||||
}
|
||||
|
||||
if (this.tag != null) {
|
||||
jsonobject.addProperty("tag", this.tag.location().toString());
|
||||
}
|
||||
|
||||
jsonobject.add("count", this.count.serializeToJson());
|
||||
jsonobject.add("durability", this.durability.serializeToJson());
|
||||
jsonobject.add("nbt", this.nbt.serializeToJson());
|
||||
if (this.enchantments.length > 0) {
|
||||
JsonArray jsonarray1 = new JsonArray();
|
||||
|
||||
for(EnchantmentPredicate enchantmentpredicate : this.enchantments) {
|
||||
jsonarray1.add(enchantmentpredicate.serializeToJson());
|
||||
}
|
||||
|
||||
jsonobject.add("enchantments", jsonarray1);
|
||||
}
|
||||
|
||||
if (this.storedEnchantments.length > 0) {
|
||||
JsonArray jsonarray2 = new JsonArray();
|
||||
|
||||
for(EnchantmentPredicate enchantmentpredicate1 : this.storedEnchantments) {
|
||||
jsonarray2.add(enchantmentpredicate1.serializeToJson());
|
||||
}
|
||||
|
||||
jsonobject.add("stored_enchantments", jsonarray2);
|
||||
}
|
||||
|
||||
if (this.potion != null) {
|
||||
jsonobject.addProperty("potion", BuiltInRegistries.POTION.getKey(this.potion).toString());
|
||||
}
|
||||
|
||||
return jsonobject;
|
||||
}
|
||||
}
|
||||
|
||||
public static ItemPredicate[] fromJsonArray(@Nullable JsonElement p_45056_) {
|
||||
if (p_45056_ != null && !p_45056_.isJsonNull()) {
|
||||
JsonArray jsonarray = GsonHelper.convertToJsonArray(p_45056_, "items");
|
||||
ItemPredicate[] aitempredicate = new ItemPredicate[jsonarray.size()];
|
||||
|
||||
for(int i = 0; i < aitempredicate.length; ++i) {
|
||||
aitempredicate[i] = fromJson(jsonarray.get(i));
|
||||
}
|
||||
|
||||
return aitempredicate;
|
||||
} else {
|
||||
return new ItemPredicate[0];
|
||||
}
|
||||
}
|
||||
|
||||
public static void register(ResourceLocation name, java.util.function.Function<JsonObject, ItemPredicate> deserializer) {
|
||||
custom_predicates.put(name, deserializer);
|
||||
}
|
||||
|
||||
public static Map<ResourceLocation, java.util.function.Function<JsonObject, ItemPredicate>> getPredicates() {
|
||||
return unmod_predicates;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private final List<EnchantmentPredicate> enchantments = Lists.newArrayList();
|
||||
private final List<EnchantmentPredicate> storedEnchantments = Lists.newArrayList();
|
||||
@Nullable
|
||||
private Set<Item> items;
|
||||
@Nullable
|
||||
private TagKey<Item> tag;
|
||||
private MinMaxBounds.Ints count = MinMaxBounds.Ints.ANY;
|
||||
private MinMaxBounds.Ints durability = MinMaxBounds.Ints.ANY;
|
||||
@Nullable
|
||||
private Potion potion;
|
||||
private NbtPredicate nbt = NbtPredicate.ANY;
|
||||
|
||||
private Builder() {
|
||||
}
|
||||
|
||||
public static ItemPredicate.Builder item() {
|
||||
return new ItemPredicate.Builder();
|
||||
}
|
||||
|
||||
public ItemPredicate.Builder of(ItemLike... p_151446_) {
|
||||
this.items = Stream.of(p_151446_).map(ItemLike::asItem).collect(ImmutableSet.toImmutableSet());
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemPredicate.Builder of(TagKey<Item> p_204146_) {
|
||||
this.tag = p_204146_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemPredicate.Builder withCount(MinMaxBounds.Ints p_151444_) {
|
||||
this.count = p_151444_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemPredicate.Builder hasDurability(MinMaxBounds.Ints p_151450_) {
|
||||
this.durability = p_151450_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemPredicate.Builder isPotion(Potion p_151442_) {
|
||||
this.potion = p_151442_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemPredicate.Builder hasNbt(CompoundTag p_45076_) {
|
||||
this.nbt = new NbtPredicate(p_45076_);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemPredicate.Builder hasEnchantment(EnchantmentPredicate p_45072_) {
|
||||
this.enchantments.add(p_45072_);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemPredicate.Builder hasStoredEnchantment(EnchantmentPredicate p_151448_) {
|
||||
this.storedEnchantments.add(p_151448_);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemPredicate build() {
|
||||
return new ItemPredicate(this.tag, this.items, this.count, this.durability, this.enchantments.toArray(EnchantmentPredicate.NONE), this.storedEnchantments.toArray(EnchantmentPredicate.NONE), this.potion, this.nbt);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import java.util.Arrays;
|
||||
import net.minecraft.advancements.CriteriaTriggers;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.storage.loot.LootContext;
|
||||
import net.minecraft.world.level.storage.loot.LootParams;
|
||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets;
|
||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
|
||||
import net.minecraft.world.level.storage.loot.predicates.LocationCheck;
|
||||
import net.minecraft.world.level.storage.loot.predicates.LootItemBlockStatePropertyCondition;
|
||||
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;
|
||||
import net.minecraft.world.level.storage.loot.predicates.MatchTool;
|
||||
|
||||
public class ItemUsedOnLocationTrigger extends SimpleCriterionTrigger<ItemUsedOnLocationTrigger.TriggerInstance> {
|
||||
final ResourceLocation id;
|
||||
|
||||
public ItemUsedOnLocationTrigger(ResourceLocation p_286779_) {
|
||||
this.id = p_286779_;
|
||||
}
|
||||
|
||||
public ResourceLocation getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public ItemUsedOnLocationTrigger.TriggerInstance createInstance(JsonObject p_286301_, ContextAwarePredicate p_286748_, DeserializationContext p_286322_) {
|
||||
ContextAwarePredicate contextawarepredicate = ContextAwarePredicate.fromElement("location", p_286322_, p_286301_.get("location"), LootContextParamSets.ADVANCEMENT_LOCATION);
|
||||
if (contextawarepredicate == null) {
|
||||
throw new JsonParseException("Failed to parse 'location' field");
|
||||
} else {
|
||||
return new ItemUsedOnLocationTrigger.TriggerInstance(this.id, p_286748_, contextawarepredicate);
|
||||
}
|
||||
}
|
||||
|
||||
public void trigger(ServerPlayer p_286813_, BlockPos p_286625_, ItemStack p_286620_) {
|
||||
ServerLevel serverlevel = p_286813_.serverLevel();
|
||||
BlockState blockstate = serverlevel.getBlockState(p_286625_);
|
||||
LootParams lootparams = (new LootParams.Builder(serverlevel)).withParameter(LootContextParams.ORIGIN, p_286625_.getCenter()).withParameter(LootContextParams.THIS_ENTITY, p_286813_).withParameter(LootContextParams.BLOCK_STATE, blockstate).withParameter(LootContextParams.TOOL, p_286620_).create(LootContextParamSets.ADVANCEMENT_LOCATION);
|
||||
LootContext lootcontext = (new LootContext.Builder(lootparams)).create((ResourceLocation)null);
|
||||
this.trigger(p_286813_, (p_286596_) -> {
|
||||
return p_286596_.matches(lootcontext);
|
||||
});
|
||||
}
|
||||
|
||||
public static class TriggerInstance extends AbstractCriterionTriggerInstance {
|
||||
private final ContextAwarePredicate location;
|
||||
|
||||
public TriggerInstance(ResourceLocation p_286265_, ContextAwarePredicate p_286333_, ContextAwarePredicate p_286319_) {
|
||||
super(p_286265_, p_286333_);
|
||||
this.location = p_286319_;
|
||||
}
|
||||
|
||||
public static ItemUsedOnLocationTrigger.TriggerInstance placedBlock(Block p_286530_) {
|
||||
ContextAwarePredicate contextawarepredicate = ContextAwarePredicate.create(LootItemBlockStatePropertyCondition.hasBlockStateProperties(p_286530_).build());
|
||||
return new ItemUsedOnLocationTrigger.TriggerInstance(CriteriaTriggers.PLACED_BLOCK.id, ContextAwarePredicate.ANY, contextawarepredicate);
|
||||
}
|
||||
|
||||
public static ItemUsedOnLocationTrigger.TriggerInstance placedBlock(LootItemCondition.Builder... p_286365_) {
|
||||
ContextAwarePredicate contextawarepredicate = ContextAwarePredicate.create(Arrays.stream(p_286365_).map(LootItemCondition.Builder::build).toArray((p_286827_) -> {
|
||||
return new LootItemCondition[p_286827_];
|
||||
}));
|
||||
return new ItemUsedOnLocationTrigger.TriggerInstance(CriteriaTriggers.PLACED_BLOCK.id, ContextAwarePredicate.ANY, contextawarepredicate);
|
||||
}
|
||||
|
||||
private static ItemUsedOnLocationTrigger.TriggerInstance itemUsedOnLocation(LocationPredicate.Builder p_286740_, ItemPredicate.Builder p_286777_, ResourceLocation p_286742_) {
|
||||
ContextAwarePredicate contextawarepredicate = ContextAwarePredicate.create(LocationCheck.checkLocation(p_286740_).build(), MatchTool.toolMatches(p_286777_).build());
|
||||
return new ItemUsedOnLocationTrigger.TriggerInstance(p_286742_, ContextAwarePredicate.ANY, contextawarepredicate);
|
||||
}
|
||||
|
||||
public static ItemUsedOnLocationTrigger.TriggerInstance itemUsedOnBlock(LocationPredicate.Builder p_286808_, ItemPredicate.Builder p_286486_) {
|
||||
return itemUsedOnLocation(p_286808_, p_286486_, CriteriaTriggers.ITEM_USED_ON_BLOCK.id);
|
||||
}
|
||||
|
||||
public static ItemUsedOnLocationTrigger.TriggerInstance allayDropItemOnBlock(LocationPredicate.Builder p_286325_, ItemPredicate.Builder p_286531_) {
|
||||
return itemUsedOnLocation(p_286325_, p_286531_, CriteriaTriggers.ALLAY_DROP_ITEM_ON_BLOCK.id);
|
||||
}
|
||||
|
||||
public boolean matches(LootContext p_286800_) {
|
||||
return this.location.matches(p_286800_);
|
||||
}
|
||||
|
||||
public JsonObject serializeToJson(SerializationContext p_286870_) {
|
||||
JsonObject jsonobject = super.serializeToJson(p_286870_);
|
||||
jsonobject.add("location", this.location.toJson(p_286870_));
|
||||
return jsonobject;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.gson.JsonObject;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.level.storage.loot.LootContext;
|
||||
|
||||
public class KilledByCrossbowTrigger extends SimpleCriterionTrigger<KilledByCrossbowTrigger.TriggerInstance> {
|
||||
static final ResourceLocation ID = new ResourceLocation("killed_by_crossbow");
|
||||
|
||||
public ResourceLocation getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
public KilledByCrossbowTrigger.TriggerInstance createInstance(JsonObject p_286238_, ContextAwarePredicate p_286227_, DeserializationContext p_286919_) {
|
||||
ContextAwarePredicate[] acontextawarepredicate = EntityPredicate.fromJsonArray(p_286238_, "victims", p_286919_);
|
||||
MinMaxBounds.Ints minmaxbounds$ints = MinMaxBounds.Ints.fromJson(p_286238_.get("unique_entity_types"));
|
||||
return new KilledByCrossbowTrigger.TriggerInstance(p_286227_, acontextawarepredicate, minmaxbounds$ints);
|
||||
}
|
||||
|
||||
public void trigger(ServerPlayer p_46872_, Collection<Entity> p_46873_) {
|
||||
List<LootContext> list = Lists.newArrayList();
|
||||
Set<EntityType<?>> set = Sets.newHashSet();
|
||||
|
||||
for(Entity entity : p_46873_) {
|
||||
set.add(entity.getType());
|
||||
list.add(EntityPredicate.createContext(p_46872_, entity));
|
||||
}
|
||||
|
||||
this.trigger(p_46872_, (p_46881_) -> {
|
||||
return p_46881_.matches(list, set.size());
|
||||
});
|
||||
}
|
||||
|
||||
public static class TriggerInstance extends AbstractCriterionTriggerInstance {
|
||||
private final ContextAwarePredicate[] victims;
|
||||
private final MinMaxBounds.Ints uniqueEntityTypes;
|
||||
|
||||
public TriggerInstance(ContextAwarePredicate p_286398_, ContextAwarePredicate[] p_286510_, MinMaxBounds.Ints p_286571_) {
|
||||
super(KilledByCrossbowTrigger.ID, p_286398_);
|
||||
this.victims = p_286510_;
|
||||
this.uniqueEntityTypes = p_286571_;
|
||||
}
|
||||
|
||||
public static KilledByCrossbowTrigger.TriggerInstance crossbowKilled(EntityPredicate.Builder... p_46901_) {
|
||||
ContextAwarePredicate[] acontextawarepredicate = new ContextAwarePredicate[p_46901_.length];
|
||||
|
||||
for(int i = 0; i < p_46901_.length; ++i) {
|
||||
EntityPredicate.Builder entitypredicate$builder = p_46901_[i];
|
||||
acontextawarepredicate[i] = EntityPredicate.wrap(entitypredicate$builder.build());
|
||||
}
|
||||
|
||||
return new KilledByCrossbowTrigger.TriggerInstance(ContextAwarePredicate.ANY, acontextawarepredicate, MinMaxBounds.Ints.ANY);
|
||||
}
|
||||
|
||||
public static KilledByCrossbowTrigger.TriggerInstance crossbowKilled(MinMaxBounds.Ints p_46894_) {
|
||||
ContextAwarePredicate[] acontextawarepredicate = new ContextAwarePredicate[0];
|
||||
return new KilledByCrossbowTrigger.TriggerInstance(ContextAwarePredicate.ANY, acontextawarepredicate, p_46894_);
|
||||
}
|
||||
|
||||
public boolean matches(Collection<LootContext> p_46898_, int p_46899_) {
|
||||
if (this.victims.length > 0) {
|
||||
List<LootContext> list = Lists.newArrayList(p_46898_);
|
||||
|
||||
for(ContextAwarePredicate contextawarepredicate : this.victims) {
|
||||
boolean flag = false;
|
||||
Iterator<LootContext> iterator = list.iterator();
|
||||
|
||||
while(iterator.hasNext()) {
|
||||
LootContext lootcontext = iterator.next();
|
||||
if (contextawarepredicate.matches(lootcontext)) {
|
||||
iterator.remove();
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!flag) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this.uniqueEntityTypes.matches(p_46899_);
|
||||
}
|
||||
|
||||
public JsonObject serializeToJson(SerializationContext p_46896_) {
|
||||
JsonObject jsonobject = super.serializeToJson(p_46896_);
|
||||
jsonobject.add("victims", ContextAwarePredicate.toJson(this.victims, p_46896_));
|
||||
jsonobject.add("unique_entity_types", this.uniqueEntityTypes.serializeToJson());
|
||||
return jsonobject;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.advancements.CriteriaTriggers;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.storage.loot.LootContext;
|
||||
|
||||
public class KilledTrigger extends SimpleCriterionTrigger<KilledTrigger.TriggerInstance> {
|
||||
final ResourceLocation id;
|
||||
|
||||
public KilledTrigger(ResourceLocation p_48102_) {
|
||||
this.id = p_48102_;
|
||||
}
|
||||
|
||||
public ResourceLocation getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public KilledTrigger.TriggerInstance createInstance(JsonObject p_286718_, ContextAwarePredicate p_286909_, DeserializationContext p_286514_) {
|
||||
return new KilledTrigger.TriggerInstance(this.id, p_286909_, EntityPredicate.fromJson(p_286718_, "entity", p_286514_), DamageSourcePredicate.fromJson(p_286718_.get("killing_blow")));
|
||||
}
|
||||
|
||||
public void trigger(ServerPlayer p_48105_, Entity p_48106_, DamageSource p_48107_) {
|
||||
LootContext lootcontext = EntityPredicate.createContext(p_48105_, p_48106_);
|
||||
this.trigger(p_48105_, (p_48112_) -> {
|
||||
return p_48112_.matches(p_48105_, lootcontext, p_48107_);
|
||||
});
|
||||
}
|
||||
|
||||
public static class TriggerInstance extends AbstractCriterionTriggerInstance {
|
||||
private final ContextAwarePredicate entityPredicate;
|
||||
private final DamageSourcePredicate killingBlow;
|
||||
|
||||
public TriggerInstance(ResourceLocation p_286471_, ContextAwarePredicate p_286673_, ContextAwarePredicate p_286390_, DamageSourcePredicate p_286643_) {
|
||||
super(p_286471_, p_286673_);
|
||||
this.entityPredicate = p_286390_;
|
||||
this.killingBlow = p_286643_;
|
||||
}
|
||||
|
||||
public static KilledTrigger.TriggerInstance playerKilledEntity(EntityPredicate p_152109_) {
|
||||
return new KilledTrigger.TriggerInstance(CriteriaTriggers.PLAYER_KILLED_ENTITY.id, ContextAwarePredicate.ANY, EntityPredicate.wrap(p_152109_), DamageSourcePredicate.ANY);
|
||||
}
|
||||
|
||||
public static KilledTrigger.TriggerInstance playerKilledEntity(EntityPredicate.Builder p_48135_) {
|
||||
return new KilledTrigger.TriggerInstance(CriteriaTriggers.PLAYER_KILLED_ENTITY.id, ContextAwarePredicate.ANY, EntityPredicate.wrap(p_48135_.build()), DamageSourcePredicate.ANY);
|
||||
}
|
||||
|
||||
public static KilledTrigger.TriggerInstance playerKilledEntity() {
|
||||
return new KilledTrigger.TriggerInstance(CriteriaTriggers.PLAYER_KILLED_ENTITY.id, ContextAwarePredicate.ANY, ContextAwarePredicate.ANY, DamageSourcePredicate.ANY);
|
||||
}
|
||||
|
||||
public static KilledTrigger.TriggerInstance playerKilledEntity(EntityPredicate p_152114_, DamageSourcePredicate p_152115_) {
|
||||
return new KilledTrigger.TriggerInstance(CriteriaTriggers.PLAYER_KILLED_ENTITY.id, ContextAwarePredicate.ANY, EntityPredicate.wrap(p_152114_), p_152115_);
|
||||
}
|
||||
|
||||
public static KilledTrigger.TriggerInstance playerKilledEntity(EntityPredicate.Builder p_152106_, DamageSourcePredicate p_152107_) {
|
||||
return new KilledTrigger.TriggerInstance(CriteriaTriggers.PLAYER_KILLED_ENTITY.id, ContextAwarePredicate.ANY, EntityPredicate.wrap(p_152106_.build()), p_152107_);
|
||||
}
|
||||
|
||||
public static KilledTrigger.TriggerInstance playerKilledEntity(EntityPredicate p_152111_, DamageSourcePredicate.Builder p_152112_) {
|
||||
return new KilledTrigger.TriggerInstance(CriteriaTriggers.PLAYER_KILLED_ENTITY.id, ContextAwarePredicate.ANY, EntityPredicate.wrap(p_152111_), p_152112_.build());
|
||||
}
|
||||
|
||||
public static KilledTrigger.TriggerInstance playerKilledEntity(EntityPredicate.Builder p_48137_, DamageSourcePredicate.Builder p_48138_) {
|
||||
return new KilledTrigger.TriggerInstance(CriteriaTriggers.PLAYER_KILLED_ENTITY.id, ContextAwarePredicate.ANY, EntityPredicate.wrap(p_48137_.build()), p_48138_.build());
|
||||
}
|
||||
|
||||
public static KilledTrigger.TriggerInstance playerKilledEntityNearSculkCatalyst() {
|
||||
return new KilledTrigger.TriggerInstance(CriteriaTriggers.KILL_MOB_NEAR_SCULK_CATALYST.id, ContextAwarePredicate.ANY, ContextAwarePredicate.ANY, DamageSourcePredicate.ANY);
|
||||
}
|
||||
|
||||
public static KilledTrigger.TriggerInstance entityKilledPlayer(EntityPredicate p_152125_) {
|
||||
return new KilledTrigger.TriggerInstance(CriteriaTriggers.ENTITY_KILLED_PLAYER.id, ContextAwarePredicate.ANY, EntityPredicate.wrap(p_152125_), DamageSourcePredicate.ANY);
|
||||
}
|
||||
|
||||
public static KilledTrigger.TriggerInstance entityKilledPlayer(EntityPredicate.Builder p_152117_) {
|
||||
return new KilledTrigger.TriggerInstance(CriteriaTriggers.ENTITY_KILLED_PLAYER.id, ContextAwarePredicate.ANY, EntityPredicate.wrap(p_152117_.build()), DamageSourcePredicate.ANY);
|
||||
}
|
||||
|
||||
public static KilledTrigger.TriggerInstance entityKilledPlayer() {
|
||||
return new KilledTrigger.TriggerInstance(CriteriaTriggers.ENTITY_KILLED_PLAYER.id, ContextAwarePredicate.ANY, ContextAwarePredicate.ANY, DamageSourcePredicate.ANY);
|
||||
}
|
||||
|
||||
public static KilledTrigger.TriggerInstance entityKilledPlayer(EntityPredicate p_152130_, DamageSourcePredicate p_152131_) {
|
||||
return new KilledTrigger.TriggerInstance(CriteriaTriggers.ENTITY_KILLED_PLAYER.id, ContextAwarePredicate.ANY, EntityPredicate.wrap(p_152130_), p_152131_);
|
||||
}
|
||||
|
||||
public static KilledTrigger.TriggerInstance entityKilledPlayer(EntityPredicate.Builder p_152122_, DamageSourcePredicate p_152123_) {
|
||||
return new KilledTrigger.TriggerInstance(CriteriaTriggers.ENTITY_KILLED_PLAYER.id, ContextAwarePredicate.ANY, EntityPredicate.wrap(p_152122_.build()), p_152123_);
|
||||
}
|
||||
|
||||
public static KilledTrigger.TriggerInstance entityKilledPlayer(EntityPredicate p_152127_, DamageSourcePredicate.Builder p_152128_) {
|
||||
return new KilledTrigger.TriggerInstance(CriteriaTriggers.ENTITY_KILLED_PLAYER.id, ContextAwarePredicate.ANY, EntityPredicate.wrap(p_152127_), p_152128_.build());
|
||||
}
|
||||
|
||||
public static KilledTrigger.TriggerInstance entityKilledPlayer(EntityPredicate.Builder p_152119_, DamageSourcePredicate.Builder p_152120_) {
|
||||
return new KilledTrigger.TriggerInstance(CriteriaTriggers.ENTITY_KILLED_PLAYER.id, ContextAwarePredicate.ANY, EntityPredicate.wrap(p_152119_.build()), p_152120_.build());
|
||||
}
|
||||
|
||||
public boolean matches(ServerPlayer p_48131_, LootContext p_48132_, DamageSource p_48133_) {
|
||||
return !this.killingBlow.matches(p_48131_, p_48133_) ? false : this.entityPredicate.matches(p_48132_);
|
||||
}
|
||||
|
||||
public JsonObject serializeToJson(SerializationContext p_48140_) {
|
||||
JsonObject jsonobject = super.serializeToJson(p_48140_);
|
||||
jsonobject.add("entity", this.entityPredicate.toJson(p_48140_));
|
||||
jsonobject.add("killing_blow", this.killingBlow.serializeToJson());
|
||||
return jsonobject;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
public class LevitationTrigger extends SimpleCriterionTrigger<LevitationTrigger.TriggerInstance> {
|
||||
static final ResourceLocation ID = new ResourceLocation("levitation");
|
||||
|
||||
public ResourceLocation getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
public LevitationTrigger.TriggerInstance createInstance(JsonObject p_286359_, ContextAwarePredicate p_286588_, DeserializationContext p_286241_) {
|
||||
DistancePredicate distancepredicate = DistancePredicate.fromJson(p_286359_.get("distance"));
|
||||
MinMaxBounds.Ints minmaxbounds$ints = MinMaxBounds.Ints.fromJson(p_286359_.get("duration"));
|
||||
return new LevitationTrigger.TriggerInstance(p_286588_, distancepredicate, minmaxbounds$ints);
|
||||
}
|
||||
|
||||
public void trigger(ServerPlayer p_49117_, Vec3 p_49118_, int p_49119_) {
|
||||
this.trigger(p_49117_, (p_49124_) -> {
|
||||
return p_49124_.matches(p_49117_, p_49118_, p_49119_);
|
||||
});
|
||||
}
|
||||
|
||||
public static class TriggerInstance extends AbstractCriterionTriggerInstance {
|
||||
private final DistancePredicate distance;
|
||||
private final MinMaxBounds.Ints duration;
|
||||
|
||||
public TriggerInstance(ContextAwarePredicate p_286511_, DistancePredicate p_286806_, MinMaxBounds.Ints p_286676_) {
|
||||
super(LevitationTrigger.ID, p_286511_);
|
||||
this.distance = p_286806_;
|
||||
this.duration = p_286676_;
|
||||
}
|
||||
|
||||
public static LevitationTrigger.TriggerInstance levitated(DistancePredicate p_49145_) {
|
||||
return new LevitationTrigger.TriggerInstance(ContextAwarePredicate.ANY, p_49145_, MinMaxBounds.Ints.ANY);
|
||||
}
|
||||
|
||||
public boolean matches(ServerPlayer p_49141_, Vec3 p_49142_, int p_49143_) {
|
||||
if (!this.distance.matches(p_49142_.x, p_49142_.y, p_49142_.z, p_49141_.getX(), p_49141_.getY(), p_49141_.getZ())) {
|
||||
return false;
|
||||
} else {
|
||||
return this.duration.matches(p_49143_);
|
||||
}
|
||||
}
|
||||
|
||||
public JsonObject serializeToJson(SerializationContext p_49147_) {
|
||||
JsonObject jsonobject = super.serializeToJson(p_49147_);
|
||||
jsonobject.add("distance", this.distance.serializeToJson());
|
||||
jsonobject.add("duration", this.duration.serializeToJson());
|
||||
return jsonobject;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonNull;
|
||||
import com.google.gson.JsonObject;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
|
||||
public class LightPredicate {
|
||||
public static final LightPredicate ANY = new LightPredicate(MinMaxBounds.Ints.ANY);
|
||||
private final MinMaxBounds.Ints composite;
|
||||
|
||||
LightPredicate(MinMaxBounds.Ints p_51339_) {
|
||||
this.composite = p_51339_;
|
||||
}
|
||||
|
||||
public boolean matches(ServerLevel p_51342_, BlockPos p_51343_) {
|
||||
if (this == ANY) {
|
||||
return true;
|
||||
} else if (!p_51342_.isLoaded(p_51343_)) {
|
||||
return false;
|
||||
} else {
|
||||
return this.composite.matches(p_51342_.getMaxLocalRawBrightness(p_51343_));
|
||||
}
|
||||
}
|
||||
|
||||
public JsonElement serializeToJson() {
|
||||
if (this == ANY) {
|
||||
return JsonNull.INSTANCE;
|
||||
} else {
|
||||
JsonObject jsonobject = new JsonObject();
|
||||
jsonobject.add("light", this.composite.serializeToJson());
|
||||
return jsonobject;
|
||||
}
|
||||
}
|
||||
|
||||
public static LightPredicate fromJson(@Nullable JsonElement p_51345_) {
|
||||
if (p_51345_ != null && !p_51345_.isJsonNull()) {
|
||||
JsonObject jsonobject = GsonHelper.convertToJsonObject(p_51345_, "light");
|
||||
MinMaxBounds.Ints minmaxbounds$ints = MinMaxBounds.Ints.fromJson(jsonobject.get("light"));
|
||||
return new LightPredicate(minmaxbounds$ints);
|
||||
} else {
|
||||
return ANY;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private MinMaxBounds.Ints composite = MinMaxBounds.Ints.ANY;
|
||||
|
||||
public static LightPredicate.Builder light() {
|
||||
return new LightPredicate.Builder();
|
||||
}
|
||||
|
||||
public LightPredicate.Builder setComposite(MinMaxBounds.Ints p_153105_) {
|
||||
this.composite = p_153105_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LightPredicate build() {
|
||||
return new LightPredicate(this.composite);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.LightningBolt;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
public class LighthingBoltPredicate implements EntitySubPredicate {
|
||||
private static final String BLOCKS_SET_ON_FIRE_KEY = "blocks_set_on_fire";
|
||||
private static final String ENTITY_STRUCK_KEY = "entity_struck";
|
||||
private final MinMaxBounds.Ints blocksSetOnFire;
|
||||
private final EntityPredicate entityStruck;
|
||||
|
||||
private LighthingBoltPredicate(MinMaxBounds.Ints p_153239_, EntityPredicate p_153240_) {
|
||||
this.blocksSetOnFire = p_153239_;
|
||||
this.entityStruck = p_153240_;
|
||||
}
|
||||
|
||||
public static LighthingBoltPredicate blockSetOnFire(MinMaxBounds.Ints p_153251_) {
|
||||
return new LighthingBoltPredicate(p_153251_, EntityPredicate.ANY);
|
||||
}
|
||||
|
||||
public static LighthingBoltPredicate fromJson(JsonObject p_220333_) {
|
||||
return new LighthingBoltPredicate(MinMaxBounds.Ints.fromJson(p_220333_.get("blocks_set_on_fire")), EntityPredicate.fromJson(p_220333_.get("entity_struck")));
|
||||
}
|
||||
|
||||
public JsonObject serializeCustomData() {
|
||||
JsonObject jsonobject = new JsonObject();
|
||||
jsonobject.add("blocks_set_on_fire", this.blocksSetOnFire.serializeToJson());
|
||||
jsonobject.add("entity_struck", this.entityStruck.serializeToJson());
|
||||
return jsonobject;
|
||||
}
|
||||
|
||||
public EntitySubPredicate.Type type() {
|
||||
return EntitySubPredicate.Types.LIGHTNING;
|
||||
}
|
||||
|
||||
public boolean matches(Entity p_153247_, ServerLevel p_153248_, @Nullable Vec3 p_153249_) {
|
||||
if (!(p_153247_ instanceof LightningBolt lightningbolt)) {
|
||||
return false;
|
||||
} else {
|
||||
return this.blocksSetOnFire.matches(lightningbolt.getBlocksSetOnFire()) && (this.entityStruck == EntityPredicate.ANY || lightningbolt.getHitEntities().anyMatch((p_153245_) -> {
|
||||
return this.entityStruck.matches(p_153248_, p_153249_, p_153245_);
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.LightningBolt;
|
||||
import net.minecraft.world.level.storage.loot.LootContext;
|
||||
|
||||
public class LightningStrikeTrigger extends SimpleCriterionTrigger<LightningStrikeTrigger.TriggerInstance> {
|
||||
static final ResourceLocation ID = new ResourceLocation("lightning_strike");
|
||||
|
||||
public ResourceLocation getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
public LightningStrikeTrigger.TriggerInstance createInstance(JsonObject p_286889_, ContextAwarePredicate p_286650_, DeserializationContext p_286384_) {
|
||||
ContextAwarePredicate contextawarepredicate = EntityPredicate.fromJson(p_286889_, "lightning", p_286384_);
|
||||
ContextAwarePredicate contextawarepredicate1 = EntityPredicate.fromJson(p_286889_, "bystander", p_286384_);
|
||||
return new LightningStrikeTrigger.TriggerInstance(p_286650_, contextawarepredicate, contextawarepredicate1);
|
||||
}
|
||||
|
||||
public void trigger(ServerPlayer p_153392_, LightningBolt p_153393_, List<Entity> p_153394_) {
|
||||
List<LootContext> list = p_153394_.stream().map((p_153390_) -> {
|
||||
return EntityPredicate.createContext(p_153392_, p_153390_);
|
||||
}).collect(Collectors.toList());
|
||||
LootContext lootcontext = EntityPredicate.createContext(p_153392_, p_153393_);
|
||||
this.trigger(p_153392_, (p_153402_) -> {
|
||||
return p_153402_.matches(lootcontext, list);
|
||||
});
|
||||
}
|
||||
|
||||
public static class TriggerInstance extends AbstractCriterionTriggerInstance {
|
||||
private final ContextAwarePredicate lightning;
|
||||
private final ContextAwarePredicate bystander;
|
||||
|
||||
public TriggerInstance(ContextAwarePredicate p_286747_, ContextAwarePredicate p_286287_, ContextAwarePredicate p_286566_) {
|
||||
super(LightningStrikeTrigger.ID, p_286747_);
|
||||
this.lightning = p_286287_;
|
||||
this.bystander = p_286566_;
|
||||
}
|
||||
|
||||
public static LightningStrikeTrigger.TriggerInstance lighthingStrike(EntityPredicate p_153414_, EntityPredicate p_153415_) {
|
||||
return new LightningStrikeTrigger.TriggerInstance(ContextAwarePredicate.ANY, EntityPredicate.wrap(p_153414_), EntityPredicate.wrap(p_153415_));
|
||||
}
|
||||
|
||||
public boolean matches(LootContext p_153419_, List<LootContext> p_153420_) {
|
||||
if (!this.lightning.matches(p_153419_)) {
|
||||
return false;
|
||||
} else {
|
||||
return this.bystander == ContextAwarePredicate.ANY || !p_153420_.stream().noneMatch(this.bystander::matches);
|
||||
}
|
||||
}
|
||||
|
||||
public JsonObject serializeToJson(SerializationContext p_153417_) {
|
||||
JsonObject jsonobject = super.serializeToJson(p_153417_);
|
||||
jsonobject.add("lightning", this.lightning.toJson(p_153417_));
|
||||
jsonobject.add("bystander", this.bystander.toJson(p_153417_));
|
||||
return jsonobject;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,243 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonNull;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.mojang.logging.LogUtils;
|
||||
import com.mojang.serialization.JsonOps;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.block.CampfireBlock;
|
||||
import net.minecraft.world.level.levelgen.structure.Structure;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
public class LocationPredicate {
|
||||
private static final Logger LOGGER = LogUtils.getLogger();
|
||||
public static final LocationPredicate ANY = new LocationPredicate(MinMaxBounds.Doubles.ANY, MinMaxBounds.Doubles.ANY, MinMaxBounds.Doubles.ANY, (ResourceKey<Biome>)null, (ResourceKey<Structure>)null, (ResourceKey<Level>)null, (Boolean)null, LightPredicate.ANY, BlockPredicate.ANY, FluidPredicate.ANY);
|
||||
private final MinMaxBounds.Doubles x;
|
||||
private final MinMaxBounds.Doubles y;
|
||||
private final MinMaxBounds.Doubles z;
|
||||
@Nullable
|
||||
private final ResourceKey<Biome> biome;
|
||||
@Nullable
|
||||
private final ResourceKey<Structure> structure;
|
||||
@Nullable
|
||||
private final ResourceKey<Level> dimension;
|
||||
@Nullable
|
||||
private final Boolean smokey;
|
||||
private final LightPredicate light;
|
||||
private final BlockPredicate block;
|
||||
private final FluidPredicate fluid;
|
||||
|
||||
public LocationPredicate(MinMaxBounds.Doubles p_207916_, MinMaxBounds.Doubles p_207917_, MinMaxBounds.Doubles p_207918_, @Nullable ResourceKey<Biome> p_207919_, @Nullable ResourceKey<Structure> p_207920_, @Nullable ResourceKey<Level> p_207921_, @Nullable Boolean p_207922_, LightPredicate p_207923_, BlockPredicate p_207924_, FluidPredicate p_207925_) {
|
||||
this.x = p_207916_;
|
||||
this.y = p_207917_;
|
||||
this.z = p_207918_;
|
||||
this.biome = p_207919_;
|
||||
this.structure = p_207920_;
|
||||
this.dimension = p_207921_;
|
||||
this.smokey = p_207922_;
|
||||
this.light = p_207923_;
|
||||
this.block = p_207924_;
|
||||
this.fluid = p_207925_;
|
||||
}
|
||||
|
||||
public static LocationPredicate inBiome(ResourceKey<Biome> p_52635_) {
|
||||
return new LocationPredicate(MinMaxBounds.Doubles.ANY, MinMaxBounds.Doubles.ANY, MinMaxBounds.Doubles.ANY, p_52635_, (ResourceKey<Structure>)null, (ResourceKey<Level>)null, (Boolean)null, LightPredicate.ANY, BlockPredicate.ANY, FluidPredicate.ANY);
|
||||
}
|
||||
|
||||
public static LocationPredicate inDimension(ResourceKey<Level> p_52639_) {
|
||||
return new LocationPredicate(MinMaxBounds.Doubles.ANY, MinMaxBounds.Doubles.ANY, MinMaxBounds.Doubles.ANY, (ResourceKey<Biome>)null, (ResourceKey<Structure>)null, p_52639_, (Boolean)null, LightPredicate.ANY, BlockPredicate.ANY, FluidPredicate.ANY);
|
||||
}
|
||||
|
||||
public static LocationPredicate inStructure(ResourceKey<Structure> p_220590_) {
|
||||
return new LocationPredicate(MinMaxBounds.Doubles.ANY, MinMaxBounds.Doubles.ANY, MinMaxBounds.Doubles.ANY, (ResourceKey<Biome>)null, p_220590_, (ResourceKey<Level>)null, (Boolean)null, LightPredicate.ANY, BlockPredicate.ANY, FluidPredicate.ANY);
|
||||
}
|
||||
|
||||
public static LocationPredicate atYLocation(MinMaxBounds.Doubles p_187443_) {
|
||||
return new LocationPredicate(MinMaxBounds.Doubles.ANY, p_187443_, MinMaxBounds.Doubles.ANY, (ResourceKey<Biome>)null, (ResourceKey<Structure>)null, (ResourceKey<Level>)null, (Boolean)null, LightPredicate.ANY, BlockPredicate.ANY, FluidPredicate.ANY);
|
||||
}
|
||||
|
||||
public boolean matches(ServerLevel p_52618_, double p_52619_, double p_52620_, double p_52621_) {
|
||||
if (!this.x.matches(p_52619_)) {
|
||||
return false;
|
||||
} else if (!this.y.matches(p_52620_)) {
|
||||
return false;
|
||||
} else if (!this.z.matches(p_52621_)) {
|
||||
return false;
|
||||
} else if (this.dimension != null && this.dimension != p_52618_.dimension()) {
|
||||
return false;
|
||||
} else {
|
||||
BlockPos blockpos = BlockPos.containing(p_52619_, p_52620_, p_52621_);
|
||||
boolean flag = p_52618_.isLoaded(blockpos);
|
||||
if (this.biome == null || flag && p_52618_.getBiome(blockpos).is(this.biome)) {
|
||||
if (this.structure == null || flag && p_52618_.structureManager().getStructureWithPieceAt(blockpos, this.structure).isValid()) {
|
||||
if (this.smokey == null || flag && this.smokey == CampfireBlock.isSmokeyPos(p_52618_, blockpos)) {
|
||||
if (!this.light.matches(p_52618_, blockpos)) {
|
||||
return false;
|
||||
} else if (!this.block.matches(p_52618_, blockpos)) {
|
||||
return false;
|
||||
} else {
|
||||
return this.fluid.matches(p_52618_, blockpos);
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public JsonElement serializeToJson() {
|
||||
if (this == ANY) {
|
||||
return JsonNull.INSTANCE;
|
||||
} else {
|
||||
JsonObject jsonobject = new JsonObject();
|
||||
if (!this.x.isAny() || !this.y.isAny() || !this.z.isAny()) {
|
||||
JsonObject jsonobject1 = new JsonObject();
|
||||
jsonobject1.add("x", this.x.serializeToJson());
|
||||
jsonobject1.add("y", this.y.serializeToJson());
|
||||
jsonobject1.add("z", this.z.serializeToJson());
|
||||
jsonobject.add("position", jsonobject1);
|
||||
}
|
||||
|
||||
if (this.dimension != null) {
|
||||
Level.RESOURCE_KEY_CODEC.encodeStart(JsonOps.INSTANCE, this.dimension).resultOrPartial(LOGGER::error).ifPresent((p_52633_) -> {
|
||||
jsonobject.add("dimension", p_52633_);
|
||||
});
|
||||
}
|
||||
|
||||
if (this.structure != null) {
|
||||
jsonobject.addProperty("structure", this.structure.location().toString());
|
||||
}
|
||||
|
||||
if (this.biome != null) {
|
||||
jsonobject.addProperty("biome", this.biome.location().toString());
|
||||
}
|
||||
|
||||
if (this.smokey != null) {
|
||||
jsonobject.addProperty("smokey", this.smokey);
|
||||
}
|
||||
|
||||
jsonobject.add("light", this.light.serializeToJson());
|
||||
jsonobject.add("block", this.block.serializeToJson());
|
||||
jsonobject.add("fluid", this.fluid.serializeToJson());
|
||||
return jsonobject;
|
||||
}
|
||||
}
|
||||
|
||||
public static LocationPredicate fromJson(@Nullable JsonElement p_52630_) {
|
||||
if (p_52630_ != null && !p_52630_.isJsonNull()) {
|
||||
JsonObject jsonobject = GsonHelper.convertToJsonObject(p_52630_, "location");
|
||||
JsonObject jsonobject1 = GsonHelper.getAsJsonObject(jsonobject, "position", new JsonObject());
|
||||
MinMaxBounds.Doubles minmaxbounds$doubles = MinMaxBounds.Doubles.fromJson(jsonobject1.get("x"));
|
||||
MinMaxBounds.Doubles minmaxbounds$doubles1 = MinMaxBounds.Doubles.fromJson(jsonobject1.get("y"));
|
||||
MinMaxBounds.Doubles minmaxbounds$doubles2 = MinMaxBounds.Doubles.fromJson(jsonobject1.get("z"));
|
||||
ResourceKey<Level> resourcekey = jsonobject.has("dimension") ? ResourceLocation.CODEC.parse(JsonOps.INSTANCE, jsonobject.get("dimension")).resultOrPartial(LOGGER::error).map((p_52637_) -> {
|
||||
return ResourceKey.create(Registries.DIMENSION, p_52637_);
|
||||
}).orElse((ResourceKey<Level>)null) : null;
|
||||
ResourceKey<Structure> resourcekey1 = jsonobject.has("structure") ? ResourceLocation.CODEC.parse(JsonOps.INSTANCE, jsonobject.get("structure")).resultOrPartial(LOGGER::error).map((p_207927_) -> {
|
||||
return ResourceKey.create(Registries.STRUCTURE, p_207927_);
|
||||
}).orElse((ResourceKey<Structure>)null) : null;
|
||||
ResourceKey<Biome> resourcekey2 = null;
|
||||
if (jsonobject.has("biome")) {
|
||||
ResourceLocation resourcelocation = new ResourceLocation(GsonHelper.getAsString(jsonobject, "biome"));
|
||||
resourcekey2 = ResourceKey.create(Registries.BIOME, resourcelocation);
|
||||
}
|
||||
|
||||
Boolean obool = jsonobject.has("smokey") ? jsonobject.get("smokey").getAsBoolean() : null;
|
||||
LightPredicate lightpredicate = LightPredicate.fromJson(jsonobject.get("light"));
|
||||
BlockPredicate blockpredicate = BlockPredicate.fromJson(jsonobject.get("block"));
|
||||
FluidPredicate fluidpredicate = FluidPredicate.fromJson(jsonobject.get("fluid"));
|
||||
return new LocationPredicate(minmaxbounds$doubles, minmaxbounds$doubles1, minmaxbounds$doubles2, resourcekey2, resourcekey1, resourcekey, obool, lightpredicate, blockpredicate, fluidpredicate);
|
||||
} else {
|
||||
return ANY;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private MinMaxBounds.Doubles x = MinMaxBounds.Doubles.ANY;
|
||||
private MinMaxBounds.Doubles y = MinMaxBounds.Doubles.ANY;
|
||||
private MinMaxBounds.Doubles z = MinMaxBounds.Doubles.ANY;
|
||||
@Nullable
|
||||
private ResourceKey<Biome> biome;
|
||||
@Nullable
|
||||
private ResourceKey<Structure> structure;
|
||||
@Nullable
|
||||
private ResourceKey<Level> dimension;
|
||||
@Nullable
|
||||
private Boolean smokey;
|
||||
private LightPredicate light = LightPredicate.ANY;
|
||||
private BlockPredicate block = BlockPredicate.ANY;
|
||||
private FluidPredicate fluid = FluidPredicate.ANY;
|
||||
|
||||
public static LocationPredicate.Builder location() {
|
||||
return new LocationPredicate.Builder();
|
||||
}
|
||||
|
||||
public LocationPredicate.Builder setX(MinMaxBounds.Doubles p_153971_) {
|
||||
this.x = p_153971_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LocationPredicate.Builder setY(MinMaxBounds.Doubles p_153975_) {
|
||||
this.y = p_153975_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LocationPredicate.Builder setZ(MinMaxBounds.Doubles p_153979_) {
|
||||
this.z = p_153979_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LocationPredicate.Builder setBiome(@Nullable ResourceKey<Biome> p_52657_) {
|
||||
this.biome = p_52657_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LocationPredicate.Builder setStructure(@Nullable ResourceKey<Structure> p_220593_) {
|
||||
this.structure = p_220593_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LocationPredicate.Builder setDimension(@Nullable ResourceKey<Level> p_153977_) {
|
||||
this.dimension = p_153977_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LocationPredicate.Builder setLight(LightPredicate p_153969_) {
|
||||
this.light = p_153969_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LocationPredicate.Builder setBlock(BlockPredicate p_52653_) {
|
||||
this.block = p_52653_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LocationPredicate.Builder setFluid(FluidPredicate p_153967_) {
|
||||
this.fluid = p_153967_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LocationPredicate.Builder setSmokey(Boolean p_52655_) {
|
||||
this.smokey = p_52655_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LocationPredicate build() {
|
||||
return new LocationPredicate(this.x, this.y, this.z, this.biome, this.structure, this.dimension, this.smokey, this.light, this.block, this.fluid);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
|
||||
public class LootTableTrigger extends SimpleCriterionTrigger<LootTableTrigger.TriggerInstance> {
|
||||
static final ResourceLocation ID = new ResourceLocation("player_generates_container_loot");
|
||||
|
||||
public ResourceLocation getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
protected LootTableTrigger.TriggerInstance createInstance(JsonObject p_286915_, ContextAwarePredicate p_286259_, DeserializationContext p_286891_) {
|
||||
ResourceLocation resourcelocation = new ResourceLocation(GsonHelper.getAsString(p_286915_, "loot_table"));
|
||||
return new LootTableTrigger.TriggerInstance(p_286259_, resourcelocation);
|
||||
}
|
||||
|
||||
public void trigger(ServerPlayer p_54598_, ResourceLocation p_54599_) {
|
||||
this.trigger(p_54598_, (p_54606_) -> {
|
||||
return p_54606_.matches(p_54599_);
|
||||
});
|
||||
}
|
||||
|
||||
public static class TriggerInstance extends AbstractCriterionTriggerInstance {
|
||||
private final ResourceLocation lootTable;
|
||||
|
||||
public TriggerInstance(ContextAwarePredicate p_286834_, ResourceLocation p_286434_) {
|
||||
super(LootTableTrigger.ID, p_286834_);
|
||||
this.lootTable = p_286434_;
|
||||
}
|
||||
|
||||
public static LootTableTrigger.TriggerInstance lootTableUsed(ResourceLocation p_54619_) {
|
||||
return new LootTableTrigger.TriggerInstance(ContextAwarePredicate.ANY, p_54619_);
|
||||
}
|
||||
|
||||
public boolean matches(ResourceLocation p_54621_) {
|
||||
return this.lootTable.equals(p_54621_);
|
||||
}
|
||||
|
||||
public JsonObject serializeToJson(SerializationContext p_54617_) {
|
||||
JsonObject jsonobject = super.serializeToJson(p_54617_);
|
||||
jsonobject.addProperty("loot_table", this.lootTable.toString());
|
||||
return jsonobject;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,305 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonNull;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import com.mojang.brigadier.StringReader;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;
|
||||
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
|
||||
public abstract class MinMaxBounds<T extends Number> {
|
||||
public static final SimpleCommandExceptionType ERROR_EMPTY = new SimpleCommandExceptionType(Component.translatable("argument.range.empty"));
|
||||
public static final SimpleCommandExceptionType ERROR_SWAPPED = new SimpleCommandExceptionType(Component.translatable("argument.range.swapped"));
|
||||
@Nullable
|
||||
protected final T min;
|
||||
@Nullable
|
||||
protected final T max;
|
||||
|
||||
protected MinMaxBounds(@Nullable T p_55303_, @Nullable T p_55304_) {
|
||||
this.min = p_55303_;
|
||||
this.max = p_55304_;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public T getMin() {
|
||||
return this.min;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public T getMax() {
|
||||
return this.max;
|
||||
}
|
||||
|
||||
public boolean isAny() {
|
||||
return this.min == null && this.max == null;
|
||||
}
|
||||
|
||||
public JsonElement serializeToJson() {
|
||||
if (this.isAny()) {
|
||||
return JsonNull.INSTANCE;
|
||||
} else if (this.min != null && this.min.equals(this.max)) {
|
||||
return new JsonPrimitive(this.min);
|
||||
} else {
|
||||
JsonObject jsonobject = new JsonObject();
|
||||
if (this.min != null) {
|
||||
jsonobject.addProperty("min", this.min);
|
||||
}
|
||||
|
||||
if (this.max != null) {
|
||||
jsonobject.addProperty("max", this.max);
|
||||
}
|
||||
|
||||
return jsonobject;
|
||||
}
|
||||
}
|
||||
|
||||
protected static <T extends Number, R extends MinMaxBounds<T>> R fromJson(@Nullable JsonElement p_55307_, R p_55308_, BiFunction<JsonElement, String, T> p_55309_, MinMaxBounds.BoundsFactory<T, R> p_55310_) {
|
||||
if (p_55307_ != null && !p_55307_.isJsonNull()) {
|
||||
if (GsonHelper.isNumberValue(p_55307_)) {
|
||||
T t2 = p_55309_.apply(p_55307_, "value");
|
||||
return p_55310_.create(t2, t2);
|
||||
} else {
|
||||
JsonObject jsonobject = GsonHelper.convertToJsonObject(p_55307_, "value");
|
||||
T t = jsonobject.has("min") ? p_55309_.apply(jsonobject.get("min"), "min") : null;
|
||||
T t1 = jsonobject.has("max") ? p_55309_.apply(jsonobject.get("max"), "max") : null;
|
||||
return p_55310_.create(t, t1);
|
||||
}
|
||||
} else {
|
||||
return p_55308_;
|
||||
}
|
||||
}
|
||||
|
||||
protected static <T extends Number, R extends MinMaxBounds<T>> R fromReader(StringReader p_55314_, MinMaxBounds.BoundsFromReaderFactory<T, R> p_55315_, Function<String, T> p_55316_, Supplier<DynamicCommandExceptionType> p_55317_, Function<T, T> p_55318_) throws CommandSyntaxException {
|
||||
if (!p_55314_.canRead()) {
|
||||
throw ERROR_EMPTY.createWithContext(p_55314_);
|
||||
} else {
|
||||
int i = p_55314_.getCursor();
|
||||
|
||||
try {
|
||||
T t = optionallyFormat(readNumber(p_55314_, p_55316_, p_55317_), p_55318_);
|
||||
T t1;
|
||||
if (p_55314_.canRead(2) && p_55314_.peek() == '.' && p_55314_.peek(1) == '.') {
|
||||
p_55314_.skip();
|
||||
p_55314_.skip();
|
||||
t1 = optionallyFormat(readNumber(p_55314_, p_55316_, p_55317_), p_55318_);
|
||||
if (t == null && t1 == null) {
|
||||
throw ERROR_EMPTY.createWithContext(p_55314_);
|
||||
}
|
||||
} else {
|
||||
t1 = t;
|
||||
}
|
||||
|
||||
if (t == null && t1 == null) {
|
||||
throw ERROR_EMPTY.createWithContext(p_55314_);
|
||||
} else {
|
||||
return p_55315_.create(p_55314_, t, t1);
|
||||
}
|
||||
} catch (CommandSyntaxException commandsyntaxexception) {
|
||||
p_55314_.setCursor(i);
|
||||
throw new CommandSyntaxException(commandsyntaxexception.getType(), commandsyntaxexception.getRawMessage(), commandsyntaxexception.getInput(), i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static <T extends Number> T readNumber(StringReader p_55320_, Function<String, T> p_55321_, Supplier<DynamicCommandExceptionType> p_55322_) throws CommandSyntaxException {
|
||||
int i = p_55320_.getCursor();
|
||||
|
||||
while(p_55320_.canRead() && isAllowedInputChat(p_55320_)) {
|
||||
p_55320_.skip();
|
||||
}
|
||||
|
||||
String s = p_55320_.getString().substring(i, p_55320_.getCursor());
|
||||
if (s.isEmpty()) {
|
||||
return (T)null;
|
||||
} else {
|
||||
try {
|
||||
return p_55321_.apply(s);
|
||||
} catch (NumberFormatException numberformatexception) {
|
||||
throw p_55322_.get().createWithContext(p_55320_, s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isAllowedInputChat(StringReader p_55312_) {
|
||||
char c0 = p_55312_.peek();
|
||||
if ((c0 < '0' || c0 > '9') && c0 != '-') {
|
||||
if (c0 != '.') {
|
||||
return false;
|
||||
} else {
|
||||
return !p_55312_.canRead(2) || p_55312_.peek(1) != '.';
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static <T> T optionallyFormat(@Nullable T p_55324_, Function<T, T> p_55325_) {
|
||||
return (T)(p_55324_ == null ? null : p_55325_.apply(p_55324_));
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
protected interface BoundsFactory<T extends Number, R extends MinMaxBounds<T>> {
|
||||
R create(@Nullable T p_55330_, @Nullable T p_55331_);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
protected interface BoundsFromReaderFactory<T extends Number, R extends MinMaxBounds<T>> {
|
||||
R create(StringReader p_55333_, @Nullable T p_55334_, @Nullable T p_55335_) throws CommandSyntaxException;
|
||||
}
|
||||
|
||||
public static class Doubles extends MinMaxBounds<Double> {
|
||||
public static final MinMaxBounds.Doubles ANY = new MinMaxBounds.Doubles((Double)null, (Double)null);
|
||||
@Nullable
|
||||
private final Double minSq;
|
||||
@Nullable
|
||||
private final Double maxSq;
|
||||
|
||||
private static MinMaxBounds.Doubles create(StringReader p_154796_, @Nullable Double p_154797_, @Nullable Double p_154798_) throws CommandSyntaxException {
|
||||
if (p_154797_ != null && p_154798_ != null && p_154797_ > p_154798_) {
|
||||
throw ERROR_SWAPPED.createWithContext(p_154796_);
|
||||
} else {
|
||||
return new MinMaxBounds.Doubles(p_154797_, p_154798_);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static Double squareOpt(@Nullable Double p_154803_) {
|
||||
return p_154803_ == null ? null : p_154803_ * p_154803_;
|
||||
}
|
||||
|
||||
private Doubles(@Nullable Double p_154784_, @Nullable Double p_154785_) {
|
||||
super(p_154784_, p_154785_);
|
||||
this.minSq = squareOpt(p_154784_);
|
||||
this.maxSq = squareOpt(p_154785_);
|
||||
}
|
||||
|
||||
public static MinMaxBounds.Doubles exactly(double p_154787_) {
|
||||
return new MinMaxBounds.Doubles(p_154787_, p_154787_);
|
||||
}
|
||||
|
||||
public static MinMaxBounds.Doubles between(double p_154789_, double p_154790_) {
|
||||
return new MinMaxBounds.Doubles(p_154789_, p_154790_);
|
||||
}
|
||||
|
||||
public static MinMaxBounds.Doubles atLeast(double p_154805_) {
|
||||
return new MinMaxBounds.Doubles(p_154805_, (Double)null);
|
||||
}
|
||||
|
||||
public static MinMaxBounds.Doubles atMost(double p_154809_) {
|
||||
return new MinMaxBounds.Doubles((Double)null, p_154809_);
|
||||
}
|
||||
|
||||
public boolean matches(double p_154811_) {
|
||||
if (this.min != null && this.min > p_154811_) {
|
||||
return false;
|
||||
} else {
|
||||
return this.max == null || !(this.max < p_154811_);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean matchesSqr(double p_154813_) {
|
||||
if (this.minSq != null && this.minSq > p_154813_) {
|
||||
return false;
|
||||
} else {
|
||||
return this.maxSq == null || !(this.maxSq < p_154813_);
|
||||
}
|
||||
}
|
||||
|
||||
public static MinMaxBounds.Doubles fromJson(@Nullable JsonElement p_154792_) {
|
||||
return fromJson(p_154792_, ANY, GsonHelper::convertToDouble, MinMaxBounds.Doubles::new);
|
||||
}
|
||||
|
||||
public static MinMaxBounds.Doubles fromReader(StringReader p_154794_) throws CommandSyntaxException {
|
||||
return fromReader(p_154794_, (p_154807_) -> {
|
||||
return p_154807_;
|
||||
});
|
||||
}
|
||||
|
||||
public static MinMaxBounds.Doubles fromReader(StringReader p_154800_, Function<Double, Double> p_154801_) throws CommandSyntaxException {
|
||||
return fromReader(p_154800_, MinMaxBounds.Doubles::create, Double::parseDouble, CommandSyntaxException.BUILT_IN_EXCEPTIONS::readerInvalidDouble, p_154801_);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Ints extends MinMaxBounds<Integer> {
|
||||
public static final MinMaxBounds.Ints ANY = new MinMaxBounds.Ints((Integer)null, (Integer)null);
|
||||
@Nullable
|
||||
private final Long minSq;
|
||||
@Nullable
|
||||
private final Long maxSq;
|
||||
|
||||
private static MinMaxBounds.Ints create(StringReader p_55378_, @Nullable Integer p_55379_, @Nullable Integer p_55380_) throws CommandSyntaxException {
|
||||
if (p_55379_ != null && p_55380_ != null && p_55379_ > p_55380_) {
|
||||
throw ERROR_SWAPPED.createWithContext(p_55378_);
|
||||
} else {
|
||||
return new MinMaxBounds.Ints(p_55379_, p_55380_);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static Long squareOpt(@Nullable Integer p_55385_) {
|
||||
return p_55385_ == null ? null : p_55385_.longValue() * p_55385_.longValue();
|
||||
}
|
||||
|
||||
private Ints(@Nullable Integer p_55369_, @Nullable Integer p_55370_) {
|
||||
super(p_55369_, p_55370_);
|
||||
this.minSq = squareOpt(p_55369_);
|
||||
this.maxSq = squareOpt(p_55370_);
|
||||
}
|
||||
|
||||
public static MinMaxBounds.Ints exactly(int p_55372_) {
|
||||
return new MinMaxBounds.Ints(p_55372_, p_55372_);
|
||||
}
|
||||
|
||||
public static MinMaxBounds.Ints between(int p_154815_, int p_154816_) {
|
||||
return new MinMaxBounds.Ints(p_154815_, p_154816_);
|
||||
}
|
||||
|
||||
public static MinMaxBounds.Ints atLeast(int p_55387_) {
|
||||
return new MinMaxBounds.Ints(p_55387_, (Integer)null);
|
||||
}
|
||||
|
||||
public static MinMaxBounds.Ints atMost(int p_154820_) {
|
||||
return new MinMaxBounds.Ints((Integer)null, p_154820_);
|
||||
}
|
||||
|
||||
public boolean matches(int p_55391_) {
|
||||
if (this.min != null && this.min > p_55391_) {
|
||||
return false;
|
||||
} else {
|
||||
return this.max == null || this.max >= p_55391_;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean matchesSqr(long p_154818_) {
|
||||
if (this.minSq != null && this.minSq > p_154818_) {
|
||||
return false;
|
||||
} else {
|
||||
return this.maxSq == null || this.maxSq >= p_154818_;
|
||||
}
|
||||
}
|
||||
|
||||
public static MinMaxBounds.Ints fromJson(@Nullable JsonElement p_55374_) {
|
||||
return fromJson(p_55374_, ANY, GsonHelper::convertToInt, MinMaxBounds.Ints::new);
|
||||
}
|
||||
|
||||
public static MinMaxBounds.Ints fromReader(StringReader p_55376_) throws CommandSyntaxException {
|
||||
return fromReader(p_55376_, (p_55389_) -> {
|
||||
return p_55389_;
|
||||
});
|
||||
}
|
||||
|
||||
public static MinMaxBounds.Ints fromReader(StringReader p_55382_, Function<Integer, Integer> p_55383_) throws CommandSyntaxException {
|
||||
return fromReader(p_55382_, MinMaxBounds.Ints::create, Integer::parseInt, CommandSyntaxException.BUILT_IN_EXCEPTIONS::readerInvalidInt, p_55383_);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonNull;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
import net.minecraft.world.effect.MobEffect;
|
||||
import net.minecraft.world.effect.MobEffectInstance;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
|
||||
public class MobEffectsPredicate {
|
||||
public static final MobEffectsPredicate ANY = new MobEffectsPredicate(Collections.emptyMap());
|
||||
private final Map<MobEffect, MobEffectsPredicate.MobEffectInstancePredicate> effects;
|
||||
|
||||
public MobEffectsPredicate(Map<MobEffect, MobEffectsPredicate.MobEffectInstancePredicate> p_56551_) {
|
||||
this.effects = p_56551_;
|
||||
}
|
||||
|
||||
public static MobEffectsPredicate effects() {
|
||||
return new MobEffectsPredicate(Maps.newLinkedHashMap());
|
||||
}
|
||||
|
||||
public MobEffectsPredicate and(MobEffect p_56554_) {
|
||||
this.effects.put(p_56554_, new MobEffectsPredicate.MobEffectInstancePredicate());
|
||||
return this;
|
||||
}
|
||||
|
||||
public MobEffectsPredicate and(MobEffect p_154978_, MobEffectsPredicate.MobEffectInstancePredicate p_154979_) {
|
||||
this.effects.put(p_154978_, p_154979_);
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean matches(Entity p_56556_) {
|
||||
if (this == ANY) {
|
||||
return true;
|
||||
} else {
|
||||
return p_56556_ instanceof LivingEntity ? this.matches(((LivingEntity)p_56556_).getActiveEffectsMap()) : false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean matches(LivingEntity p_56558_) {
|
||||
return this == ANY ? true : this.matches(p_56558_.getActiveEffectsMap());
|
||||
}
|
||||
|
||||
public boolean matches(Map<MobEffect, MobEffectInstance> p_56562_) {
|
||||
if (this == ANY) {
|
||||
return true;
|
||||
} else {
|
||||
for(Map.Entry<MobEffect, MobEffectsPredicate.MobEffectInstancePredicate> entry : this.effects.entrySet()) {
|
||||
MobEffectInstance mobeffectinstance = p_56562_.get(entry.getKey());
|
||||
if (!entry.getValue().matches(mobeffectinstance)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static MobEffectsPredicate fromJson(@Nullable JsonElement p_56560_) {
|
||||
if (p_56560_ != null && !p_56560_.isJsonNull()) {
|
||||
JsonObject jsonobject = GsonHelper.convertToJsonObject(p_56560_, "effects");
|
||||
Map<MobEffect, MobEffectsPredicate.MobEffectInstancePredicate> map = Maps.newLinkedHashMap();
|
||||
|
||||
for(Map.Entry<String, JsonElement> entry : jsonobject.entrySet()) {
|
||||
ResourceLocation resourcelocation = new ResourceLocation(entry.getKey());
|
||||
MobEffect mobeffect = BuiltInRegistries.MOB_EFFECT.getOptional(resourcelocation).orElseThrow(() -> {
|
||||
return new JsonSyntaxException("Unknown effect '" + resourcelocation + "'");
|
||||
});
|
||||
MobEffectsPredicate.MobEffectInstancePredicate mobeffectspredicate$mobeffectinstancepredicate = MobEffectsPredicate.MobEffectInstancePredicate.fromJson(GsonHelper.convertToJsonObject(entry.getValue(), entry.getKey()));
|
||||
map.put(mobeffect, mobeffectspredicate$mobeffectinstancepredicate);
|
||||
}
|
||||
|
||||
return new MobEffectsPredicate(map);
|
||||
} else {
|
||||
return ANY;
|
||||
}
|
||||
}
|
||||
|
||||
public JsonElement serializeToJson() {
|
||||
if (this == ANY) {
|
||||
return JsonNull.INSTANCE;
|
||||
} else {
|
||||
JsonObject jsonobject = new JsonObject();
|
||||
|
||||
for(Map.Entry<MobEffect, MobEffectsPredicate.MobEffectInstancePredicate> entry : this.effects.entrySet()) {
|
||||
jsonobject.add(BuiltInRegistries.MOB_EFFECT.getKey(entry.getKey()).toString(), entry.getValue().serializeToJson());
|
||||
}
|
||||
|
||||
return jsonobject;
|
||||
}
|
||||
}
|
||||
|
||||
public static class MobEffectInstancePredicate {
|
||||
private final MinMaxBounds.Ints amplifier;
|
||||
private final MinMaxBounds.Ints duration;
|
||||
@Nullable
|
||||
private final Boolean ambient;
|
||||
@Nullable
|
||||
private final Boolean visible;
|
||||
|
||||
public MobEffectInstancePredicate(MinMaxBounds.Ints p_56572_, MinMaxBounds.Ints p_56573_, @Nullable Boolean p_56574_, @Nullable Boolean p_56575_) {
|
||||
this.amplifier = p_56572_;
|
||||
this.duration = p_56573_;
|
||||
this.ambient = p_56574_;
|
||||
this.visible = p_56575_;
|
||||
}
|
||||
|
||||
public MobEffectInstancePredicate() {
|
||||
this(MinMaxBounds.Ints.ANY, MinMaxBounds.Ints.ANY, (Boolean)null, (Boolean)null);
|
||||
}
|
||||
|
||||
public boolean matches(@Nullable MobEffectInstance p_56578_) {
|
||||
if (p_56578_ == null) {
|
||||
return false;
|
||||
} else if (!this.amplifier.matches(p_56578_.getAmplifier())) {
|
||||
return false;
|
||||
} else if (!this.duration.matches(p_56578_.getDuration())) {
|
||||
return false;
|
||||
} else if (this.ambient != null && this.ambient != p_56578_.isAmbient()) {
|
||||
return false;
|
||||
} else {
|
||||
return this.visible == null || this.visible == p_56578_.isVisible();
|
||||
}
|
||||
}
|
||||
|
||||
public JsonElement serializeToJson() {
|
||||
JsonObject jsonobject = new JsonObject();
|
||||
jsonobject.add("amplifier", this.amplifier.serializeToJson());
|
||||
jsonobject.add("duration", this.duration.serializeToJson());
|
||||
jsonobject.addProperty("ambient", this.ambient);
|
||||
jsonobject.addProperty("visible", this.visible);
|
||||
return jsonobject;
|
||||
}
|
||||
|
||||
public static MobEffectsPredicate.MobEffectInstancePredicate fromJson(JsonObject p_56580_) {
|
||||
MinMaxBounds.Ints minmaxbounds$ints = MinMaxBounds.Ints.fromJson(p_56580_.get("amplifier"));
|
||||
MinMaxBounds.Ints minmaxbounds$ints1 = MinMaxBounds.Ints.fromJson(p_56580_.get("duration"));
|
||||
Boolean obool = p_56580_.has("ambient") ? GsonHelper.getAsBoolean(p_56580_, "ambient") : null;
|
||||
Boolean obool1 = p_56580_.has("visible") ? GsonHelper.getAsBoolean(p_56580_, "visible") : null;
|
||||
return new MobEffectsPredicate.MobEffectInstancePredicate(minmaxbounds$ints, minmaxbounds$ints1, obool, obool1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonNull;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NbtUtils;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.nbt.TagParser;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
public class NbtPredicate {
|
||||
public static final NbtPredicate ANY = new NbtPredicate((CompoundTag)null);
|
||||
@Nullable
|
||||
private final CompoundTag tag;
|
||||
|
||||
public NbtPredicate(@Nullable CompoundTag p_57475_) {
|
||||
this.tag = p_57475_;
|
||||
}
|
||||
|
||||
public boolean matches(ItemStack p_57480_) {
|
||||
return this == ANY ? true : this.matches(p_57480_.getTag());
|
||||
}
|
||||
|
||||
public boolean matches(Entity p_57478_) {
|
||||
return this == ANY ? true : this.matches(getEntityTagToCompare(p_57478_));
|
||||
}
|
||||
|
||||
public boolean matches(@Nullable Tag p_57484_) {
|
||||
if (p_57484_ == null) {
|
||||
return this == ANY;
|
||||
} else {
|
||||
return this.tag == null || NbtUtils.compareNbt(this.tag, p_57484_, true);
|
||||
}
|
||||
}
|
||||
|
||||
public JsonElement serializeToJson() {
|
||||
return (JsonElement)(this != ANY && this.tag != null ? new JsonPrimitive(this.tag.toString()) : JsonNull.INSTANCE);
|
||||
}
|
||||
|
||||
public static NbtPredicate fromJson(@Nullable JsonElement p_57482_) {
|
||||
if (p_57482_ != null && !p_57482_.isJsonNull()) {
|
||||
CompoundTag compoundtag;
|
||||
try {
|
||||
compoundtag = TagParser.parseTag(GsonHelper.convertToString(p_57482_, "nbt"));
|
||||
} catch (CommandSyntaxException commandsyntaxexception) {
|
||||
throw new JsonSyntaxException("Invalid nbt tag: " + commandsyntaxexception.getMessage());
|
||||
}
|
||||
|
||||
return new NbtPredicate(compoundtag);
|
||||
} else {
|
||||
return ANY;
|
||||
}
|
||||
}
|
||||
|
||||
public static CompoundTag getEntityTagToCompare(Entity p_57486_) {
|
||||
CompoundTag compoundtag = p_57486_.saveWithoutId(new CompoundTag());
|
||||
if (p_57486_ instanceof Player) {
|
||||
ItemStack itemstack = ((Player)p_57486_).getInventory().getSelected();
|
||||
if (!itemstack.isEmpty()) {
|
||||
compoundtag.put("SelectedItem", itemstack.save(new CompoundTag()));
|
||||
}
|
||||
}
|
||||
|
||||
return compoundtag;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.advancements.CriteriaTriggers;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.storage.loot.LootContext;
|
||||
|
||||
public class PickedUpItemTrigger extends SimpleCriterionTrigger<PickedUpItemTrigger.TriggerInstance> {
|
||||
private final ResourceLocation id;
|
||||
|
||||
public PickedUpItemTrigger(ResourceLocation p_221296_) {
|
||||
this.id = p_221296_;
|
||||
}
|
||||
|
||||
public ResourceLocation getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
protected PickedUpItemTrigger.TriggerInstance createInstance(JsonObject p_286475_, ContextAwarePredicate p_286683_, DeserializationContext p_286255_) {
|
||||
ItemPredicate itempredicate = ItemPredicate.fromJson(p_286475_.get("item"));
|
||||
ContextAwarePredicate contextawarepredicate = EntityPredicate.fromJson(p_286475_, "entity", p_286255_);
|
||||
return new PickedUpItemTrigger.TriggerInstance(this.id, p_286683_, itempredicate, contextawarepredicate);
|
||||
}
|
||||
|
||||
public void trigger(ServerPlayer p_221299_, ItemStack p_221300_, @Nullable Entity p_221301_) {
|
||||
LootContext lootcontext = EntityPredicate.createContext(p_221299_, p_221301_);
|
||||
this.trigger(p_221299_, (p_221306_) -> {
|
||||
return p_221306_.matches(p_221299_, p_221300_, lootcontext);
|
||||
});
|
||||
}
|
||||
|
||||
public static class TriggerInstance extends AbstractCriterionTriggerInstance {
|
||||
private final ItemPredicate item;
|
||||
private final ContextAwarePredicate entity;
|
||||
|
||||
public TriggerInstance(ResourceLocation p_286249_, ContextAwarePredicate p_286258_, ItemPredicate p_286761_, ContextAwarePredicate p_286491_) {
|
||||
super(p_286249_, p_286258_);
|
||||
this.item = p_286761_;
|
||||
this.entity = p_286491_;
|
||||
}
|
||||
|
||||
public static PickedUpItemTrigger.TriggerInstance thrownItemPickedUpByEntity(ContextAwarePredicate p_286865_, ItemPredicate p_286788_, ContextAwarePredicate p_286327_) {
|
||||
return new PickedUpItemTrigger.TriggerInstance(CriteriaTriggers.THROWN_ITEM_PICKED_UP_BY_ENTITY.getId(), p_286865_, p_286788_, p_286327_);
|
||||
}
|
||||
|
||||
public static PickedUpItemTrigger.TriggerInstance thrownItemPickedUpByPlayer(ContextAwarePredicate p_286405_, ItemPredicate p_286518_, ContextAwarePredicate p_286381_) {
|
||||
return new PickedUpItemTrigger.TriggerInstance(CriteriaTriggers.THROWN_ITEM_PICKED_UP_BY_PLAYER.getId(), p_286405_, p_286518_, p_286381_);
|
||||
}
|
||||
|
||||
public boolean matches(ServerPlayer p_221323_, ItemStack p_221324_, LootContext p_221325_) {
|
||||
if (!this.item.matches(p_221324_)) {
|
||||
return false;
|
||||
} else {
|
||||
return this.entity.matches(p_221325_);
|
||||
}
|
||||
}
|
||||
|
||||
public JsonObject serializeToJson(SerializationContext p_221331_) {
|
||||
JsonObject jsonobject = super.serializeToJson(p_221331_);
|
||||
jsonobject.add("item", this.item.serializeToJson());
|
||||
jsonobject.add("entity", this.entity.toJson(p_221331_));
|
||||
return jsonobject;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.storage.loot.LootContext;
|
||||
|
||||
public class PlayerHurtEntityTrigger extends SimpleCriterionTrigger<PlayerHurtEntityTrigger.TriggerInstance> {
|
||||
static final ResourceLocation ID = new ResourceLocation("player_hurt_entity");
|
||||
|
||||
public ResourceLocation getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
public PlayerHurtEntityTrigger.TriggerInstance createInstance(JsonObject p_286442_, ContextAwarePredicate p_286426_, DeserializationContext p_286750_) {
|
||||
DamagePredicate damagepredicate = DamagePredicate.fromJson(p_286442_.get("damage"));
|
||||
ContextAwarePredicate contextawarepredicate = EntityPredicate.fromJson(p_286442_, "entity", p_286750_);
|
||||
return new PlayerHurtEntityTrigger.TriggerInstance(p_286426_, damagepredicate, contextawarepredicate);
|
||||
}
|
||||
|
||||
public void trigger(ServerPlayer p_60113_, Entity p_60114_, DamageSource p_60115_, float p_60116_, float p_60117_, boolean p_60118_) {
|
||||
LootContext lootcontext = EntityPredicate.createContext(p_60113_, p_60114_);
|
||||
this.trigger(p_60113_, (p_60126_) -> {
|
||||
return p_60126_.matches(p_60113_, lootcontext, p_60115_, p_60116_, p_60117_, p_60118_);
|
||||
});
|
||||
}
|
||||
|
||||
public static class TriggerInstance extends AbstractCriterionTriggerInstance {
|
||||
private final DamagePredicate damage;
|
||||
private final ContextAwarePredicate entity;
|
||||
|
||||
public TriggerInstance(ContextAwarePredicate p_286866_, DamagePredicate p_286225_, ContextAwarePredicate p_286266_) {
|
||||
super(PlayerHurtEntityTrigger.ID, p_286866_);
|
||||
this.damage = p_286225_;
|
||||
this.entity = p_286266_;
|
||||
}
|
||||
|
||||
public static PlayerHurtEntityTrigger.TriggerInstance playerHurtEntity() {
|
||||
return new PlayerHurtEntityTrigger.TriggerInstance(ContextAwarePredicate.ANY, DamagePredicate.ANY, ContextAwarePredicate.ANY);
|
||||
}
|
||||
|
||||
public static PlayerHurtEntityTrigger.TriggerInstance playerHurtEntity(DamagePredicate p_156062_) {
|
||||
return new PlayerHurtEntityTrigger.TriggerInstance(ContextAwarePredicate.ANY, p_156062_, ContextAwarePredicate.ANY);
|
||||
}
|
||||
|
||||
public static PlayerHurtEntityTrigger.TriggerInstance playerHurtEntity(DamagePredicate.Builder p_60150_) {
|
||||
return new PlayerHurtEntityTrigger.TriggerInstance(ContextAwarePredicate.ANY, p_60150_.build(), ContextAwarePredicate.ANY);
|
||||
}
|
||||
|
||||
public static PlayerHurtEntityTrigger.TriggerInstance playerHurtEntity(EntityPredicate p_156067_) {
|
||||
return new PlayerHurtEntityTrigger.TriggerInstance(ContextAwarePredicate.ANY, DamagePredicate.ANY, EntityPredicate.wrap(p_156067_));
|
||||
}
|
||||
|
||||
public static PlayerHurtEntityTrigger.TriggerInstance playerHurtEntity(DamagePredicate p_156064_, EntityPredicate p_156065_) {
|
||||
return new PlayerHurtEntityTrigger.TriggerInstance(ContextAwarePredicate.ANY, p_156064_, EntityPredicate.wrap(p_156065_));
|
||||
}
|
||||
|
||||
public static PlayerHurtEntityTrigger.TriggerInstance playerHurtEntity(DamagePredicate.Builder p_156059_, EntityPredicate p_156060_) {
|
||||
return new PlayerHurtEntityTrigger.TriggerInstance(ContextAwarePredicate.ANY, p_156059_.build(), EntityPredicate.wrap(p_156060_));
|
||||
}
|
||||
|
||||
public boolean matches(ServerPlayer p_60143_, LootContext p_60144_, DamageSource p_60145_, float p_60146_, float p_60147_, boolean p_60148_) {
|
||||
if (!this.damage.matches(p_60143_, p_60145_, p_60146_, p_60147_, p_60148_)) {
|
||||
return false;
|
||||
} else {
|
||||
return this.entity.matches(p_60144_);
|
||||
}
|
||||
}
|
||||
|
||||
public JsonObject serializeToJson(SerializationContext p_60152_) {
|
||||
JsonObject jsonobject = super.serializeToJson(p_60152_);
|
||||
jsonobject.add("damage", this.damage.serializeToJson());
|
||||
jsonobject.add("entity", this.entity.toJson(p_60152_));
|
||||
return jsonobject;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.storage.loot.LootContext;
|
||||
|
||||
public class PlayerInteractTrigger extends SimpleCriterionTrigger<PlayerInteractTrigger.TriggerInstance> {
|
||||
static final ResourceLocation ID = new ResourceLocation("player_interacted_with_entity");
|
||||
|
||||
public ResourceLocation getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
protected PlayerInteractTrigger.TriggerInstance createInstance(JsonObject p_286617_, ContextAwarePredicate p_286504_, DeserializationContext p_286558_) {
|
||||
ItemPredicate itempredicate = ItemPredicate.fromJson(p_286617_.get("item"));
|
||||
ContextAwarePredicate contextawarepredicate = EntityPredicate.fromJson(p_286617_, "entity", p_286558_);
|
||||
return new PlayerInteractTrigger.TriggerInstance(p_286504_, itempredicate, contextawarepredicate);
|
||||
}
|
||||
|
||||
public void trigger(ServerPlayer p_61495_, ItemStack p_61496_, Entity p_61497_) {
|
||||
LootContext lootcontext = EntityPredicate.createContext(p_61495_, p_61497_);
|
||||
this.trigger(p_61495_, (p_61501_) -> {
|
||||
return p_61501_.matches(p_61496_, lootcontext);
|
||||
});
|
||||
}
|
||||
|
||||
public static class TriggerInstance extends AbstractCriterionTriggerInstance {
|
||||
private final ItemPredicate item;
|
||||
private final ContextAwarePredicate entity;
|
||||
|
||||
public TriggerInstance(ContextAwarePredicate p_286824_, ItemPredicate p_286719_, ContextAwarePredicate p_286219_) {
|
||||
super(PlayerInteractTrigger.ID, p_286824_);
|
||||
this.item = p_286719_;
|
||||
this.entity = p_286219_;
|
||||
}
|
||||
|
||||
public static PlayerInteractTrigger.TriggerInstance itemUsedOnEntity(ContextAwarePredicate p_286452_, ItemPredicate.Builder p_286289_, ContextAwarePredicate p_286370_) {
|
||||
return new PlayerInteractTrigger.TriggerInstance(p_286452_, p_286289_.build(), p_286370_);
|
||||
}
|
||||
|
||||
public static PlayerInteractTrigger.TriggerInstance itemUsedOnEntity(ItemPredicate.Builder p_286235_, ContextAwarePredicate p_286667_) {
|
||||
return itemUsedOnEntity(ContextAwarePredicate.ANY, p_286235_, p_286667_);
|
||||
}
|
||||
|
||||
public boolean matches(ItemStack p_61522_, LootContext p_61523_) {
|
||||
return !this.item.matches(p_61522_) ? false : this.entity.matches(p_61523_);
|
||||
}
|
||||
|
||||
public JsonObject serializeToJson(SerializationContext p_61525_) {
|
||||
JsonObject jsonobject = super.serializeToJson(p_61525_);
|
||||
jsonobject.add("item", this.item.serializeToJson());
|
||||
jsonobject.add("entity", this.entity.toJson(p_61525_));
|
||||
return jsonobject;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,327 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import it.unimi.dsi.fastutil.objects.Object2BooleanMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Predicate;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.advancements.Advancement;
|
||||
import net.minecraft.advancements.AdvancementProgress;
|
||||
import net.minecraft.advancements.CriterionProgress;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.PlayerAdvancements;
|
||||
import net.minecraft.server.ServerAdvancementManager;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.stats.RecipeBook;
|
||||
import net.minecraft.stats.Stat;
|
||||
import net.minecraft.stats.StatType;
|
||||
import net.minecraft.stats.StatsCounter;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.projectile.ProjectileUtil;
|
||||
import net.minecraft.world.level.GameType;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.world.phys.EntityHitResult;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
public class PlayerPredicate implements EntitySubPredicate {
|
||||
public static final int LOOKING_AT_RANGE = 100;
|
||||
private final MinMaxBounds.Ints level;
|
||||
@Nullable
|
||||
private final GameType gameType;
|
||||
private final Map<Stat<?>, MinMaxBounds.Ints> stats;
|
||||
private final Object2BooleanMap<ResourceLocation> recipes;
|
||||
private final Map<ResourceLocation, PlayerPredicate.AdvancementPredicate> advancements;
|
||||
private final EntityPredicate lookingAt;
|
||||
|
||||
private static PlayerPredicate.AdvancementPredicate advancementPredicateFromJson(JsonElement p_62290_) {
|
||||
if (p_62290_.isJsonPrimitive()) {
|
||||
boolean flag = p_62290_.getAsBoolean();
|
||||
return new PlayerPredicate.AdvancementDonePredicate(flag);
|
||||
} else {
|
||||
Object2BooleanMap<String> object2booleanmap = new Object2BooleanOpenHashMap<>();
|
||||
JsonObject jsonobject = GsonHelper.convertToJsonObject(p_62290_, "criterion data");
|
||||
jsonobject.entrySet().forEach((p_62288_) -> {
|
||||
boolean flag1 = GsonHelper.convertToBoolean(p_62288_.getValue(), "criterion test");
|
||||
object2booleanmap.put(p_62288_.getKey(), flag1);
|
||||
});
|
||||
return new PlayerPredicate.AdvancementCriterionsPredicate(object2booleanmap);
|
||||
}
|
||||
}
|
||||
|
||||
PlayerPredicate(MinMaxBounds.Ints p_156746_, @Nullable GameType p_156747_, Map<Stat<?>, MinMaxBounds.Ints> p_156748_, Object2BooleanMap<ResourceLocation> p_156749_, Map<ResourceLocation, PlayerPredicate.AdvancementPredicate> p_156750_, EntityPredicate p_156751_) {
|
||||
this.level = p_156746_;
|
||||
this.gameType = p_156747_;
|
||||
this.stats = p_156748_;
|
||||
this.recipes = p_156749_;
|
||||
this.advancements = p_156750_;
|
||||
this.lookingAt = p_156751_;
|
||||
}
|
||||
|
||||
public boolean matches(Entity p_222484_, ServerLevel p_222485_, @Nullable Vec3 p_222486_) {
|
||||
if (!(p_222484_ instanceof ServerPlayer serverplayer)) {
|
||||
return false;
|
||||
} else if (!this.level.matches(serverplayer.experienceLevel)) {
|
||||
return false;
|
||||
} else if (this.gameType != null && this.gameType != serverplayer.gameMode.getGameModeForPlayer()) {
|
||||
return false;
|
||||
} else {
|
||||
StatsCounter statscounter = serverplayer.getStats();
|
||||
|
||||
for(Map.Entry<Stat<?>, MinMaxBounds.Ints> entry : this.stats.entrySet()) {
|
||||
int i = statscounter.getValue(entry.getKey());
|
||||
if (!entry.getValue().matches(i)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
RecipeBook recipebook = serverplayer.getRecipeBook();
|
||||
|
||||
for(Object2BooleanMap.Entry<ResourceLocation> entry2 : this.recipes.object2BooleanEntrySet()) {
|
||||
if (recipebook.contains(entry2.getKey()) != entry2.getBooleanValue()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.advancements.isEmpty()) {
|
||||
PlayerAdvancements playeradvancements = serverplayer.getAdvancements();
|
||||
ServerAdvancementManager serveradvancementmanager = serverplayer.getServer().getAdvancements();
|
||||
|
||||
for(Map.Entry<ResourceLocation, PlayerPredicate.AdvancementPredicate> entry1 : this.advancements.entrySet()) {
|
||||
Advancement advancement = serveradvancementmanager.getAdvancement(entry1.getKey());
|
||||
if (advancement == null || !entry1.getValue().test(playeradvancements.getOrStartProgress(advancement))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.lookingAt != EntityPredicate.ANY) {
|
||||
Vec3 vec3 = serverplayer.getEyePosition();
|
||||
Vec3 vec31 = serverplayer.getViewVector(1.0F);
|
||||
Vec3 vec32 = vec3.add(vec31.x * 100.0D, vec31.y * 100.0D, vec31.z * 100.0D);
|
||||
EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(serverplayer.level(), serverplayer, vec3, vec32, (new AABB(vec3, vec32)).inflate(1.0D), (p_156765_) -> {
|
||||
return !p_156765_.isSpectator();
|
||||
}, 0.0F);
|
||||
if (entityhitresult == null || entityhitresult.getType() != HitResult.Type.ENTITY) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Entity entity = entityhitresult.getEntity();
|
||||
if (!this.lookingAt.matches(serverplayer, entity) || !serverplayer.hasLineOfSight(entity)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static PlayerPredicate fromJson(JsonObject p_222492_) {
|
||||
MinMaxBounds.Ints minmaxbounds$ints = MinMaxBounds.Ints.fromJson(p_222492_.get("level"));
|
||||
String s = GsonHelper.getAsString(p_222492_, "gamemode", "");
|
||||
GameType gametype = GameType.byName(s, (GameType)null);
|
||||
Map<Stat<?>, MinMaxBounds.Ints> map = Maps.newHashMap();
|
||||
JsonArray jsonarray = GsonHelper.getAsJsonArray(p_222492_, "stats", (JsonArray)null);
|
||||
if (jsonarray != null) {
|
||||
for(JsonElement jsonelement : jsonarray) {
|
||||
JsonObject jsonobject = GsonHelper.convertToJsonObject(jsonelement, "stats entry");
|
||||
ResourceLocation resourcelocation = new ResourceLocation(GsonHelper.getAsString(jsonobject, "type"));
|
||||
StatType<?> stattype = BuiltInRegistries.STAT_TYPE.get(resourcelocation);
|
||||
if (stattype == null) {
|
||||
throw new JsonParseException("Invalid stat type: " + resourcelocation);
|
||||
}
|
||||
|
||||
ResourceLocation resourcelocation1 = new ResourceLocation(GsonHelper.getAsString(jsonobject, "stat"));
|
||||
Stat<?> stat = getStat(stattype, resourcelocation1);
|
||||
MinMaxBounds.Ints minmaxbounds$ints1 = MinMaxBounds.Ints.fromJson(jsonobject.get("value"));
|
||||
map.put(stat, minmaxbounds$ints1);
|
||||
}
|
||||
}
|
||||
|
||||
Object2BooleanMap<ResourceLocation> object2booleanmap = new Object2BooleanOpenHashMap<>();
|
||||
JsonObject jsonobject1 = GsonHelper.getAsJsonObject(p_222492_, "recipes", new JsonObject());
|
||||
|
||||
for(Map.Entry<String, JsonElement> entry : jsonobject1.entrySet()) {
|
||||
ResourceLocation resourcelocation2 = new ResourceLocation(entry.getKey());
|
||||
boolean flag = GsonHelper.convertToBoolean(entry.getValue(), "recipe present");
|
||||
object2booleanmap.put(resourcelocation2, flag);
|
||||
}
|
||||
|
||||
Map<ResourceLocation, PlayerPredicate.AdvancementPredicate> map1 = Maps.newHashMap();
|
||||
JsonObject jsonobject2 = GsonHelper.getAsJsonObject(p_222492_, "advancements", new JsonObject());
|
||||
|
||||
for(Map.Entry<String, JsonElement> entry1 : jsonobject2.entrySet()) {
|
||||
ResourceLocation resourcelocation3 = new ResourceLocation(entry1.getKey());
|
||||
PlayerPredicate.AdvancementPredicate playerpredicate$advancementpredicate = advancementPredicateFromJson(entry1.getValue());
|
||||
map1.put(resourcelocation3, playerpredicate$advancementpredicate);
|
||||
}
|
||||
|
||||
EntityPredicate entitypredicate = EntityPredicate.fromJson(p_222492_.get("looking_at"));
|
||||
return new PlayerPredicate(minmaxbounds$ints, gametype, map, object2booleanmap, map1, entitypredicate);
|
||||
}
|
||||
|
||||
private static <T> Stat<T> getStat(StatType<T> p_62268_, ResourceLocation p_62269_) {
|
||||
Registry<T> registry = p_62268_.getRegistry();
|
||||
T t = registry.get(p_62269_);
|
||||
if (t == null) {
|
||||
throw new JsonParseException("Unknown object " + p_62269_ + " for stat type " + BuiltInRegistries.STAT_TYPE.getKey(p_62268_));
|
||||
} else {
|
||||
return p_62268_.get(t);
|
||||
}
|
||||
}
|
||||
|
||||
private static <T> ResourceLocation getStatValueId(Stat<T> p_62266_) {
|
||||
return p_62266_.getType().getRegistry().getKey(p_62266_.getValue());
|
||||
}
|
||||
|
||||
public JsonObject serializeCustomData() {
|
||||
JsonObject jsonobject = new JsonObject();
|
||||
jsonobject.add("level", this.level.serializeToJson());
|
||||
if (this.gameType != null) {
|
||||
jsonobject.addProperty("gamemode", this.gameType.getName());
|
||||
}
|
||||
|
||||
if (!this.stats.isEmpty()) {
|
||||
JsonArray jsonarray = new JsonArray();
|
||||
this.stats.forEach((p_222489_, p_222490_) -> {
|
||||
JsonObject jsonobject3 = new JsonObject();
|
||||
jsonobject3.addProperty("type", BuiltInRegistries.STAT_TYPE.getKey(p_222489_.getType()).toString());
|
||||
jsonobject3.addProperty("stat", getStatValueId(p_222489_).toString());
|
||||
jsonobject3.add("value", p_222490_.serializeToJson());
|
||||
jsonarray.add(jsonobject3);
|
||||
});
|
||||
jsonobject.add("stats", jsonarray);
|
||||
}
|
||||
|
||||
if (!this.recipes.isEmpty()) {
|
||||
JsonObject jsonobject1 = new JsonObject();
|
||||
this.recipes.forEach((p_222499_, p_222500_) -> {
|
||||
jsonobject1.addProperty(p_222499_.toString(), p_222500_);
|
||||
});
|
||||
jsonobject.add("recipes", jsonobject1);
|
||||
}
|
||||
|
||||
if (!this.advancements.isEmpty()) {
|
||||
JsonObject jsonobject2 = new JsonObject();
|
||||
this.advancements.forEach((p_222495_, p_222496_) -> {
|
||||
jsonobject2.add(p_222495_.toString(), p_222496_.toJson());
|
||||
});
|
||||
jsonobject.add("advancements", jsonobject2);
|
||||
}
|
||||
|
||||
jsonobject.add("looking_at", this.lookingAt.serializeToJson());
|
||||
return jsonobject;
|
||||
}
|
||||
|
||||
public EntitySubPredicate.Type type() {
|
||||
return EntitySubPredicate.Types.PLAYER;
|
||||
}
|
||||
|
||||
static class AdvancementCriterionsPredicate implements PlayerPredicate.AdvancementPredicate {
|
||||
private final Object2BooleanMap<String> criterions;
|
||||
|
||||
public AdvancementCriterionsPredicate(Object2BooleanMap<String> p_62293_) {
|
||||
this.criterions = p_62293_;
|
||||
}
|
||||
|
||||
public JsonElement toJson() {
|
||||
JsonObject jsonobject = new JsonObject();
|
||||
this.criterions.forEach(jsonobject::addProperty);
|
||||
return jsonobject;
|
||||
}
|
||||
|
||||
public boolean test(AdvancementProgress p_62296_) {
|
||||
for(Object2BooleanMap.Entry<String> entry : this.criterions.object2BooleanEntrySet()) {
|
||||
CriterionProgress criterionprogress = p_62296_.getCriterion(entry.getKey());
|
||||
if (criterionprogress == null || criterionprogress.isDone() != entry.getBooleanValue()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
static class AdvancementDonePredicate implements PlayerPredicate.AdvancementPredicate {
|
||||
private final boolean state;
|
||||
|
||||
public AdvancementDonePredicate(boolean p_62301_) {
|
||||
this.state = p_62301_;
|
||||
}
|
||||
|
||||
public JsonElement toJson() {
|
||||
return new JsonPrimitive(this.state);
|
||||
}
|
||||
|
||||
public boolean test(AdvancementProgress p_62304_) {
|
||||
return p_62304_.isDone() == this.state;
|
||||
}
|
||||
}
|
||||
|
||||
interface AdvancementPredicate extends Predicate<AdvancementProgress> {
|
||||
JsonElement toJson();
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private MinMaxBounds.Ints level = MinMaxBounds.Ints.ANY;
|
||||
@Nullable
|
||||
private GameType gameType;
|
||||
private final Map<Stat<?>, MinMaxBounds.Ints> stats = Maps.newHashMap();
|
||||
private final Object2BooleanMap<ResourceLocation> recipes = new Object2BooleanOpenHashMap<>();
|
||||
private final Map<ResourceLocation, PlayerPredicate.AdvancementPredicate> advancements = Maps.newHashMap();
|
||||
private EntityPredicate lookingAt = EntityPredicate.ANY;
|
||||
|
||||
public static PlayerPredicate.Builder player() {
|
||||
return new PlayerPredicate.Builder();
|
||||
}
|
||||
|
||||
public PlayerPredicate.Builder setLevel(MinMaxBounds.Ints p_156776_) {
|
||||
this.level = p_156776_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PlayerPredicate.Builder addStat(Stat<?> p_156769_, MinMaxBounds.Ints p_156770_) {
|
||||
this.stats.put(p_156769_, p_156770_);
|
||||
return this;
|
||||
}
|
||||
|
||||
public PlayerPredicate.Builder addRecipe(ResourceLocation p_156781_, boolean p_156782_) {
|
||||
this.recipes.put(p_156781_, p_156782_);
|
||||
return this;
|
||||
}
|
||||
|
||||
public PlayerPredicate.Builder setGameType(GameType p_156774_) {
|
||||
this.gameType = p_156774_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PlayerPredicate.Builder setLookingAt(EntityPredicate p_156772_) {
|
||||
this.lookingAt = p_156772_;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PlayerPredicate.Builder checkAdvancementDone(ResourceLocation p_156784_, boolean p_156785_) {
|
||||
this.advancements.put(p_156784_, new PlayerPredicate.AdvancementDonePredicate(p_156785_));
|
||||
return this;
|
||||
}
|
||||
|
||||
public PlayerPredicate.Builder checkAdvancementCriterions(ResourceLocation p_156778_, Map<String, Boolean> p_156779_) {
|
||||
this.advancements.put(p_156778_, new PlayerPredicate.AdvancementCriterionsPredicate(new Object2BooleanOpenHashMap<>(p_156779_)));
|
||||
return this;
|
||||
}
|
||||
|
||||
public PlayerPredicate build() {
|
||||
return new PlayerPredicate(this.level, this.gameType, this.stats, this.recipes, this.advancements, this.lookingAt);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.advancements.CriteriaTriggers;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
|
||||
public class PlayerTrigger extends SimpleCriterionTrigger<PlayerTrigger.TriggerInstance> {
|
||||
final ResourceLocation id;
|
||||
|
||||
public PlayerTrigger(ResourceLocation p_222616_) {
|
||||
this.id = p_222616_;
|
||||
}
|
||||
|
||||
public ResourceLocation getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public PlayerTrigger.TriggerInstance createInstance(JsonObject p_286310_, ContextAwarePredicate p_286629_, DeserializationContext p_286901_) {
|
||||
return new PlayerTrigger.TriggerInstance(this.id, p_286629_);
|
||||
}
|
||||
|
||||
public void trigger(ServerPlayer p_222619_) {
|
||||
this.trigger(p_222619_, (p_222625_) -> {
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
public static class TriggerInstance extends AbstractCriterionTriggerInstance {
|
||||
public TriggerInstance(ResourceLocation p_286413_, ContextAwarePredicate p_286749_) {
|
||||
super(p_286413_, p_286749_);
|
||||
}
|
||||
|
||||
public static PlayerTrigger.TriggerInstance located(LocationPredicate p_222636_) {
|
||||
return new PlayerTrigger.TriggerInstance(CriteriaTriggers.LOCATION.id, EntityPredicate.wrap(EntityPredicate.Builder.entity().located(p_222636_).build()));
|
||||
}
|
||||
|
||||
public static PlayerTrigger.TriggerInstance located(EntityPredicate p_222634_) {
|
||||
return new PlayerTrigger.TriggerInstance(CriteriaTriggers.LOCATION.id, EntityPredicate.wrap(p_222634_));
|
||||
}
|
||||
|
||||
public static PlayerTrigger.TriggerInstance sleptInBed() {
|
||||
return new PlayerTrigger.TriggerInstance(CriteriaTriggers.SLEPT_IN_BED.id, ContextAwarePredicate.ANY);
|
||||
}
|
||||
|
||||
public static PlayerTrigger.TriggerInstance raidWon() {
|
||||
return new PlayerTrigger.TriggerInstance(CriteriaTriggers.RAID_WIN.id, ContextAwarePredicate.ANY);
|
||||
}
|
||||
|
||||
public static PlayerTrigger.TriggerInstance avoidVibration() {
|
||||
return new PlayerTrigger.TriggerInstance(CriteriaTriggers.AVOID_VIBRATION.id, ContextAwarePredicate.ANY);
|
||||
}
|
||||
|
||||
public static PlayerTrigger.TriggerInstance tick() {
|
||||
return new PlayerTrigger.TriggerInstance(CriteriaTriggers.TICK.id, ContextAwarePredicate.ANY);
|
||||
}
|
||||
|
||||
public static PlayerTrigger.TriggerInstance walkOnBlockWithEquipment(Block p_222638_, Item p_222639_) {
|
||||
return located(EntityPredicate.Builder.entity().equipment(EntityEquipmentPredicate.Builder.equipment().feet(ItemPredicate.Builder.item().of(p_222639_).build()).build()).steppingOn(LocationPredicate.Builder.location().setBlock(BlockPredicate.Builder.block().of(p_222638_).build()).build()).build());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
public class RecipeCraftedTrigger extends SimpleCriterionTrigger<RecipeCraftedTrigger.TriggerInstance> {
|
||||
static final ResourceLocation ID = new ResourceLocation("recipe_crafted");
|
||||
|
||||
public ResourceLocation getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
protected RecipeCraftedTrigger.TriggerInstance createInstance(JsonObject p_286541_, ContextAwarePredicate p_286267_, DeserializationContext p_286402_) {
|
||||
ResourceLocation resourcelocation = new ResourceLocation(GsonHelper.getAsString(p_286541_, "recipe_id"));
|
||||
ItemPredicate[] aitempredicate = ItemPredicate.fromJsonArray(p_286541_.get("ingredients"));
|
||||
return new RecipeCraftedTrigger.TriggerInstance(p_286267_, resourcelocation, List.of(aitempredicate));
|
||||
}
|
||||
|
||||
public void trigger(ServerPlayer p_281468_, ResourceLocation p_282903_, List<ItemStack> p_282070_) {
|
||||
this.trigger(p_281468_, (p_282798_) -> {
|
||||
return p_282798_.matches(p_282903_, p_282070_);
|
||||
});
|
||||
}
|
||||
|
||||
public static class TriggerInstance extends AbstractCriterionTriggerInstance {
|
||||
private final ResourceLocation recipeId;
|
||||
private final List<ItemPredicate> predicates;
|
||||
|
||||
public TriggerInstance(ContextAwarePredicate p_286913_, ResourceLocation p_286906_, List<ItemPredicate> p_286302_) {
|
||||
super(RecipeCraftedTrigger.ID, p_286913_);
|
||||
this.recipeId = p_286906_;
|
||||
this.predicates = p_286302_;
|
||||
}
|
||||
|
||||
public static RecipeCraftedTrigger.TriggerInstance craftedItem(ResourceLocation p_282794_, List<ItemPredicate> p_281369_) {
|
||||
return new RecipeCraftedTrigger.TriggerInstance(ContextAwarePredicate.ANY, p_282794_, p_281369_);
|
||||
}
|
||||
|
||||
public static RecipeCraftedTrigger.TriggerInstance craftedItem(ResourceLocation p_283538_) {
|
||||
return new RecipeCraftedTrigger.TriggerInstance(ContextAwarePredicate.ANY, p_283538_, List.of());
|
||||
}
|
||||
|
||||
boolean matches(ResourceLocation p_283528_, List<ItemStack> p_283698_) {
|
||||
if (!p_283528_.equals(this.recipeId)) {
|
||||
return false;
|
||||
} else {
|
||||
List<ItemStack> list = new ArrayList<>(p_283698_);
|
||||
|
||||
for(ItemPredicate itempredicate : this.predicates) {
|
||||
boolean flag = false;
|
||||
Iterator<ItemStack> iterator = list.iterator();
|
||||
|
||||
while(iterator.hasNext()) {
|
||||
if (itempredicate.matches(iterator.next())) {
|
||||
iterator.remove();
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!flag) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public JsonObject serializeToJson(SerializationContext p_281942_) {
|
||||
JsonObject jsonobject = super.serializeToJson(p_281942_);
|
||||
jsonobject.addProperty("recipe_id", this.recipeId.toString());
|
||||
if (this.predicates.size() > 0) {
|
||||
JsonArray jsonarray = new JsonArray();
|
||||
|
||||
for(ItemPredicate itempredicate : this.predicates) {
|
||||
jsonarray.add(itempredicate.serializeToJson());
|
||||
}
|
||||
|
||||
jsonobject.add("ingredients", jsonarray);
|
||||
}
|
||||
|
||||
return jsonobject;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
import net.minecraft.world.item.crafting.Recipe;
|
||||
|
||||
public class RecipeUnlockedTrigger extends SimpleCriterionTrigger<RecipeUnlockedTrigger.TriggerInstance> {
|
||||
static final ResourceLocation ID = new ResourceLocation("recipe_unlocked");
|
||||
|
||||
public ResourceLocation getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
public RecipeUnlockedTrigger.TriggerInstance createInstance(JsonObject p_286387_, ContextAwarePredicate p_286739_, DeserializationContext p_286649_) {
|
||||
ResourceLocation resourcelocation = new ResourceLocation(GsonHelper.getAsString(p_286387_, "recipe"));
|
||||
return new RecipeUnlockedTrigger.TriggerInstance(p_286739_, resourcelocation);
|
||||
}
|
||||
|
||||
public void trigger(ServerPlayer p_63719_, Recipe<?> p_63720_) {
|
||||
this.trigger(p_63719_, (p_63723_) -> {
|
||||
return p_63723_.matches(p_63720_);
|
||||
});
|
||||
}
|
||||
|
||||
public static RecipeUnlockedTrigger.TriggerInstance unlocked(ResourceLocation p_63729_) {
|
||||
return new RecipeUnlockedTrigger.TriggerInstance(ContextAwarePredicate.ANY, p_63729_);
|
||||
}
|
||||
|
||||
public static class TriggerInstance extends AbstractCriterionTriggerInstance {
|
||||
private final ResourceLocation recipe;
|
||||
|
||||
public TriggerInstance(ContextAwarePredicate p_286461_, ResourceLocation p_286775_) {
|
||||
super(RecipeUnlockedTrigger.ID, p_286461_);
|
||||
this.recipe = p_286775_;
|
||||
}
|
||||
|
||||
public JsonObject serializeToJson(SerializationContext p_63742_) {
|
||||
JsonObject jsonobject = super.serializeToJson(p_63742_);
|
||||
jsonobject.addProperty("recipe", this.recipe.toString());
|
||||
return jsonobject;
|
||||
}
|
||||
|
||||
public boolean matches(Recipe<?> p_63740_) {
|
||||
return this.recipe.equals(p_63740_.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonElement;
|
||||
import net.minecraft.world.level.storage.loot.Deserializers;
|
||||
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;
|
||||
|
||||
public class SerializationContext {
|
||||
public static final SerializationContext INSTANCE = new SerializationContext();
|
||||
private final Gson predicateGson = Deserializers.createConditionSerializer().create();
|
||||
|
||||
public final JsonElement serializeConditions(LootItemCondition[] p_64773_) {
|
||||
return this.predicateGson.toJsonTree(p_64773_);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
|
||||
public class ShotCrossbowTrigger extends SimpleCriterionTrigger<ShotCrossbowTrigger.TriggerInstance> {
|
||||
static final ResourceLocation ID = new ResourceLocation("shot_crossbow");
|
||||
|
||||
public ResourceLocation getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
public ShotCrossbowTrigger.TriggerInstance createInstance(JsonObject p_286679_, ContextAwarePredicate p_286410_, DeserializationContext p_286233_) {
|
||||
ItemPredicate itempredicate = ItemPredicate.fromJson(p_286679_.get("item"));
|
||||
return new ShotCrossbowTrigger.TriggerInstance(p_286410_, itempredicate);
|
||||
}
|
||||
|
||||
public void trigger(ServerPlayer p_65463_, ItemStack p_65464_) {
|
||||
this.trigger(p_65463_, (p_65467_) -> {
|
||||
return p_65467_.matches(p_65464_);
|
||||
});
|
||||
}
|
||||
|
||||
public static class TriggerInstance extends AbstractCriterionTriggerInstance {
|
||||
private final ItemPredicate item;
|
||||
|
||||
public TriggerInstance(ContextAwarePredicate p_286262_, ItemPredicate p_286755_) {
|
||||
super(ShotCrossbowTrigger.ID, p_286262_);
|
||||
this.item = p_286755_;
|
||||
}
|
||||
|
||||
public static ShotCrossbowTrigger.TriggerInstance shotCrossbow(ItemPredicate p_159432_) {
|
||||
return new ShotCrossbowTrigger.TriggerInstance(ContextAwarePredicate.ANY, p_159432_);
|
||||
}
|
||||
|
||||
public static ShotCrossbowTrigger.TriggerInstance shotCrossbow(ItemLike p_65484_) {
|
||||
return new ShotCrossbowTrigger.TriggerInstance(ContextAwarePredicate.ANY, ItemPredicate.Builder.item().of(p_65484_).build());
|
||||
}
|
||||
|
||||
public boolean matches(ItemStack p_65482_) {
|
||||
return this.item.matches(p_65482_);
|
||||
}
|
||||
|
||||
public JsonObject serializeToJson(SerializationContext p_65486_) {
|
||||
JsonObject jsonobject = super.serializeToJson(p_65486_);
|
||||
jsonobject.add("item", this.item.serializeToJson());
|
||||
return jsonobject;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.gson.JsonObject;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
import net.minecraft.advancements.CriterionTrigger;
|
||||
import net.minecraft.server.PlayerAdvancements;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.level.storage.loot.LootContext;
|
||||
|
||||
public abstract class SimpleCriterionTrigger<T extends AbstractCriterionTriggerInstance> implements CriterionTrigger<T> {
|
||||
private final Map<PlayerAdvancements, Set<CriterionTrigger.Listener<T>>> players = Maps.newIdentityHashMap();
|
||||
|
||||
public final void addPlayerListener(PlayerAdvancements p_66243_, CriterionTrigger.Listener<T> p_66244_) {
|
||||
this.players.computeIfAbsent(p_66243_, (p_66252_) -> {
|
||||
return Sets.newHashSet();
|
||||
}).add(p_66244_);
|
||||
}
|
||||
|
||||
public final void removePlayerListener(PlayerAdvancements p_66254_, CriterionTrigger.Listener<T> p_66255_) {
|
||||
Set<CriterionTrigger.Listener<T>> set = this.players.get(p_66254_);
|
||||
if (set != null) {
|
||||
set.remove(p_66255_);
|
||||
if (set.isEmpty()) {
|
||||
this.players.remove(p_66254_);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public final void removePlayerListeners(PlayerAdvancements p_66241_) {
|
||||
this.players.remove(p_66241_);
|
||||
}
|
||||
|
||||
protected abstract T createInstance(JsonObject p_66248_, ContextAwarePredicate p_286603_, DeserializationContext p_66250_);
|
||||
|
||||
public final T createInstance(JsonObject p_66246_, DeserializationContext p_66247_) {
|
||||
ContextAwarePredicate contextawarepredicate = EntityPredicate.fromJson(p_66246_, "player", p_66247_);
|
||||
return this.createInstance(p_66246_, contextawarepredicate, p_66247_);
|
||||
}
|
||||
|
||||
protected void trigger(ServerPlayer p_66235_, Predicate<T> p_66236_) {
|
||||
PlayerAdvancements playeradvancements = p_66235_.getAdvancements();
|
||||
Set<CriterionTrigger.Listener<T>> set = this.players.get(playeradvancements);
|
||||
if (set != null && !set.isEmpty()) {
|
||||
LootContext lootcontext = EntityPredicate.createContext(p_66235_, p_66235_);
|
||||
List<CriterionTrigger.Listener<T>> list = null;
|
||||
|
||||
for(CriterionTrigger.Listener<T> listener : set) {
|
||||
T t = listener.getTriggerInstance();
|
||||
if (p_66236_.test(t) && t.getPlayerPredicate().matches(lootcontext)) {
|
||||
if (list == null) {
|
||||
list = Lists.newArrayList();
|
||||
}
|
||||
|
||||
list.add(listener);
|
||||
}
|
||||
}
|
||||
|
||||
if (list != null) {
|
||||
for(CriterionTrigger.Listener<T> listener1 : list) {
|
||||
listener1.run(playeradvancements);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
public class SlideDownBlockTrigger extends SimpleCriterionTrigger<SlideDownBlockTrigger.TriggerInstance> {
|
||||
static final ResourceLocation ID = new ResourceLocation("slide_down_block");
|
||||
|
||||
public ResourceLocation getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
public SlideDownBlockTrigger.TriggerInstance createInstance(JsonObject p_286879_, ContextAwarePredicate p_286565_, DeserializationContext p_286581_) {
|
||||
Block block = deserializeBlock(p_286879_);
|
||||
StatePropertiesPredicate statepropertiespredicate = StatePropertiesPredicate.fromJson(p_286879_.get("state"));
|
||||
if (block != null) {
|
||||
statepropertiespredicate.checkState(block.getStateDefinition(), (p_66983_) -> {
|
||||
throw new JsonSyntaxException("Block " + block + " has no property " + p_66983_);
|
||||
});
|
||||
}
|
||||
|
||||
return new SlideDownBlockTrigger.TriggerInstance(p_286565_, block, statepropertiespredicate);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static Block deserializeBlock(JsonObject p_66988_) {
|
||||
if (p_66988_.has("block")) {
|
||||
ResourceLocation resourcelocation = new ResourceLocation(GsonHelper.getAsString(p_66988_, "block"));
|
||||
return BuiltInRegistries.BLOCK.getOptional(resourcelocation).orElseThrow(() -> {
|
||||
return new JsonSyntaxException("Unknown block type '" + resourcelocation + "'");
|
||||
});
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void trigger(ServerPlayer p_66979_, BlockState p_66980_) {
|
||||
this.trigger(p_66979_, (p_66986_) -> {
|
||||
return p_66986_.matches(p_66980_);
|
||||
});
|
||||
}
|
||||
|
||||
public static class TriggerInstance extends AbstractCriterionTriggerInstance {
|
||||
@Nullable
|
||||
private final Block block;
|
||||
private final StatePropertiesPredicate state;
|
||||
|
||||
public TriggerInstance(ContextAwarePredicate p_286920_, @Nullable Block p_286622_, StatePropertiesPredicate p_286692_) {
|
||||
super(SlideDownBlockTrigger.ID, p_286920_);
|
||||
this.block = p_286622_;
|
||||
this.state = p_286692_;
|
||||
}
|
||||
|
||||
public static SlideDownBlockTrigger.TriggerInstance slidesDownBlock(Block p_67007_) {
|
||||
return new SlideDownBlockTrigger.TriggerInstance(ContextAwarePredicate.ANY, p_67007_, StatePropertiesPredicate.ANY);
|
||||
}
|
||||
|
||||
public JsonObject serializeToJson(SerializationContext p_67011_) {
|
||||
JsonObject jsonobject = super.serializeToJson(p_67011_);
|
||||
if (this.block != null) {
|
||||
jsonobject.addProperty("block", BuiltInRegistries.BLOCK.getKey(this.block).toString());
|
||||
}
|
||||
|
||||
jsonobject.add("state", this.state.serializeToJson());
|
||||
return jsonobject;
|
||||
}
|
||||
|
||||
public boolean matches(BlockState p_67009_) {
|
||||
if (this.block != null && !p_67009_.is(this.block)) {
|
||||
return false;
|
||||
} else {
|
||||
return this.state.matches(p_67009_);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.monster.Slime;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
public class SlimePredicate implements EntitySubPredicate {
|
||||
private final MinMaxBounds.Ints size;
|
||||
|
||||
private SlimePredicate(MinMaxBounds.Ints p_223420_) {
|
||||
this.size = p_223420_;
|
||||
}
|
||||
|
||||
public static SlimePredicate sized(MinMaxBounds.Ints p_223427_) {
|
||||
return new SlimePredicate(p_223427_);
|
||||
}
|
||||
|
||||
public static SlimePredicate fromJson(JsonObject p_223429_) {
|
||||
MinMaxBounds.Ints minmaxbounds$ints = MinMaxBounds.Ints.fromJson(p_223429_.get("size"));
|
||||
return new SlimePredicate(minmaxbounds$ints);
|
||||
}
|
||||
|
||||
public JsonObject serializeCustomData() {
|
||||
JsonObject jsonobject = new JsonObject();
|
||||
jsonobject.add("size", this.size.serializeToJson());
|
||||
return jsonobject;
|
||||
}
|
||||
|
||||
public boolean matches(Entity p_223423_, ServerLevel p_223424_, @Nullable Vec3 p_223425_) {
|
||||
if (p_223423_ instanceof Slime slime) {
|
||||
return this.size.matches(slime.getSize());
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public EntitySubPredicate.Type type() {
|
||||
return EntitySubPredicate.Types.SLIME;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
public class StartRidingTrigger extends SimpleCriterionTrigger<StartRidingTrigger.TriggerInstance> {
|
||||
static final ResourceLocation ID = new ResourceLocation("started_riding");
|
||||
|
||||
public ResourceLocation getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
public StartRidingTrigger.TriggerInstance createInstance(JsonObject p_286276_, ContextAwarePredicate p_286282_, DeserializationContext p_286851_) {
|
||||
return new StartRidingTrigger.TriggerInstance(p_286282_);
|
||||
}
|
||||
|
||||
public void trigger(ServerPlayer p_160388_) {
|
||||
this.trigger(p_160388_, (p_160394_) -> {
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
public static class TriggerInstance extends AbstractCriterionTriggerInstance {
|
||||
public TriggerInstance(ContextAwarePredicate p_286351_) {
|
||||
super(StartRidingTrigger.ID, p_286351_);
|
||||
}
|
||||
|
||||
public static StartRidingTrigger.TriggerInstance playerStartsRiding(EntityPredicate.Builder p_160402_) {
|
||||
return new StartRidingTrigger.TriggerInstance(EntityPredicate.wrap(p_160402_.build()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,225 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonNull;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
import net.minecraft.util.StringRepresentable;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.StateDefinition;
|
||||
import net.minecraft.world.level.block.state.StateHolder;
|
||||
import net.minecraft.world.level.block.state.properties.Property;
|
||||
import net.minecraft.world.level.material.FluidState;
|
||||
|
||||
public class StatePropertiesPredicate {
|
||||
public static final StatePropertiesPredicate ANY = new StatePropertiesPredicate(ImmutableList.of());
|
||||
private final List<StatePropertiesPredicate.PropertyMatcher> properties;
|
||||
|
||||
private static StatePropertiesPredicate.PropertyMatcher fromJson(String p_67687_, JsonElement p_67688_) {
|
||||
if (p_67688_.isJsonPrimitive()) {
|
||||
String s2 = p_67688_.getAsString();
|
||||
return new StatePropertiesPredicate.ExactPropertyMatcher(p_67687_, s2);
|
||||
} else {
|
||||
JsonObject jsonobject = GsonHelper.convertToJsonObject(p_67688_, "value");
|
||||
String s = jsonobject.has("min") ? getStringOrNull(jsonobject.get("min")) : null;
|
||||
String s1 = jsonobject.has("max") ? getStringOrNull(jsonobject.get("max")) : null;
|
||||
return (StatePropertiesPredicate.PropertyMatcher)(s != null && s.equals(s1) ? new StatePropertiesPredicate.ExactPropertyMatcher(p_67687_, s) : new StatePropertiesPredicate.RangedPropertyMatcher(p_67687_, s, s1));
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String getStringOrNull(JsonElement p_67690_) {
|
||||
return p_67690_.isJsonNull() ? null : p_67690_.getAsString();
|
||||
}
|
||||
|
||||
StatePropertiesPredicate(List<StatePropertiesPredicate.PropertyMatcher> p_67662_) {
|
||||
this.properties = ImmutableList.copyOf(p_67662_);
|
||||
}
|
||||
|
||||
public <S extends StateHolder<?, S>> boolean matches(StateDefinition<?, S> p_67670_, S p_67671_) {
|
||||
for(StatePropertiesPredicate.PropertyMatcher statepropertiespredicate$propertymatcher : this.properties) {
|
||||
if (!statepropertiespredicate$propertymatcher.match(p_67670_, p_67671_)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean matches(BlockState p_67668_) {
|
||||
return this.matches(p_67668_.getBlock().getStateDefinition(), p_67668_);
|
||||
}
|
||||
|
||||
public boolean matches(FluidState p_67685_) {
|
||||
return this.matches(p_67685_.getType().getStateDefinition(), p_67685_);
|
||||
}
|
||||
|
||||
public void checkState(StateDefinition<?, ?> p_67673_, Consumer<String> p_67674_) {
|
||||
this.properties.forEach((p_67678_) -> {
|
||||
p_67678_.checkState(p_67673_, p_67674_);
|
||||
});
|
||||
}
|
||||
|
||||
public static StatePropertiesPredicate fromJson(@Nullable JsonElement p_67680_) {
|
||||
if (p_67680_ != null && !p_67680_.isJsonNull()) {
|
||||
JsonObject jsonobject = GsonHelper.convertToJsonObject(p_67680_, "properties");
|
||||
List<StatePropertiesPredicate.PropertyMatcher> list = Lists.newArrayList();
|
||||
|
||||
for(Map.Entry<String, JsonElement> entry : jsonobject.entrySet()) {
|
||||
list.add(fromJson(entry.getKey(), entry.getValue()));
|
||||
}
|
||||
|
||||
return new StatePropertiesPredicate(list);
|
||||
} else {
|
||||
return ANY;
|
||||
}
|
||||
}
|
||||
|
||||
public JsonElement serializeToJson() {
|
||||
if (this == ANY) {
|
||||
return JsonNull.INSTANCE;
|
||||
} else {
|
||||
JsonObject jsonobject = new JsonObject();
|
||||
if (!this.properties.isEmpty()) {
|
||||
this.properties.forEach((p_67683_) -> {
|
||||
jsonobject.add(p_67683_.getName(), p_67683_.toJson());
|
||||
});
|
||||
}
|
||||
|
||||
return jsonobject;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private final List<StatePropertiesPredicate.PropertyMatcher> matchers = Lists.newArrayList();
|
||||
|
||||
private Builder() {
|
||||
}
|
||||
|
||||
public static StatePropertiesPredicate.Builder properties() {
|
||||
return new StatePropertiesPredicate.Builder();
|
||||
}
|
||||
|
||||
public StatePropertiesPredicate.Builder hasProperty(Property<?> p_67701_, String p_67702_) {
|
||||
this.matchers.add(new StatePropertiesPredicate.ExactPropertyMatcher(p_67701_.getName(), p_67702_));
|
||||
return this;
|
||||
}
|
||||
|
||||
public StatePropertiesPredicate.Builder hasProperty(Property<Integer> p_67695_, int p_67696_) {
|
||||
return this.hasProperty(p_67695_, Integer.toString(p_67696_));
|
||||
}
|
||||
|
||||
public StatePropertiesPredicate.Builder hasProperty(Property<Boolean> p_67704_, boolean p_67705_) {
|
||||
return this.hasProperty(p_67704_, Boolean.toString(p_67705_));
|
||||
}
|
||||
|
||||
public <T extends Comparable<T> & StringRepresentable> StatePropertiesPredicate.Builder hasProperty(Property<T> p_67698_, T p_67699_) {
|
||||
return this.hasProperty(p_67698_, p_67699_.getSerializedName());
|
||||
}
|
||||
|
||||
public StatePropertiesPredicate build() {
|
||||
return new StatePropertiesPredicate(this.matchers);
|
||||
}
|
||||
}
|
||||
|
||||
static class ExactPropertyMatcher extends StatePropertiesPredicate.PropertyMatcher {
|
||||
private final String value;
|
||||
|
||||
public ExactPropertyMatcher(String p_67709_, String p_67710_) {
|
||||
super(p_67709_);
|
||||
this.value = p_67710_;
|
||||
}
|
||||
|
||||
protected <T extends Comparable<T>> boolean match(StateHolder<?, ?> p_67713_, Property<T> p_67714_) {
|
||||
T t = p_67713_.getValue(p_67714_);
|
||||
Optional<T> optional = p_67714_.getValue(this.value);
|
||||
return optional.isPresent() && t.compareTo(optional.get()) == 0;
|
||||
}
|
||||
|
||||
public JsonElement toJson() {
|
||||
return new JsonPrimitive(this.value);
|
||||
}
|
||||
}
|
||||
|
||||
abstract static class PropertyMatcher {
|
||||
private final String name;
|
||||
|
||||
public PropertyMatcher(String p_67717_) {
|
||||
this.name = p_67717_;
|
||||
}
|
||||
|
||||
public <S extends StateHolder<?, S>> boolean match(StateDefinition<?, S> p_67719_, S p_67720_) {
|
||||
Property<?> property = p_67719_.getProperty(this.name);
|
||||
return property == null ? false : this.match(p_67720_, property);
|
||||
}
|
||||
|
||||
protected abstract <T extends Comparable<T>> boolean match(StateHolder<?, ?> p_67724_, Property<T> p_67725_);
|
||||
|
||||
public abstract JsonElement toJson();
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void checkState(StateDefinition<?, ?> p_67722_, Consumer<String> p_67723_) {
|
||||
Property<?> property = p_67722_.getProperty(this.name);
|
||||
if (property == null) {
|
||||
p_67723_.accept(this.name);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
static class RangedPropertyMatcher extends StatePropertiesPredicate.PropertyMatcher {
|
||||
@Nullable
|
||||
private final String minValue;
|
||||
@Nullable
|
||||
private final String maxValue;
|
||||
|
||||
public RangedPropertyMatcher(String p_67730_, @Nullable String p_67731_, @Nullable String p_67732_) {
|
||||
super(p_67730_);
|
||||
this.minValue = p_67731_;
|
||||
this.maxValue = p_67732_;
|
||||
}
|
||||
|
||||
protected <T extends Comparable<T>> boolean match(StateHolder<?, ?> p_67735_, Property<T> p_67736_) {
|
||||
T t = p_67735_.getValue(p_67736_);
|
||||
if (this.minValue != null) {
|
||||
Optional<T> optional = p_67736_.getValue(this.minValue);
|
||||
if (!optional.isPresent() || t.compareTo(optional.get()) < 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.maxValue != null) {
|
||||
Optional<T> optional1 = p_67736_.getValue(this.maxValue);
|
||||
if (!optional1.isPresent() || t.compareTo(optional1.get()) > 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public JsonElement toJson() {
|
||||
JsonObject jsonobject = new JsonObject();
|
||||
if (this.minValue != null) {
|
||||
jsonobject.addProperty("min", this.minValue);
|
||||
}
|
||||
|
||||
if (this.maxValue != null) {
|
||||
jsonobject.addProperty("max", this.maxValue);
|
||||
}
|
||||
|
||||
return jsonobject;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.storage.loot.LootContext;
|
||||
|
||||
public class SummonedEntityTrigger extends SimpleCriterionTrigger<SummonedEntityTrigger.TriggerInstance> {
|
||||
static final ResourceLocation ID = new ResourceLocation("summoned_entity");
|
||||
|
||||
public ResourceLocation getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
public SummonedEntityTrigger.TriggerInstance createInstance(JsonObject p_286669_, ContextAwarePredicate p_286745_, DeserializationContext p_286637_) {
|
||||
ContextAwarePredicate contextawarepredicate = EntityPredicate.fromJson(p_286669_, "entity", p_286637_);
|
||||
return new SummonedEntityTrigger.TriggerInstance(p_286745_, contextawarepredicate);
|
||||
}
|
||||
|
||||
public void trigger(ServerPlayer p_68257_, Entity p_68258_) {
|
||||
LootContext lootcontext = EntityPredicate.createContext(p_68257_, p_68258_);
|
||||
this.trigger(p_68257_, (p_68265_) -> {
|
||||
return p_68265_.matches(lootcontext);
|
||||
});
|
||||
}
|
||||
|
||||
public static class TriggerInstance extends AbstractCriterionTriggerInstance {
|
||||
private final ContextAwarePredicate entity;
|
||||
|
||||
public TriggerInstance(ContextAwarePredicate p_286853_, ContextAwarePredicate p_286838_) {
|
||||
super(SummonedEntityTrigger.ID, p_286853_);
|
||||
this.entity = p_286838_;
|
||||
}
|
||||
|
||||
public static SummonedEntityTrigger.TriggerInstance summonedEntity(EntityPredicate.Builder p_68276_) {
|
||||
return new SummonedEntityTrigger.TriggerInstance(ContextAwarePredicate.ANY, EntityPredicate.wrap(p_68276_.build()));
|
||||
}
|
||||
|
||||
public boolean matches(LootContext p_68280_) {
|
||||
return this.entity.matches(p_68280_);
|
||||
}
|
||||
|
||||
public JsonObject serializeToJson(SerializationContext p_68278_) {
|
||||
JsonObject jsonobject = super.serializeToJson(p_68278_);
|
||||
jsonobject.add("entity", this.entity.toJson(p_68278_));
|
||||
return jsonobject;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
|
||||
public class TagPredicate<T> {
|
||||
private final TagKey<T> tag;
|
||||
private final boolean expected;
|
||||
|
||||
public TagPredicate(TagKey<T> p_270819_, boolean p_270913_) {
|
||||
this.tag = p_270819_;
|
||||
this.expected = p_270913_;
|
||||
}
|
||||
|
||||
public static <T> TagPredicate<T> is(TagKey<T> p_270668_) {
|
||||
return new TagPredicate<>(p_270668_, true);
|
||||
}
|
||||
|
||||
public static <T> TagPredicate<T> isNot(TagKey<T> p_270264_) {
|
||||
return new TagPredicate<>(p_270264_, false);
|
||||
}
|
||||
|
||||
public boolean matches(Holder<T> p_270125_) {
|
||||
return p_270125_.is(this.tag) == this.expected;
|
||||
}
|
||||
|
||||
public JsonElement serializeToJson() {
|
||||
JsonObject jsonobject = new JsonObject();
|
||||
jsonobject.addProperty("id", this.tag.location().toString());
|
||||
jsonobject.addProperty("expected", this.expected);
|
||||
return jsonobject;
|
||||
}
|
||||
|
||||
public static <T> TagPredicate<T> fromJson(@Nullable JsonElement p_270982_, ResourceKey<? extends Registry<T>> p_270978_) {
|
||||
if (p_270982_ == null) {
|
||||
throw new JsonParseException("Expected a tag predicate");
|
||||
} else {
|
||||
JsonObject jsonobject = GsonHelper.convertToJsonObject(p_270982_, "Tag Predicate");
|
||||
ResourceLocation resourcelocation = new ResourceLocation(GsonHelper.getAsString(jsonobject, "id"));
|
||||
boolean flag = GsonHelper.getAsBoolean(jsonobject, "expected");
|
||||
return new TagPredicate<>(TagKey.create(p_270978_, resourcelocation), flag);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.animal.Animal;
|
||||
import net.minecraft.world.level.storage.loot.LootContext;
|
||||
|
||||
public class TameAnimalTrigger extends SimpleCriterionTrigger<TameAnimalTrigger.TriggerInstance> {
|
||||
static final ResourceLocation ID = new ResourceLocation("tame_animal");
|
||||
|
||||
public ResourceLocation getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
public TameAnimalTrigger.TriggerInstance createInstance(JsonObject p_286910_, ContextAwarePredicate p_286765_, DeserializationContext p_286732_) {
|
||||
ContextAwarePredicate contextawarepredicate = EntityPredicate.fromJson(p_286910_, "entity", p_286732_);
|
||||
return new TameAnimalTrigger.TriggerInstance(p_286765_, contextawarepredicate);
|
||||
}
|
||||
|
||||
public void trigger(ServerPlayer p_68830_, Animal p_68831_) {
|
||||
LootContext lootcontext = EntityPredicate.createContext(p_68830_, p_68831_);
|
||||
this.trigger(p_68830_, (p_68838_) -> {
|
||||
return p_68838_.matches(lootcontext);
|
||||
});
|
||||
}
|
||||
|
||||
public static class TriggerInstance extends AbstractCriterionTriggerInstance {
|
||||
private final ContextAwarePredicate entity;
|
||||
|
||||
public TriggerInstance(ContextAwarePredicate p_286593_, ContextAwarePredicate p_286484_) {
|
||||
super(TameAnimalTrigger.ID, p_286593_);
|
||||
this.entity = p_286484_;
|
||||
}
|
||||
|
||||
public static TameAnimalTrigger.TriggerInstance tamedAnimal() {
|
||||
return new TameAnimalTrigger.TriggerInstance(ContextAwarePredicate.ANY, ContextAwarePredicate.ANY);
|
||||
}
|
||||
|
||||
public static TameAnimalTrigger.TriggerInstance tamedAnimal(EntityPredicate p_68849_) {
|
||||
return new TameAnimalTrigger.TriggerInstance(ContextAwarePredicate.ANY, EntityPredicate.wrap(p_68849_));
|
||||
}
|
||||
|
||||
public boolean matches(LootContext p_68853_) {
|
||||
return this.entity.matches(p_68853_);
|
||||
}
|
||||
|
||||
public JsonObject serializeToJson(SerializationContext p_68851_) {
|
||||
JsonObject jsonobject = super.serializeToJson(p_68851_);
|
||||
jsonobject.add("entity", this.entity.toJson(p_68851_));
|
||||
return jsonobject;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.storage.loot.LootContext;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
public class TargetBlockTrigger extends SimpleCriterionTrigger<TargetBlockTrigger.TriggerInstance> {
|
||||
static final ResourceLocation ID = new ResourceLocation("target_hit");
|
||||
|
||||
public ResourceLocation getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
public TargetBlockTrigger.TriggerInstance createInstance(JsonObject p_286400_, ContextAwarePredicate p_286802_, DeserializationContext p_286826_) {
|
||||
MinMaxBounds.Ints minmaxbounds$ints = MinMaxBounds.Ints.fromJson(p_286400_.get("signal_strength"));
|
||||
ContextAwarePredicate contextawarepredicate = EntityPredicate.fromJson(p_286400_, "projectile", p_286826_);
|
||||
return new TargetBlockTrigger.TriggerInstance(p_286802_, minmaxbounds$ints, contextawarepredicate);
|
||||
}
|
||||
|
||||
public void trigger(ServerPlayer p_70212_, Entity p_70213_, Vec3 p_70214_, int p_70215_) {
|
||||
LootContext lootcontext = EntityPredicate.createContext(p_70212_, p_70213_);
|
||||
this.trigger(p_70212_, (p_70224_) -> {
|
||||
return p_70224_.matches(lootcontext, p_70214_, p_70215_);
|
||||
});
|
||||
}
|
||||
|
||||
public static class TriggerInstance extends AbstractCriterionTriggerInstance {
|
||||
private final MinMaxBounds.Ints signalStrength;
|
||||
private final ContextAwarePredicate projectile;
|
||||
|
||||
public TriggerInstance(ContextAwarePredicate p_286385_, MinMaxBounds.Ints p_286505_, ContextAwarePredicate p_286608_) {
|
||||
super(TargetBlockTrigger.ID, p_286385_);
|
||||
this.signalStrength = p_286505_;
|
||||
this.projectile = p_286608_;
|
||||
}
|
||||
|
||||
public static TargetBlockTrigger.TriggerInstance targetHit(MinMaxBounds.Ints p_286700_, ContextAwarePredicate p_286883_) {
|
||||
return new TargetBlockTrigger.TriggerInstance(ContextAwarePredicate.ANY, p_286700_, p_286883_);
|
||||
}
|
||||
|
||||
public JsonObject serializeToJson(SerializationContext p_70240_) {
|
||||
JsonObject jsonobject = super.serializeToJson(p_70240_);
|
||||
jsonobject.add("signal_strength", this.signalStrength.serializeToJson());
|
||||
jsonobject.add("projectile", this.projectile.toJson(p_70240_));
|
||||
return jsonobject;
|
||||
}
|
||||
|
||||
public boolean matches(LootContext p_70242_, Vec3 p_70243_, int p_70244_) {
|
||||
if (!this.signalStrength.matches(p_70244_)) {
|
||||
return false;
|
||||
} else {
|
||||
return this.projectile.matches(p_70242_);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.npc.AbstractVillager;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.storage.loot.LootContext;
|
||||
|
||||
public class TradeTrigger extends SimpleCriterionTrigger<TradeTrigger.TriggerInstance> {
|
||||
static final ResourceLocation ID = new ResourceLocation("villager_trade");
|
||||
|
||||
public ResourceLocation getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
public TradeTrigger.TriggerInstance createInstance(JsonObject p_286654_, ContextAwarePredicate p_286835_, DeserializationContext p_286772_) {
|
||||
ContextAwarePredicate contextawarepredicate = EntityPredicate.fromJson(p_286654_, "villager", p_286772_);
|
||||
ItemPredicate itempredicate = ItemPredicate.fromJson(p_286654_.get("item"));
|
||||
return new TradeTrigger.TriggerInstance(p_286835_, contextawarepredicate, itempredicate);
|
||||
}
|
||||
|
||||
public void trigger(ServerPlayer p_70960_, AbstractVillager p_70961_, ItemStack p_70962_) {
|
||||
LootContext lootcontext = EntityPredicate.createContext(p_70960_, p_70961_);
|
||||
this.trigger(p_70960_, (p_70970_) -> {
|
||||
return p_70970_.matches(lootcontext, p_70962_);
|
||||
});
|
||||
}
|
||||
|
||||
public static class TriggerInstance extends AbstractCriterionTriggerInstance {
|
||||
private final ContextAwarePredicate villager;
|
||||
private final ItemPredicate item;
|
||||
|
||||
public TriggerInstance(ContextAwarePredicate p_286523_, ContextAwarePredicate p_286395_, ItemPredicate p_286263_) {
|
||||
super(TradeTrigger.ID, p_286523_);
|
||||
this.villager = p_286395_;
|
||||
this.item = p_286263_;
|
||||
}
|
||||
|
||||
public static TradeTrigger.TriggerInstance tradedWithVillager() {
|
||||
return new TradeTrigger.TriggerInstance(ContextAwarePredicate.ANY, ContextAwarePredicate.ANY, ItemPredicate.ANY);
|
||||
}
|
||||
|
||||
public static TradeTrigger.TriggerInstance tradedWithVillager(EntityPredicate.Builder p_191437_) {
|
||||
return new TradeTrigger.TriggerInstance(EntityPredicate.wrap(p_191437_.build()), ContextAwarePredicate.ANY, ItemPredicate.ANY);
|
||||
}
|
||||
|
||||
public boolean matches(LootContext p_70985_, ItemStack p_70986_) {
|
||||
if (!this.villager.matches(p_70985_)) {
|
||||
return false;
|
||||
} else {
|
||||
return this.item.matches(p_70986_);
|
||||
}
|
||||
}
|
||||
|
||||
public JsonObject serializeToJson(SerializationContext p_70983_) {
|
||||
JsonObject jsonobject = super.serializeToJson(p_70983_);
|
||||
jsonobject.add("item", this.item.serializeToJson());
|
||||
jsonobject.add("villager", this.villager.toJson(p_70983_));
|
||||
return jsonobject;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
public class UsedEnderEyeTrigger extends SimpleCriterionTrigger<UsedEnderEyeTrigger.TriggerInstance> {
|
||||
static final ResourceLocation ID = new ResourceLocation("used_ender_eye");
|
||||
|
||||
public ResourceLocation getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
public UsedEnderEyeTrigger.TriggerInstance createInstance(JsonObject p_286292_, ContextAwarePredicate p_286488_, DeserializationContext p_286702_) {
|
||||
MinMaxBounds.Doubles minmaxbounds$doubles = MinMaxBounds.Doubles.fromJson(p_286292_.get("distance"));
|
||||
return new UsedEnderEyeTrigger.TriggerInstance(p_286488_, minmaxbounds$doubles);
|
||||
}
|
||||
|
||||
public void trigger(ServerPlayer p_73936_, BlockPos p_73937_) {
|
||||
double d0 = p_73936_.getX() - (double)p_73937_.getX();
|
||||
double d1 = p_73936_.getZ() - (double)p_73937_.getZ();
|
||||
double d2 = d0 * d0 + d1 * d1;
|
||||
this.trigger(p_73936_, (p_73934_) -> {
|
||||
return p_73934_.matches(d2);
|
||||
});
|
||||
}
|
||||
|
||||
public static class TriggerInstance extends AbstractCriterionTriggerInstance {
|
||||
private final MinMaxBounds.Doubles level;
|
||||
|
||||
public TriggerInstance(ContextAwarePredicate p_286567_, MinMaxBounds.Doubles p_286810_) {
|
||||
super(UsedEnderEyeTrigger.ID, p_286567_);
|
||||
this.level = p_286810_;
|
||||
}
|
||||
|
||||
public boolean matches(double p_73952_) {
|
||||
return this.level.matchesSqr(p_73952_);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package net.minecraft.advancements.critereon;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
|
||||
public class UsedTotemTrigger extends SimpleCriterionTrigger<UsedTotemTrigger.TriggerInstance> {
|
||||
static final ResourceLocation ID = new ResourceLocation("used_totem");
|
||||
|
||||
public ResourceLocation getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
public UsedTotemTrigger.TriggerInstance createInstance(JsonObject p_286841_, ContextAwarePredicate p_286597_, DeserializationContext p_286414_) {
|
||||
ItemPredicate itempredicate = ItemPredicate.fromJson(p_286841_.get("item"));
|
||||
return new UsedTotemTrigger.TriggerInstance(p_286597_, itempredicate);
|
||||
}
|
||||
|
||||
public void trigger(ServerPlayer p_74432_, ItemStack p_74433_) {
|
||||
this.trigger(p_74432_, (p_74436_) -> {
|
||||
return p_74436_.matches(p_74433_);
|
||||
});
|
||||
}
|
||||
|
||||
public static class TriggerInstance extends AbstractCriterionTriggerInstance {
|
||||
private final ItemPredicate item;
|
||||
|
||||
public TriggerInstance(ContextAwarePredicate p_286406_, ItemPredicate p_286462_) {
|
||||
super(UsedTotemTrigger.ID, p_286406_);
|
||||
this.item = p_286462_;
|
||||
}
|
||||
|
||||
public static UsedTotemTrigger.TriggerInstance usedTotem(ItemPredicate p_163725_) {
|
||||
return new UsedTotemTrigger.TriggerInstance(ContextAwarePredicate.ANY, p_163725_);
|
||||
}
|
||||
|
||||
public static UsedTotemTrigger.TriggerInstance usedTotem(ItemLike p_74453_) {
|
||||
return new UsedTotemTrigger.TriggerInstance(ContextAwarePredicate.ANY, ItemPredicate.Builder.item().of(p_74453_).build());
|
||||
}
|
||||
|
||||
public boolean matches(ItemStack p_74451_) {
|
||||
return this.item.matches(p_74451_);
|
||||
}
|
||||
|
||||
public JsonObject serializeToJson(SerializationContext p_74455_) {
|
||||
JsonObject jsonobject = super.serializeToJson(p_74455_);
|
||||
jsonobject.add("item", this.item.serializeToJson());
|
||||
return jsonobject;
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user