diff --git a/src/main/java/net/minecraftforge/client/event/ClientPlayerChangeGameModeEvent.java b/src/main/java/net/minecraftforge/client/event/ClientPlayerChangeGameModeEvent.java index a315f84472..64cbd70d7c 100644 --- a/src/main/java/net/minecraftforge/client/event/ClientPlayerChangeGameModeEvent.java +++ b/src/main/java/net/minecraftforge/client/event/ClientPlayerChangeGameModeEvent.java @@ -1,3 +1,22 @@ +/* + * Minecraft Forge + * Copyright (c) 2016-2020. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + package net.minecraftforge.client.event; import net.minecraft.client.network.play.NetworkPlayerInfo; diff --git a/src/main/java/net/minecraftforge/client/model/generators/CustomLoaderBuilder.java b/src/main/java/net/minecraftforge/client/model/generators/CustomLoaderBuilder.java index ba5b4f3ed3..d870254b63 100644 --- a/src/main/java/net/minecraftforge/client/model/generators/CustomLoaderBuilder.java +++ b/src/main/java/net/minecraftforge/client/model/generators/CustomLoaderBuilder.java @@ -1,3 +1,22 @@ +/* + * Minecraft Forge + * Copyright (c) 2016-2020. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + package net.minecraftforge.client.model.generators; import com.google.common.base.Preconditions; diff --git a/src/main/java/net/minecraftforge/client/model/generators/loaders/CompositeModelBuilder.java b/src/main/java/net/minecraftforge/client/model/generators/loaders/CompositeModelBuilder.java index 65638705cc..57742df792 100644 --- a/src/main/java/net/minecraftforge/client/model/generators/loaders/CompositeModelBuilder.java +++ b/src/main/java/net/minecraftforge/client/model/generators/loaders/CompositeModelBuilder.java @@ -1,3 +1,22 @@ +/* + * Minecraft Forge + * Copyright (c) 2016-2020. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + package net.minecraftforge.client.model.generators.loaders; import com.google.common.base.Preconditions; diff --git a/src/main/java/net/minecraftforge/client/model/generators/loaders/DynamicBucketModelBuilder.java b/src/main/java/net/minecraftforge/client/model/generators/loaders/DynamicBucketModelBuilder.java index 2c47b87d7a..99c4765105 100644 --- a/src/main/java/net/minecraftforge/client/model/generators/loaders/DynamicBucketModelBuilder.java +++ b/src/main/java/net/minecraftforge/client/model/generators/loaders/DynamicBucketModelBuilder.java @@ -1,3 +1,22 @@ +/* + * Minecraft Forge + * Copyright (c) 2016-2020. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + package net.minecraftforge.client.model.generators.loaders; import com.google.common.base.Preconditions; diff --git a/src/main/java/net/minecraftforge/client/model/generators/loaders/ItemLayersModelBuilder.java b/src/main/java/net/minecraftforge/client/model/generators/loaders/ItemLayersModelBuilder.java index 712ec2e3a3..aaa9c81a32 100644 --- a/src/main/java/net/minecraftforge/client/model/generators/loaders/ItemLayersModelBuilder.java +++ b/src/main/java/net/minecraftforge/client/model/generators/loaders/ItemLayersModelBuilder.java @@ -1,3 +1,22 @@ +/* + * Minecraft Forge + * Copyright (c) 2016-2020. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + package net.minecraftforge.client.model.generators.loaders; import com.google.common.base.Preconditions; diff --git a/src/main/java/net/minecraftforge/client/model/generators/loaders/MultiLayerModelBuilder.java b/src/main/java/net/minecraftforge/client/model/generators/loaders/MultiLayerModelBuilder.java index be690db5d6..5a83e0576e 100644 --- a/src/main/java/net/minecraftforge/client/model/generators/loaders/MultiLayerModelBuilder.java +++ b/src/main/java/net/minecraftforge/client/model/generators/loaders/MultiLayerModelBuilder.java @@ -1,3 +1,22 @@ +/* + * Minecraft Forge + * Copyright (c) 2016-2020. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + package net.minecraftforge.client.model.generators.loaders; import com.google.common.base.Preconditions; diff --git a/src/main/java/net/minecraftforge/client/model/generators/loaders/OBJLoaderBuilder.java b/src/main/java/net/minecraftforge/client/model/generators/loaders/OBJLoaderBuilder.java index 343dd3c274..255748560d 100644 --- a/src/main/java/net/minecraftforge/client/model/generators/loaders/OBJLoaderBuilder.java +++ b/src/main/java/net/minecraftforge/client/model/generators/loaders/OBJLoaderBuilder.java @@ -1,3 +1,22 @@ +/* + * Minecraft Forge + * Copyright (c) 2016-2020. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + package net.minecraftforge.client.model.generators.loaders; import com.google.common.base.Preconditions; diff --git a/src/main/java/net/minecraftforge/client/model/generators/loaders/SeparatePerspectiveModelBuilder.java b/src/main/java/net/minecraftforge/client/model/generators/loaders/SeparatePerspectiveModelBuilder.java index 401b52ab1e..fe7d5c497a 100644 --- a/src/main/java/net/minecraftforge/client/model/generators/loaders/SeparatePerspectiveModelBuilder.java +++ b/src/main/java/net/minecraftforge/client/model/generators/loaders/SeparatePerspectiveModelBuilder.java @@ -1,3 +1,22 @@ +/* + * Minecraft Forge + * Copyright (c) 2016-2020. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + package net.minecraftforge.client.model.generators.loaders; import com.google.common.base.Preconditions; diff --git a/src/main/java/net/minecraftforge/fluids/FluidStack.java b/src/main/java/net/minecraftforge/fluids/FluidStack.java index cf364bd156..3a3dbcf98a 100644 --- a/src/main/java/net/minecraftforge/fluids/FluidStack.java +++ b/src/main/java/net/minecraftforge/fluids/FluidStack.java @@ -19,12 +19,15 @@ package net.minecraftforge.fluids; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import net.minecraft.fluid.Fluid; import net.minecraft.fluid.Fluids; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; import net.minecraft.network.PacketBuffer; import net.minecraft.util.ResourceLocation; +import net.minecraft.util.registry.Registry; import net.minecraft.util.text.ITextComponent; import net.minecraftforge.common.util.Constants; import net.minecraftforge.registries.ForgeRegistries; @@ -36,6 +39,8 @@ import javax.annotation.Nullable; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import java.util.Optional; + /** * ItemStack substitute for Fluids. * @@ -50,6 +55,18 @@ public class FluidStack public static final FluidStack EMPTY = new FluidStack(Fluids.EMPTY, 0); + public static final Codec CODEC = RecordCodecBuilder.create( + instance -> instance.group( + Registry.FLUID.fieldOf("FluidName").forGetter(FluidStack::getFluid), + Codec.INT.fieldOf("Amount").forGetter(FluidStack::getAmount), + CompoundNBT.CODEC.optionalFieldOf("Tag").forGetter(stack -> Optional.ofNullable(stack.getTag())) + ).apply(instance, (fluid, amount, tag) -> { + FluidStack stack = new FluidStack(fluid, amount); + tag.ifPresent(stack::setTag); + return stack; + }) + ); + private boolean isEmpty; private int amount; private CompoundNBT tag; diff --git a/src/test/java/net/minecraftforge/debug/CodecsTest.java b/src/test/java/net/minecraftforge/debug/CodecsTest.java new file mode 100644 index 0000000000..cc2515f95a --- /dev/null +++ b/src/test/java/net/minecraftforge/debug/CodecsTest.java @@ -0,0 +1,79 @@ +/* + * Minecraft Forge + * Copyright (c) 2016-2020. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package net.minecraftforge.debug; + +import net.minecraft.fluid.Fluids; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.nbt.NBTDynamicOps; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fml.common.Mod; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +/** + * Created to host any custom codecs forge may be adding. + */ +@Mod("forge_codecs_test") +public class CodecsTest +{ + private static final Logger LOGGER = LogManager.getLogger(); + + public CodecsTest() + { + testFluidStackCodec(); + } + + /** + * Makes sure FluidStack.CODEC produces the same data as FluidStack.write + */ + private void testFluidStackCodec() + { + FluidStack noTag = new FluidStack(Fluids.WATER, 10); + FluidStack withTag = new FluidStack(Fluids.LAVA, 10); + withTag.getOrCreateChildTag("test").putString("value", "This is a test"); + + CompoundNBT noTag_write = noTag.writeToNBT(new CompoundNBT()); + CompoundNBT withTag_write = withTag.writeToNBT(new CompoundNBT()); + + CompoundNBT noTag_encode = (CompoundNBT)FluidStack.CODEC.encodeStart(NBTDynamicOps.INSTANCE, noTag).getOrThrow(false, error -> { + LOGGER.error("Error encoding noTag: {}", error); + }); + CompoundNBT withTag_encode = (CompoundNBT)FluidStack.CODEC.encodeStart(NBTDynamicOps.INSTANCE, withTag).getOrThrow(false, error -> { + LOGGER.error("Error encoding withTag: {}", error); + }); + + if (!noTag_write.equals(noTag_encode)) + throw new IllegalStateException("Encoded noTag does not match"); + if (!withTag_write.equals(withTag_encode)) + throw new IllegalStateException("Encoded withTag does not match"); + + FluidStack noTag_decode = FluidStack.CODEC.decode(NBTDynamicOps.INSTANCE, noTag_encode).getOrThrow(false, error -> { + LOGGER.error("Error decoding noTag: {}", error); + }).getFirst(); + FluidStack withTag_decode = FluidStack.CODEC.decode(NBTDynamicOps.INSTANCE, withTag_encode).getOrThrow(false, error -> { + LOGGER.error("Error decoding withTag: {}", error); + }).getFirst(); + + if (!noTag.equals(noTag_decode)) + throw new IllegalStateException("Decoded noTag does not match"); + if (!withTag.equals(withTag_decode)) + throw new IllegalStateException("Decoded withTag does not match"); + } +} diff --git a/src/test/resources/META-INF/mods.toml b/src/test/resources/META-INF/mods.toml index dfbd2280c7..8b548842c0 100644 --- a/src/test/resources/META-INF/mods.toml +++ b/src/test/resources/META-INF/mods.toml @@ -92,3 +92,5 @@ license="LGPL v2.1" modId="player_game_mode_event_test" [[mods]] modId="structure_spawn_list_event_test" +[[mods]] + modId="forge_codecs_test"