statistics, block placed and interacted events, stats event test
This commit is contained in:
1 parent
860c9b6d21
commit
d7ca974f1a
12 files changed
+210
-7
No files matched your search
@@ -0,0 +1,27 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.ItemPlacementContext;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.util.ActionResult;
|
||||
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.CallbackInfoReturnable;
|
||||
|
||||
import static carpet.script.CarpetEventServer.Event.PLAYER_PLACES_BLOCK;
|
||||
|
||||
@Mixin(BlockItem.class)
|
||||
public class BlockItem_scarpetEventMixin
|
||||
{
|
||||
@Inject(method = "place(Lnet/minecraft/item/ItemPlacementContext;)Lnet/minecraft/util/ActionResult;", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/block/Block;onPlaced(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;Lnet/minecraft/entity/LivingEntity;Lnet/minecraft/item/ItemStack;)V",
|
||||
shift = At.Shift.AFTER
|
||||
))
|
||||
private void afterPlacement(ItemPlacementContext context, CallbackInfoReturnable<ActionResult> cir)
|
||||
{
|
||||
if (context.getPlayer() instanceof ServerPlayerEntity && PLAYER_PLACES_BLOCK.isNeeded())
|
||||
PLAYER_PLACES_BLOCK.onBlockPlaced((ServerPlayerEntity) context.getPlayer(), context.getBlockPos(), context.getHand(), context.getStack());
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ 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_DROPS_ITEM;
|
||||
import static carpet.script.CarpetEventServer.Event.PLAYER_DROPS_STACK;
|
||||
import static carpet.script.CarpetEventServer.Event.PLAYER_INERACTSW_WITH_ENTITY;
|
||||
import static carpet.script.CarpetEventServer.Event.PLAYER_INTERACTS_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;
|
||||
@@ -87,7 +87,7 @@ public class ServerPlayNetworkHandler_scarpetEventsMixin
|
||||
@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",
|
||||
shift = At.Shift.AFTER
|
||||
shift = At.Shift.BEFORE
|
||||
))
|
||||
private void onClicked(PlayerActionC2SPacket packet, CallbackInfo ci)
|
||||
{
|
||||
@@ -208,7 +208,7 @@ public class ServerPlayNetworkHandler_scarpetEventsMixin
|
||||
))
|
||||
private void onEntityInteract(PlayerInteractEntityC2SPacket playerInteractEntityC2SPacket_1, CallbackInfo ci)
|
||||
{
|
||||
PLAYER_INERACTSW_WITH_ENTITY.onEntityAction(player, playerInteractEntityC2SPacket_1.getEntity(player.getServerWorld()), playerInteractEntityC2SPacket_1.getHand());
|
||||
PLAYER_INTERACTS_WITH_ENTITY.onEntityAction(player, playerInteractEntityC2SPacket_1.getEntity(player.getServerWorld()), playerInteractEntityC2SPacket_1.getHand());
|
||||
}
|
||||
|
||||
@Inject(method = "onPlayerInteractEntity", at = @At(
|
||||
|
||||
@@ -3,9 +3,15 @@ package carpet.mixins;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.network.ServerPlayerInteractionManager;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
@@ -14,6 +20,8 @@ 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;
|
||||
import static carpet.script.CarpetEventServer.Event.PLAYER_INTERACTS_WITH_BLOCK;
|
||||
|
||||
|
||||
@Mixin(ServerPlayerInteractionManager.class)
|
||||
public class ServerPlayerInteractionManager_scarpetEventsMixin
|
||||
@@ -29,4 +37,13 @@ public class ServerPlayerInteractionManager_scarpetEventsMixin
|
||||
{
|
||||
PLAYER_BREAK_BLOCK.onBlockBroken(player, blockPos_1, blockState_1);
|
||||
}
|
||||
|
||||
@Inject(method = "interactBlock", at = @At(
|
||||
value = "RETURN",
|
||||
ordinal = 2
|
||||
))
|
||||
private void onBlockActivated(PlayerEntity playerArg, World world, ItemStack stack, Hand hand, BlockHitResult blockHitResult, CallbackInfoReturnable<ActionResult> cir)
|
||||
{
|
||||
PLAYER_INTERACTS_WITH_BLOCK.onBlockHit(player, hand, blockHitResult);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.fakes.StatTypeInterface;
|
||||
import net.minecraft.stat.Stat;
|
||||
import net.minecraft.stat.StatType;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Mixin(StatType.class)
|
||||
public class StatType_scarpetMixin<T> implements StatTypeInterface<T>
|
||||
{
|
||||
@Shadow @Final private Map<T, Stat<T>> stats;
|
||||
|
||||
@Override
|
||||
public boolean hasStatCreated(T key)
|
||||
{
|
||||
return this.stats.containsKey(key);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user