-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9920ceb
commit c43de8f
Showing
10 changed files
with
356 additions
and
90 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerDropItem_NetworkHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* OKTW Galaxy Project | ||
* Copyright (C) 2018-2022 | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package one.oktw.galaxy.mixin.event; | ||
|
||
import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket; | ||
import net.minecraft.server.network.ServerPlayNetworkHandler; | ||
import net.minecraft.server.network.ServerPlayerEntity; | ||
import one.oktw.galaxy.Main; | ||
import one.oktw.galaxy.event.type.PlayerDropItemEvent; | ||
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; | ||
|
||
@Mixin(ServerPlayNetworkHandler.class) | ||
public class MixinPlayerDropItem_NetworkHandler { | ||
@Shadow | ||
public ServerPlayerEntity player; | ||
|
||
@Inject( | ||
method = "onPlayerAction", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lnet/minecraft/server/network/ServerPlayerEntity;dropSelectedItem(Z)Z", | ||
shift = At.Shift.BEFORE | ||
), cancellable = true) | ||
private void onPlayerAction(PlayerActionC2SPacket packet, CallbackInfo ci) { | ||
Main main = Main.Companion.getMain(); | ||
if (main != null && main.getEventManager().emit(new PlayerDropItemEvent(player)).getCancel()) { | ||
ci.cancel(); | ||
player.currentScreenHandler.syncState(); | ||
} | ||
} | ||
|
||
|
||
} |
45 changes: 45 additions & 0 deletions
45
src/main/java/one/oktw/galaxy/mixin/event/MixinPlayerPickupItem_ItemEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* OKTW Galaxy Project | ||
* Copyright (C) 2018-2022 | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package one.oktw.galaxy.mixin.event; | ||
|
||
import net.minecraft.entity.ItemEntity; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.server.network.ServerPlayerEntity; | ||
import one.oktw.galaxy.Main; | ||
import one.oktw.galaxy.event.type.PlayerPickupItemEvent; | ||
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(ItemEntity.class) | ||
public class MixinPlayerPickupItem_ItemEntity { | ||
@Inject( | ||
method = "onPlayerCollision", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lnet/minecraft/entity/player/PlayerEntity;triggerItemPickedUpByEntityCriteria(Lnet/minecraft/entity/ItemEntity;)V", | ||
shift = At.Shift.AFTER | ||
)) | ||
private void onPlayerCollision(PlayerEntity player, CallbackInfo ci) { | ||
Main main = Main.Companion.getMain(); | ||
if (main == null) return; | ||
main.getEventManager().emit(new PlayerPickupItemEvent((ServerPlayerEntity) player)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/main/kotlin/one/oktw/galaxy/event/type/PlayerPickupItemEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* OKTW Galaxy Project | ||
* Copyright (C) 2018-2022 | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package one.oktw.galaxy.event.type | ||
|
||
import net.minecraft.server.network.ServerPlayerEntity | ||
|
||
class PlayerPickupItemEvent(val player: ServerPlayerEntity) : Event |
23 changes: 23 additions & 0 deletions
23
src/main/kotlin/one/oktw/galaxy/event/type/PlayerSwapItemInHandEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* OKTW Galaxy Project | ||
* Copyright (C) 2018-2022 | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package one.oktw.galaxy.event.type | ||
|
||
import net.minecraft.server.network.ServerPlayerEntity | ||
|
||
class PlayerSwapItemInHandEvent(val player: ServerPlayerEntity) : Event |
Oops, something went wrong.