forked from MinecraftForge/MinecraftForge
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add FluidStack codec, and a test mod that verifies its behaviour matc…
…hes the existing write/read logic. Add missing license headers.
- Loading branch information
Showing
11 changed files
with
250 additions
and
0 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
src/main/java/net/minecraftforge/client/event/ClientPlayerChangeGameModeEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/java/net/minecraftforge/client/model/generators/CustomLoaderBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/java/net/minecraftforge/client/model/generators/loaders/CompositeModelBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...in/java/net/minecraftforge/client/model/generators/loaders/DynamicBucketModelBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/java/net/minecraftforge/client/model/generators/loaders/ItemLayersModelBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/java/net/minecraftforge/client/model/generators/loaders/MultiLayerModelBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/java/net/minecraftforge/client/model/generators/loaders/OBJLoaderBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...a/net/minecraftforge/client/model/generators/loaders/SeparatePerspectiveModelBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters