Skip to content

Commit

Permalink
port to 1.20.6 but crash
Browse files Browse the repository at this point in the history
  • Loading branch information
anviaan committed Jul 24, 2024
1 parent 9f94259 commit 1101a18
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 70 deletions.
20 changes: 15 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.6-SNAPSHOT'
id 'fabric-loom' version '1.7-SNAPSHOT'
id 'maven-publish'
}

Expand Down Expand Up @@ -28,10 +28,8 @@ dependencies {

modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

modImplementation "dev.onyxstudios.cardinal-components-api:cardinal-components-base:${project.cardinal_components_version}"
modImplementation "dev.onyxstudios.cardinal-components-api:cardinal-components-entity:${project.cardinal_components_version}"
include "dev.onyxstudios.cardinal-components-api:cardinal-components-base:${project.cardinal_components_version}"
include "dev.onyxstudios.cardinal-components-api:cardinal-components-entity:${project.cardinal_components_version}"
modImplementation include ("org.ladysnake.cardinal-components-api:cardinal-components-base:${project.cca_version}")
modImplementation include ("org.ladysnake.cardinal-components-api:cardinal-components-entity:${project.cca_version}")

modLocalRuntime("com.terraformersmc:modmenu:${project.modmenu_version}")
}
Expand Down Expand Up @@ -59,4 +57,16 @@ jar {
from("LICENSE") {
rename { "${it}_${project.base.archivesName.get()}"}
}
}

publishing {
publications {
create("mavenJava", MavenPublication) {
artifactId = project.archives_base_name
from components.java
}
}

repositories {
}
}
10 changes: 7 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ maven_group=net.anvian.record_days_survived
archives_base_name=(Fabric)RecordDaySurvived-1.20.6

# Dependencies
fabric_version=0.99.4+1.20.6
cardinal_components_version=6.0.0
modmenu_version=10.0.0-beta.1
fabric_version=0.100.4+1.20.6

# Cardinal Components
cca_version=6.0.0

# Mod Menu
modmenu_version=10.0.0
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.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
2 changes: 1 addition & 1 deletion 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/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/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 Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package net.anvian.record_days_survived;

import net.anvian.record_days_survived.command.RecordCommand;
import net.anvian.record_days_survived.components.ModComponents;
import net.anvian.record_days_survived.components.DayComponent;
import net.anvian.record_days_survived.components.RecordDayComponent;
import net.anvian.record_days_survived.components.TicksPassedComponent;
import net.anvian.record_days_survived.util.DaysUtil;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
Expand All @@ -10,19 +12,32 @@
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerEntityEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Style;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import org.ladysnake.cca.api.v3.component.ComponentKey;
import org.ladysnake.cca.api.v3.component.ComponentRegistry;
import org.ladysnake.cca.api.v3.entity.EntityComponentFactoryRegistry;
import org.ladysnake.cca.api.v3.entity.EntityComponentInitializer;
import org.ladysnake.cca.api.v3.entity.RespawnCopyStrategy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Objects;

public class RecordDaysSurvivedMod implements ModInitializer {
public class RecordDaysSurvivedMod implements ModInitializer, EntityComponentInitializer {
public static final String MOD_ID = "record_days_survived";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);

public static final ComponentKey<DayComponent> DAY = ComponentRegistry.getOrCreate(
Identifier.of(RecordDaysSurvivedMod.MOD_ID, "days"), DayComponent.class);
public static final ComponentKey<RecordDayComponent> RECORD_DAY = ComponentRegistry.getOrCreate(
Identifier.of(RecordDaysSurvivedMod.MOD_ID, "record_day"), RecordDayComponent.class);
public static final ComponentKey<TicksPassedComponent> TICKS_PASSED = ComponentRegistry.getOrCreate(
Identifier.of(RecordDaysSurvivedMod.MOD_ID, "ticks_passed"), TicksPassedComponent.class);

private static long ticksPassed = 1200;

@Override
Expand All @@ -31,7 +46,7 @@ public void onInitialize() {
RecordCommand.register(dispatcher));

ServerEntityEvents.ENTITY_LOAD.register((entity, world) -> {
if (entity instanceof ServerPlayerEntity) {
if (entity instanceof PlayerEntity) {
ServerCommandSource source = entity.getCommandSource().withEntity(entity);

Objects.requireNonNull(entity.getServer()).getCommandManager().executeWithPrefix(source, "record_day report");
Expand All @@ -40,7 +55,7 @@ public void onInitialize() {
});

ServerPlayerEvents.AFTER_RESPAWN.register((oldPlayer, newPlayer, alive) -> {
int recordDay = ModComponents.RECORD_DAY.get(newPlayer).getRecordDay();
int recordDay = newPlayer.getComponent(RECORD_DAY).getRecordDay();

newPlayer.sendMessage(Text.translatable("reset").fillStyle(Style.EMPTY.withBold(true)));
newPlayer.sendMessage(Text.of(I18n.translate("report_record_day", recordDay)));
Expand All @@ -49,12 +64,12 @@ public void onInitialize() {
ServerTickEvents.START_SERVER_TICK.register((server -> {
long worldTime = server.getOverworld().getTime();

for (ServerPlayerEntity player : server.getPlayerManager().getPlayerList()) {
for (PlayerEntity player : server.getPlayerManager().getPlayerList()) {

//one minute has passed
if (worldTime % 1200 == 0) {
ModComponents.TICKS_PASSED.get(player).addTickPassed(worldTime);
ticksPassed = ModComponents.TICKS_PASSED.get(player).getTicksPassed();
player.getComponent(TICKS_PASSED).addTickPassed(worldTime);
ticksPassed = player.getComponent(TICKS_PASSED).getTicksPassed();
}

//one day has passed
Expand All @@ -66,11 +81,18 @@ public void onInitialize() {
}));

EntitySleepEvents.STOP_SLEEPING.register((entity, sleepingPos) -> {
if (entity instanceof ServerPlayerEntity) {
if (entity instanceof PlayerEntity) {
DaysUtil.dayPassed(entity);
}
});

LOGGER.info("Record Days Survived mod initialized!");
}

@Override
public void registerEntityComponentFactories(EntityComponentFactoryRegistry registry) {
registry.registerForPlayers(DAY, DayComponent::new, RespawnCopyStrategy.LOSSLESS_ONLY);
registry.registerForPlayers(RECORD_DAY, RecordDayComponent::new, RespawnCopyStrategy.ALWAYS_COPY);
registry.registerForPlayers(TICKS_PASSED, TicksPassedComponent::new, RespawnCopyStrategy.NEVER_COPY);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.anvian.record_days_survived.components.ModComponents;
import net.anvian.record_days_survived.RecordDaysSurvivedMod;
import net.minecraft.command.argument.EntityArgumentType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.command.CommandManager;
Expand Down Expand Up @@ -34,12 +34,10 @@ public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
}

private static int reportDay(CommandContext<ServerCommandSource> context) {
var day = ModComponents.DAY.get(context.getSource().getPlayer());
var record = ModComponents.RECORD_DAY.get(context.getSource().getPlayer());
context.getSource().sendMessage(Text.translatable("title_report"));

int days = day.getDays();
int recordDay = record.getRecordDay();
int days = context.getSource().getPlayer().getComponent(RecordDaysSurvivedMod.DAY).getDays();
int recordDay = context.getSource().getPlayer().getComponent(RecordDaysSurvivedMod.RECORD_DAY).getRecordDay();

context.getSource().sendFeedback(() -> Text.translatable("report_day", days), false);
context.getSource().sendFeedback(() -> Text.translatable("report_record_day", recordDay), false);
Expand All @@ -49,8 +47,8 @@ var record = ModComponents.RECORD_DAY.get(context.getSource().getPlayer());

private static int setDay(CommandContext<ServerCommandSource> context) {
int value = IntegerArgumentType.getInteger(context, "value");
var day = ModComponents.DAY.get(context.getSource().getPlayer());
var record = ModComponents.RECORD_DAY.get(context.getSource().getPlayer());
var day = context.getSource().getPlayer().getComponent(RecordDaysSurvivedMod.DAY);
var record = context.getSource().getPlayer().getComponent(RecordDaysSurvivedMod.RECORD_DAY);

day.setDays(value);

Expand All @@ -68,8 +66,8 @@ var record = ModComponents.RECORD_DAY.get(context.getSource().getPlayer());
private static int setDayWithTarget(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
int value = IntegerArgumentType.getInteger(context, "value");
PlayerEntity target = EntityArgumentType.getPlayer(context, "target");
var day = ModComponents.DAY.get(target);
var record = ModComponents.RECORD_DAY.get(context.getSource().getPlayer());
var day = target.getComponent(RecordDaysSurvivedMod.DAY);
var record = context.getSource().getPlayer().getComponent(RecordDaysSurvivedMod.RECORD_DAY);

day.setDays(value);

Expand All @@ -86,7 +84,7 @@ var record = ModComponents.RECORD_DAY.get(context.getSource().getPlayer());

private static int setRecordDay(CommandContext<ServerCommandSource> context) {
int value = IntegerArgumentType.getInteger(context, "value");
var record = ModComponents.RECORD_DAY.get(context.getSource().getPlayer());
var record = context.getSource().getPlayer().getComponent(RecordDaysSurvivedMod.RECORD_DAY);

record.setRecordDay(value);

Expand All @@ -99,7 +97,7 @@ private static int setRecordDayWithTarget(CommandContext<ServerCommandSource> co
int value = IntegerArgumentType.getInteger(context, "value");
PlayerEntity target = EntityArgumentType.getPlayer(context, "target");

var record = ModComponents.RECORD_DAY.get(target);
var record = target.getComponent(RecordDaysSurvivedMod.RECORD_DAY);
record.setRecordDay(value);

context.getSource().sendFeedback(() -> Text.translatable("set_record_day_with_target", target.getName(), value), true);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
package net.anvian.record_days_survived.components;

import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.registry.RegistryWrapper;
import org.ladysnake.cca.api.v3.component.Component;

public class DayComponent implements Component {
private final PlayerEntity player;
private int days;

public DayComponent(PlayerEntity player) {
this.player = player;
days = 0;
}

@Override
public void readFromNbt(NbtCompound tag, RegistryWrapper.WrapperLookup registryLookup) {
days = tag.getInt("days");
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
package net.anvian.record_days_survived.components;

import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.registry.RegistryWrapper;
import org.ladysnake.cca.api.v3.component.Component;

public class RecordDayComponent implements Component {
private final PlayerEntity player;
private int recordDay;

public RecordDayComponent(PlayerEntity player) {
this.player = player;
recordDay = 0;
}

@Override
public void readFromNbt(NbtCompound tag, RegistryWrapper.WrapperLookup registryLookup) {
recordDay = tag.getInt("recordDay");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,38 @@
package net.anvian.record_days_survived.components;

import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.registry.RegistryWrapper;
import org.ladysnake.cca.api.v3.component.Component;

public class TicksPassedComponent implements Component {
private long tickPassed;
private final PlayerEntity player;
private long ticksPassed;

public TicksPassedComponent(PlayerEntity player) {
this.player = player;
this.ticksPassed = 1200;
}

@Override
public void readFromNbt(NbtCompound tag, RegistryWrapper.WrapperLookup registryLookup) {
tickPassed = tag.getLong("ticksPassed");
ticksPassed = tag.getLong("ticksPassed");
}

@Override
public void writeToNbt(NbtCompound tag, RegistryWrapper.WrapperLookup registryLookup) {
tag.putLong("ticksPassed", tickPassed);
tag.putLong("ticksPassed", ticksPassed);
}

public long getTicksPassed() {
return tickPassed;
return ticksPassed;
}

public void addTickPassed(long worldTime) {
tickPassed = worldTime;
ticksPassed = worldTime;
}

public void resetTickPassed(){
tickPassed = 1200;
public void resetTickPassed() {
ticksPassed = 1200;
}
}
10 changes: 5 additions & 5 deletions src/main/java/net/anvian/record_days_survived/util/DaysUtil.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.anvian.record_days_survived.util;

import net.anvian.record_days_survived.components.ModComponents;
import net.anvian.record_days_survived.RecordDaysSurvivedMod;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.entity.LivingEntity;
import net.minecraft.text.Text;
Expand All @@ -9,9 +9,9 @@ public class DaysUtil {
public static void dayPassed(LivingEntity entity) {
int days, recordDay;

var day = ModComponents.DAY.get(entity);
var record = ModComponents.RECORD_DAY.get(entity);
var tick = ModComponents.TICKS_PASSED.get(entity);
var day = entity.getComponent(RecordDaysSurvivedMod.DAY);
var record = entity.getComponent(RecordDaysSurvivedMod.RECORD_DAY);
var tick = entity.getComponent(RecordDaysSurvivedMod.TICKS_PASSED);

day.addDays(1);
tick.resetTickPassed();
Expand All @@ -24,7 +24,7 @@ var record = ModComponents.RECORD_DAY.get(entity);
}

if (days > recordDay) {
ModComponents.RECORD_DAY.get(entity).setRecordDay(days);
entity.getComponent(RecordDaysSurvivedMod.RECORD_DAY).setRecordDay(days);
}
}
}
4 changes: 2 additions & 2 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
"net.anvian.record_days_survived.RecordDaysSurvivedMod"
],
"cardinal_components-entity": [
"net.anvian.record_days_survived.components.ModComponents"
"net.anvian.record_days_survived.RecordDaysSurvivedMod"
]
},
"mixins": [
"record_days_survived.mixins.json"
],
"depends": {
"fabricloader": ">=0.15.11",
"minecraft": ">=1.20.5",
"minecraft": "~1.20.6",
"java": ">=21",
"fabric-api": "*"
},
Expand Down

0 comments on commit 1101a18

Please sign in to comment.