schedules and events from jarmod
This commit is contained in:
1 parent
4ec6e0e03e
commit
730446b219
14 files changed
+825
-62
No files matched your search
@@ -1,5 +1,6 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.CarpetServer;
|
||||
import carpet.fakes.MinecraftServerInterface;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.ServerTask;
|
||||
@@ -7,6 +8,9 @@ import net.minecraft.util.NonBlockingThreadExecutor;
|
||||
import net.minecraft.util.SystemUtil;
|
||||
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 java.util.function.BooleanSupplier;
|
||||
|
||||
@@ -31,4 +35,13 @@ public abstract class MinecraftServer_scarpetMixin extends NonBlockingThreadExec
|
||||
tick(isAhead);
|
||||
executeTaskQueue();
|
||||
}
|
||||
|
||||
@Inject(method = "tick", at = @At(
|
||||
value = "CONSTANT",
|
||||
args = "stringValue=tallying"
|
||||
))
|
||||
public void tickTasks(BooleanSupplier booleanSupplier_1, CallbackInfo ci)
|
||||
{
|
||||
CarpetServer.scriptServer.events.onTick();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.CarpetServer;
|
||||
import carpet.CarpetSettings;
|
||||
import net.minecraft.server.network.ServerPlayNetworkHandler;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.network.packet.ClientCommandC2SPacket;
|
||||
import net.minecraft.server.network.packet.PlayerActionC2SPacket;
|
||||
import net.minecraft.server.network.packet.PlayerInputC2SPacket;
|
||||
import net.minecraft.server.network.packet.PlayerInteractBlockC2SPacket;
|
||||
import net.minecraft.server.network.packet.PlayerInteractEntityC2SPacket;
|
||||
import net.minecraft.server.network.packet.PlayerInteractItemC2SPacket;
|
||||
import net.minecraft.server.network.packet.PlayerMoveC2SPacket;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
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 ServerPlayNetworkHandler_scarpetEventsMixin
|
||||
{
|
||||
@Shadow public ServerPlayerEntity player;
|
||||
|
||||
@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())
|
||||
{
|
||||
CarpetServer.scriptServer.events.onMountControls(player, p.getSideways(), p.getForward(), p.isJumping(), p.isSneaking());
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "onPlayerMove", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/server/network/ServerPlayerEntity;jump()V"
|
||||
))
|
||||
private void onJump(PlayerMoveC2SPacket playerMoveC2SPacket_1, CallbackInfo ci)
|
||||
{
|
||||
CarpetServer.scriptServer.events.onPlayerJumped(player);
|
||||
}
|
||||
|
||||
@Inject(method = "onPlayerAction", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/server/network/ServerPlayerInteractionManager;method_14263(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/math/Direction;)V"
|
||||
))
|
||||
private void onClicked(PlayerActionC2SPacket packet, CallbackInfo ci)
|
||||
{
|
||||
CarpetServer.scriptServer.events.onBlockClicked(player, packet.getPos(), packet.getDirection());
|
||||
}
|
||||
|
||||
@Inject(method = "onPlayerInteractBlock", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/server/network/ServerPlayerInteractionManager;interactBlock(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/world/World;Lnet/minecraft/item/ItemStack;Lnet/minecraft/util/Hand;Lnet/minecraft/util/hit/BlockHitResult;)Lnet/minecraft/util/ActionResult;"
|
||||
))
|
||||
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 );
|
||||
}
|
||||
|
||||
@Inject(method = "onPlayerInteractItem", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/server/network/ServerPlayerEntity;updateLastActionTime()V"
|
||||
))
|
||||
private void onItemClicked(PlayerInteractItemC2SPacket playerInteractItemC2SPacket_1, CallbackInfo ci)
|
||||
{
|
||||
CarpetServer.scriptServer.events.onRightClick(player, playerInteractItemC2SPacket_1.getHand());
|
||||
}
|
||||
|
||||
@Inject(method = "onClientCommand", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/server/network/ServerPlayerEntity;setSneaking(Z)V",
|
||||
ordinal = 0
|
||||
))
|
||||
private void onStartSneaking(ClientCommandC2SPacket clientCommandC2SPacket_1, CallbackInfo ci)
|
||||
{
|
||||
CarpetServer.scriptServer.events.onStartSneaking(player);
|
||||
}
|
||||
|
||||
@Inject(method = "onClientCommand", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/server/network/ServerPlayerEntity;setSneaking(Z)V",
|
||||
ordinal = 1
|
||||
))
|
||||
private void onStopSneaking(ClientCommandC2SPacket clientCommandC2SPacket_1, CallbackInfo ci)
|
||||
{
|
||||
CarpetServer.scriptServer.events.onStopSneaking(player);
|
||||
}
|
||||
|
||||
@Inject(method = "onClientCommand", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/server/network/ServerPlayerEntity;setSprinting(Z)V",
|
||||
ordinal = 0
|
||||
))
|
||||
private void onStartSprinting(ClientCommandC2SPacket clientCommandC2SPacket_1, CallbackInfo ci)
|
||||
{
|
||||
CarpetServer.scriptServer.events.onStartSprinting(player);
|
||||
}
|
||||
|
||||
@Inject(method = "onClientCommand", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/server/network/ServerPlayerEntity;setSprinting(Z)V",
|
||||
ordinal = 1
|
||||
))
|
||||
private void onStopSprinting(ClientCommandC2SPacket clientCommandC2SPacket_1, CallbackInfo ci)
|
||||
{
|
||||
CarpetServer.scriptServer.events.onStopSprinting(player);
|
||||
}
|
||||
|
||||
@Inject(method = "onClientCommand", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/server/network/ServerPlayerEntity;isSleeping()Z",
|
||||
shift = At.Shift.BEFORE
|
||||
))
|
||||
private void onWakeUp(ClientCommandC2SPacket clientCommandC2SPacket_1, CallbackInfo ci)
|
||||
{
|
||||
//weird one - doesn't seem to work, maybe MP
|
||||
CarpetServer.scriptServer.events.onOutOfBed(player);
|
||||
}
|
||||
|
||||
@Inject(method = "onClientCommand", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/server/network/ServerPlayerEntity;isFallFlying()Z",
|
||||
shift = At.Shift.BEFORE
|
||||
))
|
||||
private void onElytraEngage(ClientCommandC2SPacket clientCommandC2SPacket_1, CallbackInfo ci)
|
||||
{
|
||||
CarpetServer.scriptServer.events.onElytraDeploy(player);
|
||||
}
|
||||
|
||||
@Inject(method = "onPlayerInteractEntity", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/server/network/ServerPlayerEntity;interact(Lnet/minecraft/entity/Entity;Lnet/minecraft/util/Hand;)Lnet/minecraft/util/ActionResult;"
|
||||
))
|
||||
private void onEntityInteract(PlayerInteractEntityC2SPacket playerInteractEntityC2SPacket_1, CallbackInfo ci)
|
||||
{
|
||||
CarpetServer.scriptServer.events.onEntityInteracted(player, playerInteractEntityC2SPacket_1.getEntity(player.getServerWorld()), playerInteractEntityC2SPacket_1.getHand());
|
||||
}
|
||||
|
||||
@Inject(method = "onPlayerInteractEntity", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/server/network/ServerPlayerEntity;attack(Lnet/minecraft/entity/Entity;)V"
|
||||
))
|
||||
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()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.CarpetServer;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.network.ServerPlayerInteractionManager;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
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.CallbackInfoReturnable;
|
||||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
|
||||
|
||||
@Mixin(ServerPlayerInteractionManager.class)
|
||||
public class ServerPlayerInteractionManager_scarpetEventsMixin
|
||||
{
|
||||
@Shadow public ServerPlayerEntity player;
|
||||
|
||||
@Inject(method = "destroyBlock", locals = LocalCapture.CAPTURE_FAILEXCEPTION, at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/block/Block;onBroken(Lnet/minecraft/world/IWorld;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)V",
|
||||
shift = At.Shift.BEFORE
|
||||
))
|
||||
private void onBlockBroken(BlockPos blockPos_1, CallbackInfoReturnable<Boolean> cir, BlockState blockState_1, boolean boolean_1)
|
||||
{
|
||||
CarpetServer.scriptServer.events.onBlockBroken(player, blockPos_1, blockState_1);
|
||||
}
|
||||
}
|
||||
@@ -3,11 +3,13 @@ package carpet.mixins;
|
||||
import carpet.CarpetSettings;
|
||||
import carpet.fakes.WorldInterface;
|
||||
import carpet.utils.SpawnReporter;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.mob.MobEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.BoundingBox;
|
||||
import net.minecraft.util.shape.VoxelShape;
|
||||
import net.minecraft.util.shape.VoxelShapes;
|
||||
import net.minecraft.world.SpawnHelper;
|
||||
import net.minecraft.world.World;
|
||||
@@ -35,13 +37,17 @@ public class SpawnHelperMixin
|
||||
if (CarpetSettings.b_lagFreeSpawning)
|
||||
{
|
||||
BlockPos.Mutable blockpos = new BlockPos.Mutable();
|
||||
for (int x = (int)bb.minX, maxx = (int)Math.ceil(bb.maxX); x < maxx; x++)
|
||||
for (int z = (int)bb.minZ, maxz = (int)Math.ceil(bb.maxZ); z < maxz; z++)
|
||||
for (int y = (int)bb.minY, maxy = (int)Math.ceil(bb.maxY); y < maxy; y++)
|
||||
for (int y = (int)bb.minY, maxy = (int)Math.ceil(bb.maxY); y < maxy; y++)
|
||||
for (int x = (int)bb.minX, maxx = (int)Math.ceil(bb.maxX); x < maxx; x++)
|
||||
for (int z = (int)bb.minZ, maxz = (int)Math.ceil(bb.maxZ); z < maxz; z++)
|
||||
{
|
||||
blockpos.set(x, y, z);
|
||||
if (world.getBlockState(blockpos).getCollisionShape(world, blockpos) != VoxelShapes.empty())
|
||||
return world.doesNotCollide(bb);
|
||||
VoxelShape box = world.getBlockState(blockpos).getCollisionShape(world, blockpos);
|
||||
if ( box == VoxelShapes.empty())
|
||||
continue;
|
||||
if (Block.isShapeFullCube(box))
|
||||
return false;
|
||||
return world.doesNotCollide(bb);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user