two more events, and nbt cleanups
This commit is contained in:
1 parent
dab9c5debe
commit
2167c929d5
10 files changed
+462
-207
No files matched your search
@@ -14,6 +14,10 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.util.function.BooleanSupplier;
|
||||
|
||||
import static carpet.script.CarpetEventServer.Event.ENDER_TICK;
|
||||
import static carpet.script.CarpetEventServer.Event.NETHER_TICK;
|
||||
import static carpet.script.CarpetEventServer.Event.TICK;
|
||||
|
||||
@Mixin(MinecraftServer.class)
|
||||
public abstract class MinecraftServer_scarpetMixin extends NonBlockingThreadExecutor<ServerTask> implements MinecraftServerInterface
|
||||
{
|
||||
@@ -42,6 +46,8 @@ public abstract class MinecraftServer_scarpetMixin extends NonBlockingThreadExec
|
||||
))
|
||||
public void tickTasks(BooleanSupplier booleanSupplier_1, CallbackInfo ci)
|
||||
{
|
||||
CarpetServer.scriptServer.events.onTick();
|
||||
TICK.onTick();
|
||||
NETHER_TICK.onTick();
|
||||
ENDER_TICK.onTick();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.CarpetServer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.server.network.ServerPlayNetworkHandler;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.network.packet.ClientCommandC2SPacket;
|
||||
@@ -16,8 +16,25 @@ 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.Redirect;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import static carpet.script.CarpetEventServer.Event.PLAYER_ATTACKS_ENTITY;
|
||||
import static carpet.script.CarpetEventServer.Event.PLAYER_CLICKS_BLOCK;
|
||||
import static carpet.script.CarpetEventServer.Event.PLAYER_DEPLOYS_ELYTRA;
|
||||
import static carpet.script.CarpetEventServer.Event.PLAYER_INERACTSW_WITH_ENTITY;
|
||||
import static carpet.script.CarpetEventServer.Event.PLAYER_RELEASED_ITEM;
|
||||
import static carpet.script.CarpetEventServer.Event.PLAYER_RIDES;
|
||||
import static carpet.script.CarpetEventServer.Event.PLAYER_JUMPS;
|
||||
import static carpet.script.CarpetEventServer.Event.PLAYER_RIGHT_CLICKS_BLOCK;
|
||||
import static carpet.script.CarpetEventServer.Event.PLAYER_STARTS_SNEAKING;
|
||||
import static carpet.script.CarpetEventServer.Event.PLAYER_STARTS_SPRINTING;
|
||||
import static carpet.script.CarpetEventServer.Event.PLAYER_STOPS_SNEAKING;
|
||||
import static carpet.script.CarpetEventServer.Event.PLAYER_STOPS_SPRINTING;
|
||||
import static carpet.script.CarpetEventServer.Event.PLAYER_USES_ITEM;
|
||||
import static carpet.script.CarpetEventServer.Event.PLAYER_WAKES_UP;
|
||||
|
||||
|
||||
@Mixin(ServerPlayNetworkHandler.class)
|
||||
public class ServerPlayNetworkHandler_scarpetEventsMixin
|
||||
{
|
||||
@@ -26,9 +43,9 @@ public class ServerPlayNetworkHandler_scarpetEventsMixin
|
||||
@Inject(method = "onPlayerInput", at = @At(value = "RETURN"))
|
||||
private void checkMoves(PlayerInputC2SPacket p, CallbackInfo ci)
|
||||
{
|
||||
if (p.getSideways() != 0.0F || p.getForward() != 0.0F || p.isJumping() || p.isSneaking())
|
||||
if (PLAYER_RIDES.isNeeded() && (p.getSideways() != 0.0F || p.getForward() != 0.0F || p.isJumping() || p.isSneaking()))
|
||||
{
|
||||
CarpetServer.scriptServer.events.onMountControls(player, p.getSideways(), p.getForward(), p.isJumping(), p.isSneaking());
|
||||
PLAYER_RIDES.onMountControls(player, p.getSideways(), p.getForward(), p.isJumping(), p.isSneaking());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,17 +55,37 @@ public class ServerPlayNetworkHandler_scarpetEventsMixin
|
||||
))
|
||||
private void onJump(PlayerMoveC2SPacket playerMoveC2SPacket_1, CallbackInfo ci)
|
||||
{
|
||||
CarpetServer.scriptServer.events.onPlayerJumped(player);
|
||||
PLAYER_JUMPS.onPlayerEvent(player);
|
||||
}
|
||||
|
||||
@Inject(method = "onPlayerAction", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/server/network/ServerPlayerInteractionManager;method_14263(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/server/network/packet/PlayerActionC2SPacket$Action;Lnet/minecraft/util/math/Direction;I)V"
|
||||
target = "Lnet/minecraft/server/network/ServerPlayerInteractionManager;method_14263(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/server/network/packet/PlayerActionC2SPacket$Action;Lnet/minecraft/util/math/Direction;I)V",
|
||||
shift = At.Shift.AFTER
|
||||
))
|
||||
private void onClicked(PlayerActionC2SPacket packet, CallbackInfo ci)
|
||||
{
|
||||
if (packet.getAction() == PlayerActionC2SPacket.Action.START_DESTROY_BLOCK)
|
||||
CarpetServer.scriptServer.events.onBlockClicked(player, packet.getPos(), packet.getDirection());
|
||||
PLAYER_CLICKS_BLOCK.onBlockAction(player, packet.getPos(), packet.getDirection());
|
||||
}
|
||||
|
||||
@Redirect(method = "onPlayerAction", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/server/network/ServerPlayerEntity;stopUsingItem()V"
|
||||
))
|
||||
private void onStopUsing(ServerPlayerEntity serverPlayerEntity)
|
||||
{
|
||||
if (PLAYER_RELEASED_ITEM.isNeeded())
|
||||
{
|
||||
Hand hand = serverPlayerEntity.getActiveHand();
|
||||
ItemStack stack = serverPlayerEntity.getActiveItem().copy();
|
||||
serverPlayerEntity.stopUsingItem();
|
||||
PLAYER_RELEASED_ITEM.onItemAction(player, hand, stack);
|
||||
}
|
||||
else
|
||||
{
|
||||
serverPlayerEntity.stopUsingItem();
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "onPlayerInteractBlock", at = @At(
|
||||
@@ -57,9 +94,12 @@ public class ServerPlayNetworkHandler_scarpetEventsMixin
|
||||
))
|
||||
private void onBlockInteracted(PlayerInteractBlockC2SPacket playerInteractBlockC2SPacket_1, CallbackInfo ci)
|
||||
{
|
||||
Hand hand = playerInteractBlockC2SPacket_1.getHand();
|
||||
BlockHitResult hitRes = playerInteractBlockC2SPacket_1.getHitY();
|
||||
CarpetServer.scriptServer.events.onRightClickBlock(player, hand, hitRes );
|
||||
if (PLAYER_RIGHT_CLICKS_BLOCK.isNeeded())
|
||||
{
|
||||
Hand hand = playerInteractBlockC2SPacket_1.getHand();
|
||||
BlockHitResult hitRes = playerInteractBlockC2SPacket_1.getHitY();
|
||||
PLAYER_RIGHT_CLICKS_BLOCK.onBlockHit(player, hand, hitRes);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "onPlayerInteractItem", at = @At(
|
||||
@@ -68,7 +108,11 @@ public class ServerPlayNetworkHandler_scarpetEventsMixin
|
||||
))
|
||||
private void onItemClicked(PlayerInteractItemC2SPacket playerInteractItemC2SPacket_1, CallbackInfo ci)
|
||||
{
|
||||
CarpetServer.scriptServer.events.onRightClick(player, playerInteractItemC2SPacket_1.getHand());
|
||||
if (PLAYER_USES_ITEM.isNeeded())
|
||||
{
|
||||
Hand hand = playerInteractItemC2SPacket_1.getHand();
|
||||
PLAYER_USES_ITEM.onItemAction(player, hand, player.getStackInHand(hand).copy());
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "onClientCommand", at = @At(
|
||||
@@ -78,7 +122,7 @@ public class ServerPlayNetworkHandler_scarpetEventsMixin
|
||||
))
|
||||
private void onStartSneaking(ClientCommandC2SPacket clientCommandC2SPacket_1, CallbackInfo ci)
|
||||
{
|
||||
CarpetServer.scriptServer.events.onStartSneaking(player);
|
||||
PLAYER_STARTS_SNEAKING.onPlayerEvent(player);
|
||||
}
|
||||
|
||||
@Inject(method = "onClientCommand", at = @At(
|
||||
@@ -88,7 +132,7 @@ public class ServerPlayNetworkHandler_scarpetEventsMixin
|
||||
))
|
||||
private void onStopSneaking(ClientCommandC2SPacket clientCommandC2SPacket_1, CallbackInfo ci)
|
||||
{
|
||||
CarpetServer.scriptServer.events.onStopSneaking(player);
|
||||
PLAYER_STOPS_SNEAKING.onPlayerEvent(player);
|
||||
}
|
||||
|
||||
@Inject(method = "onClientCommand", at = @At(
|
||||
@@ -98,7 +142,7 @@ public class ServerPlayNetworkHandler_scarpetEventsMixin
|
||||
))
|
||||
private void onStartSprinting(ClientCommandC2SPacket clientCommandC2SPacket_1, CallbackInfo ci)
|
||||
{
|
||||
CarpetServer.scriptServer.events.onStartSprinting(player);
|
||||
PLAYER_STARTS_SPRINTING.onPlayerEvent(player);
|
||||
}
|
||||
|
||||
@Inject(method = "onClientCommand", at = @At(
|
||||
@@ -108,7 +152,7 @@ public class ServerPlayNetworkHandler_scarpetEventsMixin
|
||||
))
|
||||
private void onStopSprinting(ClientCommandC2SPacket clientCommandC2SPacket_1, CallbackInfo ci)
|
||||
{
|
||||
CarpetServer.scriptServer.events.onStopSprinting(player);
|
||||
PLAYER_STOPS_SPRINTING.onPlayerEvent(player);
|
||||
}
|
||||
|
||||
@Inject(method = "onClientCommand", at = @At(
|
||||
@@ -119,7 +163,7 @@ public class ServerPlayNetworkHandler_scarpetEventsMixin
|
||||
private void onWakeUp(ClientCommandC2SPacket clientCommandC2SPacket_1, CallbackInfo ci)
|
||||
{
|
||||
//weird one - doesn't seem to work, maybe MP
|
||||
CarpetServer.scriptServer.events.onOutOfBed(player);
|
||||
PLAYER_WAKES_UP.onPlayerEvent(player);
|
||||
}
|
||||
|
||||
@Inject(method = "onClientCommand", at = @At(
|
||||
@@ -129,7 +173,7 @@ public class ServerPlayNetworkHandler_scarpetEventsMixin
|
||||
))
|
||||
private void onElytraEngage(ClientCommandC2SPacket clientCommandC2SPacket_1, CallbackInfo ci)
|
||||
{
|
||||
CarpetServer.scriptServer.events.onElytraDeploy(player);
|
||||
PLAYER_DEPLOYS_ELYTRA.onPlayerEvent(player);
|
||||
}
|
||||
|
||||
@Inject(method = "onPlayerInteractEntity", at = @At(
|
||||
@@ -138,7 +182,7 @@ public class ServerPlayNetworkHandler_scarpetEventsMixin
|
||||
))
|
||||
private void onEntityInteract(PlayerInteractEntityC2SPacket playerInteractEntityC2SPacket_1, CallbackInfo ci)
|
||||
{
|
||||
CarpetServer.scriptServer.events.onEntityInteracted(player, playerInteractEntityC2SPacket_1.getEntity(player.getServerWorld()), playerInteractEntityC2SPacket_1.getHand());
|
||||
PLAYER_INERACTSW_WITH_ENTITY.onEntityAction(player, playerInteractEntityC2SPacket_1.getEntity(player.getServerWorld()), playerInteractEntityC2SPacket_1.getHand());
|
||||
}
|
||||
|
||||
@Inject(method = "onPlayerInteractEntity", at = @At(
|
||||
@@ -148,6 +192,6 @@ public class ServerPlayNetworkHandler_scarpetEventsMixin
|
||||
private void onEntityAttack(PlayerInteractEntityC2SPacket playerInteractEntityC2SPacket_1, CallbackInfo ci)
|
||||
{
|
||||
//todo add hit and hand in the future
|
||||
CarpetServer.scriptServer.events.onEntityAttacked(player, playerInteractEntityC2SPacket_1.getEntity(player.getServerWorld()));
|
||||
PLAYER_ATTACKS_ENTITY.onEntityAction(player, playerInteractEntityC2SPacket_1.getEntity(player.getServerWorld()), null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.world.World;
|
||||
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.Redirect;
|
||||
|
||||
import static carpet.script.CarpetEventServer.Event.PLAYER_FINISHED_USING_ITEM;
|
||||
|
||||
@Mixin(ServerPlayerEntity.class)
|
||||
public abstract class ServerPlayerEntity_scarpetEventMixin extends PlayerEntity
|
||||
{
|
||||
public ServerPlayerEntity_scarpetEventMixin(World world_1, GameProfile gameProfile_1)
|
||||
{
|
||||
super(world_1, gameProfile_1);
|
||||
}
|
||||
|
||||
@Shadow protected abstract void method_6040();
|
||||
|
||||
@Redirect(method = "method_6040", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/entity/player/PlayerEntity;method_6040()V"
|
||||
))
|
||||
private void finishedUsingItem(PlayerEntity playerEntity)
|
||||
{
|
||||
if (PLAYER_FINISHED_USING_ITEM.isNeeded())
|
||||
{
|
||||
Hand hand = getActiveHand();
|
||||
ItemStack stack = getActiveItem().copy();
|
||||
// do vanilla
|
||||
super.method_6040();
|
||||
PLAYER_FINISHED_USING_ITEM.onItemAction((ServerPlayerEntity) (Object)this, hand, stack);
|
||||
}
|
||||
else
|
||||
{
|
||||
// do vanilla
|
||||
super.method_6040();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.CarpetServer;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
@@ -14,6 +13,8 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
|
||||
|
||||
import static carpet.script.CarpetEventServer.Event.PLAYER_BREAK_BLOCK;
|
||||
|
||||
@Mixin(ServerPlayerInteractionManager.class)
|
||||
public class ServerPlayerInteractionManager_scarpetEventsMixin
|
||||
{
|
||||
@@ -26,6 +27,6 @@ public class ServerPlayerInteractionManager_scarpetEventsMixin
|
||||
))
|
||||
private void onBlockBroken(BlockPos blockPos_1, CallbackInfoReturnable<Boolean> cir, BlockState blockState_1, BlockEntity be, Block b, boolean boolean_1)
|
||||
{
|
||||
CarpetServer.scriptServer.events.onBlockBroken(player, blockPos_1, blockState_1);
|
||||
PLAYER_BREAK_BLOCK.onBlockBroken(player, blockPos_1, blockState_1);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user