Skip to content

Commit

Permalink
background improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ToCraft committed May 16, 2024
1 parent d0077d5 commit e0efca7
Show file tree
Hide file tree
Showing 15 changed files with 103 additions and 101 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/push_build_and_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Set up JDK 17
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: 17
java-version: 21
distribution: 'temurin'
- name: Validate Gradle Wrapper
uses: gradle/actions/wrapper-validation@v3
Expand Down Expand Up @@ -63,10 +63,10 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Set up JDK 17
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: 17
java-version: 21
distribution: 'temurin'
- name: Validate Gradle Wrapper
uses: gradle/actions/wrapper-validation@v3
Expand Down
5 changes: 5 additions & 0 deletions common/src/main/java/tocraft/remorphed/Remorphed.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@
import org.slf4j.LoggerFactory;
import tocraft.craftedcore.config.ConfigLoader;
import tocraft.craftedcore.event.common.CommandEvents;
import tocraft.craftedcore.event.common.EntityEvents;
import tocraft.craftedcore.event.common.PlayerEvents;
import tocraft.craftedcore.network.ModernNetworking;
import tocraft.craftedcore.platform.PlatformData;
import tocraft.craftedcore.platform.VersionChecker;
import tocraft.remorphed.command.RemorphedCommand;
import tocraft.remorphed.config.RemorphedConfig;
import tocraft.remorphed.events.ShapeEventsCallback;
import tocraft.remorphed.handler.LivingDeathHandler;
import tocraft.remorphed.handler.PlayerRespawnHandler;
import tocraft.remorphed.impl.RemorphedPlayerDataProvider;
import tocraft.remorphed.network.NetworkHandler;
import tocraft.walkers.Walkers;
Expand Down Expand Up @@ -54,6 +57,8 @@ public void initialize() {
ShapeEvents.UNLOCK_SHAPE.register(((player, type) -> new ShapeEventsCallback().event(player, type)));
ShapeEvents.SWAP_SHAPE.register(((player, shape) -> new ShapeEventsCallback().event(player, ShapeType.from(shape))));
CommandEvents.REGISTRATION.register(new RemorphedCommand());
EntityEvents.LIVING_DEATH.register(new LivingDeathHandler());
PlayerEvents.PLAYER_RESPAWN.register(new PlayerRespawnHandler());

// allow unlocking friendly mobs via the "normal" method
Walkers.CONFIG.unlockOverridesCurrentShape = Remorphed.CONFIG.unlockFriendlyNormal;
Expand Down
4 changes: 4 additions & 0 deletions common/src/main/java/tocraft/remorphed/RemorphedClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import net.fabricmc.api.Environment;
import net.minecraft.client.KeyMapping;
import org.lwjgl.glfw.GLFW;
import tocraft.craftedcore.event.client.ClientPlayerEvents;
import tocraft.craftedcore.event.client.ClientTickEvents;
import tocraft.craftedcore.registration.KeyBindingRegistry;
import tocraft.remorphed.handler.client.ClientPlayerRespawnHandler;
import tocraft.remorphed.network.ClientNetworking;
import tocraft.remorphed.tick.KeyPressHandler;

Expand All @@ -21,5 +23,7 @@ public void initialize() {
// Register event handlers
ClientTickEvents.CLIENT_PRE.register(new KeyPressHandler());
ClientNetworking.registerPacketHandlers();

ClientPlayerEvents.CLIENT_PLAYER_RESPAWN.register(new ClientPlayerRespawnHandler());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.HashMap;
import java.util.Map;

@SuppressWarnings("CanBeFinal")
public class RemorphedConfig implements Config {
@Synchronize
public boolean creativeUnlockAll = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,22 @@
package tocraft.remorphed.mixin;
package tocraft.remorphed.handler;

import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import tocraft.craftedcore.event.common.EntityEvents;
import tocraft.remorphed.Remorphed;
import tocraft.remorphed.impl.RemorphedPlayerDataProvider;
import tocraft.walkers.api.PlayerShape;
import tocraft.walkers.api.PlayerShapeChanger;
import tocraft.walkers.api.variant.ShapeType;

@Mixin(LivingEntity.class)
public abstract class LivingEntityMixin extends Entity {

private LivingEntityMixin(EntityType<? extends LivingEntity> type, Level world) {
super(type, world);
}

@Inject(method = "die", at = @At("HEAD"))
public void onDeath(DamageSource damageSource, CallbackInfo ci) {
if (!((Object) this instanceof Player) && damageSource.getEntity() instanceof ServerPlayer killer) {
ShapeType<?> type = ShapeType.from((LivingEntity) (Object) this);
public class LivingDeathHandler implements EntityEvents.LivingDeath {
@Override
public InteractionResult die(LivingEntity entity, DamageSource source) {
if (!(entity instanceof Player) && source.getEntity() instanceof ServerPlayer killer) {
ShapeType<?> type = ShapeType.from(entity);
if (type != null) {
((RemorphedPlayerDataProvider) killer).remorphed$addKill(type);

Expand All @@ -37,5 +26,7 @@ public void onDeath(DamageSource damageSource, CallbackInfo ci) {
}
}
}

return InteractionResult.PASS;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package tocraft.remorphed.handler;

import net.minecraft.client.player.LocalPlayer;
import net.minecraft.server.level.ServerPlayer;
import tocraft.craftedcore.event.client.ClientPlayerEvents;
import tocraft.craftedcore.event.common.PlayerEvents;
import tocraft.remorphed.impl.RemorphedPlayerDataProvider;

public class PlayerRespawnHandler implements PlayerEvents.PlayerRespawn {
@Override
public void clone(ServerPlayer oldPlayer, ServerPlayer newPlayer) {
((RemorphedPlayerDataProvider) newPlayer).remorphed$setUnlockedShapes(((RemorphedPlayerDataProvider) oldPlayer).remorphed$getUnlockedShapes());
((RemorphedPlayerDataProvider) newPlayer).remorphed$getFavorites().clear();
((RemorphedPlayerDataProvider) newPlayer).remorphed$getFavorites().addAll(((RemorphedPlayerDataProvider) oldPlayer).remorphed$getFavorites());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package tocraft.remorphed.handler.client;

import net.minecraft.client.player.LocalPlayer;
import tocraft.craftedcore.event.client.ClientPlayerEvents;
import tocraft.remorphed.impl.RemorphedPlayerDataProvider;

public class ClientPlayerRespawnHandler implements ClientPlayerEvents.ClientPlayerRespawn {
@Override
public void respawn(LocalPlayer oldPlayer, LocalPlayer newPlayer) {
((RemorphedPlayerDataProvider) newPlayer).remorphed$setUnlockedShapes(((RemorphedPlayerDataProvider) oldPlayer).remorphed$getUnlockedShapes());
((RemorphedPlayerDataProvider) newPlayer).remorphed$getFavorites().clear();
((RemorphedPlayerDataProvider) newPlayer).remorphed$getFavorites().addAll(((RemorphedPlayerDataProvider) oldPlayer).remorphed$getFavorites());
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Map;
import java.util.Set;

@SuppressWarnings({"DataFlowIssue", "resource", "ControlFlowStatementWithoutBraces"})
@Mixin(Player.class)
public abstract class PlayerEntityMixin extends LivingEntity implements RemorphedPlayerDataProvider {
@Unique
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static <T extends LivingEntity> void sendSwap2ndShapeRequest(@NotNull Sha
ModernNetworking.sendToServer(NetworkHandler.SHAPE_REQUEST, compound);
}

@SuppressWarnings({"ALL"})
@SuppressWarnings({"DataFlowIssue", "unchecked"})
private static void handleShapeRequestPacket(ModernNetworking.Context context, CompoundTag compound) {
context.getPlayer().getServer().execute(() -> {
// check if player is blacklisted
Expand Down Expand Up @@ -88,7 +88,7 @@ public static void sendFavoriteRequest(ShapeType<? extends LivingEntity> type, b
ModernNetworking.sendToServer(FAVORITE_UPDATE, packet);
}

@SuppressWarnings("ALL")
@SuppressWarnings({"unchecked", "DataFlowIssue"})
private static void handleFavoriteRequestPacket(ModernNetworking.Context context, CompoundTag packet) {
EntityType<? extends LivingEntity> entityType = (EntityType<? extends LivingEntity>) BuiltInRegistries.ENTITY_TYPE.get(new ResourceLocation(packet.getString("id")));
int variant = packet.getInt("variant");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Collectors;

@SuppressWarnings({"DataFlowIssue", "SequencedCollectionMethodCanBeUsed"})
@Environment(EnvType.CLIENT)
public class RemorphedScreen extends Screen {
private final List<ShapeType<?>> unlocked = new CopyOnWriteArrayList<>();
Expand Down Expand Up @@ -210,7 +211,7 @@ private void populateEntityWidgets(List<ShapeType<?>> rendered) {
addRenderableWidget(entityWidget);
entityWidgets.add(entityWidget);
} else {
Remorphed.LOGGER.error("invalid shape type: " + type.getEntityType().getDescriptionId());
Remorphed.LOGGER.error("invalid shape type: {}", type.getEntityType().getDescriptionId());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void renderWidget(GuiGraphics context, int mouseX, int mouseY, float delt
// ARGH
InventoryScreen.renderEntityInInventory(context, getX() + (float) this.getWidth() / 2, (int) (getY() + this.getHeight() * .75f), size, new Vector3f(), new Quaternionf().rotationXYZ(0.43633232F, (float) Math.PI, (float) Math.PI), null, entity);
} catch (Exception e) {
Remorphed.LOGGER.error("Error while rendering " + ShapeType.createTooltipText(entity).getString(), e);
Remorphed.LOGGER.error("Error while rendering {}", ShapeType.createTooltipText(entity).getString(), e);
crashed = true;
MultiBufferSource.BufferSource immediate = Minecraft.getInstance().renderBuffers().bufferSource();
immediate.endBatch();
Expand Down
5 changes: 1 addition & 4 deletions common/src/main/resources/remorphed.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@
"package": "tocraft.remorphed.mixin",
"compatibilityLevel": "JAVA_17",
"mixins": [
"LivingEntityMixin",
"PlayerEntityMixin",
"PlayerListMixin",
"ServerEntityMixin",
"ServerPlayerEntityMixin"
"ServerEntityMixin"
],
"client": [
"ClientPlayerDataCacheMixin",
"accessor.ScreenAccessor"
],
"injectors": {
Expand Down
42 changes: 42 additions & 0 deletions neoforge/src/main/resources/META-INF/neoforge.mods.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
modLoader = "javafml"
loaderVersion = "[1,)"
issueTrackerURL = "https://github.com/ToCraft/Remorphed/issues"
displayURL = "https://github.com/ToCraft/Remorphed"
license = "MIT"

[[mixins]]
config = "remorphed.mixins.json"

[[mods]]
modId = "remorphed"
version = "${version}"
displayName = "ReMorphed"
authors = "To_Craft"
credits = "Original mod by Draylar"
description = '''
Transform like in the old-school morph mod!
'''
logoFile = "icon.png"

[[dependencies.remorphed]]
modId = "minecraft"
mandatory = true
versionRange = "[${minecraft_version},)"
ordering = "NONE"
side = "BOTH"

[[dependencies.remorphed]]
modId = "craftedcore"
mandatory = true
type = "required"
versionRange = "[${craftedcore_version},)"
ordering = "AFTER"
side = "BOTH"

[[dependencies.remorphed]]
modId = "walkers"
mandatory = true
type = "required"
versionRange = "[${woodwalkers_version},)"
ordering = "AFTER"
side = "BOTH"

0 comments on commit e0efca7

Please sign in to comment.