added __on_player_chooses_recipe and __on_player_switches_slot events
This commit is contained in:
1 parent
fff3ccf3f6
commit
690c85f3b0
4 files changed
+126
No files matched your search
@@ -1,6 +1,9 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.packet.c2s.play.ButtonClickC2SPacket;
|
||||
import net.minecraft.network.packet.c2s.play.CraftRequestC2SPacket;
|
||||
import net.minecraft.network.packet.c2s.play.UpdateSelectedSlotC2SPacket;
|
||||
import net.minecraft.server.network.ServerPlayNetworkHandler;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.network.packet.c2s.play.ClientCommandC2SPacket;
|
||||
@@ -29,10 +32,12 @@ 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_CHOOSES_RECIPE;
|
||||
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_SWITCHES_SLOT;
|
||||
import static carpet.script.CarpetEventServer.Event.PLAYER_USES_ITEM;
|
||||
import static carpet.script.CarpetEventServer.Event.PLAYER_WAKES_UP;
|
||||
|
||||
@@ -219,4 +224,28 @@ public class ServerPlayNetworkHandler_scarpetEventsMixin
|
||||
//todo add hit and hand in the future
|
||||
PLAYER_ATTACKS_ENTITY.onEntityAction(player, playerInteractEntityC2SPacket_1.getEntity(player.getServerWorld()), null);
|
||||
}
|
||||
|
||||
@Inject(method = "onButtonClick", at = @At("HEAD"))
|
||||
private void onItemBeingPickedFromInventory(ButtonClickC2SPacket packet, CallbackInfo ci)
|
||||
{
|
||||
// crafts not int the crafting window
|
||||
//CarpetSettings.LOG.error("Player clicks button "+packet.getButtonId());
|
||||
}
|
||||
@Inject(method = "onCraftRequest", at = @At("HEAD"))
|
||||
private void onRecipeSelectedInRecipeManager(CraftRequestC2SPacket packet, CallbackInfo ci)
|
||||
{
|
||||
if (PLAYER_CHOOSES_RECIPE.isNeeded())
|
||||
{
|
||||
PLAYER_CHOOSES_RECIPE.onRecipeSelected(player, packet.getRecipe(), packet.shouldCraftAll());
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "onUpdateSelectedSlot", at = @At("HEAD"))
|
||||
private void onUpdatedSelectedSLot(UpdateSelectedSlotC2SPacket packet, CallbackInfo ci)
|
||||
{
|
||||
if (PLAYER_SWITCHES_SLOT.isNeeded())
|
||||
{
|
||||
PLAYER_SWITCHES_SLOT.onSlotSwitch(player, player.inventory.selectedSlot, packet.getSelectedSlot());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -488,6 +488,37 @@ public class CarpetEventServer
|
||||
handler.call( () -> Collections.singletonList(((c, t) -> new EntityValue(player))), player::getCommandSource);
|
||||
}
|
||||
},
|
||||
PLAYER_CHOOSES_RECIPE("player_chooses_recipe", 3, false)
|
||||
{
|
||||
@Override
|
||||
public void onRecipeSelected(ServerPlayerEntity player, Identifier recipe, boolean fullStack)
|
||||
{
|
||||
handler.call( () ->
|
||||
{
|
||||
return Arrays.asList(
|
||||
((c, t) -> new EntityValue(player)),
|
||||
((c, t) -> new StringValue(NBTSerializableValue.nameFromRegistryId(recipe))),
|
||||
((c, t) -> new NumericValue(fullStack))
|
||||
);
|
||||
}, player::getCommandSource);
|
||||
}
|
||||
},
|
||||
PLAYER_SWITCHES_SLOT("player_switches_slot", 3, false)
|
||||
{
|
||||
@Override
|
||||
public void onSlotSwitch(ServerPlayerEntity player, int from, int to)
|
||||
{
|
||||
if (from == to) return; // initial slot update
|
||||
handler.call( () ->
|
||||
{
|
||||
return Arrays.asList(
|
||||
((c, t) -> new EntityValue(player)),
|
||||
((c, t) -> new NumericValue(from)),
|
||||
((c, t) -> new NumericValue(to))
|
||||
);
|
||||
}, player::getCommandSource);
|
||||
}
|
||||
},
|
||||
PLAYER_TAKES_DAMAGE("player_takes_damage", 4, false)
|
||||
{
|
||||
@Override
|
||||
@@ -647,6 +678,8 @@ public class CarpetEventServer
|
||||
public void onEntityAction(ServerPlayerEntity player, Entity entity, Hand enumhand) { }
|
||||
public void onDimensionChange(ServerPlayerEntity player, Vec3d from, Vec3d to, DimensionType fromDim, DimensionType dimTo) {}
|
||||
public void onDamage(Entity target, float amount, DamageSource source) { }
|
||||
public void onRecipeSelected(ServerPlayerEntity player, Identifier recipe, boolean fullStack) {}
|
||||
public void onSlotSwitch(ServerPlayerEntity player, int from, int to) {}
|
||||
|
||||
|
||||
public void onWorldEvent(ServerWorld world, BlockPos pos) { }
|
||||
|
||||
Reference in new issue
Block a user