diff --git a/README.md b/README.md index a5642fe..209987e 100644 --- a/README.md +++ b/README.md @@ -1,34 +1,5 @@ -# Create Fabric Addon Template +# Create Custom Portal API Integration -This template mod comes pre-configured for developing an addon mod for Create on Fabric. +A Create addon compatibility mod for customportalapi portals to function with Create trains. - -## Setup - -This template is an extension of the base [Fabric Example Mod](https://github.com/FabricMC/fabric-example-mod). -Setup is mostly the same. - -Additionally, set `recipe_viewer` in [gradle.properties](gradle.properties). Remember to remove unused -example code. Make sure versions are up-to-date. - -When you publish your mod, you should use jars provided by GitHub Actions. These jars will have -build number metadata and will be compressed by the Machete plugin. - -## Features -- Access to Create and all of its dependencies -- Mojang Mappings base, with Quilt Mappings and Parchment providing Javadoc and parameters -- QuiltFlower decompiler for high quality Minecraft sources: `gradlew genSourcesWithQuiltflower` -- GitHub Actions automatic build workflow -- Machete Gradle plugin to shrink jar file sizes -- Developer QOL: Mod Menu, LazyDFU, recipe viewers - -## Other Templates -- [Multi-loader template](https://github.com/Fabricators-of-Create/create-multiloader-addon-template) -- [Forge-only template](https://github.com/kotakotik22/CreateAddonTemplate) - -## Help -Questions? Join us in the #devchat channel of the [Create Discord](https://discord.com/invite/hmaD7Se). - -## License - -This template is available under the CC0 license. Feel free to do as you wish with it. +Link to the customportalapi GitHub: https://github.com/kyrptonaught/customportalapi diff --git a/build.gradle b/build.gradle index f974d15..f0886f2 100644 --- a/build.gradle +++ b/build.gradle @@ -27,7 +27,7 @@ repositories { maven { url = "https://api.modrinth.com/maven" } // LazyDFU maven { url = "https://maven.terraformersmc.com/releases/" } // Mod Menu maven { url = "https://mvn.devos.one/snapshots/" } // Create, Porting Lib, Forge Tags, Milk Lib, Registrate - maven { url = "https://cursemaven.com" } // Forge Config API Port + maven { url = "https://raw.githubusercontent.com/Fuzss/modresources/main/maven/" } // Forge Config API Port maven { url = "https://maven.jamieswhiteshirt.com/libs-release" } // Reach Entity Attributes maven { url = "https://jitpack.io/" } // Mixin Extras, Fabric ASM maven { url = "https://maven.tterrag.com/" } // Flywheel @@ -77,14 +77,15 @@ dependencies { processResources { // require dependencies to be the version compiled against or newer - Map properties = new HashMap<>() - properties.put("version", version) - properties.put("fabric_loader_version", fabric_loader_version) - properties.put("fabric_api_version", fabric_api_version) - properties.put("create_version", create_version) - properties.put("minecraft_version", minecraft_version) - - properties.forEach((k, v) -> inputs.property(k, v)) + Map properties = Map.of( + "version", version, + "fabric_loader_version", fabric_loader_version, + "fabric_api_version", fabric_api_version, + "create_version", create_version, + "minecraft_version", minecraft_version + ) + + inputs.properties(properties) filesMatching("fabric.mod.json") { expand properties diff --git a/gradle.properties b/gradle.properties index 6d6defe..cfe4948 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,8 +9,8 @@ minecraft_version = 1.18.2 # Dependencies # https://fabricmc.net/develop -fabric_loader_version = 0.14.11 -fabric_api_version = 0.67.0+1.18.2 +fabric_loader_version = 0.15.7 +fabric_api_version = 0.77.0+1.18.2 # Mappings # https://lambdaurora.dev/tools/import_quilt.html @@ -20,18 +20,18 @@ parchment_version = 2022.11.06 # Create # https://modrinth.com/mod/create-fabric/versions -create_version = 0.5.0.i-988+1.18.2 +create_version = 0.5.1-f-build.1415+mc1.18.2 # Development QOL # Create supports all 3 recipe viewers: JEI, REI, and EMI. This decides which is enabled at runtime. # set to disabled to have none of them. recipe_viewer = unspecified # JEI - https://www.curseforge.com/minecraft/mc-mods/jei/files/all -jei_version = 10.2.1.283 -# REI - https://modrinth.com/mod/roughly-enough-items/versions -rei_version = 8.3.583 +jei_version = 10.2.1.1006 +# REI - https://modrinth.com/mod/rei/versions +rei_version = 8.3.681 # EMI - https://modrinth.com/mod/emi/versions -emi_version = 0.5.3+1.18.2 +emi_version = 0.7.3+1.18.2 # Mod Menu - https://modrinth.com/mod/modmenu/versions modmenu_version = 3.2.5 diff --git a/src/main/java/reign/createaddons/customportalapiintegrations/mixin/CustomPortalBlockMixin.java b/src/main/java/reign/createaddons/customportalapiintegrations/mixin/CustomPortalBlockMixin.java new file mode 100644 index 0000000..a5583c6 --- /dev/null +++ b/src/main/java/reign/createaddons/customportalapiintegrations/mixin/CustomPortalBlockMixin.java @@ -0,0 +1,22 @@ +package reign.createaddons.customportalapiintegrations.mixin; + + +import net.kyrptonaught.customportalapi.CustomPortalBlock; + +import net.minecraft.core.BlockPos; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.state.BlockState; + +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; + +@Mixin(CustomPortalBlock.class) +public abstract class CustomPortalBlockMixin { + @Inject(method = "entityInside", at = @At(value = "HEAD"), cancellable = true) + public void customPortalBlock$entityInside(BlockState state, Level world, BlockPos pos, Entity entity, CallbackInfo ci) { + if (entity.isVehicle() || entity.isPassenger()) ci.cancel(); + } +} diff --git a/src/main/java/reign/createaddons/customportalapiintegrations/mixin/DCEntityMixin.java b/src/main/java/reign/createaddons/customportalapiintegrations/mixin/DCEntityMixin.java new file mode 100644 index 0000000..3189f9d --- /dev/null +++ b/src/main/java/reign/createaddons/customportalapiintegrations/mixin/DCEntityMixin.java @@ -0,0 +1,20 @@ +package reign.createaddons.customportalapiintegrations.mixin; + +import com.simibubi.create.content.trains.entity.Carriage; + +import net.kyrptonaught.customportalapi.interfaces.EntityInCustomPortal; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; + +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; + +@Mixin(Carriage.DimensionalCarriageEntity.class) +public abstract class DCEntityMixin { + @Inject(method = "dismountPlayer", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerPlayer;setPortalCooldown()V")) + public void dimensionalCarriageEntity$setCustomPortalCooldown(ServerLevel sLevel, ServerPlayer sp, Integer seat, boolean capture, CallbackInfo ci) { + ((EntityInCustomPortal)(Object)sp).setDidTP(true); + } +} diff --git a/src/main/java/reign/createaddons/customportalapiintegrations/mixin/TrackBlockMixin.java b/src/main/java/reign/createaddons/customportalapiintegrations/mixin/TrackBlockMixin.java index 0c3f54c..0a2937d 100644 --- a/src/main/java/reign/createaddons/customportalapiintegrations/mixin/TrackBlockMixin.java +++ b/src/main/java/reign/createaddons/customportalapiintegrations/mixin/TrackBlockMixin.java @@ -3,9 +3,9 @@ import java.util.Random; import com.google.common.base.Predicates; -import com.simibubi.create.content.contraptions.components.structureMovement.glue.SuperGlueEntity; -import com.simibubi.create.content.logistics.trains.track.TrackBlock; -import com.simibubi.create.content.logistics.trains.track.TrackTileEntity; +import com.simibubi.create.content.contraptions.glue.SuperGlueEntity; +import com.simibubi.create.content.trains.track.TrackBlock; +import com.simibubi.create.content.trains.track.TrackBlockEntity; import com.simibubi.create.foundation.utility.BlockFace; import com.simibubi.create.foundation.utility.Components; import com.simibubi.create.foundation.utility.Iterate; @@ -21,6 +21,7 @@ import net.kyrptonaught.customportalapi.util.PortalLink; import net.minecraft.ChatFormatting; import net.minecraft.core.Direction; +import net.minecraft.core.Direction.Axis; import net.minecraft.network.chat.MutableComponent; import net.minecraft.resources.ResourceKey; import net.minecraft.server.MinecraftServer; @@ -42,8 +43,8 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import com.simibubi.create.content.logistics.trains.TrackPropagator; -import com.simibubi.create.content.logistics.trains.track.TrackShape; +import com.simibubi.create.content.trains.track.TrackPropagator; +import com.simibubi.create.content.trains.track.TrackShape; import net.minecraft.core.BlockPos; import net.minecraft.server.level.ServerLevel; @@ -53,21 +54,17 @@ @Mixin(TrackBlock.class) public abstract class TrackBlockMixin { - - @Shadow - protected abstract void connectToNether(ServerLevel level, BlockPos pos, BlockState state); - @Shadow @Final public static final EnumProperty SHAPE = EnumProperty.create("shape", TrackShape.class); @Shadow @Final - public static final BooleanProperty HAS_TE = BooleanProperty.create("turn"); + public static final BooleanProperty HAS_BE = BooleanProperty.create("turn"); protected void connectToOtherDimension(ServerLevel level, BlockPos pos, BlockState state) { TrackShape shape = state.getValue(TrackBlock.SHAPE); - Direction.Axis portalTest = shape == TrackShape.XO ? Direction.Axis.X : shape == TrackShape.ZO ? Direction.Axis.Z : null; + Axis portalTest = shape == TrackShape.XO ? Axis.X : shape == TrackShape.ZO ? Axis.Z : null; if (portalTest == null) return; @@ -78,31 +75,7 @@ protected void connectToOtherDimension(ServerLevel level, BlockPos pos, BlockSta for(Direction d : Iterate.directionsInAxis(portalTest)) { BlockPos portalPos = pos.relative(d); BlockState portalState = level.getBlockState(portalPos); - if (!(portalState.getBlock() instanceof NetherPortalBlock) && !(portalState.getBlock() instanceof CustomPortalBlock)) - continue; - if(portalState.getBlock() instanceof NetherPortalBlock) { - connectToNether(level, pos, state); - } - if(portalState.getBlock() instanceof CustomPortalBlock) { - connectToCustomPortal(level, pos, state); - } - } - } - - protected void connectToCustomPortal(ServerLevel level, BlockPos pos, BlockState state) { - TrackShape shape = state.getValue(TrackBlock.SHAPE); - Direction.Axis portalTest = shape == TrackShape.XO ? Direction.Axis.X : shape == TrackShape.ZO ? Direction.Axis.Z : null; - if (portalTest == null) - return; - - boolean pop = false; - String fail = null; - BlockPos failPos = null; - - for(Direction d : Iterate.directionsInAxis(portalTest)) { - BlockPos portalPos = pos.relative(d); - BlockState portalState = level.getBlockState(portalPos); - if (!(portalState.getBlock() instanceof CustomPortalBlock)) + if (!(portalState.getBlock() instanceof CustomPortalBlock || portalState.getBlock() instanceof NetherPortalBlock)) continue; pop = true; @@ -124,16 +97,16 @@ protected void connectToCustomPortal(ServerLevel level, BlockPos pos, BlockState } level.setBlock(pos, state.setValue(SHAPE, TrackShape.asPortal(d)) - .setValue(HAS_TE, true), 3); - BlockEntity te = level.getBlockEntity(pos); - if (te instanceof TrackTileEntity tte) - tte.bind(otherLevel.dimension(), otherTrackPos); + .setValue(HAS_BE, true), 3); + BlockEntity be = level.getBlockEntity(pos); + if (be instanceof TrackBlockEntity tbe) + tbe.bind(otherLevel.dimension(), otherTrackPos); otherLevel.setBlock(otherTrackPos, state.setValue(SHAPE, TrackShape.asPortal(otherTrack.getFace())) - .setValue(HAS_TE, true), 3); - BlockEntity otherTe = otherLevel.getBlockEntity(otherTrackPos); - if (otherTe instanceof TrackTileEntity tte) - tte.bind(level.dimension(), pos); + .setValue(HAS_BE, true), 3); + BlockEntity otherBE = otherLevel.getBlockEntity(otherTrackPos); + if (otherBE instanceof TrackBlockEntity tbe) + tbe.bind(level.dimension(), pos); pop = false; } @@ -169,7 +142,7 @@ protected void connectToCustomPortal(ServerLevel level, BlockPos pos, BlockState protected Pair getOtherSide(ServerLevel level, BlockFace inboundTrack) { BlockPos portalPos = inboundTrack.getConnectedPos(); BlockState portalState = level.getBlockState(portalPos); - if (!(portalState.getBlock() instanceof NetherPortalBlock) && !(portalState.getBlock() instanceof CustomPortalBlock)) + if (!(portalState.getBlock() instanceof NetherPortalBlock || portalState.getBlock() instanceof CustomPortalBlock)) return null; MinecraftServer minecraftserver = level.getServer(); @@ -186,10 +159,10 @@ protected Pair getOtherSide(ServerLevel level, BlockFace return null; PortalForcer teleporter = otherLevel.getPortalForcer(); - PortalInfo portalinfo = null; SuperGlueEntity probe = new SuperGlueEntity(level, new AABB(portalPos)); probe.setYRot(inboundTrack.getFace() .toYRot()); + PortalInfo portalinfo = null; if(portalState.getBlock() instanceof NetherPortalBlock) { portalinfo = probe.findDimensionEntryPoint(otherLevel); } else { @@ -205,9 +178,8 @@ protected Pair getOtherSide(ServerLevel level, BlockFace return null; Direction targetDirection = inboundTrack.getFace(); - if (targetDirection.getAxis() == CustomPortalHelper.getAxisFrom(otherPortalState)) { + if (targetDirection.getAxis() == CustomPortalHelper.getAxisFrom(otherPortalState)) targetDirection = targetDirection.getClockWise(); - } BlockPos otherPos = otherPortalPos.relative(targetDirection); return Pair.of(otherLevel, new BlockFace(otherPos, targetDirection.getOpposite())); } diff --git a/src/main/resources/assets/createcustomportalapiintegration/icon.png b/src/main/resources/assets/createcustomportalapiintegration/icon.png new file mode 100644 index 0000000..cb58935 Binary files /dev/null and b/src/main/resources/assets/createcustomportalapiintegration/icon.png differ diff --git a/src/main/resources/assets/modid/icon.png b/src/main/resources/assets/modid/icon.png deleted file mode 100644 index a57204c..0000000 Binary files a/src/main/resources/assets/modid/icon.png and /dev/null differ diff --git a/src/main/resources/createcustomportalapiintegration.mixins.json b/src/main/resources/createcustomportalapiintegration.mixins.json index 8afbcf7..f277f35 100644 --- a/src/main/resources/createcustomportalapiintegration.mixins.json +++ b/src/main/resources/createcustomportalapiintegration.mixins.json @@ -4,11 +4,13 @@ "package": "reign.createaddons.customportalapiintegrations.mixin", "compatibilityLevel": "JAVA_17", "mixins": [ + "CustomPortalBlockMixin", + "DCEntityMixin", + "TrackBlockMixin" ], "client": [ ], "server": [ - "TrackBlockMixin" ], "injectors": { "defaultRequire": 1 diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 02236a4..d1b7a5e 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -3,7 +3,7 @@ "id": "createcustomportalapiintegration", "version": "${version}", "name": "Create Custom Portal API Integration", - "description": "This is an example description! Tell everyone what your mod is about!", + "description": "A compatibility mod between Create's trains and customportalapi's portals.", "authors": [ "ReignOfFROZE" ], @@ -11,7 +11,7 @@ "sources": "https://github.com/Fabricators-of-Create/create-fabric-addon-template" }, "license": "CC0", - "icon": "assets/modid/icon.png", + "icon": "assets/createcustomportalapiintegration/icon.png", "environment": "*", "entrypoints": { "main": [