Skip to content

Commit

Permalink
Another banger of a linter config change
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubydesic committed Mar 4, 2021
1 parent 7384c80 commit 192eb0e
Show file tree
Hide file tree
Showing 32 changed files with 447 additions and 116 deletions.
13 changes: 12 additions & 1 deletion .checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@
<module name="Checker">
<property name="charset" value="UTF-8"/>

<property name="severity" value="warning"/>
<property name="severity" value="error"/>

<property name="fileExtensions" value="java, properties, xml"/>

<!-- VS CUSTOM RULES -->
<module name="NewlineAtEndOfFile"/>
<!-- END VS CUSTOM RULES -->

<!-- Excludes all 'module-info.java' files -->
<!-- See https://checkstyle.org/config_filefilters.html -->
<module name="BeforeExecutionExclusionFileFilter">
Expand All @@ -48,6 +53,12 @@
</module>

<module name="TreeWalker">
<!-- VS CUSTOM RULES -->
<module name="FinalLocalVariable">
<property name="tokens" value="VARIABLE_DEF,PARAMETER_DEF"/>
<property name="validateEnhancedForLoopVariable" value="true"/>
</module>
<!-- END VS CUSTOM RULES -->
<module name="OuterTypeFilename"/>
<module name="IllegalTokenText">
<property name="tokens" value="STRING_LITERAL, CHAR_LITERAL"/>
Expand Down
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[*]
insert_final_newline = true
insert_final_newline=true

[*.{kt,kts,java}]
indent_size=4
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ out
!.idea/codeStyles/
# inspection profile
!.idea/inspectionProfiles/
# checkstyle config
!.idea/checkstyle-idea.xml
# saveactions config
!.idea/saveactions_settings.xml
# recommended plugins
!.idea/externalDependencies.xml

Expand Down
20 changes: 0 additions & 20 deletions .idea/checkstyle-idea.xml

This file was deleted.

3 changes: 3 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/externalDependencies.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions .idea/saveactions_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Physics-and-Ships

Valkyrien Skies remake part 3
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public interface WorldRendererChunkInfoAccessor {
* <p>The easy fix for this problem is to use a wildcard target.
*/
@Invoker(value = "<init>")
static WorldRenderer.ChunkInfo vs$new(WorldRenderer worldRenderer, ChunkBuilder.BuiltChunk chunk,
@Nullable Direction direction, int propagationLevel) {
static WorldRenderer.ChunkInfo vs$new(final WorldRenderer worldRenderer, final ChunkBuilder.BuiltChunk chunk,
@Nullable final Direction direction, final int propagationLevel) {
throw new AssertionError("MixinWorldRendererChunkInfo failed to apply");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.valkyrienskies.mod.mixin.block;

import net.minecraft.block.Block;
import net.minecraft.entity.ItemEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.joml.Vector3d;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.valkyrienskies.core.game.ships.ShipData;
import org.valkyrienskies.mod.common.VSGameUtilsKt;

@Mixin(Block.class)
public class MixinBlock {

/**
* Ensure that items drop in the world and not in the shipyard.
*/
@Redirect(
method = "dropStack",
at = @At(
value = "NEW",
target = "net/minecraft/entity/ItemEntity",
ordinal = 0
)
)
private static ItemEntity moveItemDrops(
// Constructor arguments
final World world, final double x, final double y, final double z, final ItemStack stack,
// dropStack arguments
final World ignore, final BlockPos pos, final ItemStack ignore2
) {
final ShipData ship = VSGameUtilsKt.getShipManagingPos(world, pos);
if (ship == null) {
// Vanilla behaviour
return new ItemEntity(world, x, y, z, stack);
}

// Extract random offset
final double dx = x - pos.getX();
final double dy = y - pos.getY();
final double dz = z - pos.getZ();

// Real position of item drop in world
final Vector3d p = VSGameUtilsKt.toWorldCoordinates(ship, pos);

return new ItemEntity(world, p.x + dx, p.y + dy, p.z + dz, stack);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package org.valkyrienskies.mod.mixin.client.particle;

import net.minecraft.client.particle.Particle;
import net.minecraft.client.world.ClientWorld;
import org.joml.Matrix4dc;
import org.joml.Vector3d;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.valkyrienskies.core.game.ships.ShipObject;
import org.valkyrienskies.mod.common.VSGameUtilsKt;

@Mixin(Particle.class)
public abstract class ParticleMixin {

@Shadow
public abstract void setPos(double x, double y, double z);

@Shadow
protected double velocityX;

@Shadow
protected double velocityY;

@Shadow
protected double velocityZ;

/**
* See also {@link org.valkyrienskies.mod.mixin.client.render.MixinWorldRenderer}
*/
@Inject(
method = "Lnet/minecraft/client/particle/Particle;<init>(Lnet/minecraft/client/world/ClientWorld;DDD)V",
at = @At("TAIL")
)
public void checkShipCoords(final ClientWorld world, final double x, final double y, final double z,
final CallbackInfo ci) {
final ShipObject ship = VSGameUtilsKt.getShipObjectManagingPos(world, (int) x >> 4, (int) z >> 4);
if (ship == null) {
return;
}

// in-world position
final Vector3d p = ship.getRenderTransform().getShipToWorldMatrix().transformPosition(new Vector3d(x, y, z));
this.setPos(p.x, p.y, p.z);
}

/**
* See also {@link org.valkyrienskies.mod.mixin.client.render.MixinWorldRenderer}
*/
@Inject(
method = "Lnet/minecraft/client/particle/Particle;<init>(Lnet/minecraft/client/world/ClientWorld;DDDDDD)V",
at = @At("TAIL")
)
public void checkShipPosAndVelocity(final ClientWorld world, final double x, final double y, final double z,
final double velocityX,
final double velocityY, final double velocityZ, final CallbackInfo ci) {

final ShipObject ship = VSGameUtilsKt.getShipObjectManagingPos(world, (int) x >> 4, (int) z >> 4);
if (ship == null) {
return;
}

final Matrix4dc transform = ship.getRenderTransform().getShipToWorldMatrix();
// in-world position
final Vector3d p = transform.transformPosition(new Vector3d(x, y, z));
// in-world velocity
final Vector3d v = transform
// Rotate velocity wrt ship transform
.transformDirection(new Vector3d(this.velocityX, this.velocityY, this.velocityZ))
// Tack on the ships linear velocity (no angular velocity param unfortunately)
.add(ship.getShipData().getPhysicsData().getLinearVelocity());

this.setPos(p.x, p.y, p.z);
this.velocityX = v.x;
this.velocityY = v.y;
this.velocityZ = v.z;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,19 @@ public class MixinBuiltChunkStorage {
* This mixin stores the [chunkBuilder] object from the constructor. It is used to create new render chunks.
*/
@Inject(method = "<init>", at = @At("TAIL"))
private void postInit(ChunkBuilder chunkBuilder, World world, int viewDistance, WorldRenderer worldRenderer,
CallbackInfo callbackInfo) {
private void postInit(final ChunkBuilder chunkBuilder, final World world, final int viewDistance,
final WorldRenderer worldRenderer, final CallbackInfo callbackInfo) {

this.vs$chunkBuilder = chunkBuilder;
}

/**
* This mixin creates render chunks for ship chunks.
*/
@Inject(method = "scheduleRebuild", at = @At("HEAD"), cancellable = true)
private void preScheduleRebuild(int x, int y, int z, boolean important, CallbackInfo callbackInfo) {
private void preScheduleRebuild(final int x, final int y, final int z, final boolean important,
final CallbackInfo callbackInfo) {

if (y < 0 || y >= sizeY) {
return; // Weird, but just ignore it
}
Expand All @@ -74,8 +77,8 @@ private void preScheduleRebuild(int x, int y, int z, boolean important, Callback
* This mixin allows {@link BuiltChunkStorage} to return the render chunks for ships.
*/
@Inject(method = "getRenderedChunk", at = @At("HEAD"), cancellable = true)
private void preGetRenderedChunk(BlockPos pos,
CallbackInfoReturnable<ChunkBuilder.BuiltChunk> callbackInfoReturnable) {
private void preGetRenderedChunk(final BlockPos pos,
final CallbackInfoReturnable<ChunkBuilder.BuiltChunk> callbackInfoReturnable) {
final int chunkX = MathHelper.floorDiv(pos.getX(), 16);
final int chunkY = MathHelper.floorDiv(pos.getY(), 16);
final int chunkZ = MathHelper.floorDiv(pos.getZ(), 16);
Expand Down
Loading

0 comments on commit 192eb0e

Please sign in to comment.