Skip to content

Commit

Permalink
Progress #21 Ported build errors. NBT storage is broken at runtime.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alatyami committed Jul 14, 2024
1 parent b46de40 commit fc90cb7
Show file tree
Hide file tree
Showing 14 changed files with 153 additions and 100 deletions.
47 changes: 27 additions & 20 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ plugins {
id 'eclipse'
id 'idea'
id 'maven-publish'
id 'net.minecraftforge.gradle' version '[6.0,6.2)'
id "org.sonarqube" version "4.2.1.3168"
id 'net.minecraftforge.gradle' version '[6.0.24,6.2)'
id "org.sonarqube" version "5.0.0.4638"
}

version = "${minecraft_version}-${mod_version}"
Expand All @@ -21,7 +21,7 @@ sonarqube {
}
}

java.toolchain.languageVersion = JavaLanguageVersion.of(17)
java.toolchain.languageVersion = JavaLanguageVersion.of(21)

println('========================================')
println('Java: ' + System.getProperty('java.version'))
Expand All @@ -32,22 +32,17 @@ println('----------------------------------------')

minecraft {
mappings channel: mapping_channel, version: mapping_version
reobf = false
copyIdeResources = true

accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')
//accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')

runs {
// applies to all the run configs below
configureEach {
workingDirectory project.file('run')
property 'forge.logging.markers', 'REGISTRIES'
property 'forge.logging.console.level', 'debug'

//mods {
// "${mod_id}" {
// source sourceSets.main
// }
//}
}

client {
Expand Down Expand Up @@ -79,8 +74,11 @@ repositories {

dependencies {
minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}"
//runtimeOnly fg.deobf("curse.maven:theoneprobe-${curseforge_theoneprobe}")
runtimeOnly fg.deobf("curse.maven:jei-${curseforge_jei}")

//runtimeOnly fg.deobf("curse.maven:jei-${curseforge_jei}")

// Hack fix for now, force jopt-simple to be exactly 5.0.4 because Mojang ships that version, but some transitive dependencies request 6.0+
implementation('net.sf.jopt-simple:jopt-simple:5.0.4') { version { strictly '5.0.4' } }
}

// This block of code expands all declared replace properties in the specified resource targets.
Expand Down Expand Up @@ -121,16 +119,8 @@ tasks.named('jar', Jar).configure {
'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
])
}

// This is the preferred method to reobfuscate your jar file
finalizedBy 'reobfJar'
}

// However if you are in a multi-project build, dev time needs unobfed jar files, so you can delay the obfuscation until publishing by doing:
// tasks.named('publish').configure {
// dependsOn 'reobfJar'
// }

// Example configuration to allow publishing using the maven-publish plugin
publishing {
publications {
Expand All @@ -148,3 +138,20 @@ publishing {
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation
}

eclipse {
// Run everytime eclipse builds the code
//autoBuildTasks genEclipseRuns
// Run when importing the project
synchronizationTasks 'genEclipseRuns'
}

// Merge the resources and classes into the same directory.
// This is done because java expects modules to be in a single directory.
// And if we have it in multiple we have to do performance intensive hacks like having the UnionFileSystem
// This will eventually be migrated to ForgeGradle so modders don't need to manually do it. But that is later.
sourceSets.each {
def dir = layout.buildDirectory.dir("sourcesSets/$it.name")
it.output.resourcesDir = dir
it.java.destinationDirectory = dir
}
19 changes: 6 additions & 13 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ org.gradle.daemon=false
# ------------------------------------------------
# Environment Properties
# ------------------------------------------------
minecraft_version=1.20.4
minecraft_version_range=[1.20.4,1.21)
forge_version=49.1.0
minecraft_version=1.20.6
minecraft_version_range=[1.20.6,1.21)
forge_version=50.1.0
forge_version_range=[0,)
loader_version_range=[0,)
mapping_channel=official
mapping_version=1.20.4
mapping_version=1.20.6

# ------------------------------------------------
# Mod Properties
Expand All @@ -23,7 +23,7 @@ mod_id=growthcraft_trapper
mod_archive_base=growthcraft-trapper
mod_name=Growthcraft Trapper
mod_license=GNU General Public License v3.0
mod_version=1.20.4.1
mod_version=1.20.6.1
mod_group_id=growthcraft
mod_authors=Alatyami
mod_description=Growthcraft Trapper is a realistic and immersive Forge mod that adds various new trapping elements to the game of Minecraft.
Expand All @@ -36,11 +36,4 @@ mod_description=Growthcraft Trapper is a realistic and immersive Forge mod that
# curseforge_MODNAME=CURSE_PROJ_ID:CURSE_FILE_ID
# ------------------------------------------------
# JEI - https://www.curseforge.com/minecraft/mc-mods/jei/files
curseforge_jei=238222:5491249
# ------------------------------------------------
# TheOneProbe https://www.curseforge.com/minecraft/mc-mods/the-one-probe/files
curseforge_theoneprobe=245211:5159289
# ------------------------------------------------
# Patchouli https://www.curseforge.com/minecraft/mc-mods/patchouli/files
curseforge_patchouli=306770:5240286
# ------------------------------------------------
curseforge_jei=238222:5466527
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-all.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
21 changes: 13 additions & 8 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand All @@ -80,13 +80,10 @@ do
esac
done

APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

APP_NAME="Gradle"
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -143,12 +140,16 @@ fi
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -193,6 +194,10 @@ if "$cygwin" || "$msys" ; then
done
fi


# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
Expand Down Expand Up @@ -237,4 +242,4 @@ eval "set -- $(
tr '\n' ' '
)" '"$@"'

exec "$JAVACMD" "$@"
exec "$JAVACMD" "$@"
3 changes: 2 additions & 1 deletion gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

Expand Down Expand Up @@ -88,4 +89,4 @@ exit /b %EXIT_CODE%
:mainEnd
if "%OS%"=="Windows_NT" endlocal

:omega
:omega
4 changes: 3 additions & 1 deletion src/main/java/growthcraft/trapper/block/AnimalTrapBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.ItemInteractionResult;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.*;
Expand Down Expand Up @@ -57,7 +59,7 @@ public MapCodec<AnimalTrapBlock> codec() {
}

@Override
public InteractionResult use(BlockState blockState, Level level, BlockPos blockPos, Player player, InteractionHand interactionHand, BlockHitResult blockHitResult) {
protected InteractionResult useWithoutItem(BlockState blockState, Level level, BlockPos blockPos, Player player, BlockHitResult blockHitResult) {
BlockEntity blockEntity = level.getBlockEntity(blockPos);

if (!(blockEntity instanceof AnimalTrapBlockEntity animalTrapBlockEntity))
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/growthcraft/trapper/block/FishtrapBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected MapCodec<FishtrapBlock> codec() {
}

@Override
public InteractionResult use(BlockState blockState, Level level, BlockPos blockPos, Player player, InteractionHand interactionHand, BlockHitResult blockHitResult) {
protected InteractionResult useWithoutItem(BlockState blockState, Level level, BlockPos blockPos, Player player, BlockHitResult blockHitResult) {
BlockEntity blockEntity = level.getBlockEntity(blockPos);

if (!(blockEntity instanceof FishtrapBlockEntity fishtrapBlockEntity))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public MapCodec<SpawnEggTrapBlock> codec() {
}

@Override
public InteractionResult use(BlockState blockState, Level level, BlockPos blockPos, Player player, InteractionHand interactionHand, BlockHitResult blockHitResult) {
protected InteractionResult useWithoutItem(BlockState blockState, Level level, BlockPos blockPos, Player player, BlockHitResult blockHitResult) {
BlockEntity blockEntity = level.getBlockEntity(blockPos);

if (!(blockEntity instanceof SpawnEggTrapBlockEntity spawnEggTrapBlockEntity))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import growthcraft.trapper.GrowthcraftTrapper;
import growthcraft.trapper.block.AnimalTrapBlock;
import growthcraft.trapper.init.GrowthcraftTrapperBlockEntities;
import growthcraft.trapper.init.GrowthcraftTrapperLootTables;
import growthcraft.trapper.init.config.GrowthcraftTrapperConfig;
import growthcraft.trapper.lib.handler.WrappedInventoryHandler;
import growthcraft.trapper.lib.utils.BlockStateUtils;
Expand All @@ -12,6 +13,7 @@
import io.netty.buffer.Unpooled;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.HolderLookup;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.Connection;
import net.minecraft.network.FriendlyByteBuf;
Expand Down Expand Up @@ -170,27 +172,26 @@ private void doTrapping(@NotNull BlockPos blockPos) {

ItemStack baitItemStack = itemStackHandler.getStackInSlot(0);

LootDataManager lootDataManager = Objects.requireNonNull(level.getServer()).getLootData();
LootTable lootTable;

String lootTableType = "";

// Depending on the bait that was used, determines what gets caught.
if (baitItemStack.is(Tags.Items.CROPS_WHEAT)) {
lootTableType = "wheat";
lootTable = lootDataManager.getElement(LootDataType.TABLE, Reference.LootTables.ANIMAL_TRAP_WHEAT);
lootTable = Objects.requireNonNull(level.getServer().reloadableRegistries()).getLootTable(GrowthcraftTrapperLootTables.ANIMAL_TRAP_WHEAT);
} else if (baitItemStack.is(Tags.Items.CROPS_CARROT)) {
lootTableType = "carrot";
lootTable = lootDataManager.getElement(LootDataType.TABLE, Reference.LootTables.ANIMAL_TRAP_CARROT);
lootTable = Objects.requireNonNull(level.getServer().reloadableRegistries()).getLootTable(GrowthcraftTrapperLootTables.ANIMAL_TRAP_CARROT);
} else if (baitItemStack.is(Tags.Items.SEEDS_WHEAT)) {
lootTableType = "seeds_wheat";
lootTable = lootDataManager.getElement(LootDataType.TABLE, Reference.LootTables.ANIMAL_TRAP_SEEDS);
lootTable = Objects.requireNonNull(level.getServer().reloadableRegistries()).getLootTable(GrowthcraftTrapperLootTables.ANIMAL_TRAP_SEEDS);
} else if (baitItemStack.is(ItemTags.LEAVES)) {
lootTableType = "leaves";
lootTable = lootDataManager.getElement(LootDataType.TABLE, Reference.LootTables.ANIMAL_TRAP_LEAVES);
lootTable = Objects.requireNonNull(level.getServer().reloadableRegistries()).getLootTable(GrowthcraftTrapperLootTables.ANIMAL_TRAP_LEAVES);
} else {
lootTableType = "invalid_bait";
lootTable = lootDataManager.getElement(LootDataType.TABLE, BuiltInLootTables.EMPTY);
lootTable = Objects.requireNonNull(level.getServer().reloadableRegistries()).getLootTable(BuiltInLootTables.EMPTY);
}

GrowthcraftTrapper.LOGGER.debug(
Expand Down Expand Up @@ -237,30 +238,30 @@ public Packet<ClientGamePacketListener> getUpdatePacket() {
}

@Override
public CompoundTag getUpdateTag() {
return this.serializeNBT();
public CompoundTag getUpdateTag(HolderLookup.Provider provider) {
return this.serializeCaps();
}

@Override
public void handleUpdateTag(CompoundTag tag) {
this.load(tag);
public void handleUpdateTag(CompoundTag tag, HolderLookup.Provider provider) {
this.loadAdditional(tag, provider);
}

@Override
public void load(CompoundTag nbt) {
super.load(nbt);
public void loadAdditional(CompoundTag nbt, HolderLookup.Provider provider) {
super.loadAdditional(nbt, provider);
itemStackHandler.deserializeNBT(nbt.getCompound("inventory"));
this.tickTimer = nbt.getInt("tickTimer");
this.tickCooldown = nbt.getInt("tickCooldown");

if (nbt.contains("CustomName", 8)) {
this.customName = Component.Serializer.fromJson(nbt.getString("CustomName"));
this.customName = Component.Serializer.fromJson(nbt.getString("CustomName"), provider);
}
}

@Override
public void onDataPacket(Connection net, ClientboundBlockEntityDataPacket pkt) {
this.load(pkt.getTag());
public void onDataPacket(Connection net, ClientboundBlockEntityDataPacket pkt, HolderLookup.Provider provider) {
this.loadAdditional(pkt.getTag(), provider);
}

@Override
Expand All @@ -276,14 +277,14 @@ public void invalidateCaps() {
}

@Override
protected void saveAdditional(CompoundTag nbt) {
protected void saveAdditional(CompoundTag nbt, HolderLookup .Provider provider) {
nbt.put("inventory", itemStackHandler.serializeNBT());
nbt.putInt("tickTimer", this.tickTimer);
nbt.putInt("tickCooldown", this.tickCooldown);
if (this.customName != null) {
nbt.putString("CustomName", Component.Serializer.toJson(this.customName));
nbt.putString("CustomName", Component.Serializer.toJson(this.customName, provider));
}
super.saveAdditional(nbt);
super.saveAdditional(nbt, provider);
}

@Override
Expand Down
Loading

0 comments on commit fc90cb7

Please sign in to comment.