Final patching

Signed-off-by: cpw <[email protected]>
This commit is contained in:
Anthony Anderson authored and cpw committed 2020-06-25 17:55:54 -04:00
1 parent 80eb12e59d
commit ca2ed1ff7a
139 files changed
+1034 -4067

No files matched your search

@@ -29,8 +29,9 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Objects;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -39,6 +40,7 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Queues;
import com.google.common.collect.Sets;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
@@ -50,6 +52,7 @@ import net.minecraft.fluid.*;
import net.minecraft.loot.LootContext;
import net.minecraft.loot.LootTable;
import net.minecraft.loot.LootTableManager;
import net.minecraft.tags.ITag;
import net.minecraft.util.*;
import net.minecraft.block.BlockState;
import net.minecraft.client.Minecraft;
@@ -87,7 +90,6 @@ import net.minecraft.network.play.server.SChangeBlockPacket;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionUtils;
import net.minecraft.stats.Stats;
import net.minecraft.tags.Tag;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.util.text.*;
import net.minecraft.world.spawner.AbstractSpawner;
@@ -106,8 +108,7 @@ import net.minecraft.world.IBlockReader;
import net.minecraft.world.IWorld;
import net.minecraft.world.IWorldReader;
import net.minecraft.world.World;
import net.minecraftforge.common.loot.IGlobalLootModifier;
import net.minecraftforge.common.loot.LootModifierManager;
import net.minecraftforge.common.data.IOptionalTagEntry;
import net.minecraftforge.common.util.BlockSnapshot;
import net.minecraftforge.event.AnvilUpdateEvent;
import net.minecraftforge.event.DifficultyChangeEvent;
@@ -1074,9 +1075,7 @@ public class ForgeHooks
return res == Result.DEFAULT ? 0 : res == Result.DENY ? -1 : 1;
}
/*
@SuppressWarnings("deprecation")
public static <T> void deserializeTagAdditions(Tag.Builder<T> builder, Function<ResourceLocation, Optional<T>> valueGetter, JsonObject json)
public static <T> void deserializeTagAdditions(List<ITag.ITagEntry> list, JsonObject json, List<ITag.Proxy> allList)
{
if (json.has("optional"))
{
@@ -1084,9 +1083,9 @@ public class ForgeHooks
{
String s = JSONUtils.getString(entry, "value");
if (!s.startsWith("#"))
builder.addOptional(valueGetter, Collections.singleton(new ResourceLocation(s)));
list.add(ForgeHooks.makeOptionalTag(true, Collections.singleton(new ResourceLocation(s))));
else
builder.addOptionalTag(new ResourceLocation(s.substring(1)));
list.add(ForgeHooks.makeOptionalTag(false, Collections.singleton(new ResourceLocation(s.substring(1)))));
}
}
@@ -1095,23 +1094,15 @@ public class ForgeHooks
for (JsonElement entry : JSONUtils.getJsonArray(json, "remove"))
{
String s = JSONUtils.getString(entry, "value");
ITag.ITagEntry dummy;
if (!s.startsWith("#"))
{
T value = valueGetter.apply(new ResourceLocation(s)).orElse(null);
if (value != null)
{
Tag.ITagEntry<T> dummyEntry = new Tag.ListEntry<>(Collections.singleton(value));
builder.remove(dummyEntry);
}
} else
{
Tag.ITagEntry<T> dummyEntry = new Tag.TagEntry<>(new ResourceLocation(s.substring(1)));
builder.remove(dummyEntry);
}
dummy = new ITag.ItemEntry(new ResourceLocation(s));
else
dummy = new ITag.TagEntry(new ResourceLocation(s.substring(1)));
allList.removeIf(e -> e.func_232968_a_().equals(dummy));
}
}
}
*/
private static final Map<IDataSerializer<?>, DataSerializerEntry> serializerEntries = GameData.getSerializerMap();
//private static final ForgeRegistry<DataSerializerEntry> serializerRegistry = (ForgeRegistry<DataSerializerEntry>) ForgeRegistries.DATA_SERIALIZERS;
@@ -1189,4 +1180,61 @@ public class ForgeHooks
return list;
}
@Deprecated//INTERNAL
public static IOptionalTagEntry makeOptionalTag(boolean items, Collection<ResourceLocation> locations) {
return items ? new OptionalItemTarget(locations) : new OptionalTagTarget(locations);
}
private static class OptionalTagTarget implements IOptionalTagEntry
{
private final Collection<ResourceLocation> referents;
public OptionalTagTarget(Collection<ResourceLocation> referents)
{
this.referents = referents;
}
@Override
public <T> boolean func_230238_a_(Function<ResourceLocation, ITag<T>> tagLookup, Function<ResourceLocation, T> itemLookup, Consumer<T> collector)
{
referents.stream()
.map(tagLookup)
.filter(Objects::nonNull)
.map(ITag::func_230236_b_)
.flatMap(List::stream)
.forEach(collector);
return true;
}
@Override
public void func_230237_a_(JsonArray array)
{
referents.stream().map(e -> "#" + e).forEach(array::add);
}
}
private static class OptionalItemTarget implements IOptionalTagEntry
{
private final Collection<ResourceLocation> locations;
public OptionalItemTarget(Collection<ResourceLocation> locations)
{
this.locations = locations;
}
@Override
public <T> boolean func_230238_a_(Function<ResourceLocation, ITag<T>> tagLookup, Function<ResourceLocation, T> itemLookup, Consumer<T> collector)
{
locations.stream().map(itemLookup).filter(Objects::nonNull).forEach(collector);
return true;
}
@Override
public void func_230237_a_(JsonArray array)
{
locations.stream().map(ResourceLocation::toString).forEach(array::add);
}
}
}
@@ -19,15 +19,16 @@
package net.minecraftforge.common;
import java.util.Collections;
import java.util.List;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IWorld;
import net.minecraft.world.IWorldReader;
import net.minecraft.world.World;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
/**
*
@@ -37,11 +38,7 @@ import javax.annotation.Nonnull;
* to support mod-shears as well.
*
*/
//TODO Change to World, not IWorldReader and make Implementor responsible for removing itself from the world.
//Better mimics vanilla behavior and allows more control for the user.
@Deprecated //TODO: Reevaluate the entire thing, loot from blocks is now a loot table. So this is just a marker now.
public interface IShearable
public interface IForgeShearable
{
/**
* Checks if the object is currently shearable
@@ -52,7 +49,8 @@ public interface IShearable
* @param pos Block's position in world.
* @return If this is shearable, and onSheared should be called.
*/
default boolean isShearable(@Nonnull ItemStack item, IWorldReader world, BlockPos pos) {
default boolean isShearable(@Nonnull ItemStack item, World world, BlockPos pos)
{
return true;
}
@@ -75,7 +73,8 @@ public interface IShearable
* @return A List containing all items from this shearing. May be empty.
*/
@Nonnull
default List<ItemStack> onSheared(@Nonnull ItemStack item, IWorld world, BlockPos pos, int fortune) {
return NonNullList.create();
default List<ItemStack> onSheared(@Nullable PlayerEntity player, @Nonnull ItemStack item, World world, BlockPos pos, int fortune)
{
return Collections.emptyList();
}
}
@@ -30,16 +30,16 @@ import net.minecraft.world.IBlockReader;
public interface IPlantable
{
default PlantType getPlantType(IBlockReader world, BlockPos pos) {
if (this instanceof CropsBlock) return PlantType.Crop;
if (this instanceof SaplingBlock) return PlantType.Plains;
if (this instanceof FlowerBlock) return PlantType.Plains;
if (this == Blocks.DEAD_BUSH) return PlantType.Desert;
if (this == Blocks.LILY_PAD) return PlantType.Water;
if (this == Blocks.RED_MUSHROOM) return PlantType.Cave;
if (this == Blocks.BROWN_MUSHROOM) return PlantType.Cave;
if (this == Blocks.NETHER_WART) return PlantType.Nether;
if (this == Blocks.TALL_GRASS) return PlantType.Plains;
return net.minecraftforge.common.PlantType.Plains;
if (this instanceof CropsBlock) return PlantType.CROP;
if (this instanceof SaplingBlock) return PlantType.PLAINS;
if (this instanceof FlowerBlock) return PlantType.PLAINS;
if (this == Blocks.DEAD_BUSH) return PlantType.DESERT;
if (this == Blocks.LILY_PAD) return PlantType.WATER;
if (this == Blocks.RED_MUSHROOM) return PlantType.CAVE;
if (this == Blocks.BROWN_MUSHROOM) return PlantType.CAVE;
if (this == Blocks.NETHER_WART) return PlantType.NETHER;
if (this == Blocks.TALL_GRASS) return PlantType.PLAINS;
return net.minecraftforge.common.PlantType.PLAINS;
}
BlockState getPlant(IBlockReader world, BlockPos pos);
@@ -22,16 +22,22 @@ package net.minecraftforge.common;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IWorldReader;
// TODO 1.16: This should not be an enum. Change it to something that functions similarly to ToolType
public enum PlantType implements IExtensibleEnum
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;
public final class PlantType
{
Plains,
Desert,
Beach,
Cave,
Water,
Nether,
Crop;
private static final Pattern INVALID_CHARACTERS = Pattern.compile("[^a-z_]"); //Only a-z and _ are allowed, meaning names must be lower case. And use _ to separate words.
private static final Map<String, PlantType> VALUES = new HashMap<>();
public static final PlantType PLAINS = get("plains");
public static final PlantType DESERT = get("desert");
public static final PlantType BEACH = get("beach");
public static final PlantType CAVE = get("cave");
public static final PlantType WATER = get("water");
public static final PlantType NETHER = get("nether");
public static final PlantType CROP = get("crop");
/**
* Getting a custom {@link PlantType}, or an existing one if it has the same name as that one. Your plant should implement {@link IPlantable}
@@ -46,9 +52,25 @@ public enum PlantType implements IExtensibleEnum
* @param name the name of the type of plant, you had better follow the style above
* @return the acquired {@link PlantType}, a new one if not found.
*/
public static PlantType create(String name)
public static PlantType get(String name)
{
throw new IllegalStateException("Enum not extended");
return VALUES.computeIfAbsent(name, e -> {
if (INVALID_CHARACTERS.matcher(e).find())
throw new IllegalArgumentException("PlantType.get() called with invalid name: " + name);
return new PlantType(e);
});
}
private final String name;
private PlantType(String name)
{
this.name = name;
}
public String getName()
{
return name;
}
}
@@ -37,7 +37,7 @@ public final class ToolType
public static ToolType get(String name)
{
if (VALID_NAME.matcher(name).find())
throw new IllegalArgumentException("ToolType.create() called with invalid name: " + name);
throw new IllegalArgumentException("ToolType.get() called with invalid name: " + name);
return values.computeIfAbsent(name, k -> new ToolType(name));
}
@@ -17,11 +17,11 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
//package net.minecraftforge.common.data;
package net.minecraftforge.common.data;
//import net.minecraft.tags.Tag.ITagEntry;
import net.minecraft.tags.ITag;
/**
* Marker class used by Forge to make a tag entry optional at runtime
*/
//public interface IOptionalTagEntry<T> extends ITagEntry<T> {}
public interface IOptionalTagEntry extends ITag.ITagEntry {}
@@ -1059,6 +1059,6 @@ public interface IForgeBlock
*/
default boolean shouldDisplayFluidOverlay(BlockState state, IBlockDisplayReader world, BlockPos pos, FluidState fluidState)
{
return state.getBlock() instanceof BreakableBlock || state.getBlock() instanceof StainedGlassBlock;
return state.getBlock() instanceof BreakableBlock || state.getBlock() instanceof LeavesBlock;
}
}
@@ -21,7 +21,13 @@ package net.minecraftforge.common.extensions;
import net.minecraft.data.TagsProvider;
import net.minecraft.tags.ITag;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.ForgeHooks;
import java.util.Arrays;
import java.util.Collection;
//TODO, Tag removal support.
public interface IForgeTagBuilder<T>
{
@@ -37,73 +43,32 @@ public interface IForgeTagBuilder<T>
return builder;
}
/*default Tag.Builder<T> addOptional(final TagCollection<T> collection, final ResourceLocation... locations)
{
return addOptional(collection, Arrays.asList(locations));
default TagsProvider.Builder<T> replace() {
return replace(true);
}
default Tag.Builder<T> addOptional(final TagCollection<T> collection, final Collection<ResourceLocation> locations)
{
return addOptional(collection.getEntryLookup(), locations);
default TagsProvider.Builder<T> replace(boolean value) {
getBuilder().getInternalBuilder().replace(value);
return getBuilder();
}
@Deprecated //Use the TagCollection version
default Tag.Builder<T> addOptional(final Function<ResourceLocation, Optional<T>> entryLookup, final Collection<ResourceLocation> locations)
default TagsProvider.Builder<T> addOptional(final ResourceLocation... locations)
{
return ((Tag.Builder<T>)this).add(new IOptionalTagEntry<T>() {
@Override
public void populate(Collection<T> itemsIn)
{
locations.stream().map(entryLookup).forEach(e -> e.ifPresent(itemsIn::add));
}
@Override
public void serialize(JsonArray array, Function<T, ResourceLocation> getNameForObject)
{
locations.stream().map(ResourceLocation::toString).forEach(array::add);
}
});
return addOptional(Arrays.asList(locations));
}
default Tag.Builder<T> addOptionalTag(final TagCollection<T> collection, @SuppressWarnings("unchecked") final Tag<T>... tags)
default TagsProvider.Builder<T> addOptional(final Collection<ResourceLocation> locations)
{
for (Tag<T> tag : tags)
addOptionalTag(tag.getId());
return ((Tag.Builder<T>)this);
return getBuilder().add(ForgeHooks.makeOptionalTag(true, locations));
}
default Tag.Builder<T> addOptionalTag(final ResourceLocation... tags)
default TagsProvider.Builder<T> addOptionalTag(final ResourceLocation... locations)
{
for (ResourceLocation rl : tags)
addOptionalTag(rl);
return ((Tag.Builder<T>)this);
return addOptionalTag(Arrays.asList(locations));
}
default Tag.Builder<T> addOptionalTag(ResourceLocation tag)
default TagsProvider.Builder<T> addOptionalTag(final Collection<ResourceLocation> locations)
{
class TagTarget<U> extends Tag.TagEntry<U> implements IOptionalTagEntry<U>
{
private Tag<U> resolvedTag = null;
protected TagTarget(ResourceLocation referent) {
super(referent);
}
@Override
public boolean resolve(@Nonnull Function<ResourceLocation, Tag<U>> resolver)
{
if (this.resolvedTag == null)
this.resolvedTag = resolver.apply(this.getSerializedId());
return true; // never fail if resolver returns null
}
@Override
public void populate(@Nonnull Collection<U> items)
{
if (this.resolvedTag != null)
items.addAll(this.resolvedTag.getAllElements());
}
};
return ((Tag.Builder<T>)this).add(new TagTarget<>(tag));
}*/
return getBuilder().add(ForgeHooks.makeOptionalTag(false, locations));
}
}