Fixed patch verifier for cases where patches lowered access levels. Closes #9383

This commit is contained in:
LexManos committed 2023-03-15 11:39:42 -07:00
1 parent 3fffc18729
commit 631e72f99d
12 files changed
+8 -197

No files matched your search

@@ -35,6 +35,11 @@ abstract class CheckPatches extends CheckTask {
}
}
}
def accessChange(previous, current) {
//return ACCESS_MAP[previous] < ACCESS_MAP[current]
return previous != current
}
void verifyPatch(Path patch, Reporter reporter, boolean fix, String patchPath, boolean hasS2SArtifact) {
final oldFixedErrors = reporter.fixed.size()
@@ -87,7 +92,7 @@ abstract class CheckPatches extends CheckTask {
pMatcher.group(6) == cMatcher.group(6) && // = ...
pMatcher.group(5) == cMatcher.group(5) && // field name
pMatcher.group(3) == cMatcher.group(3) && // static
(ACCESS_MAP[pMatcher.group(2)] < ACCESS_MAP[cMatcher.group(2)] || pMatcher.group(4) != cMatcher.group(4))) {
(accessChange(pMatcher.group(2), cMatcher.group(2)) || pMatcher.group(4) != cMatcher.group(4))) {
reporter.report("Patch contains access changes or final removal at line ${i + 1}, file: $patchPath", false)
}
@@ -98,7 +103,7 @@ abstract class CheckPatches extends CheckTask {
pMatcher.group(6) == cMatcher.group(6) && // params
pMatcher.group(5) == cMatcher.group(5) && // <T> void name
pMatcher.group(3) == cMatcher.group(3) && // static
(ACCESS_MAP[pMatcher.group(2)] < ACCESS_MAP[cMatcher.group(2)] || pMatcher.group(4) != cMatcher.group(4))) {
(accessChange(pMatcher.group(2), cMatcher.group(2)) || pMatcher.group(4) != cMatcher.group(4))) {
reporter.report("Patch contains access changes or final removal at line ${i + 1}, file: $patchPath", false)
}
@@ -109,7 +114,7 @@ abstract class CheckPatches extends CheckTask {
pMatcher.group(6) == cMatcher.group(6) && // ClassName<> extends ...
pMatcher.group(5) == cMatcher.group(5) && // class | interface
pMatcher.group(3) == cMatcher.group(3) && // static
(ACCESS_MAP[pMatcher.group(2)] < ACCESS_MAP[cMatcher.group(2)] || pMatcher.group(4) != cMatcher.group(4))) {
(accessChange(pMatcher.group(2), cMatcher.group(2)) || pMatcher.group(4) != cMatcher.group(4))) {
reporter.report("Patch contains access changes or final removal at line ${i + 1}, file: $patchPath", false)
}
}
@@ -58,15 +58,6 @@
}
}
@@ -924,7 +_,7 @@
RenderSystem.m_157429_(1.0F, 1.0F, 1.0F, 1.0F);
}
- public void m_264541_(PoseStack p_265563_, float p_265127_) {
+ protected void m_264541_(PoseStack p_265563_, float p_265127_) {
RenderSystem.m_69465_();
RenderSystem.m_69458_(false);
float f = (float)Math.min(this.f_92977_, this.f_92978_);
@@ -1054,7 +_,7 @@
ItemStack itemstack = this.f_92986_.f_91074_.m_150109_().m_36056_();
if (itemstack.m_41619_()) {
@@ -30,15 +30,6 @@
}
public void m_246368_(int p_248864_) {
@@ -70,7 +_,7 @@
}
}
- int m_245088_() {
+ private int m_245088_() {
return this.f_244575_ != null ? this.f_244575_.f_243714_.size() : 1;
}
@@ -124,6 +_,9 @@
void m_247381_(int p_248895_, int p_250245_, int p_250458_, int p_251337_, NativeImage[] p_248825_) {
@@ -1,11 +0,0 @@
--- a/net/minecraft/world/damagesource/DamageSource.java
+++ b/net/minecraft/world/damagesource/DamageSource.java
@@ -32,7 +_,7 @@
return this.f_268569_ != this.f_268595_;
}
- public DamageSource(Holder<DamageType> p_270906_, @Nullable Entity p_270796_, @Nullable Entity p_270459_, @Nullable Vec3 p_270623_) {
+ private DamageSource(Holder<DamageType> p_270906_, @Nullable Entity p_270796_, @Nullable Entity p_270459_, @Nullable Vec3 p_270623_) {
this.f_268495_ = p_270906_;
this.f_268569_ = p_270459_;
this.f_268595_ = p_270796_;
@@ -1,11 +0,0 @@
--- a/net/minecraft/world/level/block/ButtonBlock.java
+++ b/net/minecraft/world/level/block/ButtonBlock.java
@@ -53,7 +_,7 @@
private final int f_244105_;
private final boolean f_243959_;
- public ButtonBlock(BlockBehaviour.Properties p_273290_, BlockSetType p_273462_, int p_273212_, boolean p_272786_) {
+ protected ButtonBlock(BlockBehaviour.Properties p_273290_, BlockSetType p_273462_, int p_273212_, boolean p_272786_) {
super(p_273290_.m_60918_(p_273462_.f_271136_()));
this.f_271519_ = p_273462_;
this.m_49959_(this.f_49792_.m_61090_().m_61124_(f_54117_, Direction.NORTH).m_61124_(f_51045_, Boolean.valueOf(false)).m_61124_(f_53179_, AttachFace.WALL));
@@ -1,11 +0,0 @@
--- a/net/minecraft/world/level/block/DecoratedPotBlock.java
+++ b/net/minecraft/world/level/block/DecoratedPotBlock.java
@@ -30,7 +_,7 @@
private static final DirectionProperty f_271251_ = BlockStateProperties.f_61374_;
private static final BooleanProperty f_271222_ = BlockStateProperties.f_61362_;
- public DecoratedPotBlock(BlockBehaviour.Properties p_273064_) {
+ protected DecoratedPotBlock(BlockBehaviour.Properties p_273064_) {
super(p_273064_);
this.m_49959_(this.f_49792_.m_61090_().m_61124_(f_271251_, Direction.NORTH).m_61124_(f_271222_, Boolean.valueOf(false)));
}
@@ -1,11 +0,0 @@
--- a/net/minecraft/world/level/block/DoorBlock.java
+++ b/net/minecraft/world/level/block/DoorBlock.java
@@ -48,7 +_,7 @@
protected static final VoxelShape f_52734_ = Block.m_49796_(0.0D, 0.0D, 0.0D, 3.0D, 16.0D, 16.0D);
private final BlockSetType f_271255_;
- public DoorBlock(BlockBehaviour.Properties p_273303_, BlockSetType p_272854_) {
+ protected DoorBlock(BlockBehaviour.Properties p_273303_, BlockSetType p_272854_) {
super(p_273303_.m_60918_(p_272854_.f_271136_()));
this.f_271255_ = p_272854_;
this.m_49959_(this.f_49792_.m_61090_().m_61124_(f_52726_, Direction.NORTH).m_61124_(f_52727_, Boolean.valueOf(false)).m_61124_(f_52728_, DoorHingeSide.LEFT).m_61124_(f_52729_, Boolean.valueOf(false)).m_61124_(f_52730_, DoubleBlockHalf.LOWER));
@@ -1,11 +0,0 @@
--- a/net/minecraft/world/level/block/PinkPetalsBlock.java
+++ b/net/minecraft/world/level/block/PinkPetalsBlock.java
@@ -24,7 +_,7 @@
public static final DirectionProperty f_271347_ = BlockStateProperties.f_61374_;
public static final IntegerProperty f_271373_ = BlockStateProperties.f_271526_;
- public PinkPetalsBlock(BlockBehaviour.Properties p_273335_) {
+ protected PinkPetalsBlock(BlockBehaviour.Properties p_273335_) {
super(p_273335_);
this.m_49959_(this.f_49792_.m_61090_().m_61124_(f_271347_, Direction.NORTH).m_61124_(f_271373_, Integer.valueOf(1)));
}
@@ -1,11 +0,0 @@
--- a/net/minecraft/world/level/block/PressurePlateBlock.java
+++ b/net/minecraft/world/level/block/PressurePlateBlock.java
@@ -17,7 +_,7 @@
public static final BooleanProperty f_55249_ = BlockStateProperties.f_61448_;
private final PressurePlateBlock.Sensitivity f_55250_;
- public PressurePlateBlock(PressurePlateBlock.Sensitivity p_273523_, BlockBehaviour.Properties p_273571_, BlockSetType p_273284_) {
+ protected PressurePlateBlock(PressurePlateBlock.Sensitivity p_273523_, BlockBehaviour.Properties p_273571_, BlockSetType p_273284_) {
super(p_273571_, p_273284_);
this.m_49959_(this.f_49792_.m_61090_().m_61124_(f_55249_, Boolean.valueOf(false)));
this.f_55250_ = p_273523_;
@@ -1,14 +1,5 @@
--- a/net/minecraft/world/level/block/TrapDoorBlock.java
+++ b/net/minecraft/world/level/block/TrapDoorBlock.java
@@ -42,7 +_,7 @@
protected static final VoxelShape f_57523_ = Block.m_49796_(0.0D, 13.0D, 0.0D, 16.0D, 16.0D, 16.0D);
private final BlockSetType f_271458_;
- public TrapDoorBlock(BlockBehaviour.Properties p_273079_, BlockSetType p_272964_) {
+ protected TrapDoorBlock(BlockBehaviour.Properties p_273079_, BlockSetType p_272964_) {
super(p_273079_.m_60918_(p_272964_.f_271136_()));
this.f_271458_ = p_272964_;
this.m_49959_(this.f_49792_.m_61090_().m_61124_(f_54117_, Direction.NORTH).m_61124_(f_57514_, Boolean.valueOf(false)).m_61124_(f_57515_, Half.BOTTOM).m_61124_(f_57516_, Boolean.valueOf(false)).m_61124_(f_57517_, Boolean.valueOf(false)));
@@ -149,4 +_,17 @@
return super.m_7417_(p_57554_, p_57555_, p_57556_, p_57557_, p_57558_, p_57559_);
@@ -1,11 +0,0 @@
--- a/net/minecraft/world/level/block/WeightedPressurePlateBlock.java
+++ b/net/minecraft/world/level/block/WeightedPressurePlateBlock.java
@@ -15,7 +_,7 @@
public static final IntegerProperty f_58198_ = BlockStateProperties.f_61426_;
private final int f_58199_;
- public WeightedPressurePlateBlock(int p_273669_, BlockBehaviour.Properties p_273512_, BlockSetType p_272868_) {
+ protected WeightedPressurePlateBlock(int p_273669_, BlockBehaviour.Properties p_273512_, BlockSetType p_272868_) {
super(p_273512_, p_272868_);
this.m_49959_(this.f_49792_.m_61090_().m_61124_(f_58198_, Integer.valueOf(0)));
this.f_58199_ = p_273669_;
@@ -1,90 +0,0 @@
/*
* Copyright (c) Forge Development LLC and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/
package net.minecraftforge.common;
import com.google.common.graph.Graph;
import com.google.common.graph.GraphBuilder;
import com.google.common.graph.MutableGraph;
import net.minecraft.advancements.Advancement;
import net.minecraft.advancements.AdvancementProgress;
import net.minecraft.server.PlayerAdvancements;
import net.minecraftforge.fml.loading.toposort.TopologicalSort;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
/**
* New implementation of {@code PlayerAdvancements#ensureAllVisible()}
*/
public class AdvancementLoadFix {
private static final Logger LOGGER = LogManager.getLogger();
private static Map<Advancement, List<Advancement>> roots;
public static void loadVisibility(final PlayerAdvancements playerAdvancements, final Set<Advancement> visible, final Set<Advancement> visibilityChanged, final Map<Advancement, AdvancementProgress> progress, final Set<Advancement> progressChanged, final Predicate<Advancement> shouldBeVisible) {
LOGGER.info("Using new advancement loading for {}", playerAdvancements);
if (roots == null) throw new RuntimeException("Why did the advancements not load yet?!");
final Set<Advancement> set = new HashSet<>();
for(Map.Entry<Advancement, AdvancementProgress> entry : progress.entrySet()) {
if (entry.getValue().isDone()) {
set.add(entry.getKey());
progressChanged.add(entry.getKey());
}
}
roots.values().stream().flatMap(Collection::stream).filter(adv -> containsAncestor(adv, set)).forEach(adv->updateVisibility(adv, visible, visibilityChanged, progress, progressChanged, shouldBeVisible));
}
private static boolean containsAncestor(final Advancement adv, final Set<Advancement> set) {
return set.contains(adv) || (adv.getParent() != null && containsAncestor(adv.getParent(), set));
}
private static void updateVisibility(final Advancement adv, final Set<Advancement> visible, final Set<Advancement> visibilityChanged, final Map<Advancement, AdvancementProgress> progress, final Set<Advancement> progressChanged, Predicate<Advancement> shouldBeVisible) {
boolean flag = shouldBeVisible.test(adv);
boolean flag1 = visible.contains(adv);
if (flag && !flag1) {
visible.add(adv);
visibilityChanged.add(adv);
if (progress.containsKey(adv)) {
progressChanged.add(adv);
}
} else if (!flag && flag1) {
visible.remove(adv);
visibilityChanged.add(adv);
}
if (flag!=flag1 && adv.getParent()!=null)
updateVisibility(adv.getParent(), visible, visibilityChanged, progress, progressChanged, shouldBeVisible);
}
public static void buildSortedTrees(final Set<Advancement> roots) {
AdvancementLoadFix.roots = roots.stream()
.map(AdvancementLoadFix::buildGraph)
.map(g -> TopologicalSort.topologicalSort(g, Comparator.comparing(Advancement::getId)))
.collect(Collectors.toMap(lst -> lst.get(0), Function.identity()));
}
private static Graph<Advancement> buildGraph(final Advancement root) {
final MutableGraph<Advancement> tree = GraphBuilder.directed().build();
addEdgesAndChildren(root, tree);
return tree;
}
private static void addEdgesAndChildren(final Advancement root, final MutableGraph<Advancement> tree) {
tree.addNode(root);
for (Advancement adv: root.getChildren()) {
addEdgesAndChildren(adv, tree);
tree.putEdge(root, adv);
}
}
}