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

Commit e4b8260

Browse files
committed
Checkstyle fixes to patchwork-events-lifecycle and patchwork-events-world
1 parent 1db1e42 commit e4b8260

11 files changed

Lines changed: 86 additions & 68 deletions

File tree

patchwork-events-lifecycle/src/main/java/com/patchworkmc/impl/event/lifecycle/LifecycleEvents.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,17 @@
1919

2020
package com.patchworkmc.impl.event.lifecycle;
2121

22-
import net.minecraft.entity.player.PlayerEntity;
23-
import net.minecraft.world.World;
2422
import net.minecraftforge.common.MinecraftForge;
2523
import net.minecraftforge.event.TickEvent;
2624
import net.minecraftforge.fml.LogicalSide;
2725

26+
import net.minecraft.entity.player.PlayerEntity;
27+
import net.minecraft.world.World;
28+
2829
import net.fabricmc.api.ModInitializer;
2930
import net.fabricmc.fabric.api.event.world.WorldTickCallback;
3031

3132
public class LifecycleEvents implements ModInitializer {
32-
@Override
33-
public void onInitialize() {
34-
WorldTickCallback.EVENT.register(world -> fireWorldTickEvent(TickEvent.Phase.END, world));
35-
}
36-
3733
public static void fireWorldTickEvent(TickEvent.Phase phase, World world) {
3834
LogicalSide side = world.isClient() ? LogicalSide.CLIENT : LogicalSide.SERVER;
3935
TickEvent.WorldTickEvent event = new TickEvent.WorldTickEvent(side, phase, world);
@@ -48,4 +44,9 @@ public static void onPlayerPreTick(PlayerEntity player) {
4844
public static void onPlayerPostTick(PlayerEntity player) {
4945
MinecraftForge.EVENT_BUS.post(new TickEvent.PlayerTickEvent(TickEvent.Phase.END, player));
5046
}
47+
48+
@Override
49+
public void onInitialize() {
50+
WorldTickCallback.EVENT.register(world -> fireWorldTickEvent(TickEvent.Phase.END, world));
51+
}
5152
}

patchwork-events-lifecycle/src/main/java/com/patchworkmc/mixin/event/lifecycle/MixinClientWorld.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,21 @@
2121

2222
import java.util.function.BooleanSupplier;
2323

24-
import net.minecraft.client.world.ClientWorld;
25-
import net.minecraft.world.World;
2624
import net.minecraftforge.event.TickEvent;
2725
import org.spongepowered.asm.mixin.Mixin;
2826
import org.spongepowered.asm.mixin.injection.At;
2927
import org.spongepowered.asm.mixin.injection.Inject;
3028
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
3129

30+
import net.minecraft.client.world.ClientWorld;
31+
import net.minecraft.world.World;
32+
3233
import com.patchworkmc.impl.event.lifecycle.LifecycleEvents;
3334

3435
@Mixin(ClientWorld.class)
3536
public class MixinClientWorld {
3637
@Inject(method = "tick", at = @At("HEAD"))
3738
private void tick(BooleanSupplier supplier, CallbackInfo callback) {
38-
LifecycleEvents.fireWorldTickEvent(TickEvent.Phase.START, (World)(Object)this);
39+
LifecycleEvents.fireWorldTickEvent(TickEvent.Phase.START, (World) (Object) this);
3940
}
4041
}

patchwork-events-lifecycle/src/main/java/com/patchworkmc/mixin/event/lifecycle/MixinPlayerEntity.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,24 @@
1919

2020
package com.patchworkmc.mixin.event.lifecycle;
2121

22-
import net.minecraft.entity.player.PlayerEntity;
2322
import org.spongepowered.asm.mixin.Mixin;
2423
import org.spongepowered.asm.mixin.injection.At;
2524
import org.spongepowered.asm.mixin.injection.Inject;
2625
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
2726

27+
import net.minecraft.entity.player.PlayerEntity;
28+
2829
import com.patchworkmc.impl.event.lifecycle.LifecycleEvents;
2930

3031
@Mixin(PlayerEntity.class)
3132
public class MixinPlayerEntity {
3233
@Inject(method = "tick", at = @At("HEAD"))
3334
public void onPlayerPreTick(CallbackInfo callback) {
34-
LifecycleEvents.onPlayerPreTick((PlayerEntity)(Object)this);
35+
LifecycleEvents.onPlayerPreTick((PlayerEntity) (Object) this);
3536
}
3637

3738
@Inject(method = "tick", at = @At("TAIL"))
3839
public void onPlayerPostTick(CallbackInfo callback) {
39-
LifecycleEvents.onPlayerPostTick((PlayerEntity)(Object)this);
40+
LifecycleEvents.onPlayerPostTick((PlayerEntity) (Object) this);
4041
}
4142
}

patchwork-events-lifecycle/src/main/java/com/patchworkmc/mixin/event/lifecycle/MixinServerWorld.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,21 @@
2121

2222
import java.util.function.BooleanSupplier;
2323

24-
import net.minecraft.server.world.ServerWorld;
25-
import net.minecraft.world.World;
2624
import net.minecraftforge.event.TickEvent;
2725
import org.spongepowered.asm.mixin.Mixin;
2826
import org.spongepowered.asm.mixin.injection.At;
2927
import org.spongepowered.asm.mixin.injection.Inject;
3028
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
3129

30+
import net.minecraft.server.world.ServerWorld;
31+
import net.minecraft.world.World;
32+
3233
import com.patchworkmc.impl.event.lifecycle.LifecycleEvents;
3334

3435
@Mixin(ServerWorld.class)
3536
public class MixinServerWorld {
3637
@Inject(method = "tick", at = @At("HEAD"))
3738
private void tick(BooleanSupplier supplier, CallbackInfo callback) {
38-
LifecycleEvents.fireWorldTickEvent(TickEvent.Phase.START, (World)(Object)this);
39+
LifecycleEvents.fireWorldTickEvent(TickEvent.Phase.START, (World) (Object) this);
3940
}
4041
}

patchwork-events-lifecycle/src/main/java/net/minecraftforge/event/TickEvent.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@
1919

2020
package net.minecraftforge.event;
2121

22+
import net.minecraftforge.eventbus.api.Event;
23+
import net.minecraftforge.fml.LogicalSide;
24+
2225
import net.minecraft.entity.player.PlayerEntity;
2326
import net.minecraft.server.network.ServerPlayerEntity;
2427
import net.minecraft.world.World;
25-
import net.minecraftforge.eventbus.api.Event;
26-
import net.minecraftforge.fml.LogicalSide;
2728

2829
public class TickEvent extends Event {
2930
public final Type type;
@@ -40,6 +41,7 @@ public TickEvent(Type type, LogicalSide side, Phase phase) {
4041
this.side = side;
4142
this.phase = phase;
4243
}
44+
4345
public enum Type {
4446
WORLD, PLAYER, CLIENT, SERVER, RENDER;
4547
}

patchwork-events-lifecycle/src/main/resources/patchwork-events-lifecycle.mixins.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
"compatibilityLevel": "JAVA_8",
55
"mixins": [
66
"MixinPlayerEntity",
7-
"MixinServerWorld"
7+
"MixinServerWorld"
88
],
99
"client": [
1010
"MixinClientWorld"
1111
],
1212
"injectors": {
13-
"defaultRequire": 1
13+
"defaultRequire": 1
1414
}
1515
}

patchwork-events-world/src/main/java/com/patchworkmc/mixin/event.world/MixinServerPlayerInteractionManager.java renamed to patchwork-events-world/src/main/java/com/patchworkmc/mixin/event/world/MixinServerPlayerInteractionManager.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@
1919

2020
package com.patchworkmc.mixin.event.world;
2121

22+
import net.minecraftforge.common.MinecraftForge;
23+
import net.minecraftforge.event.world.BlockEvent;
24+
import org.spongepowered.asm.mixin.Mixin;
25+
import org.spongepowered.asm.mixin.Shadow;
26+
import org.spongepowered.asm.mixin.injection.At;
27+
import org.spongepowered.asm.mixin.injection.Inject;
28+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
29+
2230
import net.minecraft.block.BlockState;
2331
import net.minecraft.block.entity.BlockEntity;
2432
import net.minecraft.client.network.packet.BlockEntityUpdateS2CPacket;
@@ -30,13 +38,6 @@
3038
import net.minecraft.util.math.BlockPos;
3139
import net.minecraft.world.EmptyBlockView;
3240
import net.minecraft.world.GameMode;
33-
import net.minecraftforge.common.MinecraftForge;
34-
import net.minecraftforge.event.world.BlockEvent;
35-
import org.spongepowered.asm.mixin.Mixin;
36-
import org.spongepowered.asm.mixin.Shadow;
37-
import org.spongepowered.asm.mixin.injection.At;
38-
import org.spongepowered.asm.mixin.injection.Inject;
39-
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
4041

4142
@Mixin(ServerPlayerInteractionManager.class)
4243
public class MixinServerPlayerInteractionManager {
@@ -52,6 +53,7 @@ private void hookBreakBlock(BlockPos pos, CallbackInfoReturnable<Boolean> callba
5253
boolean preCancelEvent = false;
5354

5455
ItemStack itemstack = player.getMainHandStack();
56+
5557
if (!itemstack.isEmpty() && !itemstack.getItem().canMine(world.getBlockState(pos), world, pos, player)) {
5658
preCancelEvent = true;
5759
}
@@ -81,6 +83,7 @@ private void hookBreakBlock(BlockPos pos, CallbackInfoReturnable<Boolean> callba
8183

8284
// Update any block entity data for this block
8385
BlockEntity entity = world.getBlockEntity(pos);
86+
8487
if (entity != null) {
8588
BlockEntityUpdateS2CPacket packet = entity.toUpdatePacket();
8689

@@ -90,7 +93,7 @@ private void hookBreakBlock(BlockPos pos, CallbackInfoReturnable<Boolean> callba
9093
}
9194

9295
callback.setReturnValue(false);
93-
} else if(event.getExpToDrop() != 0) {
96+
} else if (event.getExpToDrop() != 0) {
9497
// TODO: Drop experience
9598
throw new UnsupportedOperationException("Cannot drop exp from a BreakEvent yet");
9699
}

patchwork-events-world/src/main/java/com/patchworkmc/mixin/event.world/MixinThreadedAnvilChunkStorage.java renamed to patchwork-events-world/src/main/java/com/patchworkmc/mixin/event/world/MixinThreadedAnvilChunkStorage.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@
1919

2020
package com.patchworkmc.mixin.event.world;
2121

22-
import net.minecraft.network.Packet;
23-
import net.minecraft.server.network.ServerPlayerEntity;
24-
import net.minecraft.server.world.ServerWorld;
25-
import net.minecraft.server.world.ThreadedAnvilChunkStorage;
26-
import net.minecraft.util.math.ChunkPos;
2722
import net.minecraftforge.common.MinecraftForge;
2823
import net.minecraftforge.event.world.ChunkWatchEvent;
2924
import org.spongepowered.asm.mixin.Mixin;
@@ -32,14 +27,20 @@
3227
import org.spongepowered.asm.mixin.injection.Inject;
3328
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
3429

30+
import net.minecraft.network.Packet;
31+
import net.minecraft.server.network.ServerPlayerEntity;
32+
import net.minecraft.server.world.ServerWorld;
33+
import net.minecraft.server.world.ThreadedAnvilChunkStorage;
34+
import net.minecraft.util.math.ChunkPos;
35+
3536
@Mixin(ThreadedAnvilChunkStorage.class)
3637
public class MixinThreadedAnvilChunkStorage {
3738
@Shadow
3839
private ServerWorld world;
3940

4041
@Inject(method = "sendWatchPackets", at = @At("HEAD"))
4142
private void fireWatchEvents(ServerPlayerEntity player, ChunkPos pos, Packet<?>[] packets, boolean withinMaxWatchDistance, boolean withinViewDistance, CallbackInfo callback) {
42-
if(withinViewDistance && !withinMaxWatchDistance) {
43+
if (withinViewDistance && !withinMaxWatchDistance) {
4344
ChunkWatchEvent.Watch event = new ChunkWatchEvent.Watch(player, pos, world);
4445

4546
MinecraftForge.EVENT_BUS.post(event);

patchwork-events-world/src/main/java/net/minecraftforge/event/world/BlockEvent.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@
1919

2020
package net.minecraftforge.event.world;
2121

22+
import net.minecraftforge.eventbus.api.Event;
23+
2224
import net.minecraft.block.BlockState;
2325
import net.minecraft.entity.player.PlayerEntity;
2426
import net.minecraft.util.math.BlockPos;
2527
import net.minecraft.world.IWorld;
2628
import net.minecraft.world.World;
27-
import net.minecraftforge.eventbus.api.Event;
2829

2930
public class BlockEvent extends Event {
3031
private final IWorld world;
@@ -55,12 +56,14 @@ public BlockState getState() {
5556
}
5657

5758
/**
58-
* Event that is fired when an Block is about to be broken by a player
59-
* Canceling this event will prevent the Block from being broken.
59+
* This event is fired when an {@link net.minecraft.block.Block} is about to be broken by a player.
60+
*
61+
* <p>This event is cancellable.
62+
* Cancelling this event will prevent the {@link net.minecraft.block.Block} from being broken.</p>
6063
*/
6164
public static class BreakEvent extends BlockEvent {
6265
/**
63-
* Reference to the Player who broke the block. If no player is available, use an EntityFakePlayer
66+
* Reference to the {@link PlayerEntity} who broke the block. If no player is available, use an {@link EntityFakePlayer}
6467
*/
6568
private final PlayerEntity player;
6669
private int exp;
@@ -77,8 +80,10 @@ public BreakEvent(World world, BlockPos pos, BlockState state, PlayerEntity play
7780
this.exp = 0;
7881

7982
// TODO: BlockState#getExpDrop
80-
/*if (state == null || !ForgeHooks.canHarvestBlock(state, player, world, pos)) // Handle empty block or player unable to break block scenario
81-
{
83+
84+
/*
85+
// Handle empty block or player unable to break block scenario
86+
if (state == null || !ForgeHooks.canHarvestBlock(state, player, world, pos)) {
8287
this.exp = 0;
8388
} else {
8489
int bonusLevel = EnchantmentHelper.getLevel(Enchantments.FORTUNE, player.getHeldItemMainhand());
@@ -92,16 +97,16 @@ public PlayerEntity getPlayer() {
9297
}
9398

9499
/**
95-
* Get the experience dropped by the block after the event has processed
100+
* Gets the experience dropped by the block after the event has processed.
96101
*
97-
* @return The experience to drop or 0 if the event was canceled
102+
* @return The experience to drop or 0 if the event was cancelled
98103
*/
99104
public int getExpToDrop() {
100105
return this.isCanceled() ? 0 : exp;
101106
}
102107

103108
/**
104-
* Set the amount of experience dropped by the block after the event has processed
109+
* Sets the amount of experience dropped by the block after the event has processed.
105110
*
106111
* @param exp 1 or higher to drop experience, else nothing will drop
107112
*/

patchwork-events-world/src/main/java/net/minecraftforge/event/world/ChunkWatchEvent.java

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@
1919

2020
package net.minecraftforge.event.world;
2121

22+
import net.minecraftforge.eventbus.api.Event;
23+
2224
import net.minecraft.server.network.ServerPlayerEntity;
2325
import net.minecraft.server.world.ServerWorld;
2426
import net.minecraft.util.math.ChunkPos;
25-
import net.minecraftforge.eventbus.api.Event;
2627

2728
/**
2829
* ChunkWatchEvent is fired when an event involving a chunk being watched occurs.<br>
@@ -35,8 +36,8 @@
3536
* The {@link #player}'s world may not be the same as the world of the chunk
3637
* when the player is teleporting to another dimension.<br>
3738
* <br>
38-
* All children of this event are fired on the {@link MinecraftForge#EVENT_BUS}.<br>
39-
**/
39+
* All children of this event are fired on the {@link net.minecraftforge.common.MinecraftForge#EVENT_BUS}.<br>
40+
*/
4041
public class ChunkWatchEvent extends Event {
4142
private final ServerWorld world;
4243
private final ServerPlayerEntity player;
@@ -66,16 +67,17 @@ public ServerWorld getWorld() {
6667
}
6768

6869
/**
69-
* ChunkWatchEvent.Watch is fired when an EntityPlayer begins watching a chunk.<br>
70-
* This event is fired when a chunk is added to the watched chunks of an EntityPlayer in
71-
* {@link net.minecraft.server.world.PlayerChunkWatchingManager#addPlayer(EntityPlayerMP)} and {@link PlayerChunkMapEntry#sendToPlayers()}. <br>
72-
* <br>
73-
* This event is not cancellable.<br>
74-
* <br>
75-
* This event does not have a result.
76-
* <br>
77-
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
78-
**/
70+
* This event is fired when an EntityPlayer begins watching a chunk.
71+
*
72+
* <p>This event is fired when a {@link ChunkPos} is added to the watched chunks of an {@link ServerPlayerEntity} in
73+
* {@link net.minecraft.server.world.ThreadedAnvilChunkStorage#sendWatchPackets(ServerPlayerEntity, ChunkPos, net.minecraft.network.Packet[], boolean, boolean)}</p>
74+
*
75+
* <p>This event is not cancellable.</p>
76+
*
77+
* <p>This event does not have a result.</p>
78+
*
79+
* <p>This event is fired on the {@link net.minecraftforge.common.MinecraftForge#EVENT_BUS}.</p>
80+
*/
7981
public static class Watch extends ChunkWatchEvent {
8082
// For EventBus
8183
public Watch() {
@@ -88,16 +90,17 @@ public Watch(ServerPlayerEntity player, ChunkPos pos, ServerWorld world) {
8890
}
8991

9092
/**
91-
* ChunkWatchEvent.UnWatch is fired when an EntityPlayer stops watching a chunk.<br>
92-
* This event is fired when a chunk is removed from the watched chunks of an EntityPlayer in
93-
* {@link PlayerChunkMapEntry#removePlayer(EntityPlayerMP)}. <br>
94-
* <br>
95-
* This event is not cancellable.<br>
96-
* <br>
97-
* This event does not have a result.<br>
98-
* <br>
99-
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
100-
**/
93+
* This event is fired when a {@link ServerPlayerEntity} stops watching a chunk.
94+
*
95+
* <p>This event is fired when a {@link ChunkPos} is removed the watched chunks of an {@link ServerPlayerEntity} in
96+
* {@link net.minecraft.server.world.ThreadedAnvilChunkStorage#sendWatchPackets(ServerPlayerEntity, ChunkPos, net.minecraft.network.Packet[], boolean, boolean)}</p>
97+
*
98+
* <p>This event is not cancellable.</p>
99+
*
100+
* <p>This event does not have a result.</p>
101+
*
102+
* <p>This event is fired on the {@link net.minecraftforge.common.MinecraftForge#EVENT_BUS}.</p>
103+
*/
101104
/* TODO public static class UnWatch extends ChunkWatchEvent {
102105
public UnWatch(ServerPlayerEntity player, ChunkPos pos, ServerWorld world) {
103106
super(player, pos, world);

0 commit comments

Comments
 (0)