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

Commit 491088c

Browse files
authored
Merge branch 'master' into master
2 parents 6180e4e + 7d7600f commit 491088c

File tree

268 files changed

+2133
-158
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

268 files changed

+2133
-158
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ allprojects {
5656
minecraft "com.mojang:minecraft:$Globals.mcVersion"
5757
mappings "net.fabricmc:yarn:${Globals.mcVersion}${Globals.yarnVersion}:v2"
5858
modCompile "net.fabricmc:fabric-loader:0.8.4+build.198"
59-
modCompile "net.fabricmc.fabric-api:fabric-api:0.4.2+build.246-1.14"
59+
modCompile "net.fabricmc.fabric-api:fabric-api:0.15.1+build.260-1.14"
6060

6161
implementation 'net.patchworkmc:patchwork-eventbus:2.0.1:all'
6262
implementation 'com.google.code.findbugs:jsr305:3.0.2'
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Minecraft Forge, Patchwork Project
3+
* Copyright (c) 2016-2020, 2019-2020
4+
*
5+
* This library is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation version 2.1
8+
* of the License.
9+
*
10+
* This library is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public
16+
* License along with this library; if not, write to the Free Software
17+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
package net.patchworkmc.api.input;
21+
22+
public interface ForgeMouse {
23+
boolean isMiddleDown();
24+
double getXVelocity();
25+
double getYVelocity();
26+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Minecraft Forge, Patchwork Project
3+
* Copyright (c) 2016-2020, 2019-2020
4+
*
5+
* This library is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation version 2.1
8+
* of the License.
9+
*
10+
* This library is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public
16+
* License along with this library; if not, write to the Free Software
17+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
package net.patchworkmc.impl.event.input;
21+
22+
import net.minecraftforge.client.event.InputEvent;
23+
import net.minecraftforge.common.MinecraftForge;
24+
import net.minecraftforge.eventbus.api.Event;
25+
26+
import net.minecraft.client.Mouse;
27+
28+
import net.patchworkmc.api.input.ForgeMouse;
29+
30+
public class InputEvents {
31+
public static void fireMouseInput(int button, int action, int mods) {
32+
MinecraftForge.EVENT_BUS.post(new InputEvent.MouseInputEvent(button, action, mods));
33+
}
34+
35+
public static void fireKeyInput(int key, int scanCode, int action, int modifiers) {
36+
MinecraftForge.EVENT_BUS.post(new InputEvent.KeyInputEvent(key, scanCode, action, modifiers));
37+
}
38+
39+
public static boolean onMouseScroll(Mouse mouseHelper, double scrollDelta) {
40+
final Event event = new InputEvent.MouseScrollEvent(scrollDelta, mouseHelper.wasLeftButtonClicked(), ((ForgeMouse) mouseHelper).isMiddleDown(), mouseHelper.wasRightButtonClicked(), mouseHelper.getX(), mouseHelper.getY());
41+
42+
return MinecraftForge.EVENT_BUS.post(event);
43+
}
44+
45+
public static boolean onRawMouseClicked(int button, int action, int mods) {
46+
return MinecraftForge.EVENT_BUS.post(new InputEvent.RawMouseEvent(button, action, mods));
47+
}
48+
}

patchwork-events-input/src/main/java/net/patchworkmc/mixin/event/input/MixinKeyboard.java

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

2020
package net.patchworkmc.mixin.event.input;
2121

22-
import net.minecraftforge.client.event.InputEvent;
23-
import net.minecraftforge.common.MinecraftForge;
2422
import org.spongepowered.asm.mixin.Mixin;
2523
import org.spongepowered.asm.mixin.Shadow;
2624
import org.spongepowered.asm.mixin.injection.At;
@@ -30,15 +28,17 @@
3028
import net.minecraft.client.Keyboard;
3129
import net.minecraft.client.MinecraftClient;
3230

31+
import net.patchworkmc.impl.event.input.InputEvents;
32+
3333
@Mixin(Keyboard.class)
3434
public abstract class MixinKeyboard {
3535
@Shadow
3636
MinecraftClient client;
3737

3838
@Inject(method = "onKey", at = @At("RETURN"))
39-
private void fireKeyInput(long window, int key, int scancode, int i, int j, CallbackInfo info) {
39+
private void fireKeyInput(long window, int key, int scancode, int action, int modifiers, CallbackInfo info) {
4040
if (window == this.client.window.getHandle()) {
41-
MinecraftForge.EVENT_BUS.post(new InputEvent.KeyInputEvent(key, scancode, i, j));
41+
InputEvents.fireKeyInput(key, scancode, action, modifiers);
4242
}
4343
}
4444
}

patchwork-events-input/src/main/java/net/patchworkmc/mixin/event/input/MixinMouse.java

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919

2020
package net.patchworkmc.mixin.event.input;
2121

22-
import net.minecraftforge.client.event.InputEvent;
23-
import net.minecraftforge.common.MinecraftForge;
24-
import net.minecraftforge.eventbus.api.Event;
2522
import org.spongepowered.asm.mixin.Mixin;
2623
import org.spongepowered.asm.mixin.Shadow;
2724
import org.spongepowered.asm.mixin.injection.At;
@@ -32,37 +29,52 @@
3229

3330
import net.minecraft.client.Mouse;
3431

35-
@Mixin(Mouse.class)
36-
public abstract class MixinMouse {
37-
@Shadow
38-
boolean middleButtonClicked;
39-
@Shadow
40-
abstract boolean wasLeftButtonClicked();
41-
@Shadow
42-
abstract boolean wasRightButtonClicked();
43-
@Shadow
44-
abstract double getX();
45-
@Shadow
46-
abstract double getY();
32+
import net.patchworkmc.api.input.ForgeMouse;
33+
import net.patchworkmc.impl.event.input.InputEvents;
4734

35+
@Mixin(Mouse.class)
36+
public abstract class MixinMouse implements ForgeMouse {
4837
@Inject(method = "onMouseButton", at = @At("RETURN"), cancellable = true)
4938
private void fireMouseInput(long window, int button, int action, int mods, CallbackInfo info) {
50-
MinecraftForge.EVENT_BUS.post(new InputEvent.MouseInputEvent(button, action, mods));
39+
InputEvents.fireMouseInput(button, action, mods);
5140
}
5241

5342
@Inject(method = "onMouseButton", at = @At(value = "FIELD", ordinal = 3, target = "Lnet/minecraft/client/Mouse;client:Lnet/minecraft/client/MinecraftClient;", shift = Shift.BEFORE), cancellable = true)
5443
private void onRawMouseClicked(long window, int button, int action, int mods, CallbackInfo info) {
55-
if (MinecraftForge.EVENT_BUS.post(new InputEvent.RawMouseEvent(button, action, mods))) {
44+
if (InputEvents.onRawMouseClicked(button, action, mods)) {
5645
info.cancel();
5746
}
5847
}
5948

6049
@Inject(method = "onMouseScroll", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isSpectator()Z", shift = Shift.BEFORE), cancellable = true)
61-
private void onMouseScroll(long window, double d, double e, CallbackInfo info, double f, float i) {
62-
final Event event = new InputEvent.MouseScrollEvent(f, wasLeftButtonClicked(), middleButtonClicked, wasRightButtonClicked(), getX(), getY());
63-
64-
if (MinecraftForge.EVENT_BUS.post(event)) {
50+
private void onMouseScroll(long window, double d, double e, CallbackInfo info, double scrollDelta, float i) {
51+
if (InputEvents.onMouseScroll((Mouse) (Object) this, scrollDelta)) {
6552
info.cancel();
6653
}
6754
}
55+
56+
// Methods added by forge
57+
@Shadow
58+
boolean middleButtonClicked;
59+
60+
@Shadow
61+
double cursorDeltaX;
62+
63+
@Shadow
64+
double cursorDeltaY;
65+
66+
@Override
67+
public boolean isMiddleDown() {
68+
return middleButtonClicked;
69+
}
70+
71+
@Override
72+
public double getXVelocity() {
73+
return cursorDeltaX;
74+
}
75+
76+
@Override
77+
public double getYVelocity() {
78+
return cursorDeltaY;
79+
}
6880
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ public Watch(ServerPlayerEntity player, ChunkPos pos, ServerWorld world) {
9191
*
9292
* <p>This event is fired on the {@link net.minecraftforge.common.MinecraftForge#EVENT_BUS}.</p>
9393
*/
94-
/* TODO public static class UnWatch extends ChunkWatchEvent {
94+
public static class UnWatch extends ChunkWatchEvent {
9595
public UnWatch(ServerPlayerEntity player, ChunkPos pos, ServerWorld world) {
9696
super(player, pos, world);
9797
}
98-
}*/
98+
}
9999
}

patchwork-events-world/src/main/java/net/patchworkmc/impl/event/world/WorldEvents.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import net.minecraftforge.common.MinecraftForge;
2626
import net.minecraftforge.event.world.BlockEvent;
27+
import net.minecraftforge.event.world.ChunkWatchEvent;
2728
import net.minecraftforge.event.world.WorldEvent;
2829

2930
import net.minecraft.block.BlockState;
@@ -32,12 +33,19 @@
3233
import net.minecraft.util.DefaultedList;
3334
import net.minecraft.world.World;
3435
import net.minecraft.entity.EntityCategory;
36+
import net.minecraft.server.network.ServerPlayerEntity;
37+
import net.minecraft.server.world.ServerWorld;
3538
import net.minecraft.util.math.BlockPos;
39+
import net.minecraft.util.math.ChunkPos;
3640
import net.minecraft.world.IWorld;
3741
import net.minecraft.world.biome.Biome;
42+
import net.minecraft.world.dimension.DimensionType;
3843
import net.minecraft.world.level.LevelInfo;
3944

40-
public class WorldEvents {
45+
import net.fabricmc.api.ModInitializer;
46+
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerWorldEvents;
47+
48+
public class WorldEvents implements ModInitializer {
4149
public static boolean onCreateWorldSpawn(IWorld world, LevelInfo settings) {
4250
return MinecraftForge.EVENT_BUS.post(new WorldEvent.CreateSpawnPosition(world, settings));
4351
}
@@ -70,4 +78,23 @@ public static float fireBlockHarvesting(DefaultedList<ItemStack> drops, World wo
7078
MinecraftForge.EVENT_BUS.post(event);
7179
return event.getDropChance();
7280
}
81+
82+
public static void fireChunkWatch(boolean watch, ServerPlayerEntity entity, ChunkPos chunkpos, ServerWorld world) {
83+
if (watch) {
84+
MinecraftForge.EVENT_BUS.post(new ChunkWatchEvent.Watch(entity, chunkpos, world));
85+
} else {
86+
MinecraftForge.EVENT_BUS.post(new ChunkWatchEvent.UnWatch(entity, chunkpos, world));
87+
}
88+
}
89+
90+
@Override
91+
public void onInitialize() {
92+
ServerWorldEvents.LOAD.register((server, world) -> {
93+
// Fabric fires this much earlier than Forge does for the overworld
94+
// So, we're going to manually fire it for the overworld.
95+
if (world.getDimension().getType() != DimensionType.OVERWORLD) {
96+
onWorldLoad(world);
97+
}
98+
});
99+
}
73100
}

patchwork-events-world/src/main/java/net/patchworkmc/mixin/event/world/MixinMinecraftServer.java

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@
2020
package net.patchworkmc.mixin.event.world;
2121

2222
import java.io.IOException;
23-
import java.util.Iterator;
2423
import java.util.Map;
2524

2625
import org.spongepowered.asm.mixin.Final;
2726
import org.spongepowered.asm.mixin.Mixin;
2827
import org.spongepowered.asm.mixin.Shadow;
2928
import org.spongepowered.asm.mixin.injection.At;
29+
import org.spongepowered.asm.mixin.injection.Inject;
3030
import org.spongepowered.asm.mixin.injection.Redirect;
31+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
3132

3233
import net.minecraft.server.MinecraftServer;
3334
import net.minecraft.server.ServerTask;
@@ -47,42 +48,10 @@ public MixinMinecraftServer(String name) {
4748
@Final
4849
private Map<DimensionType, ServerWorld> worlds;
4950

50-
/*
51-
// This is a variant of the world load hook that is less likely to break mods and more likely to break on updates.
52-
// Should get called once per loop, regardless of which if branch it takes.
53-
@Inject(
54-
method = "createWorlds",
55-
slice = @Slice(
56-
from = @At(value = "INVOKE", target = "java/util/Iterator.hasNext ()Z")
57-
),
58-
at = @At(value = "JUMP", opcode = Opcodes.GOTO),
59-
locals = LocalCapture.CAPTURE_FAILHARD
60-
)
61-
private void hookCreateWorlds(WorldSaveHandler worldSaveHandler, LevelProperties properties, LevelInfo levelInfo, WorldGenerationProgressListener worldGenerationProgressListener, CallbackInfo ci, ServerWorld serverWorld, ServerWorld serverWorld2, Iterator var7, DimensionType dimensionType) {
62-
WorldEvents.onWorldLoad(this.worlds.get(dimensionType));
63-
}
64-
65-
*/
66-
67-
// This injection gets called at the beginning of each loop, and is used to special case the overworld dimension type.
68-
@Redirect(method = "createWorlds", at = @At(value = "INVOKE", target = "java/util/Iterator.next ()Ljava/lang/Object;"))
69-
private Object proxyNextWorldToSpecialCaseOverworld(Iterator<DimensionType> iterator) {
70-
DimensionType type = iterator.next();
71-
72-
if (type == DimensionType.OVERWORLD) {
73-
WorldEvents.onWorldLoad(this.worlds.get(type));
74-
}
75-
76-
return type;
77-
}
78-
79-
// This injection handles every other dimension type.
80-
@Redirect(method = "createWorlds", at = @At(value = "INVOKE", target = "java/util/Map.put (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", ordinal = 1))
81-
private Object proxyPutWorld(Map<Object, Object> worlds, Object type, Object world) {
82-
worlds.put(type, world);
83-
WorldEvents.onWorldLoad((ServerWorld) world);
84-
85-
return world;
51+
// Fabric usually fires the event much earlier in the method, so this is just picking a point closer to when Forge would fire it.
52+
@Inject(method = "createWorlds", at = @At(value = "INVOKE", target = "net/minecraft/world/dimension/DimensionType.getAll ()Ljava/lang/Iterable;"))
53+
private void fireLoadForOverworld(CallbackInfo info) {
54+
WorldEvents.onWorldLoad(worlds.get(DimensionType.OVERWORLD));
8655
}
8756

8857
@Redirect(method = "shutdown", at = @At(value = "INVOKE", target = "net/minecraft/server/world/ServerWorld.close ()V"))

patchwork-events-world/src/main/java/net/patchworkmc/mixin/event/world/MixinThreadedAnvilChunkStorage.java

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

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

22-
import net.minecraftforge.common.MinecraftForge;
23-
import net.minecraftforge.event.world.ChunkWatchEvent;
2422
import org.spongepowered.asm.mixin.Mixin;
2523
import org.spongepowered.asm.mixin.Shadow;
2624
import org.spongepowered.asm.mixin.injection.At;
@@ -33,17 +31,17 @@
3331
import net.minecraft.server.world.ThreadedAnvilChunkStorage;
3432
import net.minecraft.util.math.ChunkPos;
3533

34+
import net.patchworkmc.impl.event.world.WorldEvents;
35+
3636
@Mixin(ThreadedAnvilChunkStorage.class)
3737
public class MixinThreadedAnvilChunkStorage {
3838
@Shadow
3939
private ServerWorld world;
4040

4141
@Inject(method = "sendWatchPackets", at = @At("HEAD"))
4242
private void fireWatchEvents(ServerPlayerEntity player, ChunkPos pos, Packet<?>[] packets, boolean withinMaxWatchDistance, boolean withinViewDistance, CallbackInfo callback) {
43-
if (withinViewDistance && !withinMaxWatchDistance) {
44-
ChunkWatchEvent.Watch event = new ChunkWatchEvent.Watch(player, pos, world);
45-
46-
MinecraftForge.EVENT_BUS.post(event);
43+
if (this.world == player.world && withinMaxWatchDistance != withinViewDistance) {
44+
WorldEvents.fireChunkWatch(withinViewDistance, player, pos, this.world);
4745
}
4846
}
4947
}

patchwork-events-world/src/main/resources/fabric.mod.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
],
1515
"depends": {
1616
"fabricloader": ">=0.8.4",
17+
"fabric": ">=0.15.0",
1718
"patchwork-fml": "*"
1819
},
1920
"mixins": [

0 commit comments

Comments
 (0)