Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 3 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
19 changes: 10 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -77,14 +77,15 @@ dependencies {

processResources {
// require dependencies to be the version compiled against or newer
Map<String, String> 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<String, String> 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
Expand Down
14 changes: 7 additions & 7 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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<TrackShape> 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;

Expand All @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -169,7 +142,7 @@ protected void connectToCustomPortal(ServerLevel level, BlockPos pos, BlockState
protected Pair<ServerLevel, BlockFace> 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();
Expand All @@ -186,10 +159,10 @@ protected Pair<ServerLevel, BlockFace> 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 {
Expand All @@ -205,9 +178,8 @@ protected Pair<ServerLevel, BlockFace> 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()));
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed src/main/resources/assets/modid/icon.png
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
"package": "reign.createaddons.customportalapiintegrations.mixin",
"compatibilityLevel": "JAVA_17",
"mixins": [
"CustomPortalBlockMixin",
"DCEntityMixin",
"TrackBlockMixin"
],
"client": [
],
"server": [
"TrackBlockMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
"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"
],
"contact": {
"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": [
Expand Down