Skip to content
This repository was archived by the owner on Oct 20, 2024. It is now read-only.

Commit b3d0d4a

Browse files
committed
Fix some issues.
1 parent 5e558a6 commit b3d0d4a

File tree

9 files changed

+57
-44
lines changed

9 files changed

+57
-44
lines changed

build.gradle

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,18 +144,25 @@ publishMods {
144144

145145
displayName = "${project.mod_version} (${project.minecraft_version})"
146146

147+
["1.19.2", "1.19.3", "1.19.4", "1.20", "1.20.1", "1.20.2", "1.20.3", "1.20.4"].each {
148+
modrinth {
149+
minecraftVersions.add(it)
150+
}
151+
curseforge {
152+
minecraftVersions.add(it)
153+
}
154+
}
155+
147156
modrinth {
148157
projectId = "sc4Mu9Zu"
149158
accessToken = providers.environmentVariable("MODRINTH_TOKEN")
150-
minecraftVersions.add("${project.minecraft_version}")
151159

152160
requires("fabric-api")
153161
embeds("dark-matter")
154162
}
155163
curseforge {
156164
projectId = "622736"
157165
accessToken = providers.environmentVariable("CURSEFORGE_TOKEN")
158-
minecraftVersions.add("${project.minecraft_version}")
159166

160167
requires("fabric-api")
161168
embeds("dark-matter")

spotbugs.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<FindBugsFilter>
3+
<Match>
4+
<!-- Must be a full match -->
5+
<Class name="~.*\.mixin\..*Mixin" />
6+
<Bug pattern="BC_IMPOSSIBLE_CAST, BC_IMPOSSIBLE_INSTANCEOF, MS_SHOULD_BE_FINAL" />
7+
</Match>
8+
<Match>
9+
<Bug pattern="EI_EXPOSE_REP, EI_EXPOSE_REP2, PA_PUBLIC_PRIMITIVE_ATTRIBUTE, BC_UNCONFIRMED_CAST" />
10+
</Match>
11+
</FindBugsFilter>

src/main/java/com/github/vini2003/linkart/Linkart.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class Linkart implements ModInitializer {
2525
public static final Logger LOGGER = LogManager.getLogger(ID);
2626
public static final ConfigManager<LinkartConfiguration> CONFIG_MANAGER = ConfigManager.of(LinkartConfiguration.class, ID, LinkartConfiguration::new)
2727
.exceptionHandler((e, stage, path) -> LOGGER.error("Failed to {} {}", stage.name().toLowerCase(), FabricLoader.getInstance().getGameDir().relativize(path)));
28-
public static LinkartConfiguration CONFIG;
28+
private static LinkartConfiguration CONFIG;
2929
public static final TagKey<Item> LINKERS = TagKey.of(itemKey(), new Identifier(ID, "linkers"));
3030

3131
static {
@@ -38,22 +38,26 @@ public void onInitialize() {
3838
});
3939

4040
ServerWorldEvents.LOAD.register((server, world) -> {
41-
if (CONFIG.chunkloading) LoadingCarts.getOrCreate(world);
41+
if (getConfig().chunkloading) LoadingCarts.getOrCreate(world);
4242
});
4343

4444
ServerTickEvents.START_WORLD_TICK.register(world -> {
45-
if (CONFIG.chunkloading && ((PersistentStateAccessor) world.getPersistentStateManager()).linkart$loadedStates().containsKey("linkart_loading_carts")) {
45+
if (getConfig().chunkloading && ((PersistentStateAccessor) world.getPersistentStateManager()).linkart$loadedStates().containsKey("linkart_loading_carts")) {
4646
LoadingCarts.getOrCreate(world).tick(world);
4747
}
4848
});
4949
}
5050

5151
public static void loadConfig() {
5252
CONFIG = CONFIG_MANAGER.load(FabricLoader.getInstance().getConfigDir(), Context.of());
53-
CONFIG_MANAGER.save(FabricLoader.getInstance().getConfigDir(), CONFIG, Context.of());
53+
CONFIG_MANAGER.save(FabricLoader.getInstance().getConfigDir(), getConfig(), Context.of());
5454
}
5555

5656
private static RegistryKey<? extends Registry<Item>> itemKey() {
5757
return RegistryKey.ofRegistry(Identifier.tryParse("item"));
5858
}
59+
60+
public static LinkartConfiguration getConfig() {
61+
return CONFIG;
62+
}
5963
}

src/main/java/com/github/vini2003/linkart/api/LinkableMinecart.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22

33
import net.minecraft.entity.vehicle.AbstractMinecartEntity;
44
import net.minecraft.item.ItemStack;
5+
import org.jetbrains.annotations.Nullable;
56

67
public interface LinkableMinecart {
78

8-
default AbstractMinecartEntity linkart$getFollowing() {
9+
default @Nullable AbstractMinecartEntity linkart$getFollowing() {
910
throw new IllegalStateException("Implemented via mixin");
1011
}
1112

1213
default void linkart$setFollowing(AbstractMinecartEntity following) {
1314
throw new IllegalStateException("Implemented via mixin");
1415
}
1516

16-
default AbstractMinecartEntity linkart$getFollower() {
17+
default @Nullable AbstractMinecartEntity linkart$getFollower() {
1718
throw new IllegalStateException("Implemented via mixin");
1819
}
1920

src/main/java/com/github/vini2003/linkart/mixin/AbstractMinecartEntityMixin.java

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,32 +30,22 @@
3030
public abstract class AbstractMinecartEntityMixin extends Entity implements LinkableMinecart {
3131

3232
// Used to smooth out acceleration
33-
@Unique
34-
private static final double SAFE_SPEEDUP_THRESHOLD = 0.4;
35-
@Unique
36-
private static final double SMOOTH_SPEEDUP_AMOUNT = 0.2;
37-
@Unique
38-
private static final double SAFE_SPEEDUP_DIFFERENCE = 0.02;
39-
@Unique
40-
private double lastMovementLength = 0.0D; // Movement length on previous tick
41-
42-
@Unique
43-
private AbstractMinecartEntity linkart$following;
44-
@Unique
45-
private AbstractMinecartEntity linkart$follower;
46-
@Unique
47-
private UUID linkart$followingUUID;
48-
@Unique
49-
private UUID linkart$followerUUID;
50-
@Unique
51-
private ItemStack linkart$itemStack = ItemStack.EMPTY;
33+
@Unique private static final double SAFE_SPEEDUP_THRESHOLD = 0.4;
34+
@Unique private static final double SMOOTH_SPEEDUP_AMOUNT = 0.2;
35+
@Unique private static final double SAFE_SPEEDUP_DIFFERENCE = 0.02;
36+
@Unique private double lastMovementLength = 0.0D; // Movement length on previous tick
37+
38+
@Unique private AbstractMinecartEntity linkart$following;
39+
@Unique private AbstractMinecartEntity linkart$follower;
40+
@Unique private UUID linkart$followingUUID;
41+
@Unique private UUID linkart$followerUUID;
42+
@Unique private ItemStack linkart$itemStack = ItemStack.EMPTY;
5243

5344
public AbstractMinecartEntityMixin(EntityType<?> type, World world) {
5445
super(type, world);
5546
}
5647

57-
@Unique
58-
private double limitMovementLength(double targetMovementLength) {
48+
@Unique private double limitMovementLength(double targetMovementLength) {
5949
double cartLastMovementLength = this.lastMovementLength;
6050

6151
boolean isLeading = (this.linkart$getFollowing() == null && this.linkart$getFollower() != null);
@@ -116,9 +106,9 @@ private Vec3d modifiedMovement(Vec3d movement) {
116106

117107
Vec3d pos = getPos();
118108
Vec3d pos2 = linkart$getFollowing().getPos();
119-
double dist = Math.max(Math.abs(pos.distanceTo(pos2)) - Linkart.CONFIG.distance, 0);
109+
double dist = Math.max(Math.abs(pos.distanceTo(pos2)) - Linkart.getConfig().distance, 0);
120110
Vec3d vec3d = pos.relativize(pos2);
121-
vec3d = vec3d.multiply(Linkart.CONFIG.velocityMultiplier);
111+
vec3d = vec3d.multiply(Linkart.getConfig().velocityMultiplier);
122112

123113
// Check if we are on a sharp curve
124114
Vec3d vel = getVelocity();
@@ -132,7 +122,7 @@ private Vec3d modifiedMovement(Vec3d movement) {
132122

133123
if (differentDirection) {
134124
// Keep ourselves going at same speed if on curve
135-
dist += Linkart.CONFIG.distance;
125+
dist += Linkart.getConfig().distance;
136126
vec3d = vel;
137127
}
138128

@@ -142,15 +132,15 @@ private Vec3d modifiedMovement(Vec3d movement) {
142132
if (dist <= 1) {
143133
// Go slower (1.0->0.8) the closer (1->0) we are
144134
setVelocity(vec3d.multiply(0.8 + 0.2 * Math.abs(dist)));
145-
} else if (dist <= Linkart.CONFIG.pathfindingDistance) {
135+
} else if (dist <= Linkart.getConfig().pathfindingDistance) {
146136
setVelocity(vec3d);
147137
} else {
148138
CartUtils.unlinkFromParent(cast);
149139
}
150140

151-
if (Linkart.CONFIG.chunkloading) {
141+
if (Linkart.getConfig().chunkloading) {
152142
if (linkart$getFollower() != null && !CartUtils.approximatelyZero(this.getVelocity().length())) {
153-
((ServerWorld) this.getWorld()).getChunkManager().addTicket(ChunkTicketType.PORTAL, this.getChunkPos(), Linkart.CONFIG.chunkloadingRadius, this.getBlockPos());
143+
((ServerWorld) this.getWorld()).getChunkManager().addTicket(ChunkTicketType.PORTAL, this.getChunkPos(), Linkart.getConfig().chunkloadingRadius, this.getBlockPos());
154144
LoadingCarts.getOrCreate((ServerWorld) getWorld()).addCart(cast);
155145
} else {
156146
LoadingCarts.getOrCreate((ServerWorld) getWorld()).removeCart(cast);

src/main/java/com/github/vini2003/linkart/mixin/PlayerEntityMixin.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ protected PlayerEntityMixin(EntityType<? extends LivingEntity> entityType, World
2626
super(entityType, world);
2727
}
2828

29-
@Unique
30-
private CartOperation operation;
29+
@Unique private CartOperation operation;
3130

3231
@Inject(at = @At("HEAD"), method = "interact", cancellable = true)
3332
void onInteract(Entity entity, Hand hand, CallbackInfoReturnable<ActionResult> cir) {
@@ -59,8 +58,7 @@ void onInteract(Entity entity, Hand hand, CallbackInfoReturnable<ActionResult> c
5958
}
6059
}
6160

62-
@Unique
63-
private void finishOperation(CallbackInfoReturnable<ActionResult> cir, AbstractMinecartEntity minecart, ActionResult result) {
61+
@Unique private void finishOperation(CallbackInfoReturnable<ActionResult> cir, AbstractMinecartEntity minecart, ActionResult result) {
6462
if (result.isAccepted()) {
6563
((ServerWorld) minecart.getWorld()).spawnParticles(ParticleTypes.HAPPY_VILLAGER, minecart.getX(), minecart.getY() + 0.2, minecart.getZ(), 10, 0.5, 0.5, 0.5, 0.5);
6664
} else {

src/main/java/com/github/vini2003/linkart/utility/CartOperation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public enum Type {
1313
public ActionResult perform(AbstractMinecartEntity minecart, CartOperation operation, ItemStack stack) {
1414
if (minecart.linkart$getFollower() == operation.minecart()) return ActionResult.FAIL; //Linking a parent cart to its follower.
1515
if (minecart.linkart$getFollowing() != null) return ActionResult.FAIL; //Linking to an already linked cart.
16-
if (Math.abs(minecart.distanceTo(operation.minecart()) - 1) > Linkart.CONFIG.pathfindingDistance)
16+
if (Math.abs(minecart.distanceTo(operation.minecart()) - 1) > Linkart.getConfig().pathfindingDistance)
1717
return ActionResult.FAIL; //Linking beyond pathfindingDistance, will just break on first tick.
1818

1919
//Leading minecarts must never be linked to a follower. This creates an immovable object or an Ouroboros, if you will.

src/main/java/com/github/vini2003/linkart/utility/CartUtils.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ public static boolean approximatelyZero(double a) {
1919
}
2020

2121
public static void unlinkFromParent(AbstractMinecartEntity entity) {
22-
if (entity == null || entity.linkart$getFollowing() == null) return;
22+
if (entity == null) return;
23+
var following = entity.linkart$getFollowing();
24+
if (following == null) return;
2325

24-
entity.linkart$getFollowing().linkart$setFollower(null);
26+
following.linkart$setFollower(null);
2527
entity.linkart$setFollowing(null);
2628

2729
entity.setVelocity(0, 0, 0);

src/main/java/com/github/vini2003/linkart/utility/CollisionUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ public static boolean shouldCollide(Entity source, Entity target) {
1616

1717
check = check.linkart$getFollower();
1818
++i;
19-
} while (check != null && i < Linkart.CONFIG.collisionDepth);
19+
} while (check != null && i < Linkart.getConfig().collisionDepth);
2020

2121
check = (AbstractMinecartEntity) source;
2222
i = 0;
2323

2424
while (check != target) {
2525
check = check.linkart$getFollowing();
2626
++i;
27-
if (check == null || i >= Linkart.CONFIG.collisionDepth) {
27+
if (check == null || i >= Linkart.getConfig().collisionDepth) {
2828
return true;
2929
}
3030
}

0 commit comments

Comments
 (0)