diff --git a/Common/build.gradle b/Common/build.gradle index 15d6372..2890640 100644 --- a/Common/build.gradle +++ b/Common/build.gradle @@ -1,58 +1,51 @@ plugins { - id 'idea' - id 'java' - id 'maven-publish' - id 'org.spongepowered.gradle.vanilla' version '0.2.1-SNAPSHOT' -} - - -base { - archivesName = "${mod_id}-common-${minecraft_version}" -} - -minecraft { - version(minecraft_version) - if(file("src/main/resources/${mod_id}.accesswidener").exists()){ - accessWideners(file("src/main/resources/${mod_id}.accesswidener")) - } + id 'multiloader-common' + id 'net.neoforged.moddev' } repositories { + maven { + name = "Shedaniel" + url "https://maven.shedaniel.me/" + } + maven { url 'https://jitpack.io' } } +neoForge { + neoFormVersion = neo_form_version + // Automatically enable AccessTransformers if the file exists + def at = file('src/main/resources/META-INF/accesstransformer.cfg') + if (at.exists()) { + accessTransformers.from(at.absolutePath) + } + parchment { + minecraftVersion = minecraft_version + mappingsVersion = parchment_version + } +} + dependencies { - compileOnly group:'org.spongepowered', name:'mixin', version:'0.8.5' - implementation group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.1' + compileOnly group: 'org.spongepowered', name: 'mixin', version: '0.8.5' + // fabric and neoforge both bundle mixinextras, so it is safe to use it in common implementation("io.github.llamalad7:mixinextras-common:${mixinextras_version}") annotationProcessor("io.github.llamalad7:mixinextras-common:${mixinextras_version}") compileOnly("me.shedaniel.cloth:cloth-config-neoforge:${cloth_config_version}") } -processResources { - - def buildProps = project.properties.clone() - - filesMatching(['pack.mcmeta']) { - - expand buildProps +configurations { + commonJava { + canBeResolved = false + canBeConsumed = true + } + commonResources { + canBeResolved = false + canBeConsumed = true } } -publishing { - publications { - mavenJava(MavenPublication) { - groupId project.group - artifactId base.archivesName .get() - version project.version - from components.java - } - } - - repositories { - maven { - url "file://" + System.getenv("local_maven") - } - } +artifacts { + commonJava sourceSets.main.java.sourceDirectories.singleFile + commonResources sourceSets.main.resources.sourceDirectories.singleFile } \ No newline at end of file diff --git a/Common/src/main/java/tschipp/carryon/client/render/CarriedObjectRender.java b/Common/src/main/java/tschipp/carryon/client/render/CarriedObjectRender.java index 037f789..5090b6e 100644 --- a/Common/src/main/java/tschipp/carryon/client/render/CarriedObjectRender.java +++ b/Common/src/main/java/tschipp/carryon/client/render/CarriedObjectRender.java @@ -63,10 +63,10 @@ public class CarriedObjectRender { private static final SequencedMap builders = new LinkedHashMap<>(Map.of( - RenderType.glint(), new ByteBufferBuilder(CarryOnRenderType.remap(RenderType.glint()).bufferSize()), - RenderType.armorEntityGlint(), new ByteBufferBuilder(CarryOnRenderType.remap(RenderType.armorEntityGlint()).bufferSize()), - RenderType.glintTranslucent(), new ByteBufferBuilder(CarryOnRenderType.remap(RenderType.glintTranslucent()).bufferSize()), - RenderType.entityGlint(), new ByteBufferBuilder(CarryOnRenderType.remap(RenderType.entityGlint()).bufferSize()) + RenderType.glint(), new ByteBufferBuilder(RenderType.glint().bufferSize()), + RenderType.armorEntityGlint(), new ByteBufferBuilder(RenderType.armorEntityGlint().bufferSize()), + RenderType.glintTranslucent(), new ByteBufferBuilder(RenderType.glintTranslucent().bufferSize()), + RenderType.entityGlint(), new ByteBufferBuilder(RenderType.entityGlint().bufferSize()) //RenderType.entityGlintDirect(), new ByteBufferBuilder(RenderType.entityGlintDirect().bufferSize()) )); @@ -112,7 +112,7 @@ public class CarriedObjectRender CarryOnData carry = CarryOnDataManager.getCarryData(player); ItemStackRenderState renderState = new ItemStackRenderState(); var layer = renderState.newLayer(); - layer.setRenderType(CarryOnRenderType.remap(RenderType.glint())); + layer.setRenderType(RenderType.glint()); if (Constants.CLIENT_CONFIG.facePlayer != CarryRenderHelper.isChest(state.getBlock())) { matrix.mulPose(Axis.YP.rotationDegrees(180)); @@ -157,7 +157,7 @@ public class CarriedObjectRender matrix.pushPose(); matrix.scale(0.8f, 0.8f, 0.8f); matrix.mulPose(Axis.YP.rotationDegrees(180)); - matrix.translate(0.0, -height - .1, width + 0.1); + matrix.translate(0.0, -height - .2, width * 1.3 + 0.1); manager.setRenderShadow(false); @@ -168,6 +168,9 @@ public class CarriedObjectRender CarryRenderHelper.performScriptTransformation(matrix, script); } + if(Constants.CLIENT_CONFIG.rotateEntitiesSideways) + matrix.mulPose(Axis.YP.rotationDegrees(90)); + if (entity instanceof LivingEntity) ((LivingEntity) entity).hurtTime = 0; @@ -240,7 +243,7 @@ public class CarriedObjectRender copy.mulPose(p.pose()); matrix.popPose(); - RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); + //RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); renderState.render(copy, buffer, light, OverlayTexture.NO_OVERLAY); @@ -259,7 +262,7 @@ public class CarriedObjectRender if (entity instanceof LivingEntity le) le.hurtTime = 0; - RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); + //RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); manager.render(entity, 0, 0, 0, 0f, matrix, buffer, light); matrix.popPose(); diff --git a/Common/src/main/java/tschipp/carryon/client/render/CarryOnRenderType.java b/Common/src/main/java/tschipp/carryon/client/render/CarryOnRenderType.java index 0919115..9e1739a 100644 --- a/Common/src/main/java/tschipp/carryon/client/render/CarryOnRenderType.java +++ b/Common/src/main/java/tschipp/carryon/client/render/CarryOnRenderType.java @@ -1,111 +1,111 @@ -package tschipp.carryon.client.render; - -import com.mojang.blaze3d.pipeline.BlendFunction; -import com.mojang.blaze3d.pipeline.RenderPipeline; -import com.mojang.blaze3d.pipeline.RenderTarget; -import com.mojang.blaze3d.platform.DepthTestFunction; -import com.mojang.blaze3d.vertex.MeshData; -import com.mojang.blaze3d.vertex.VertexFormat; -import net.minecraft.client.renderer.RenderType; -import org.jetbrains.annotations.NotNull; - -import java.util.IdentityHashMap; -import java.util.Map; - -//Credit: klikli for the idea and code for this wrapper -public class CarryOnRenderType extends RenderType { - - private static final Map remappedTypes = new IdentityHashMap<>(); - private final RenderPipeline pipeline; - private final RenderType original; - - private CarryOnRenderType(RenderType original, RenderPipeline pipeline) { - super(String.format("%s_carryon", original.toString()), original.bufferSize(), original.affectsCrumbling(), true, original::setupRenderState, original::clearRenderState); - this.pipeline = pipeline; - this.original = original; - } - - public static RenderType remap(RenderType in) { - return remappedTypes.computeIfAbsent(in, (type) -> { - - //modify the pipeline - var pipeline = toBuilder(in.getRenderPipeline()) - .withBlend(BlendFunction.TRANSLUCENT) - .withDepthTestFunction(DepthTestFunction.NO_DEPTH_TEST) - .withCull(false); - - return new CarryOnRenderType(type, pipeline.build()); - }); - } - - private static RenderPipeline.Builder toBuilder(RenderPipeline pipeline) { - RenderPipeline.Builder builder = RenderPipeline.builder(); - builder.withLocation(pipeline.getLocation()); - builder.withFragmentShader(pipeline.getFragmentShader()); - builder.withVertexShader(pipeline.getVertexShader()); - - if (!pipeline.getShaderDefines().isEmpty()) { - for (Map.Entry entry : pipeline.getShaderDefines().values().entrySet()) { - try { - int parsed = Integer.parseInt(entry.getValue()); - builder.withShaderDefine(entry.getKey(), parsed); - } catch (NumberFormatException e) { - float parsed = Float.parseFloat(entry.getValue()); - builder.withShaderDefine(entry.getKey(), parsed); - } - } - for (String flag : pipeline.getShaderDefines().flags()) { - builder.withShaderDefine(flag); - } - } - - if (!pipeline.getSamplers().isEmpty()) { - pipeline.getSamplers().forEach(builder::withSampler); - } - - if (!pipeline.getUniforms().isEmpty()) { - pipeline.getUniforms().forEach(u -> builder.withUniform(u.name(), u.type())); - } - - builder.withDepthTestFunction(pipeline.getDepthTestFunction()); - builder.withPolygonMode(pipeline.getPolygonMode()); - builder.withCull(pipeline.isCull()); - builder.withColorWrite(pipeline.isWriteColor(), pipeline.isWriteAlpha()); - builder.withDepthWrite(pipeline.isWriteDepth()); - builder.withColorLogic(pipeline.getColorLogic()); - - if (pipeline.getBlendFunction().isPresent()) - builder.withBlend(pipeline.getBlendFunction().get()); - else - builder.withoutBlend(); - builder.withVertexFormat(pipeline.getVertexFormat(), pipeline.getVertexFormatMode()); - builder.withDepthBias(pipeline.getDepthBiasScaleFactor(), pipeline.getDepthBiasConstant()); - - return builder; - } - - @Override - public void draw(@NotNull MeshData meshData) { - this.original.draw(meshData); - } - - @Override - public @NotNull RenderTarget getRenderTarget() { - return this.original.getRenderTarget(); - } - - @Override - public @NotNull RenderPipeline getRenderPipeline() { - return this.pipeline; //get our own modified pipeline - } - - @Override - public @NotNull VertexFormat format() { - return this.original.format(); - } - - @Override - public VertexFormat.@NotNull Mode mode() { - return this.original.mode(); - } -} +//package tschipp.carryon.client.render; +// +//import com.mojang.blaze3d.pipeline.BlendFunction; +//import com.mojang.blaze3d.pipeline.RenderPipeline; +//import com.mojang.blaze3d.pipeline.RenderTarget; +//import com.mojang.blaze3d.platform.DepthTestFunction; +//import com.mojang.blaze3d.vertex.MeshData; +//import com.mojang.blaze3d.vertex.VertexFormat; +//import net.minecraft.client.renderer.RenderType; +//import org.jetbrains.annotations.NotNull; +// +//import java.util.IdentityHashMap; +//import java.util.Map; +// +////Credit: klikli for the idea and code for this wrapper +//public class CarryOnRenderType extends RenderType { +// +// private static final Map remappedTypes = new IdentityHashMap<>(); +// private final RenderPipeline pipeline; +// private final RenderType original; +// +// private CarryOnRenderType(RenderType original, RenderPipeline pipeline) { +// super(String.format("%s_carryon", original.toString()), original.bufferSize(), original.affectsCrumbling(), true, original::setupRenderState, original::clearRenderState); +// this.pipeline = pipeline; +// this.original = original; +// } +// +// public static RenderType remap(RenderType in) { +// return remappedTypes.computeIfAbsent(in, (type) -> { +// +// //modify the pipeline +// var pipeline = toBuilder(in.getRenderPipeline()) +// .withBlend(BlendFunction.TRANSLUCENT) +// .withDepthTestFunction(DepthTestFunction.NO_DEPTH_TEST) +// .withCull(false); +// +// return new CarryOnRenderType(type, pipeline.build()); +// }); +// } +// +// private static RenderPipeline.Builder toBuilder(RenderPipeline pipeline) { +// RenderPipeline.Builder builder = RenderPipeline.builder(); +// builder.withLocation(pipeline.getLocation()); +// builder.withFragmentShader(pipeline.getFragmentShader()); +// builder.withVertexShader(pipeline.getVertexShader()); +// +// if (!pipeline.getShaderDefines().isEmpty()) { +// for (Map.Entry entry : pipeline.getShaderDefines().values().entrySet()) { +// try { +// int parsed = Integer.parseInt(entry.getValue()); +// builder.withShaderDefine(entry.getKey(), parsed); +// } catch (NumberFormatException e) { +// float parsed = Float.parseFloat(entry.getValue()); +// builder.withShaderDefine(entry.getKey(), parsed); +// } +// } +// for (String flag : pipeline.getShaderDefines().flags()) { +// builder.withShaderDefine(flag); +// } +// } +// +// if (!pipeline.getSamplers().isEmpty()) { +// pipeline.getSamplers().forEach(builder::withSampler); +// } +// +// if (!pipeline.getUniforms().isEmpty()) { +// pipeline.getUniforms().forEach(u -> builder.withUniform(u.name(), u.type())); +// } +// +// builder.withDepthTestFunction(pipeline.getDepthTestFunction()); +// builder.withPolygonMode(pipeline.getPolygonMode()); +// builder.withCull(pipeline.isCull()); +// builder.withColorWrite(pipeline.isWriteColor(), pipeline.isWriteAlpha()); +// builder.withDepthWrite(pipeline.isWriteDepth()); +// builder.withColorLogic(pipeline.getColorLogic()); +// +// if (pipeline.getBlendFunction().isPresent()) +// builder.withBlend(pipeline.getBlendFunction().get()); +// else +// builder.withoutBlend(); +// builder.withVertexFormat(pipeline.getVertexFormat(), pipeline.getVertexFormatMode()); +// builder.withDepthBias(pipeline.getDepthBiasScaleFactor(), pipeline.getDepthBiasConstant()); +// +// return builder; +// } +// +// @Override +// public void draw(@NotNull MeshData meshData) { +// this.original.draw(meshData); +// } +// +// @Override +// public @NotNull RenderTarget getRenderTarget() { +// return this.original.getRenderTarget(); +// } +// +// @Override +// public @NotNull RenderPipeline getRenderPipeline() { +// return this.pipeline; //get our own modified pipeline +// } +// +// @Override +// public @NotNull VertexFormat format() { +// return this.original.format(); +// } +// +// @Override +// public VertexFormat.@NotNull Mode mode() { +// return this.original.mode(); +// } +//} diff --git a/Common/src/main/java/tschipp/carryon/client/render/CarryRenderHelper.java b/Common/src/main/java/tschipp/carryon/client/render/CarryRenderHelper.java index 1e0c144..5a4893b 100644 --- a/Common/src/main/java/tschipp/carryon/client/render/CarryRenderHelper.java +++ b/Common/src/main/java/tschipp/carryon/client/render/CarryRenderHelper.java @@ -25,6 +25,7 @@ import com.mojang.math.Axis; import net.minecraft.client.Minecraft; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.util.Mth; +import net.minecraft.util.ProblemReporter; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntitySpawnReason; import net.minecraft.world.entity.LivingEntity; @@ -34,6 +35,8 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.storage.TagValueInput; +import net.minecraft.world.level.storage.ValueInput; import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.shapes.VoxelShape; import org.joml.Quaternionf; @@ -208,7 +211,7 @@ public class CarryRenderHelper matrix.mulPose(Axis.YP.rotationDegrees(180)); matrix.scale((10 - multiplier) * 0.08f, (10 - multiplier) * 0.08f, (10 - multiplier) * 0.08f); - matrix.translate(0.0, height / 2 + -(height / 2) + 1, width - 0.1 < 0.7 ? width - 0.1 + (0.7 - (width - 0.1)) : width - 0.1); + matrix.translate(0.0, height / 2 + -(height / 4) + 1, width - 0.1 < 0.7 ? width - 0.1 + (0.7 - (width - 0.1)) : width - 0.1); if (pose == Pose.SWIMMING || pose == Pose.FALL_FLYING) { @@ -219,6 +222,9 @@ public class CarryRenderHelper matrix.translate(0, 0, 0.2); } + if(Constants.CLIENT_CONFIG.rotateEntitiesSideways) + matrix.mulPose(Axis.YP.rotationDegrees(90)); + } @@ -365,8 +371,10 @@ public class CarryRenderHelper if(render.renderNameEntity().isPresent()) entity = BuiltInRegistries.ENTITY_TYPE.get(render.renderNameEntity().get()).get().value().create(player.level(), EntitySpawnReason.EVENT); - if(render.renderNBT().isPresent()) - entity.load(render.renderNBT().get()); + if(render.renderNBT().isPresent()) { + ValueInput input = TagValueInput.create(new ProblemReporter.ScopedCollector(Constants.LOG), player.registryAccess(), render.renderNBT().get()); + entity.load(input); + } } return entity; @@ -394,7 +402,10 @@ public class CarryRenderHelper else if(carry.isCarrying(CarryType.ENTITY)) { Entity entity = getRenderEntity(player); - return entity.getBbWidth(); + float w = entity.getBbWidth(); + if (Constants.CLIENT_CONFIG.rotateEntitiesSideways) + return w - (w*w) * 0.35f; + return w * 0.9f; } else return 1f; diff --git a/Common/src/main/java/tschipp/carryon/common/carry/CarryOnData.java b/Common/src/main/java/tschipp/carryon/common/carry/CarryOnData.java index 7c07eec..78016c6 100644 --- a/Common/src/main/java/tschipp/carryon/common/carry/CarryOnData.java +++ b/Common/src/main/java/tschipp/carryon/common/carry/CarryOnData.java @@ -20,7 +20,9 @@ package tschipp.carryon.common.carry; +import com.mojang.serialization.Codec; import com.mojang.serialization.DataResult; +import com.mojang.serialization.MapCodec; import net.minecraft.core.BlockPos; import net.minecraft.core.HolderLookup; import net.minecraft.core.registries.BuiltInRegistries; @@ -29,6 +31,7 @@ import net.minecraft.nbt.NbtOps; import net.minecraft.nbt.NbtUtils; import net.minecraft.nbt.Tag; import net.minecraft.server.level.ServerPlayer; +import net.minecraft.util.ProblemReporter; import net.minecraft.world.entity.AreaEffectCloud; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntitySpawnReason; @@ -37,6 +40,9 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.properties.BlockStateProperties; +import net.minecraft.world.level.storage.TagValueInput; +import net.minecraft.world.level.storage.TagValueOutput; +import net.minecraft.world.level.storage.ValueInput; import tschipp.carryon.Constants; import tschipp.carryon.common.scripting.CarryOnScript; @@ -50,6 +56,24 @@ public class CarryOnData { private boolean keyPressed = false; private CarryOnScript activeScript; private int selectedSlot = 0; + private static final ProblemReporter problemReporter = new ProblemReporter.ScopedCollector(Constants.LOG); + + public static final Codec CODEC = CompoundTag.CODEC.flatXmap( + tag -> { + try { + return DataResult.success(new CarryOnData(tag)); + } catch (Exception e) { + return DataResult.error(e::getMessage); + } + }, + carry -> { + try { + return DataResult.success(carry.getNbt()); + } catch (Exception e) { + return DataResult.error(e::getMessage); + } + } + ); public CarryOnData(CompoundTag data) { @@ -107,7 +131,9 @@ public class CarryOnData { if(tile != null) { - CompoundTag tileData = tile.saveWithId(tile.getLevel().registryAccess()); + TagValueOutput output = TagValueOutput.createWithContext(problemReporter, player.registryAccess()); + tile.saveWithId(output); + Tag tileData = output.buildResult(); nbt.put("tile", tileData); } } @@ -135,8 +161,9 @@ public class CarryOnData { public void setEntity(Entity entity) { this.type = CarryType.ENTITY; - CompoundTag entityData = new CompoundTag(); - entity.save(entityData); + TagValueOutput output = TagValueOutput.createWithContext(new ProblemReporter.ScopedCollector(Constants.LOG), entity.registryAccess()); + entity.save(output); + Tag entityData = output.buildResult(); nbt.put("entity", entityData); } @@ -145,7 +172,8 @@ public class CarryOnData { if(this.type != CarryType.ENTITY) throw new IllegalStateException("Called getEntity on data that contained " + this.type); - var optionalEntity = EntityType.create(nbt.getCompoundOrEmpty("entity"), level, EntitySpawnReason.BUCKET); + ValueInput in = TagValueInput.create(problemReporter, level.registryAccess(), nbt.getCompoundOrEmpty("entity")); + var optionalEntity = EntityType.create(in, level, EntitySpawnReason.BUCKET); if(optionalEntity.isPresent()) return optionalEntity.get(); diff --git a/Common/src/main/java/tschipp/carryon/common/carry/PickupHandler.java b/Common/src/main/java/tschipp/carryon/common/carry/PickupHandler.java index 18f630a..6a6773d 100644 --- a/Common/src/main/java/tschipp/carryon/common/carry/PickupHandler.java +++ b/Common/src/main/java/tschipp/carryon/common/carry/PickupHandler.java @@ -25,6 +25,7 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.server.level.ServerPlayer; import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundSource; +import net.minecraft.util.ProblemReporter; import net.minecraft.world.InteractionHand; import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.effect.MobEffects; @@ -39,6 +40,7 @@ import net.minecraft.world.level.GameType; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.storage.TagValueOutput; import net.minecraft.world.phys.Vec3; import tschipp.carryon.CarryOnCommon; import tschipp.carryon.Constants; @@ -96,8 +98,11 @@ public class PickupHandler { BlockEntity blockEntity = level.getBlockEntity(pos); BlockState state = level.getBlockState(pos); CompoundTag nbt = null; - if(blockEntity != null) - nbt = blockEntity.saveWithId(level.registryAccess()); + if(blockEntity != null) { + TagValueOutput output = TagValueOutput.createWithContext(new ProblemReporter.ScopedCollector(Constants.LOG), level.registryAccess()); + blockEntity.saveWithId(output); + nbt = output.buildResult(); + } if(!ListHandler.isPermitted(state.getBlock())) return false; @@ -231,7 +236,7 @@ public class PickupHandler { } otherPlayer.startRiding(player, true); - Services.PLATFORM.sendPacketToAllPlayers(Constants.PACKET_ID_START_RIDING_OTHER, new ClientboundStartRidingOtherPlayerPacket(player.getId(), otherPlayer.getId(), true), player.serverLevel()); + Services.PLATFORM.sendPacketToAllPlayers(Constants.PACKET_ID_START_RIDING_OTHER, new ClientboundStartRidingOtherPlayerPacket(player.getId(), otherPlayer.getId(), true), player.level()); carry.setCarryingPlayer(); player.swing(InteractionHand.MAIN_HAND, true); player.level().playSound(null, player.getOnPos(), SoundEvents.ARMOR_EQUIP_GENERIC.value(), SoundSource.AMBIENT, 1.0f, 0.5f); diff --git a/Common/src/main/java/tschipp/carryon/common/carry/PlacementHandler.java b/Common/src/main/java/tschipp/carryon/common/carry/PlacementHandler.java index 128e795..e871dcf 100644 --- a/Common/src/main/java/tschipp/carryon/common/carry/PlacementHandler.java +++ b/Common/src/main/java/tschipp/carryon/common/carry/PlacementHandler.java @@ -179,7 +179,7 @@ public class PlacementHandler if (carry.isCarrying(CarryType.PLAYER)) { Entity otherPlayer = player.getFirstPassenger(); player.ejectPassengers(); - Services.PLATFORM.sendPacketToAllPlayers(Constants.PACKET_ID_START_RIDING_OTHER, new ClientboundStartRidingOtherPlayerPacket(player.getId(), otherPlayer.getId(), false), player.serverLevel()); + Services.PLATFORM.sendPacketToAllPlayers(Constants.PACKET_ID_START_RIDING_OTHER, new ClientboundStartRidingOtherPlayerPacket(player.getId(), otherPlayer.getId(), false), player.level()); carry.clear(); CarryOnDataManager.setCarryData(player, carry); otherPlayer.teleportTo(placementPos.x, placementPos.y, placementPos.z); diff --git a/Common/src/main/java/tschipp/carryon/common/config/CarryConfig.java b/Common/src/main/java/tschipp/carryon/common/config/CarryConfig.java index 942bd4c..6532f2b 100644 --- a/Common/src/main/java/tschipp/carryon/common/config/CarryConfig.java +++ b/Common/src/main/java/tschipp/carryon/common/config/CarryConfig.java @@ -351,6 +351,12 @@ public class CarryConfig ) public boolean facePlayer = false; + @Property( + type = PropertyType.BOOLEAN, + description = "If Entities should be rotated sideways when carried" + ) + public boolean rotateEntitiesSideways = false; + @Property( type = PropertyType.BOOLEAN, description = "Arms should render on sides when carrying. Set to false if you experience issues with mods that replace the player model (like MoBends, etc)" diff --git a/Common/src/main/java/tschipp/carryon/common/scripting/Matchables.java b/Common/src/main/java/tschipp/carryon/common/scripting/Matchables.java index 6bcfb97..db8a4ab 100644 --- a/Common/src/main/java/tschipp/carryon/common/scripting/Matchables.java +++ b/Common/src/main/java/tschipp/carryon/common/scripting/Matchables.java @@ -127,7 +127,7 @@ public final class Matchables @Override public boolean matches(ServerPlayer player) { - ServerAdvancementManager manager = player.server.getAdvancements(); + ServerAdvancementManager manager = player.getServer().getAdvancements(); AdvancementHolder adv = manager.get(ResourceLocation.parse(advancement.isEmpty() ? "" : advancement)); boolean achievement = adv == null ? true : player.getAdvancements().getOrStartProgress(adv).isDone(); diff --git a/Common/src/main/java/tschipp/carryon/common/scripting/ScriptManager.java b/Common/src/main/java/tschipp/carryon/common/scripting/ScriptManager.java index 5cd67a9..9e8687e 100644 --- a/Common/src/main/java/tschipp/carryon/common/scripting/ScriptManager.java +++ b/Common/src/main/java/tschipp/carryon/common/scripting/ScriptManager.java @@ -23,11 +23,14 @@ package tschipp.carryon.common.scripting; import net.minecraft.core.BlockPos; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.Tag; +import net.minecraft.util.ProblemReporter; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.storage.TagValueOutput; import tschipp.carryon.Constants; import tschipp.carryon.common.scripting.CarryOnScript.ScriptObject.ScriptObjectBlock; import tschipp.carryon.common.scripting.CarryOnScript.ScriptObject.ScriptObjectEntity; @@ -67,8 +70,9 @@ public class ScriptManager float height = entity.getBbHeight(); float width = entity.getBbWidth(); float health = entity instanceof LivingEntity ? ((LivingEntity) entity).getHealth() : 0.0f; - CompoundTag tag = new CompoundTag(); - entity.save(tag); + TagValueOutput output = TagValueOutput.createWithContext(new ProblemReporter.ScopedCollector(Constants.LOG), entity.registryAccess()); + entity.save(output); + CompoundTag tag = output.buildResult(); for (CarryOnScript script : SCRIPTS) { diff --git a/Common/src/main/java/tschipp/carryon/mixin/PlayerMixin.java b/Common/src/main/java/tschipp/carryon/mixin/PlayerMixin.java index 5a9f7ae..738f9c9 100644 --- a/Common/src/main/java/tschipp/carryon/mixin/PlayerMixin.java +++ b/Common/src/main/java/tschipp/carryon/mixin/PlayerMixin.java @@ -30,6 +30,8 @@ import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.Level; +import net.minecraft.world.level.storage.ValueInput; +import net.minecraft.world.level.storage.ValueOutput; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; @@ -39,6 +41,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import tschipp.carryon.common.carry.CarryOnData; import tschipp.carryon.common.carry.CarryOnDataManager; +import java.util.Optional; + @Mixin(Player.class) public abstract class PlayerMixin extends LivingEntity implements CarryOnDataManager.ICarrying { @@ -76,20 +80,18 @@ public abstract class PlayerMixin extends LivingEntity implements CarryOnDataMan } - @Inject(method = "addAdditionalSaveData(Lnet/minecraft/nbt/CompoundTag;)V", at = @At("RETURN")) - private void onAddAdditionalSaveData(CompoundTag tag, CallbackInfo info) + @Inject(method = "addAdditionalSaveData(Lnet/minecraft/world/level/storage/ValueOutput;)V", at = @At("RETURN")) + private void onAddAdditionalSaveData(ValueOutput output, CallbackInfo ci) { CarryOnData carry = CarryOnDataManager.getCarryData((Player)(Object)this); - tag.put("CarryOnData", carry.getNbt()); + output.store("CarryOnData", CarryOnData.CODEC, carry); } - @Inject(method = "readAdditionalSaveData(Lnet/minecraft/nbt/CompoundTag;)V", at = @At("RETURN")) - private void onReadAdditionalSaveData(CompoundTag tag, CallbackInfo info) + @Inject(method = "readAdditionalSaveData(Lnet/minecraft/world/level/storage/ValueInput;)V", at = @At("RETURN")) + private void onReadAdditionalSaveData(ValueInput input, CallbackInfo ci) { - if (tag.contains("CarryOnData")) { - CarryOnData data = new CarryOnData(tag.getCompoundOrEmpty("CarryOnData")); - setCarryOnData(data); - } + Optional res = input.read("CarryOnData", CarryOnData.CODEC); + res.ifPresent(this::setCarryOnData); } } diff --git a/Common/src/main/resources/carryon.mixins.json b/Common/src/main/resources/carryon.mixins.json index ded44ef..820444e 100644 --- a/Common/src/main/resources/carryon.mixins.json +++ b/Common/src/main/resources/carryon.mixins.json @@ -20,5 +20,5 @@ "injectors": { "defaultRequire": 1 }, - "refmap": "${refmap_target}refmap.json" + "refmap": "${mod_id}.refmap.json" } \ No newline at end of file diff --git a/Fabric/build.gradle b/Fabric/build.gradle index 121076c..ed15c5b 100644 --- a/Fabric/build.gradle +++ b/Fabric/build.gradle @@ -1,35 +1,24 @@ plugins { - id 'java' - id 'maven-publish' - id 'idea' + id 'multiloader-loader' id 'fabric-loom' version '1.10-SNAPSHOT' } -base { - archivesName = "${mod_id}-fabric-${minecraft_version}" -} - -/* -apply from: 'https://raw.githubusercontent.com/MinecraftModDevelopment/Gradle-Collection/22e7d543a18cd30675277fbfa3669e3d9e206010/generic/secrets.gradle' - -if (project.hasProperty('secretFile')) { - loadSecrets(new File((String) findProperty('secretFile'))) -} -*/ - -if (System.getenv('BUILD_NUMBER') != null) { - version += "." + System.getenv('BUILD_NUMBER') -} repositories { maven { - url "https://maven.siphalor.de/" - name "Siphalor's Maven" + name = "Shedaniel" + url "https://maven.shedaniel.me/" } - maven { url "https://maven.terraformersmc.com/releases/" } + maven { url 'https://jitpack.io' } + + maven { + name = "Terraformers" + url = "https://maven.terraformersmc.com/" + } } + dependencies { minecraft "com.mojang:minecraft:${minecraft_version}" mappings loom.layered() { @@ -39,19 +28,17 @@ dependencies { modImplementation "net.fabricmc:fabric-loader:${fabric_loader_version}" modImplementation "net.fabricmc.fabric-api:fabric-api:${fabric_version}" implementation group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.1' - implementation project(":Common") - - //modRuntimeOnly "de.siphalor:amecsapi-1.20:1.5.6+mc1.20.2" modApi("me.shedaniel.cloth:cloth-config-fabric:${cloth_config_version}") { exclude(group: "net.fabricmc.fabric-api") } - modApi "com.terraformersmc:modmenu:13.0.0-beta.1" + modApi "com.terraformersmc:modmenu:15.0.0-beta.3" } loom { - if (project(":Common").file("src/main/resources/${mod_id}.accesswidener").exists()) { - accessWidenerPath.set(project(":Common").file("src/main/resources/${mod_id}.accesswidener")) + def aw = project(':Common').file("src/main/resources/${mod_id}.accesswidener") + if (aw.exists()) { + accessWidenerPath.set(aw) } mixin { defaultRefmapName.set("${mod_id}.refmap.json") @@ -71,31 +58,3 @@ loom { } } } - -tasks.withType(JavaCompile).configureEach { - source(project(":Common").sourceSets.main.allSource) -} -tasks.withType(Javadoc).configureEach { - source(project(":Common").sourceSets.main.allJava) -} -tasks.named("sourcesJar", Jar) { - from(project(":Common").sourceSets.main.allSource) -} - -processResources { - from project(":Common").sourceSets.main.resources -} - -publishing { - publications { - mavenJava(MavenPublication) { - artifactId base.archivesName.get() - from components.java - } - } - repositories { - maven { - url "file://" + System.getenv("local_maven") - } - } -} diff --git a/Forge/build.gradle b/Forge/build.gradle index a5b5d21..d256613 100644 --- a/Forge/build.gradle +++ b/Forge/build.gradle @@ -1,26 +1,10 @@ plugins { - id 'idea' - id 'java' - id 'maven-publish' + id 'multiloader-loader' id 'net.minecraftforge.gradle' version '[6.0.36,6.2)' id 'org.spongepowered.mixin' version '0.7-SNAPSHOT' id 'org.parchmentmc.librarian.forgegradle' version '1.+' } -/* -apply from: 'https://raw.githubusercontent.com/MinecraftModDevelopment/Gradle-Collection/22e7d543a18cd30675277fbfa3669e3d9e206010/generic/secrets.gradle' - -if (project.hasProperty('secretFile')) { - loadSecrets(new File((String) findProperty('secretFile'))) -} - - */ -if (System.getenv('BUILD_NUMBER') != null) { - version += "." + System.getenv('BUILD_NUMBER') -} - - - base { archivesName = "${mod_id}-forge-${minecraft_version}" } @@ -32,6 +16,14 @@ mixin { config "${mod_id}.forge.mixins.json" } +tasks.named('jar', Jar).configure { + manifest { + attributes([ + "MixinConfigs" : "${mod_id}.mixins.json,${mod_id}.forge.mixins.json" + ]) + } +} + jarJar.enable() build.dependsOn tasks.jarJar @@ -40,8 +32,9 @@ minecraft { copyIdeResources = true reobf = false - if (file('src/main/resources/META-INF/accesstransformer.cfg').exists()) { - accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') + def at = file('src/main/resources/META-INF/accesstransformer.cfg') + if (at.exists()) { + accessTransformer = at } runs { @@ -51,6 +44,7 @@ minecraft { taskName 'Client' property 'mixin.env.remapRefMap', 'true' property 'mixin.env.refMapRemappingFile', "${projectDir}/build/createSrgToMcp/output.srg" + property 'eventbus.api.strictRuntimeChecks', 'true' args "-mixin.config=${mod_id}.mixins.json", "-mixin.config=${mod_id}.forge.mixins.json" mods { modClientRun { @@ -66,6 +60,7 @@ minecraft { taskName 'Server' property 'mixin.env.remapRefMap', 'true' property 'mixin.env.refMapRemappingFile', "${projectDir}/build/createSrgToMcp/output.srg" + property 'eventbus.api.strictRuntimeChecks', 'true' args "-mixin.config=${mod_id}.mixins.json", "-mixin.config=${mod_id}.forge.mixins.json" mods { modServerRun { @@ -82,6 +77,7 @@ minecraft { taskName 'Data' property 'mixin.env.remapRefMap', 'true' property 'mixin.env.refMapRemappingFile', "${projectDir}/build/createSrgToMcp/output.srg" + property 'eventbus.api.strictRuntimeChecks', 'true' args "-mixin.config=${mod_id}.mixins.json", "-mixin.config=${mod_id}.forge.mixins.json" mods { modDataRun { @@ -96,17 +92,25 @@ minecraft { sourceSets.main.resources.srcDir 'src/generated/resources' repositories { + maven { + name = "Shedaniel" + url "https://maven.shedaniel.me/" + } + + maven { url 'https://jitpack.io' } + flatDir { dirs 'libs' } - maven { url 'https://jitpack.io' } } + dependencies { minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}" compileOnly project(":Common") annotationProcessor 'org.spongepowered:mixin:0.8.5-SNAPSHOT:processor' + annotationProcessor 'net.minecraftforge:eventbus-validator:7.0-beta.7' // 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' } } @@ -117,7 +121,7 @@ dependencies { //implementation fg.deobf("net.darkhax.gamestages:GameStages-Forge-1.19.2:11.0.2") - implementation(fg.deobf("me.shedaniel.cloth:cloth-config-forge:${cloth_config_version}")) + compileOnly(fg.deobf("me.shedaniel.cloth:cloth-config-neoforge:${cloth_config_version}")) fileTree("libs").matching { include "*.jar" @@ -132,47 +136,14 @@ dependencies { } -tasks.withType(JavaCompile).configureEach { - source(project(":Common").sourceSets.main.allSource) -} -tasks.withType(Javadoc).configureEach { - source(project(":Common").sourceSets.main.allJava) -} -tasks.named("sourcesJar", Jar) { - from(project(":Common").sourceSets.main.allSource) -} - -processResources { - from project(":Common").sourceSets.main.resources -} - -tasks.named('jar', Jar).configure { - manifest { - attributes([ - "MixinConfigs" : "${mod_id}.mixins.json,${mod_id}.forge.mixins.json" - ]) - } -} - publishing { publications { mavenJava(MavenPublication) { - artifactId base.archivesName.get() - from components.java fg.component(it) } } - repositories { - maven { - url "file://" + System.getenv("local_maven") - } - } } -// 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 diff --git a/Forge/src/main/java/tschipp/carryon/CarryOnForge.java b/Forge/src/main/java/tschipp/carryon/CarryOnForge.java index a80feeb..546ab7d 100644 --- a/Forge/src/main/java/tschipp/carryon/CarryOnForge.java +++ b/Forge/src/main/java/tschipp/carryon/CarryOnForge.java @@ -21,6 +21,7 @@ package tschipp.carryon; import net.minecraft.resources.ResourceLocation; +import net.minecraftforge.eventbus.api.listener.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventBusSubscriber; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; @@ -43,12 +44,11 @@ public class CarryOnForge { // Use Forge to bootstrap the Common mod. CarryOnCommon.registerConfig(); - context.getModEventBus().addListener(this::setup); - ConfigLoaderImpl.initialize(context); } - private void setup(final FMLCommonSetupEvent event) + @SubscribeEvent + public static void setup(final FMLCommonSetupEvent event) { network = ChannelBuilder.named(ResourceLocation.fromNamespaceAndPath(Constants.MOD_ID, "carryonpackets")).simpleChannel(); diff --git a/Forge/src/main/java/tschipp/carryon/compat/ClothConfigCompatForge.java b/Forge/src/main/java/tschipp/carryon/compat/ClothConfigCompatForge.java index 5ab8ea3..516b364 100644 --- a/Forge/src/main/java/tschipp/carryon/compat/ClothConfigCompatForge.java +++ b/Forge/src/main/java/tschipp/carryon/compat/ClothConfigCompatForge.java @@ -6,11 +6,11 @@ import tschipp.carryon.config.forge.ConfigLoaderImpl; public class ClothConfigCompatForge { - public static Screen createScreen(BuiltConfig client, BuiltConfig common, Screen screen) { - - return ClothConfigCompat.getConfigScreen(client, common, screen, () -> { - ConfigLoaderImpl.saveConfig(client); ConfigLoaderImpl.saveConfig(common);}); - } +// public static Screen createScreen(BuiltConfig client, BuiltConfig common, Screen screen) { +// +// return ClothConfigCompat.getConfigScreen(client, common, screen, () -> { +// ConfigLoaderImpl.saveConfig(client); ConfigLoaderImpl.saveConfig(common);}); +// } } diff --git a/Forge/src/main/java/tschipp/carryon/config/forge/ConfigLoaderImpl.java b/Forge/src/main/java/tschipp/carryon/config/forge/ConfigLoaderImpl.java index 6bdf19c..39bda58 100644 --- a/Forge/src/main/java/tschipp/carryon/config/forge/ConfigLoaderImpl.java +++ b/Forge/src/main/java/tschipp/carryon/config/forge/ConfigLoaderImpl.java @@ -27,29 +27,27 @@ import net.minecraft.server.MinecraftServer; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.common.ForgeConfigSpec; import net.minecraftforge.common.util.LogicalSidedProvider; -import net.minecraftforge.eventbus.api.IEventBus; -import net.minecraftforge.fml.DistExecutor; +import net.minecraftforge.eventbus.api.listener.SubscribeEvent; import net.minecraftforge.fml.LogicalSide; import net.minecraftforge.fml.ModLoadingContext; +import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.config.IConfigSpec; import net.minecraftforge.fml.config.ModConfig; import net.minecraftforge.fml.event.config.ModConfigEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import net.minecraftforge.fml.loading.FMLServiceProvider; import net.minecraftforge.server.ServerLifecycleHooks; +import tschipp.carryon.Constants; import tschipp.carryon.config.*; import java.util.*; +@Mod.EventBusSubscriber(modid = Constants.MOD_ID) public class ConfigLoaderImpl { public static final Map CONFIGS = new HashMap<>(); public static void initialize(FMLJavaModLoadingContext context) { - IEventBus bus = context.getModEventBus(); - bus.addListener(ConfigLoaderImpl::onConfigLoad); - bus.addListener(ConfigLoaderImpl::onConfigReload); - ConfigLoaderImpl.CONFIGS.forEach((spec, config) -> { if(config.fileName.contains("client")) context.registerConfig(ModConfig.Type.CLIENT, spec, config.fileName+".toml"); @@ -58,10 +56,12 @@ public class ConfigLoaderImpl { }); } + @SubscribeEvent public static void onConfigLoad(ModConfigEvent.Loading loading) { loadConfig(loading.getConfig().getSpec()); } + @SubscribeEvent public static void onConfigReload(ModConfigEvent.Reloading loading) { loadConfig(loading.getConfig().getSpec()); } diff --git a/Forge/src/main/java/tschipp/carryon/events/ClientEvents.java b/Forge/src/main/java/tschipp/carryon/events/ClientEvents.java index 3cd9860..4e557af 100644 --- a/Forge/src/main/java/tschipp/carryon/events/ClientEvents.java +++ b/Forge/src/main/java/tschipp/carryon/events/ClientEvents.java @@ -31,7 +31,7 @@ import net.minecraftforge.client.event.RenderHandEvent; import net.minecraftforge.client.event.ScreenEvent; import net.minecraftforge.event.TickEvent.ClientTickEvent; import net.minecraftforge.event.TickEvent.Phase; -import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.eventbus.api.listener.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import tschipp.carryon.CarryOnCommonClient; import tschipp.carryon.Constants; @@ -44,7 +44,7 @@ import tschipp.carryon.common.carry.CarryOnDataManager; public class ClientEvents { @SubscribeEvent - public static void renderHand(RenderHandEvent event) + public static boolean renderHand(RenderHandEvent event) { Player player = Minecraft.getInstance().player; MultiBufferSource buffer = event.getMultiBufferSource(); @@ -52,9 +52,9 @@ public class ClientEvents { int light = event.getPackedLight(); float partialTicks = event.getPartialTick(); - if(CarriedObjectRender.drawFirstPerson(player, buffer, matrix, light, partialTicks) && CarryRenderHelper.getPerspective() == 0) - event.setCanceled(true); - } + //If true, cancels event + return CarriedObjectRender.drawFirstPerson(player, buffer, matrix, light, partialTicks) && CarryRenderHelper.getPerspective() == 0; + } /* @SubscribeEvent @@ -66,27 +66,25 @@ public class ClientEvents { */ @SubscribeEvent - public static void onGuiInit(ScreenEvent.Init.Pre event) + public static boolean onGuiInit(ScreenEvent.Init.Pre event) { - if (event.getScreen() != null) - { - boolean inventory = event.getScreen() instanceof AbstractContainerScreen; - Minecraft mc = Minecraft.getInstance(); - Player player = mc.player; + boolean inventory = event.getScreen() instanceof AbstractContainerScreen; + Minecraft mc = Minecraft.getInstance(); + Player player = mc.player; - if (player != null && inventory) - { - CarryOnData carry = CarryOnDataManager.getCarryData(player); - if (carry.isCarrying()) - { - mc.player.closeContainer(); - mc.screen = null; - mc.mouseHandler.grabMouse(); - event.setCanceled(true); - } - } - } - } + if (player != null && inventory) + { + CarryOnData carry = CarryOnDataManager.getCarryData(player); + if (carry.isCarrying()) + { + mc.player.closeContainer(); + mc.screen = null; + mc.mouseHandler.grabMouse(); + return true; + } + } + return false; + } @SubscribeEvent public static void onClientTick(ClientTickEvent.Post event) diff --git a/Forge/src/main/java/tschipp/carryon/events/CommonEvents.java b/Forge/src/main/java/tschipp/carryon/events/CommonEvents.java index 771cb61..2e3352f 100644 --- a/Forge/src/main/java/tschipp/carryon/events/CommonEvents.java +++ b/Forge/src/main/java/tschipp/carryon/events/CommonEvents.java @@ -31,6 +31,7 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.ServerLevelAccessor; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.util.BlockSnapshot; +import net.minecraftforge.common.util.Result; import net.minecraftforge.event.AddReloadListenerEvent; import net.minecraftforge.event.OnDatapackSyncEvent; import net.minecraftforge.event.RegisterCommandsEvent; @@ -47,11 +48,10 @@ import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.event.level.BlockEvent; import net.minecraftforge.event.level.BlockEvent.BreakEvent; import net.minecraftforge.event.level.BlockEvent.EntityPlaceEvent; -import net.minecraftforge.eventbus.api.Event; -import net.minecraftforge.eventbus.api.Event.Result; -import net.minecraftforge.eventbus.api.EventPriority; -import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.eventbus.api.listener.Priority; +import net.minecraftforge.eventbus.api.listener.SubscribeEvent; import net.minecraftforge.fml.common.Mod; +import oshi.jna.platform.mac.SystemB; import tschipp.carryon.CarryOnCommon; import tschipp.carryon.Constants; import tschipp.carryon.common.carry.CarryOnData; @@ -65,27 +65,23 @@ import tschipp.carryon.config.ConfigLoader; @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE, modid = Constants.MOD_ID) public class CommonEvents { - @SubscribeEvent(priority = EventPriority.HIGH) - public static void onBlockClick(PlayerInteractEvent.RightClickBlock event) + @SubscribeEvent(priority = Priority.HIGH) + public static boolean onBlockClick(PlayerInteractEvent.RightClickBlock event) { - if (event.isCanceled()) - return; - Player player = event.getEntity(); Level level = event.getLevel(); BlockPos pos = event.getPos(); if (level.isClientSide) - return; + return false; boolean success = false; CarryOnData carry = CarryOnDataManager.getCarryData(player); if (!carry.isCarrying()) { if (PickupHandler.tryPickUpBlock((ServerPlayer) player, pos, level, (pState, pPos) -> { - BlockEvent.BreakEvent breakEvent = new BreakEvent(level, pPos, pState, player); - MinecraftForge.EVENT_BUS.post(breakEvent); - return !breakEvent.isCanceled(); + BlockEvent.BreakEvent breakEvent = new BreakEvent(level, pPos, pState, player, Result.DEFAULT); + return !BreakEvent.BUS.post(breakEvent); })) { success = true; } @@ -94,15 +90,13 @@ public class CommonEvents PlacementHandler.tryPlaceBlock((ServerPlayer) player, pos, event.getFace(), (pos2, state) -> { BlockSnapshot snapshot = BlockSnapshot.create(level.dimension(), level, pos2); EntityPlaceEvent event1 = new EntityPlaceEvent(snapshot, level.getBlockState(pos), player); - MinecraftForge.EVENT_BUS.post(event1); - return !event1.isCanceled(); + return !EntityPlaceEvent.BUS.post(event1); }); } else { PlacementHandler.tryPlaceEntity((ServerPlayer) player, pos, event.getFace(), (pPos, toPlace) -> { if (toPlace instanceof Mob mob) { FinalizeSpawn checkSpawn = new FinalizeSpawn(mob, (ServerLevelAccessor) level, pPos.x, pPos.y, pPos.z, level.getCurrentDifficultyAt(new BlockPos((int) pPos.x, (int) pPos.y, (int) pPos.z)), EntitySpawnReason.EVENT, null, null, null); - MinecraftForge.EVENT_BUS.post(checkSpawn); - return event.getResult() != Result.DENY; + return !FinalizeSpawn.BUS.post(checkSpawn); } return true; }); @@ -111,40 +105,38 @@ public class CommonEvents } if (success) { - event.setUseBlock(Event.Result.DENY); - event.setUseItem(Event.Result.DENY); + event.setUseBlock(Result.DENY); + event.setUseItem(Result.DENY); event.setCancellationResult(InteractionResult.SUCCESS); - event.setCanceled(true); + return true; } + return false; } - @SubscribeEvent(priority = EventPriority.HIGH) - public static void onEntityRightClick(PlayerInteractEvent.EntityInteract event) + @SubscribeEvent(priority = Priority.HIGH) + public static boolean onEntityRightClick(PlayerInteractEvent.EntityInteract event) { - if (event.isCanceled()) - return; - Player player = event.getEntity(); Level level = event.getLevel(); Entity target = event.getTarget(); if (level.isClientSide) - return; + return false; CarryOnData carry = CarryOnDataManager.getCarryData(player); if (!carry.isCarrying()) { if (PickupHandler.tryPickupEntity((ServerPlayer) player, target, (toPickup) -> { EntityPickupEvent pickupEvent = new EntityPickupEvent((ServerPlayer) player, toPickup); - MinecraftForge.EVENT_BUS.post(pickupEvent); - return !pickupEvent.isCanceled(); + return !EntityPickupEvent.BUS.post(pickupEvent); })) { event.setCancellationResult(InteractionResult.SUCCESS); - event.setCanceled(true); - return; + return true; } } else if (carry.isCarrying(CarryType.ENTITY) || carry.isCarrying(CarryType.PLAYER)) { PlacementHandler.tryStackEntity((ServerPlayer) player, target); } + + return false; } @SubscribeEvent @@ -198,19 +190,16 @@ public class CommonEvents } @SubscribeEvent - public static void attackEntity(AttackEntityEvent event) + public static boolean attackEntity(AttackEntityEvent event) { - if(!CarryOnCommon.onAttackedByPlayer(event.getEntity())) - event.setCanceled(true); - } + return !CarryOnCommon.onAttackedByPlayer(event.getEntity()); + } @SubscribeEvent - public static void onBreakBlock(BreakEvent event) + public static boolean onBreakBlock(BreakEvent event) { - if (!CarryOnCommon.onTryBreakBlock(event.getPlayer())) { - event.setCanceled(true); - } - } + return !CarryOnCommon.onTryBreakBlock(event.getPlayer()); + } @SubscribeEvent public static void playerAttack(LivingAttackEvent event) diff --git a/Forge/src/main/java/tschipp/carryon/events/EntityPickupEvent.java b/Forge/src/main/java/tschipp/carryon/events/EntityPickupEvent.java index 5be9fc5..6c80e40 100644 --- a/Forge/src/main/java/tschipp/carryon/events/EntityPickupEvent.java +++ b/Forge/src/main/java/tschipp/carryon/events/EntityPickupEvent.java @@ -22,17 +22,11 @@ package tschipp.carryon.events; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.Entity; -import net.minecraftforge.eventbus.api.Cancelable; -import net.minecraftforge.eventbus.api.Event; +import net.minecraftforge.eventbus.api.bus.CancellableEventBus; +import net.minecraftforge.eventbus.api.event.RecordEvent; +import net.minecraftforge.eventbus.api.event.characteristic.Cancellable; -@Cancelable -public class EntityPickupEvent extends Event { +public record EntityPickupEvent(ServerPlayer player, Entity target) implements Cancellable, RecordEvent { - public final ServerPlayer player; - public final Entity target; - - public EntityPickupEvent(ServerPlayer player, Entity target) { - this.player = player; - this.target = target; - } + public static final CancellableEventBus BUS = CancellableEventBus.create(EntityPickupEvent.class); } diff --git a/Forge/src/main/java/tschipp/carryon/events/ModBusEvents.java b/Forge/src/main/java/tschipp/carryon/events/ModBusEvents.java index da2ddf7..aa8d7f8 100644 --- a/Forge/src/main/java/tschipp/carryon/events/ModBusEvents.java +++ b/Forge/src/main/java/tschipp/carryon/events/ModBusEvents.java @@ -19,9 +19,8 @@ */ package tschipp.carryon.events; - -import net.minecraftforge.eventbus.api.EventPriority; -import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.eventbus.api.listener.Priority; +import net.minecraftforge.eventbus.api.listener.SubscribeEvent; import net.minecraftforge.fml.InterModComms; import net.minecraftforge.fml.InterModComms.IMCMessage; import net.minecraftforge.fml.common.Mod; @@ -36,7 +35,7 @@ import java.util.stream.Stream; @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD, modid = Constants.MOD_ID) public class ModBusEvents { - @SubscribeEvent(priority = EventPriority.LOW) + @SubscribeEvent(priority = Priority.LOW) public static void serverLoad(InterModProcessEvent event) { Stream messages = InterModComms.getMessages(Constants.MOD_ID); diff --git a/Forge/src/main/java/tschipp/carryon/events/ModClientEvents.java b/Forge/src/main/java/tschipp/carryon/events/ModClientEvents.java index 624b4f3..98c4e34 100644 --- a/Forge/src/main/java/tschipp/carryon/events/ModClientEvents.java +++ b/Forge/src/main/java/tschipp/carryon/events/ModClientEvents.java @@ -24,7 +24,7 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.client.ConfigScreenHandler; import net.minecraftforge.client.event.RegisterKeyMappingsEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.eventbus.api.listener.SubscribeEvent; import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus; @@ -52,7 +52,7 @@ public class ModClientEvents if(Services.PLATFORM.isModLoaded("cloth_config")) { BuiltConfig[] configs = ConfigLoaderImpl.CONFIGS.values().toArray(new BuiltConfig[0]); - ModLoadingContext.get().registerExtensionPoint(ConfigScreenHandler.ConfigScreenFactory.class, () -> new ConfigScreenHandler.ConfigScreenFactory((mc, prevScreen) -> ClothConfigCompatForge.createScreen(configs[1], configs[0], prevScreen))); + //ModLoadingContext.get().registerExtensionPoint(ConfigScreenHandler.ConfigScreenFactory.class, () -> new ConfigScreenHandler.ConfigScreenFactory((mc, prevScreen) -> ClothConfigCompatForge.createScreen(configs[1], configs[0], prevScreen))); } } } diff --git a/Forge/src/main/resources/META-INF/mods.toml b/Forge/src/main/resources/META-INF/mods.toml index f800d57..5a33201 100644 --- a/Forge/src/main/resources/META-INF/mods.toml +++ b/Forge/src/main/resources/META-INF/mods.toml @@ -19,7 +19,7 @@ issueTrackerURL="https://github.com/Tschipp/CarryOn/issues" # Does this dependency have to exist - if not, ordering below must be specified mandatory=true #mandatory # The version range of the dependency - versionRange="${forge_version_range}" #mandatory + versionRange="${forge_loader_version_range}" #mandatory # An ordering relationship for the dependency - BEFORE or AFTER required if the relationship is not mandatory ordering="NONE" # Side this dependency is applied on - BOTH, CLIENT or SERVER diff --git a/Forge/src/main/resources/carryon.forge.mixins.json b/Forge/src/main/resources/carryon.forge.mixins.json index 57e1d4e..0df58a2 100644 --- a/Forge/src/main/resources/carryon.forge.mixins.json +++ b/Forge/src/main/resources/carryon.forge.mixins.json @@ -12,6 +12,5 @@ ], "injectors": { "defaultRequire": 1 - }, - "refmap": "${refmap_target}refmap.json" + } } \ No newline at end of file diff --git a/NeoForge/build.gradle b/NeoForge/build.gradle index 311945e..57aa5d8 100644 --- a/NeoForge/build.gradle +++ b/NeoForge/build.gradle @@ -1,120 +1,174 @@ plugins { - id 'idea' - id 'maven-publish' - id 'net.neoforged.gradle.userdev' version '7.0.168' - id 'java-library' + id 'multiloader-loader' + id 'net.neoforged.moddev' } - -if (System.getenv('BUILD_NUMBER') != null) { - version += "." + System.getenv('BUILD_NUMBER') -} - -base { - archivesName = "${mod_id}-neoforge-${minecraft_version}" -} - -//jarJar.enable() - -//archivesBaseName = "${mod_id}-neoforge-${minecraft_version}" - -/* -mixin { - add sourceSets.main, "${mod_id}.refmap.json" - - config "${mod_id}.mixins.json" - config "${mod_id}.forge.mixins.json" -} -*/ - -if (file('src/main/resources/META-INF/accesstransformer.cfg').exists()) { - minecraft.accessTransformers.file file('src/main/resources/META-INF/accesstransformer.cfg') -} - -runs { - // applies to all the run configs below - configureEach { - systemProperty 'forge.logging.markers', 'REGISTRIES' - systemProperty 'forge.logging.console.level', 'debug' - modSource project.sourceSets.main +repositories { + maven { + name = "Shedaniel" + url "https://maven.shedaniel.me/" } - client { - // Comma-separated list of namespaces to load gametests from. Empty = all namespaces. - systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id + maven { url 'https://jitpack.io' } +} + +neoForge { + version = neoforge_version + // Automatically enable neoforge AccessTransformers if the file exists + def at = project(':Common').file('src/main/resources/META-INF/accesstransformer.cfg') + if (at.exists()) { + accessTransformers.from(at.absolutePath) } - - server { - systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id - programArgument '--nogui' + parchment { + minecraftVersion = minecraft_version + mappingsVersion = parchment_version } - - // This run config launches GameTestServer and runs all registered gametests, then exits. - // By default, the server will crash when no gametests are provided. - // The gametest system is also enabled by default for other run configs under the /test command. - gameTestServer { - systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id + runs { + configureEach { + systemProperty('neoforge.enabledGameTestNamespaces', mod_id) + ideName = "NeoForge ${it.name.capitalize()} (${project.path})" // Unify the run config names with fabric + } + client { + client() + } + data { + clientData() + } + server { + server() + } } + mods { + "${mod_id}" { + sourceSet sourceSets.main + } + } +} - /* - data { - // example of overriding the workingDirectory set in configureEach above, uncomment if you want to use it - // workingDirectory project.file('run-data') - // Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources. - programArguments.addAll '--mod', project.mod_id, '--all', '--output', file('src/generated/resources/').getAbsolutePath(), '--existing', file('src/main/resources/').getAbsolutePath() - }*/ +dependencies { + api "me.shedaniel.cloth:cloth-config-neoforge:${cloth_config_version}" } sourceSets.main.resources { srcDir 'src/generated/resources' } -configurations { - runtimeClasspath.extendsFrom localRuntime -} - - -tasks.named("test").configure { - enabled = false -} - -dependencies { - implementation "net.neoforged:neoforge:${neoforge_version}" - compileOnly project(":Common") - - api "me.shedaniel.cloth:cloth-config-neoforge:${cloth_config_version}" - //implementation fg.deobf("net.darkhax.gamestages:GameStages-Forge-1.19.2:11.0.2") - //implementation fg.deobf("net.darkhax.bookshelf:Bookshelf-Forge-1.19.3:17.0.2") -} - -// NeoGradle compiles the game, but we don't want to add our common code to the game's code -Spec notNeoTask = { Task it -> !it.name.startsWith("neo") } as Spec - -tasks.withType(JavaCompile).matching(notNeoTask).configureEach { - source(project(":Common").sourceSets.main.allSource) -} - -tasks.withType(Javadoc).matching(notNeoTask).configureEach { - source(project(":Common").sourceSets.main.allJava) -} - -tasks.named("sourcesJar", Jar) { - from(project(":Common").sourceSets.main.allSource) -} - -tasks.withType(ProcessResources).matching(notNeoTask).configureEach { - from project(":Common").sourceSets.main.resources -} - -publishing { - publications { - mavenJava(MavenPublication) { - artifactId base.archivesName.get() - from components.java - } - } - repositories { - maven { - url "file://" + System.getenv("local_maven") - } - } -} \ No newline at end of file +//plugins { +// id 'idea' +// id 'maven-publish' +// id 'net.neoforged.gradle.userdev' version '7.0.168' +// id 'java-library' +//} +// +// +//if (System.getenv('BUILD_NUMBER') != null) { +// version += "." + System.getenv('BUILD_NUMBER') +//} +// +//base { +// archivesName = "${mod_id}-neoforge-${minecraft_version}" +//} +// +////jarJar.enable() +// +////archivesBaseName = "${mod_id}-neoforge-${minecraft_version}" +// +///* +//mixin { +// add sourceSets.main, "${mod_id}.refmap.json" +// +// config "${mod_id}.mixins.json" +// config "${mod_id}.forge.mixins.json" +//} +//*/ +// +//if (file('src/main/resources/META-INF/accesstransformer.cfg').exists()) { +// minecraft.accessTransformers.file file('src/main/resources/META-INF/accesstransformer.cfg') +//} +// +//runs { +// // applies to all the run configs below +// configureEach { +// systemProperty 'forge.logging.markers', 'REGISTRIES' +// systemProperty 'forge.logging.console.level', 'debug' +// modSource project.sourceSets.main +// } +// +// client { +// // Comma-separated list of namespaces to load gametests from. Empty = all namespaces. +// systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id +// } +// +// server { +// systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id +// programArgument '--nogui' +// } +// +// // This run config launches GameTestServer and runs all registered gametests, then exits. +// // By default, the server will crash when no gametests are provided. +// // The gametest system is also enabled by default for other run configs under the /test command. +// gameTestServer { +// systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id +// } +// +// /* +// data { +// // example of overriding the workingDirectory set in configureEach above, uncomment if you want to use it +// // workingDirectory project.file('run-data') +// +// // Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources. +// programArguments.addAll '--mod', project.mod_id, '--all', '--output', file('src/generated/resources/').getAbsolutePath(), '--existing', file('src/main/resources/').getAbsolutePath() +// }*/ +//} +// +//sourceSets.main.resources { srcDir 'src/generated/resources' } +// +//configurations { +// runtimeClasspath.extendsFrom localRuntime +//} +// +// +//tasks.named("test").configure { +// enabled = false +//} +// +//dependencies { +// implementation "net.neoforged:neoforge:${neoforge_version}" +// compileOnly project(":Common") +// +// api "me.shedaniel.cloth:cloth-config-neoforge:${cloth_config_version}" +// //implementation fg.deobf("net.darkhax.gamestages:GameStages-Forge-1.19.2:11.0.2") +// //implementation fg.deobf("net.darkhax.bookshelf:Bookshelf-Forge-1.19.3:17.0.2") +//} +// +//// NeoGradle compiles the game, but we don't want to add our common code to the game's code +//Spec notNeoTask = { Task it -> !it.name.startsWith("neo") } as Spec +// +//tasks.withType(JavaCompile).matching(notNeoTask).configureEach { +// source(project(":Common").sourceSets.main.allSource) +//} +// +//tasks.withType(Javadoc).matching(notNeoTask).configureEach { +// source(project(":Common").sourceSets.main.allJava) +//} +// +//tasks.named("sourcesJar", Jar) { +// from(project(":Common").sourceSets.main.allSource) +//} +// +//tasks.withType(ProcessResources).matching(notNeoTask).configureEach { +// from project(":Common").sourceSets.main.resources +//} +// +//publishing { +// publications { +// mavenJava(MavenPublication) { +// artifactId base.archivesName.get() +// from components.java +// } +// } +// repositories { +// maven { +// url "file://" + System.getenv("local_maven") +// } +// } +//} \ No newline at end of file diff --git a/NeoForge/src/main/java/tschipp/carryon/config/neoforge/ConfigLoaderImpl.java b/NeoForge/src/main/java/tschipp/carryon/config/neoforge/ConfigLoaderImpl.java index e16ea09..b289711 100644 --- a/NeoForge/src/main/java/tschipp/carryon/config/neoforge/ConfigLoaderImpl.java +++ b/NeoForge/src/main/java/tschipp/carryon/config/neoforge/ConfigLoaderImpl.java @@ -42,7 +42,7 @@ import tschipp.carryon.config.*; import java.util.*; import java.util.function.Consumer; -@EventBusSubscriber(modid = Constants.MOD_ID, bus = EventBusSubscriber.Bus.MOD) +@EventBusSubscriber(modid = Constants.MOD_ID) public class ConfigLoaderImpl { public static final Map CONFIGS = new LinkedHashMap<>(); diff --git a/NeoForge/src/main/java/tschipp/carryon/events/ClientEvents.java b/NeoForge/src/main/java/tschipp/carryon/events/ClientEvents.java index bccedaa..358276c 100644 --- a/NeoForge/src/main/java/tschipp/carryon/events/ClientEvents.java +++ b/NeoForge/src/main/java/tschipp/carryon/events/ClientEvents.java @@ -41,7 +41,7 @@ import tschipp.carryon.client.render.CarryRenderHelper; import tschipp.carryon.common.carry.CarryOnData; import tschipp.carryon.common.carry.CarryOnDataManager; -@EventBusSubscriber(bus = EventBusSubscriber.Bus.GAME, modid = Constants.MOD_ID, value = Dist.CLIENT) +@EventBusSubscriber(modid = Constants.MOD_ID, value = Dist.CLIENT) public class ClientEvents { @OnlyIn(Dist.CLIENT) @@ -60,10 +60,9 @@ public class ClientEvents { @OnlyIn(Dist.CLIENT) @SubscribeEvent - public static void onRenderLevel(RenderLevelStageEvent event) + public static void onRenderLevel(RenderLevelStageEvent.AfterParticles event) { - if(event.getStage() == RenderLevelStageEvent.Stage.AFTER_PARTICLES) - CarriedObjectRender.drawThirdPerson(event.getPartialTick().getGameTimeDeltaPartialTick(true), event.getPoseStack().last().pose()); + CarriedObjectRender.drawThirdPerson(event.getPartialTick().getGameTimeDeltaPartialTick(true), event.getPoseStack().last().pose()); } @OnlyIn(Dist.CLIENT) diff --git a/NeoForge/src/main/java/tschipp/carryon/events/CommonEvents.java b/NeoForge/src/main/java/tschipp/carryon/events/CommonEvents.java index c5cee43..6a0d8f1 100644 --- a/NeoForge/src/main/java/tschipp/carryon/events/CommonEvents.java +++ b/NeoForge/src/main/java/tschipp/carryon/events/CommonEvents.java @@ -55,7 +55,7 @@ import tschipp.carryon.common.carry.PlacementHandler; import tschipp.carryon.common.scripting.ScriptReloadListener; import tschipp.carryon.config.ConfigLoader; -@EventBusSubscriber(bus = EventBusSubscriber.Bus.GAME, modid = Constants.MOD_ID) +@EventBusSubscriber(modid = Constants.MOD_ID) public class CommonEvents { @SubscribeEvent(priority = EventPriority.HIGH) diff --git a/NeoForge/src/main/java/tschipp/carryon/events/ModBusEvents.java b/NeoForge/src/main/java/tschipp/carryon/events/ModBusEvents.java index 42b449b..bfdae94 100644 --- a/NeoForge/src/main/java/tschipp/carryon/events/ModBusEvents.java +++ b/NeoForge/src/main/java/tschipp/carryon/events/ModBusEvents.java @@ -32,7 +32,7 @@ import tschipp.carryon.common.config.ListHandler; import java.util.stream.Stream; -@EventBusSubscriber(bus = EventBusSubscriber.Bus.MOD, modid = Constants.MOD_ID) +@EventBusSubscriber(modid = Constants.MOD_ID) public class ModBusEvents { @SubscribeEvent(priority = EventPriority.LOW) diff --git a/NeoForge/src/main/java/tschipp/carryon/events/ModClientEvents.java b/NeoForge/src/main/java/tschipp/carryon/events/ModClientEvents.java index fd8324f..8371962 100644 --- a/NeoForge/src/main/java/tschipp/carryon/events/ModClientEvents.java +++ b/NeoForge/src/main/java/tschipp/carryon/events/ModClientEvents.java @@ -29,7 +29,7 @@ import net.neoforged.neoforge.client.event.RegisterKeyMappingsEvent; import tschipp.carryon.Constants; import tschipp.carryon.client.keybinds.CarryOnKeybinds; -@EventBusSubscriber(bus = EventBusSubscriber.Bus.MOD, modid = Constants.MOD_ID, value = Dist.CLIENT) +@EventBusSubscriber(modid = Constants.MOD_ID, value = Dist.CLIENT) public class ModClientEvents { @OnlyIn(Dist.CLIENT) diff --git a/NeoForge/src/main/resources/carryon.neoforge.mixins.json b/NeoForge/src/main/resources/carryon.neoforge.mixins.json index eba3407..8536f54 100644 --- a/NeoForge/src/main/resources/carryon.neoforge.mixins.json +++ b/NeoForge/src/main/resources/carryon.neoforge.mixins.json @@ -12,5 +12,4 @@ "injectors": { "defaultRequire": 1 } - //"refmap": "${refmap_target}refmap.json" } \ No newline at end of file diff --git a/build.gradle b/build.gradle index ee4fea8..d990e9a 100644 --- a/build.gradle +++ b/build.gradle @@ -1,108 +1,6 @@ plugins { - // Required for NeoGradle - id "org.jetbrains.gradle.plugin.idea-ext" version "1.1.7" -} - -subprojects { - - apply plugin: 'java' - - java.toolchain.languageVersion = JavaLanguageVersion.of(21) - java.withSourcesJar() - java.withJavadocJar() - - jar { - from(rootProject.file("LICENSE")) { - rename { "${it}_${mod_id}" } - } - manifest { - attributes([ - 'Specification-Title' : mod_name, - 'Specification-Vendor' : mod_author, - 'Specification-Version' : project.jar.archiveVersion, - 'Implementation-Title' : project.name, - 'Implementation-Version' : project.jar.archiveVersion, - 'Implementation-Vendor' : mod_author, - 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), - 'Timestamp' : System.currentTimeMillis(), - 'Built-On-Java' : "${System.getProperty('java.vm.version')} (${System.getProperty('java.vm.vendor')})", - 'Built-On-Minecraft' : minecraft_version - ]) - } - } - - sourcesJar { - from(rootProject.file("LICENSE")) { - rename { "${it}_${mod_name}" } - } - } - - repositories { - - mavenCentral() - - maven { - name = 'Sponge / Mixin' - url = 'https://repo.spongepowered.org/repository/maven-public/' - } - - maven { - name = 'BlameJared Maven (CrT / Bookshelf)' - url = 'https://maven.blamejared.com' - } - - maven { - name = "Shedaniel" - url "https://maven.shedaniel.me/" - } - } - - tasks.withType(JavaCompile).configureEach { - - it.options.encoding = 'UTF-8' - it.options.release = 21 - } - - processResources { - def expandProps = [ - "version": version, - "group": project.group, //Else we target the task's group. - "minecraft_version": minecraft_version, - "forge_version": forge_version, - "forge_loader_version_range": forge_loader_version_range, - "forge_version_range": forge_version_range, - "minecraft_version_range": minecraft_version_range, - "fabric_version": fabric_version, - "fabric_loader_version": fabric_loader_version, - "mod_name": mod_name, - "mod_author": mod_author, - "mod_id": mod_id, - "license": license, - "description": project.description, - "neoforge_version": neoforge_version, - "neoforge_loader_version_range": neoforge_loader_version_range, - "credits": credits, - "refmap_target": "${mod_id}." - ] - - filesMatching(['pack.mcmeta', 'fabric.mod.json', 'META-INF/mods.toml', 'META-INF/neoforge.mods.toml', '*.mixins.json']) { - expand expandProps - } - inputs.properties(expandProps) - } - - // Disables Gradle's custom module metadata from being published to maven. The - // metadata includes mapped dependencies which are not reasonably consumable by - // other mod developers. - tasks.withType(GenerateModuleMetadata) { - - enabled = false - } - - idea { - module { - downloadSources = true - downloadJavadoc = true - } - } -} + // see https://fabricmc.net/develop/ for new versions + id 'fabric-loom' version '1.10-SNAPSHOT' apply false + // see https://projects.neoforged.net/neoforged/moddevgradle for new versions + id 'net.neoforged.moddev' version '2.0.62-beta' apply false +} \ No newline at end of file diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle new file mode 100644 index 0000000..1957c33 --- /dev/null +++ b/buildSrc/build.gradle @@ -0,0 +1,3 @@ +plugins { + id 'groovy-gradle-plugin' +} \ No newline at end of file diff --git a/buildSrc/src/main/groovy/multiloader-common.gradle b/buildSrc/src/main/groovy/multiloader-common.gradle new file mode 100644 index 0000000..982e675 --- /dev/null +++ b/buildSrc/src/main/groovy/multiloader-common.gradle @@ -0,0 +1,133 @@ +plugins { + id 'java-library' + id 'maven-publish' +} + +base { + archivesName = "${mod_id}-${project.name}-${minecraft_version}" +} + +java { + toolchain.languageVersion = JavaLanguageVersion.of(java_version) + withSourcesJar() + withJavadocJar() +} + +repositories { + mavenCentral() + // https://docs.gradle.org/current/userguide/declaring_repositories.html#declaring_content_exclusively_found_in_one_repository + exclusiveContent { + forRepository { + maven { + name = 'Sponge' + url = 'https://repo.spongepowered.org/repository/maven-public' + } + } + filter { includeGroupAndSubgroups('org.spongepowered') } + } + exclusiveContent { + forRepositories( + maven { + name = 'ParchmentMC' + url = 'https://maven.parchmentmc.org/' + }, + maven { + name = "NeoForge" + url = 'https://maven.neoforged.net/releases' + } + ) + filter { includeGroup('org.parchmentmc.data') } + } + maven { + name = 'BlameJared' + url = 'https://maven.blamejared.com' + } +} + +// Declare capabilities on the outgoing configurations. +// Read more about capabilities here: https://docs.gradle.org/current/userguide/component_capabilities.html#sec:declaring-additional-capabilities-for-a-local-component +['apiElements', 'runtimeElements', 'sourcesElements', 'javadocElements'].each { variant -> + configurations."$variant".outgoing { + capability("$group:${project.name}:$version") + capability("$group:${base.archivesName.get()}:$version") + capability("$group:$mod_id-${project.name}-${minecraft_version}:$version") + capability("$group:$mod_id:$version") + } + publishing.publications.configureEach { + suppressPomMetadataWarningsFor(variant) + } +} + +sourcesJar { + from(rootProject.file('LICENSE')) { + rename { "${it}_${mod_name}" } + } +} + +jar { + from(rootProject.file('LICENSE')) { + rename { "${it}_${mod_name}" } + } + + manifest { + attributes([ + 'Specification-Title' : mod_name, + 'Specification-Vendor' : mod_author, + 'Specification-Version' : project.jar.archiveVersion, + 'Implementation-Title' : project.name, + 'Implementation-Version': project.jar.archiveVersion, + 'Implementation-Vendor' : mod_author, + 'Built-On-Minecraft' : minecraft_version + ]) + } +} + +processResources { + var expandProps = [ + 'version' : version, + 'group' : project.group, //Else we target the task's group. + 'minecraft_version' : minecraft_version, + 'minecraft_version_range' : minecraft_version_range, + 'fabric_version' : fabric_version, + 'fabric_loader_version' : fabric_loader_version, + 'mod_name' : mod_name, + 'mod_author' : mod_author, + 'mod_id' : mod_id, + 'license' : license, + 'description' : project.description, + 'neoforge_version' : neoforge_version, + 'neoforge_loader_version_range': neoforge_loader_version_range, + "forge_version": forge_version, + "forge_loader_version_range": forge_loader_version_range, + 'credits' : credits, + 'java_version' : java_version + ] + + var jsonExpandProps = expandProps.collectEntries { + key, value -> [(key): value instanceof String ? value.replace("\n", "\\\\n") : value] + } + + filesMatching(['META-INF/mods.toml', 'META-INF/neoforge.mods.toml']) { + expand expandProps + } + + filesMatching(['pack.mcmeta', 'fabric.mod.json', '*.mixins.json']) { + expand jsonExpandProps + } + + inputs.properties(expandProps) +} + +publishing { + publications { + register('mavenJava', MavenPublication) { + artifactId base.archivesName.get() + from components.java + } + } + repositories { + maven { + url System.getenv('local_maven_url') + } + } +} \ No newline at end of file diff --git a/buildSrc/src/main/groovy/multiloader-loader.gradle b/buildSrc/src/main/groovy/multiloader-loader.gradle new file mode 100644 index 0000000..6c44aea --- /dev/null +++ b/buildSrc/src/main/groovy/multiloader-loader.gradle @@ -0,0 +1,44 @@ +plugins { + id 'multiloader-common' +} + +configurations { + commonJava{ + canBeResolved = true + } + commonResources{ + canBeResolved = true + } +} + +dependencies { + compileOnly(project(':Common')) { + capabilities { + requireCapability "$group:$mod_id" + } + } + commonJava project(path: ':Common', configuration: 'commonJava') + commonResources project(path: ':Common', configuration: 'commonResources') +} + +tasks.named('compileJava', JavaCompile) { + dependsOn(configurations.commonJava) + source(configurations.commonJava) +} + +processResources { + dependsOn(configurations.commonResources) + from(configurations.commonResources) +} + +tasks.named('javadoc', Javadoc).configure { + dependsOn(configurations.commonJava) + source(configurations.commonJava) +} + +tasks.named('sourcesJar', Jar) { + dependsOn(configurations.commonJava) + from(configurations.commonJava) + dependsOn(configurations.commonResources) + from(configurations.commonResources) +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 038ddca..e25ba0a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,33 +1,36 @@ # Project -version=2.4.0 +version=2.5.0 group=tschipp.carryon # Common -minecraft_version=1.21.5 +minecraft_version=1.21.6 mod_name=Carry On mod_author=Tschipp, PurpliciousCow mod_id=carryon license=GNU LGPLv3 credits= description=Carry On is a simple mod that improves game interaction by allowing players to pick up, carry, and place single block Tile Entities using only their empty hands. -minecraft_version_range=[1.21.5, 1.22) +minecraft_version_range=[1.21.6, 1.22) +neo_form_version=1.21.6-20250617.151856 +java_version=21 +parchment_version=2025.06.29 + # Forge -forge_version=55.0.24 +forge_version=56.0.9 forge_loader_version_range=[55,) -forge_version_range=[55,) -parchment_mappings=2025.06.15-1.21.5 +parchment_mappings=2025.06.29-1.21.6 //forge_ats_enabled=true # Fabric -fabric_version=0.121.0+1.21.5 -fabric_loader_version=0.16.13 -parchment_mappings_fabric=1.21.5:2025.06.15 +fabric_version=0.128.2+1.21.6 +fabric_loader_version=0.16.14 +parchment_mappings_fabric=1.21.6:2025.06.29 # Neoforge -neoforge_version=21.5.78 +neoforge_version=21.6.20-beta neoforge_loader_version_range=[4,) -neogradle.subsystems.parchment.minecraftVersion=1.21.5 -neogradle.subsystems.parchment.mappingsVersion=2025.06.15 +neogradle.subsystems.parchment.minecraftVersion=1.21.6 +neogradle.subsystems.parchment.mappingsVersion=2025.06.29 # Gradle @@ -35,4 +38,4 @@ org.gradle.jvmargs=-Xmx3G org.gradle.daemon=false mixinextras_version=0.3.6 -cloth_config_version=17.0.144 \ No newline at end of file +cloth_config_version=19.0.147 \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index a1ad556..8ca4152 100644 --- a/settings.gradle +++ b/settings.gradle @@ -2,49 +2,61 @@ pluginManagement { repositories { gradlePluginPortal() mavenLocal() - - maven { - url "https://plugins.gradle.org/m2/" + mavenCentral() + exclusiveContent { + forRepository { + maven { + name = 'Fabric' + url = uri('https://maven.fabricmc.net') + } + } + filter { + includeGroup('net.fabricmc') + includeGroup('fabric-loom') + } } - - maven { - name = 'Fabric' - url = 'https://maven.fabricmc.net/' + exclusiveContent { + forRepository { + maven { + name = 'Sponge' + url = uri('https://repo.spongepowered.org/repository/maven-public') + } + } + filter { + includeGroupAndSubgroups("org.spongepowered") + } } - - maven { - name = 'Sponge Snapshots' - url = 'https://repo.spongepowered.org/repository/maven-public/' + exclusiveContent { + forRepository { + maven { + name = 'Forge' + url = uri('https://maven.minecraftforge.net') + } + } + filter { + includeGroupAndSubgroups('net.minecraftforge') + } } - maven { url 'https://jitpack.io' } - maven { name = 'ParchmentMC' url = 'https://maven.parchmentmc.org' } - maven { - name = 'Forge' - url = 'https://maven.minecraftforge.net/' - } - - maven { - name = 'NeoForge' - url = 'https://maven.neoforged.net/releases/' - } - - maven { - url 'https://maven.blamejared.com' - } } } + + plugins { id 'org.gradle.toolchains.foojay-resolver-convention' version '0.8.0' } +if (System.getenv('BUILD_NUMBER') != null) { + version += "." + System.getenv('BUILD_NUMBER') +} + rootProject.name = 'CarryOn' //include("Common", "Fabric", "NeoForge") include("Common", "Fabric", "Forge", "NeoForge") \ No newline at end of file