Refactor and 1.17-pre1 (#96)

* Fix #94

Signed-off-by: shedaniel <daniel@shedaniel.me>

* Add Chunk data save and load events, closes #89 (#92)

* Created Chunk save and load event. Closes #89

* Fixed missing licence

* Update common/src/main/java/me/shedaniel/architectury/event/events/ChunkEvent.java

* Update common/src/main/java/me/shedaniel/architectury/event/events/ChunkEvent.java

* Update common/src/main/java/me/shedaniel/architectury/event/events/ChunkEvent.java

* Supply ServerLevel in ChunkEvent.LOAD, style cleanup

Signed-off-by: shedaniel <daniel@shedaniel.me>

* Add "Data" suffix to Chunk IO Events and mark level as nullable for load

* Update common/src/main/java/me/shedaniel/architectury/event/events/ChunkEvent.java

* Bump to 1.16

Co-authored-by: shedaniel <daniel@shedaniel.me>
Co-authored-by: Max <maxh2709@gmail.com>

* Update pr.yml

* Add NetworkManager hook for Entity spawn packets (#88)

* New utility hook for creating a entity spawn packet. before every mod had to implement this in itself.

* Apply suggestions from code review

Co-authored-by: shedaniel <daniel@shedaniel.me>

* Update common/src/main/java/me/shedaniel/architectury/networking/NetworkManager.java

* Update common/src/main/java/me/shedaniel/architectury/networking/NetworkManager.java

* Properly implement SpawnEntityPacket & Format style

Signed-off-by: shedaniel <daniel@shedaniel.me>

* Format

Signed-off-by: shedaniel <daniel@shedaniel.me>

* createEntitySpawnPacket -> createAddEntityPacket for mojmap consistency

Signed-off-by: shedaniel <daniel@shedaniel.me>

* Bump version to 1.17

Co-authored-by: Max <maxh2709@gmail.com>
Co-authored-by: shedaniel <daniel@shedaniel.me>

* Add Javadocs for all events (#91)

* javadoc for ClientChatEvent

* javadoc for ClientPlayerEvent

* javadoc for ClientRawInputEvent

* Added javadoc for ClientScreenInputEvent

* Bit refactoring and removed javadoc @see to the caller methods

* Add javadoc for BlockEvent

* Add javadoc for ChatEvent

* Add javadoc for CommandPerformEvent and CommandRegistrationEvent

* Add javadoc for EntityEvent

* Add javadoc for ExplosionEvent

* Add javadoc for GuiEvent

* Add javadoc for InteractionEvent

* Add javadoc for LightningEvent, RecipeUpdateEvent & TextureStitchEvent

* Add javadoc for LifecycleEvent & ClientLifecycleEvent

* Add javadoc for TooltipEvent

* Add javadoc for TickEvent and partly PlayerEvent

* More javadoc for PlayerEvent

* Finally all event have javadoc

* Update common/src/main/java/me/shedaniel/architectury/event/events/CommandPerformEvent.java

Co-authored-by: Juuxel <6596629+Juuxel@users.noreply.github.com>

* Update common/src/main/java/me/shedaniel/architectury/event/events/CommandPerformEvent.java

Co-authored-by: Juuxel <6596629+Juuxel@users.noreply.github.com>

* Update common/src/main/java/me/shedaniel/architectury/event/events/CommandPerformEvent.java

Co-authored-by: Juuxel <6596629+Juuxel@users.noreply.github.com>

* Update common/src/main/java/me/shedaniel/architectury/event/events/ChatEvent.java

Co-authored-by: Juuxel <6596629+Juuxel@users.noreply.github.com>

* Update common/src/main/java/me/shedaniel/architectury/event/events/CommandRegistrationEvent.java

Co-authored-by: Juuxel <6596629+Juuxel@users.noreply.github.com>

* Update common/src/main/java/me/shedaniel/architectury/event/events/EntityEvent.java

Co-authored-by: Juuxel <6596629+Juuxel@users.noreply.github.com>

* Update common/src/main/java/me/shedaniel/architectury/event/events/EntityEvent.java

Co-authored-by: Juuxel <6596629+Juuxel@users.noreply.github.com>

* Update common/src/main/java/me/shedaniel/architectury/event/events/EntityEvent.java

Co-authored-by: Juuxel <6596629+Juuxel@users.noreply.github.com>

* Update common/src/main/java/me/shedaniel/architectury/event/events/EntityEvent.java

Co-authored-by: Juuxel <6596629+Juuxel@users.noreply.github.com>

* Update common/src/main/java/me/shedaniel/architectury/event/events/client/ClientScreenInputEvent.java

Co-authored-by: Juuxel <6596629+Juuxel@users.noreply.github.com>

* Update common/src/main/java/me/shedaniel/architectury/event/events/client/ClientScreenInputEvent.java

Co-authored-by: Juuxel <6596629+Juuxel@users.noreply.github.com>

* Update common/src/main/java/me/shedaniel/architectury/event/events/BlockEvent.java

Co-authored-by: Max <maxh2709@gmail.com>

* Update common/src/main/java/me/shedaniel/architectury/event/events/BlockEvent.java

Co-authored-by: Max <maxh2709@gmail.com>

* Update common/src/main/java/me/shedaniel/architectury/event/events/BlockEvent.java

Co-authored-by: Max <maxh2709@gmail.com>

* Update common/src/main/java/me/shedaniel/architectury/event/events/BlockEvent.java

Co-authored-by: Max <maxh2709@gmail.com>

* Update common/src/main/java/me/shedaniel/architectury/event/events/LifecycleEvent.java

Co-authored-by: Max <maxh2709@gmail.com>

* Update common/src/main/java/me/shedaniel/architectury/event/events/LifecycleEvent.java

Co-authored-by: Max <maxh2709@gmail.com>

* Update common/src/main/java/me/shedaniel/architectury/event/events/LifecycleEvent.java

Co-authored-by: Max <maxh2709@gmail.com>

* Update common/src/main/java/me/shedaniel/architectury/event/events/PlayerEvent.java

Co-authored-by: Max <maxh2709@gmail.com>

* Apply suggestions from code review

Co-authored-by: Max <maxh2709@gmail.com>
Co-authored-by: Juuxel <6596629+Juuxel@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: Juuxel <6596629+Juuxel@users.noreply.github.com>
Co-authored-by: Max <maxh2709@gmail.com>

* Apply suggestions from code review

Co-authored-by: Max <maxh2709@gmail.com>
Co-authored-by: Juuxel <6596629+Juuxel@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: Max <maxh2709@gmail.com>
Co-authored-by: Juuxel <6596629+Juuxel@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: Max <maxh2709@gmail.com>
Co-authored-by: Juuxel <6596629+Juuxel@users.noreply.github.com>

* Apply suggestions from code review

* Apply suggestions from code review

Co-authored-by: shedaniel <daniel@shedaniel.me>

* Applied some more reviews

* Applied some more reviews

* Applied suggestions

* Reformat and apply some minor suggestions

* Apply suggestions from review (first batch)

* Remove double return javadoc

* Apply suggestions from code review

Co-authored-by: shedaniel <daniel@shedaniel.me>

* Add "scaled" to mouse coordinates

* Final touches

Signed-off-by: shedaniel <daniel@shedaniel.me>

* Remove invalid tips

Signed-off-by: shedaniel <daniel@shedaniel.me>

Co-authored-by: Juuxel <6596629+Juuxel@users.noreply.github.com>
Co-authored-by: Max <maxh2709@gmail.com>
Co-authored-by: shedaniel <daniel@shedaniel.me>

* Refactor

Signed-off-by: shedaniel <daniel@shedaniel.me>

* Update common/src/main/java/dev/architectury/event/events/common/InteractionEvent.java

Co-authored-by: Max <maxh2709@gmail.com>

* Apply suggestions from code review

Co-authored-by: Max <maxh2709@gmail.com>

* attack -> hurt

Signed-off-by: shedaniel <daniel@shedaniel.me>

* Update @param for InteractionEvent#FARMLAND_TRAMPLE

Signed-off-by: shedaniel <daniel@shedaniel.me>

* world -> level

Signed-off-by: shedaniel <daniel@shedaniel.me>

* Relocate hooks

Signed-off-by: shedaniel <daniel@shedaniel.me>

* Organize imports

Signed-off-by: shedaniel <daniel@shedaniel.me>

* Registry -> Registrar Please voice out your opinion!!

Signed-off-by: shedaniel <daniel@shedaniel.me>

* Some more renames
itemOptional -> optionalItem
RegistryBuilder -> RegistrarBuilder
RegistryOption -> RegistrarOption
Not forcing RegistryEntry on new registries, vanilla types don't have them

Signed-off-by: shedaniel <daniel@shedaniel.me>

* Java 16-ification

Signed-off-by: shedaniel <daniel@shedaniel.me>

* Optimise imports after the var change

Signed-off-by: shedaniel <daniel@shedaniel.me>

* Un-minimize architectury-common.mixins.json

Signed-off-by: shedaniel <daniel@shedaniel.me>

Co-authored-by: canitzp <12819060+canitzp@users.noreply.github.com>
Co-authored-by: Max <maxh2709@gmail.com>
Co-authored-by: Juuxel <6596629+Juuxel@users.noreply.github.com>
This commit is contained in:
shedaniel
2021-05-30 19:08:11 +08:00
committed by GitHub
parent 28867f012d
commit 8b262d07c0
229 changed files with 3529 additions and 2354 deletions

View File

@@ -17,20 +17,24 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package me.shedaniel.architectury.test;
package dev.architectury.test;
import me.shedaniel.architectury.platform.Platform;
import me.shedaniel.architectury.test.debug.ConsoleMessageSink;
import me.shedaniel.architectury.test.debug.MessageSink;
import me.shedaniel.architectury.test.debug.client.ClientOverlayMessageSink;
import me.shedaniel.architectury.test.events.DebugEvents;
import me.shedaniel.architectury.test.gamerule.TestGameRules;
import me.shedaniel.architectury.test.registry.TestRegistries;
import me.shedaniel.architectury.test.registry.client.TestKeybinds;
import me.shedaniel.architectury.test.tags.TestTags;
import me.shedaniel.architectury.test.trade.TestTrades;
import me.shedaniel.architectury.utils.Env;
import me.shedaniel.architectury.utils.EnvExecutor;
import dev.architectury.platform.Platform;
import dev.architectury.registry.level.entity.EntityRendererRegistry;
import dev.architectury.test.debug.ConsoleMessageSink;
import dev.architectury.test.debug.MessageSink;
import dev.architectury.test.debug.client.ClientOverlayMessageSink;
import dev.architectury.test.entity.TestEntity;
import dev.architectury.test.events.DebugEvents;
import dev.architectury.test.gamerule.TestGameRules;
import dev.architectury.test.registry.TestRegistries;
import dev.architectury.test.registry.client.TestKeybinds;
import dev.architectury.test.tags.TestTags;
import dev.architectury.test.trade.TestTrades;
import dev.architectury.utils.Env;
import dev.architectury.utils.EnvExecutor;
import net.minecraft.client.model.geom.ModelLayers;
import net.minecraft.client.renderer.entity.MinecartRenderer;
public class TestMod {
public static final MessageSink SINK = EnvExecutor.getEnvSpecific(() -> ClientOverlayMessageSink::new, () -> ConsoleMessageSink::new);
@@ -42,7 +46,14 @@ public class TestMod {
TestGameRules.init();
TestTags.initialize();
TestTrades.init();
if (Platform.getEnvironment() == Env.CLIENT)
TestKeybinds.initialize();
if (Platform.getEnvironment() == Env.CLIENT) {
initializeClient();
}
}
public static void initializeClient() {
TestKeybinds.initialize();
EntityRendererRegistry.register(TestEntity.TYPE, context ->
new MinecartRenderer<>(context, ModelLayers.MINECART));
}
}

View File

@@ -17,7 +17,7 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package me.shedaniel.architectury.test.debug;
package dev.architectury.test.debug;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

View File

@@ -17,7 +17,7 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package me.shedaniel.architectury.test.debug;
package dev.architectury.test.debug;
public interface MessageSink {
void accept(String message);

View File

@@ -17,13 +17,13 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package me.shedaniel.architectury.test.debug.client;
package dev.architectury.test.debug.client;
import com.google.common.collect.Lists;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import me.shedaniel.architectury.event.events.GuiEvent;
import me.shedaniel.architectury.test.debug.ConsoleMessageSink;
import dev.architectury.event.events.client.ClientGuiEvent;
import dev.architectury.test.debug.ConsoleMessageSink;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.Util;
@@ -42,8 +42,8 @@ public class ClientOverlayMessageSink extends ConsoleMessageSink {
private final List<Message> messages = Collections.synchronizedList(Lists.newArrayList());
public ClientOverlayMessageSink() {
GuiEvent.RENDER_POST.register((screen, matrices, mouseX, mouseY, delta) -> render(matrices, delta));
GuiEvent.RENDER_HUD.register((matrices, tickDelta) -> {
ClientGuiEvent.RENDER_POST.register((screen, matrices, mouseX, mouseY, delta) -> render(matrices, delta));
ClientGuiEvent.RENDER_HUD.register((matrices, tickDelta) -> {
if (Minecraft.getInstance().screen == null && !Minecraft.getInstance().options.renderDebug) {
render(matrices, tickDelta);
}
@@ -59,26 +59,26 @@ public class ClientOverlayMessageSink extends ConsoleMessageSink {
public void render(PoseStack matrices, float delta) {
matrices.pushPose();
matrices.scale(0.5f, 0.5f, 1f);
Minecraft minecraft = Minecraft.getInstance();
long currentMills = Util.getMillis();
int lineHeight = minecraft.font.lineHeight;
var minecraft = Minecraft.getInstance();
var currentMills = Util.getMillis();
var lineHeight = minecraft.font.lineHeight;
synchronized (messages) {
Iterator<Message> messageIterator = messages.iterator();
int y = 1;
var messageIterator = messages.iterator();
var y = 1;
RenderSystem.enableBlend();
while (messageIterator.hasNext()) {
Message message = messageIterator.next();
int timeExisted = (int) (currentMills - message.created);
var message = messageIterator.next();
var timeExisted = (int) (currentMills - message.created);
if (timeExisted >= 5000) {
messageIterator.remove();
} else {
if (y - 1 < minecraft.getWindow().getGuiScaledHeight()) {
int textWidth = minecraft.font.width(message.text);
int alpha = (int) Mth.clamp((5000 - timeExisted) / 5000f * 400f + 8, 0, 255);
var textWidth = minecraft.font.width(message.text);
var alpha = (int) Mth.clamp((5000 - timeExisted) / 5000f * 400f + 8, 0, 255);
GuiComponent.fill(matrices, 0, y - 1, 2 + textWidth + 1, y + lineHeight - 1, 0x505050 + ((alpha * 144 / 255) << 24));
minecraft.font.draw(matrices, message.text, 1, y, 0xE0E0E0 + (alpha << 24));
}
@@ -91,13 +91,6 @@ public class ClientOverlayMessageSink extends ConsoleMessageSink {
matrices.popPose();
}
private static class Message {
private final Component text;
private final long created;
public Message(Component text, long created) {
this.text = text;
this.created = created;
}
private record Message(Component text, long created) {
}
}

View File

@@ -0,0 +1,45 @@
/*
* This file is part of architectury.
* Copyright (C) 2020, 2021 architectury
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package dev.architectury.test.entity;
import dev.architectury.networking.NetworkManager;
import net.minecraft.network.protocol.Packet;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MobCategory;
import net.minecraft.world.entity.vehicle.AbstractMinecart;
import net.minecraft.world.level.Level;
public class TestEntity extends AbstractMinecart {
public static final EntityType<TestEntity> TYPE = EntityType.Builder.of(TestEntity::new, MobCategory.MISC).sized(0.98F, 0.7F).clientTrackingRange(8).build("test_entity");
public TestEntity(EntityType<? extends AbstractMinecart> entityType, Level level) {
super(entityType, level);
}
@Override
public Type getMinecartType() {
return Type.RIDEABLE;
}
@Override
public Packet<?> getAddEntityPacket() {
return NetworkManager.createAddEntityPacket(this);
}
}

View File

@@ -0,0 +1,347 @@
/*
* This file is part of architectury.
* Copyright (C) 2020, 2021 architectury
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package dev.architectury.test.events;
import com.mojang.blaze3d.platform.InputConstants;
import dev.architectury.event.CompoundEventResult;
import dev.architectury.event.EventResult;
import dev.architectury.event.events.client.*;
import dev.architectury.event.events.common.*;
import dev.architectury.hooks.level.ExplosionHooks;
import dev.architectury.platform.Platform;
import dev.architectury.test.TestMod;
import dev.architectury.utils.Env;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.screens.inventory.AnvilScreen;
import net.minecraft.core.Position;
import net.minecraft.core.Vec3i;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import java.util.Optional;
public class DebugEvents {
public static void initialize() {
debugEvents();
if (Platform.getEnvironment() == Env.CLIENT)
debugEventsClient();
}
public static void debugEvents() {
BlockEvent.BREAK.register((world, pos, state, player, xp) -> {
TestMod.SINK.accept(player.getScoreboardName() + " breaks " + toShortString(pos) + logSide(player.level));
return EventResult.pass();
});
BlockEvent.PLACE.register((world, pos, state, placer) -> {
TestMod.SINK.accept(Optional.ofNullable(placer).map(Entity::getScoreboardName).orElse("null") + " places block at " + toShortString(pos) + logSide(world));
return EventResult.pass();
});
ChatEvent.SERVER.register((player, message, component) -> {
TestMod.SINK.accept("Server chat received: " + message.getRaw());
return EventResult.pass();
});
CommandPerformEvent.EVENT.register(event -> {
TestMod.SINK.accept("Server command performed: " + event.getResults().getReader().getString());
return EventResult.pass();
});
CommandRegistrationEvent.EVENT.register((dispatcher, selection) -> {
TestMod.SINK.accept("Server commands registers");
});
EntityEvent.LIVING_DEATH.register((entity, source) -> {
if (entity instanceof Player) {
TestMod.SINK.accept(entity.getScoreboardName() + " died to " + source.getMsgId() + logSide(entity.level));
}
return EventResult.pass();
});
EntityEvent.LIVING_HURT.register((entity, source, amount) -> {
if (source.getDirectEntity() instanceof Player) {
TestMod.SINK.accept(source.getDirectEntity().getScoreboardName() + " deals %.2f damage" + logSide(entity.level), amount);
}
return EventResult.pass();
});
EntityEvent.ADD.register((entity, level) -> {
if (entity instanceof Player) {
TestMod.SINK.accept(entity.getScoreboardName() + " was added to " + level.dimension().location().toString() + logSide(level));
}
return EventResult.pass();
});
EntityEvent.ENTER_SECTION.register(((entity, nx, ny, nz, ox, oy, oz) -> {
if (entity instanceof Player player) {
TestMod.SINK.accept("%s switched section: %s => %s", entity.getScoreboardName(), sectionPos(ox, oy, oz), sectionPos(nx, oy, nz));
player.displayClientMessage(new TextComponent("Entering chunk: " + sectionPos(nx, ny, nz)), true);
}
}));
EntityEvent.LIVING_CHECK_SPAWN.register(((entity, level, x, y, z, type, spawner) -> {
var sb = new StringBuilder();
sb.append(entity.getType());
sb.append(" is trying to spawn");
sb.append(" at ");
sb.append(toShortString(new Vec3(x, y, z)));
if (level instanceof Level) {
sb.append(" in world ");
sb.append(((Level) level).dimension().location());
}
sb.append(" from cause ");
sb.append(type.name());
if (spawner != null) {
sb.append(" (");
sb.append(spawner);
sb.append(") ");
}
TestMod.SINK.accept(sb.toString());
return EventResult.pass();
}));
ExplosionEvent.DETONATE.register((world, explosion, affectedEntities) -> {
TestMod.SINK.accept(world.dimension().location() + " explodes at " + toShortString(ExplosionHooks.getPosition(explosion)) + logSide(world));
});
InteractionEvent.LEFT_CLICK_BLOCK.register((player, hand, pos, face) -> {
TestMod.SINK.accept(player.getScoreboardName() + " left clicks " + toShortString(pos) + logSide(player.level));
return EventResult.pass();
});
InteractionEvent.RIGHT_CLICK_BLOCK.register((player, hand, pos, face) -> {
TestMod.SINK.accept(player.getScoreboardName() + " right clicks " + toShortString(pos) + logSide(player.level));
return EventResult.pass();
});
InteractionEvent.RIGHT_CLICK_ITEM.register((player, hand) -> {
TestMod.SINK.accept(player.getScoreboardName() + " uses " + (hand == InteractionHand.MAIN_HAND ? "main hand" : "off hand") + logSide(player.level));
return CompoundEventResult.pass();
});
InteractionEvent.INTERACT_ENTITY.register((player, entity, hand) -> {
TestMod.SINK.accept(player.getScoreboardName() + " interacts with " + entity.getScoreboardName() + " using " + (hand == InteractionHand.MAIN_HAND ? "main hand" : "off hand") + logSide(player.level));
return EventResult.pass();
});
InteractionEvent.FARMLAND_TRAMPLE.register((level, pos, state, distance, entity) -> {
if (entity instanceof Player && ((Player) entity).getItemBySlot(EquipmentSlot.FEET).getItem() == Items.DIAMOND_BOOTS) {
return EventResult.interrupt(false);
}
TestMod.SINK.accept("%s trampled farmland (%s) at %s in %s (Fall height: %f blocks)", entity, state, pos, level, distance);
return EventResult.pass();
});
LifecycleEvent.SERVER_BEFORE_START.register(instance -> {
TestMod.SINK.accept("Server ready to start");
});
LifecycleEvent.SERVER_STARTING.register(instance -> {
TestMod.SINK.accept("Server starting");
});
LifecycleEvent.SERVER_STARTED.register(instance -> {
TestMod.SINK.accept("Server started");
});
LifecycleEvent.SERVER_STOPPING.register(instance -> {
TestMod.SINK.accept("Server stopping");
});
LifecycleEvent.SERVER_STOPPED.register(instance -> {
TestMod.SINK.accept("Server stopped");
});
LifecycleEvent.SERVER_LEVEL_LOAD.register(instance -> {
TestMod.SINK.accept("Server world loaded: " + instance.dimension().location());
});
LifecycleEvent.SERVER_LEVEL_UNLOAD.register(instance -> {
TestMod.SINK.accept("Server world unloaded: " + instance.dimension().location());
});
LifecycleEvent.SERVER_LEVEL_SAVE.register(instance -> {
TestMod.SINK.accept("Server world saved: " + instance.dimension().location());
});
PlayerEvent.PLAYER_JOIN.register(player -> {
TestMod.SINK.accept(player.getScoreboardName() + " joined" + logSide(player.level));
});
PlayerEvent.PLAYER_QUIT.register(player -> {
TestMod.SINK.accept(player.getScoreboardName() + " quit" + logSide(player.level));
});
PlayerEvent.PLAYER_RESPAWN.register((player, conqueredEnd) -> {
if (!conqueredEnd) {
TestMod.SINK.accept(player.getScoreboardName() + " respawns " + logSide(player.level));
}
});
PlayerEvent.PLAYER_CLONE.register((oldPlayer, newPlayer, wonGame) -> {
TestMod.SINK.accept("Player cloned: " + newPlayer.getScoreboardName() + logSide(newPlayer.level));
});
PlayerEvent.PLAYER_ADVANCEMENT.register((player, advancement) -> {
TestMod.SINK.accept(player.getScoreboardName() + " was awarded with %s" + logSide(player.level), advancement.getChatComponent().getString());
});
PlayerEvent.CRAFT_ITEM.register((player, constructed, inventory) -> {
TestMod.SINK.accept(player.getScoreboardName() + " crafts " + new TranslatableComponent(constructed.getDescriptionId()).getString() + logSide(player.level));
});
PlayerEvent.SMELT_ITEM.register((player, smelted) -> {
TestMod.SINK.accept(player.getScoreboardName() + " smelts " + new TranslatableComponent(smelted.getDescriptionId()).getString() + logSide(player.level));
});
PlayerEvent.PICKUP_ITEM_POST.register((player, entity, stack) -> {
TestMod.SINK.accept(player.getScoreboardName() + " picks up " + new TranslatableComponent(stack.getDescriptionId()).getString() + logSide(player.level));
});
PlayerEvent.DROP_ITEM.register((player, entity) -> {
TestMod.SINK.accept(player.getScoreboardName() + " drops " + new TranslatableComponent(entity.getItem().getDescriptionId()).getString() + logSide(player.level));
return EventResult.pass();
});
PlayerEvent.OPEN_MENU.register((player, menu) -> {
TestMod.SINK.accept(player.getScoreboardName() + " opens " + toSimpleName(menu) + logSide(player.level));
});
PlayerEvent.CLOSE_MENU.register((player, menu) -> {
TestMod.SINK.accept(player.getScoreboardName() + " closes " + toSimpleName(menu) + logSide(player.level));
});
PlayerEvent.CHANGE_DIMENSION.register((player, oldLevel, newLevel) -> {
TestMod.SINK.accept(player.getScoreboardName() + " switched from " + oldLevel.location() + " to " + newLevel.location() + logSide(player.level));
});
PlayerEvent.FILL_BUCKET.register(((player, level, stack, target) -> {
TestMod.SINK.accept("%s used a bucket (%s) in %s%s while looking at %s", player.getScoreboardName(), stack, level.dimension().location(), logSide(level), target == null ? "nothing" : target.getLocation());
return CompoundEventResult.pass();
}));
LightningEvent.STRIKE.register((bolt, level, pos, toStrike) -> {
TestMod.SINK.accept(bolt.getScoreboardName() + " struck at " + toShortString(pos) + logSide(level));
});
ChunkEvent.LOAD_DATA.register((chunk, level, nbt) -> {
TestMod.SINK.accept("Chunk loaded at x=" + chunk.getPos().x + ", z=" + chunk.getPos().z + " in dimension '" + level.dimension().location() + "'");
});
ChunkEvent.SAVE_DATA.register((chunk, level, nbt) -> {
TestMod.SINK.accept("Chunk saved at x=" + chunk.getPos().x + ", z=" + chunk.getPos().z + " in dimension '" + level.dimension().location() + "'");
});
}
public static String toShortString(Vec3i pos) {
return pos.getX() + ", " + pos.getY() + ", " + pos.getZ();
}
public static String toShortString(Position pos) {
return pos.x() + ", " + pos.y() + ", " + pos.z();
}
public static String logSide(Level level) {
if (level.isClientSide())
return " (client)";
return " (server)";
}
@Environment(EnvType.CLIENT)
public static void debugEventsClient() {
ClientTickEvent.CLIENT_LEVEL_PRE.register(instance -> {
try {
// Uncomment the following line to see the profiler spike for root.tick.level.architecturyClientLevelPreTick
//Thread.sleep(10);
} catch (Throwable e) {
e.printStackTrace();
}
});
ClientChatEvent.PROCESS.register(message -> {
TestMod.SINK.accept("Client chat sent: " + message);
return CompoundEventResult.pass();
});
ClientChatEvent.RECEIVED.register((type, message, sender) -> {
TestMod.SINK.accept("Client chat received: " + message.getString());
return CompoundEventResult.pass();
});
ClientLifecycleEvent.CLIENT_LEVEL_LOAD.register(world -> {
TestMod.SINK.accept("Client world loaded: " + world.dimension().location().toString());
});
ClientPlayerEvent.CLIENT_PLAYER_JOIN.register(player -> {
TestMod.SINK.accept(player.getScoreboardName() + " joined (client)");
});
ClientPlayerEvent.CLIENT_PLAYER_QUIT.register(player -> {
if (player != null) {
TestMod.SINK.accept(player.getScoreboardName() + " quit (client)");
}
});
ClientPlayerEvent.CLIENT_PLAYER_RESPAWN.register((oldPlayer, newPlayer) -> {
TestMod.SINK.accept(newPlayer.getScoreboardName() + " respawned (client)");
});
ClientGuiEvent.INIT_PRE.register((screen, access) -> {
TestMod.SINK.accept(toSimpleName(screen) + " initializes");
return EventResult.pass();
});
InteractionEvent.CLIENT_LEFT_CLICK_AIR.register((player, hand) -> {
TestMod.SINK.accept(player.getScoreboardName() + " left clicks air" + logSide(player.level));
});
InteractionEvent.CLIENT_RIGHT_CLICK_AIR.register((player, hand) -> {
TestMod.SINK.accept(player.getScoreboardName() + " right clicks air" + logSide(player.level));
});
ClientRecipeUpdateEvent.EVENT.register(recipeManager -> {
TestMod.SINK.accept("Client recipes received");
});
ClientTextureStitchEvent.POST.register(atlas -> {
TestMod.SINK.accept("Client texture stitched: " + atlas.location());
});
ClientScreenInputEvent.MOUSE_SCROLLED_PRE.register((client, screen, mouseX, mouseY, amount) -> {
TestMod.SINK.accept("Screen Mouse scrolled: %.2f distance", amount);
return EventResult.pass();
});
ClientScreenInputEvent.MOUSE_CLICKED_PRE.register((client, screen, mouseX, mouseY, button) -> {
TestMod.SINK.accept("Screen Mouse clicked: " + button);
return EventResult.pass();
});
ClientScreenInputEvent.MOUSE_RELEASED_PRE.register((client, screen, mouseX, mouseY, button) -> {
TestMod.SINK.accept("Screen Mouse released: " + button);
return EventResult.pass();
});
ClientScreenInputEvent.MOUSE_DRAGGED_PRE.register((client, screen, mouseX1, mouseY1, button, mouseX2, mouseY2) -> {
TestMod.SINK.accept("Screen Mouse dragged: %d (%d,%d) by (%d,%d)", button, (int) mouseX1, (int) mouseY1, (int) mouseX2, (int) mouseY2);
return EventResult.pass();
});
ClientScreenInputEvent.CHAR_TYPED_PRE.register((client, screen, character, keyCode) -> {
TestMod.SINK.accept("Screen Char typed: " + character);
return EventResult.pass();
});
ClientScreenInputEvent.KEY_PRESSED_PRE.register((client, screen, keyCode, scanCode, modifiers) -> {
TestMod.SINK.accept("Screen Key pressed: " + InputConstants.getKey(keyCode, scanCode).getDisplayName().getString());
return EventResult.pass();
});
ClientScreenInputEvent.KEY_RELEASED_PRE.register((client, screen, keyCode, scanCode, modifiers) -> {
TestMod.SINK.accept("Screen Key released: " + InputConstants.getKey(keyCode, scanCode).getDisplayName().getString());
return EventResult.pass();
});
ClientRawInputEvent.MOUSE_SCROLLED.register((client, amount) -> {
TestMod.SINK.accept("Raw Mouse scrolled: %.2f distance", amount);
return EventResult.pass();
});
ClientRawInputEvent.MOUSE_CLICKED_PRE.register((client, button, action, mods) -> {
TestMod.SINK.accept("Raw Mouse clicked: " + button);
return EventResult.pass();
});
ClientRawInputEvent.KEY_PRESSED.register((client, keyCode, scanCode, action, modifiers) -> {
TestMod.SINK.accept("Raw Key pressed: " + InputConstants.getKey(keyCode, scanCode).getDisplayName().getString());
return EventResult.pass();
});
ClientGuiEvent.SET_SCREEN.register(screen -> {
if (screen instanceof AnvilScreen) {
return CompoundEventResult.interruptFalse(screen);
}
TestMod.SINK.accept("Screen has been changed to " + toSimpleName(screen));
return CompoundEventResult.pass();
});
}
private static String chunkPos(int x, int z) {
return "[" + x + ", " + z + "]";
}
private static String sectionPos(int x, int y, int z) {
return "[" + x + ", " + y + ", " + z + "]";
}
private static String toSimpleName(Object o) {
return o == null ? "null" : o.getClass().getSimpleName() + "@" + Integer.toHexString(o.hashCode());
}
}

View File

@@ -17,14 +17,14 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package me.shedaniel.architectury.test.gamerule;
package dev.architectury.test.gamerule;
import me.shedaniel.architectury.registry.GameRuleFactory;
import dev.architectury.registry.level.GameRuleFactory;
import net.minecraft.world.level.GameRules;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import static me.shedaniel.architectury.registry.GameRuleRegistry.register;
import static dev.architectury.registry.level.GameRuleRegistry.register;
public class TestGameRules {
private static final Logger LOGGER = LogManager.getLogger();

View File

@@ -17,17 +17,19 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package me.shedaniel.architectury.test.registry;
package dev.architectury.test.registry;
import me.shedaniel.architectury.hooks.EntityHooks;
import me.shedaniel.architectury.registry.BlockProperties;
import me.shedaniel.architectury.registry.DeferredRegister;
import me.shedaniel.architectury.registry.RegistrySupplier;
import me.shedaniel.architectury.test.TestMod;
import me.shedaniel.architectury.test.registry.objects.EquippableTickingItem;
import me.shedaniel.architectury.test.tab.TestCreativeTabs;
import dev.architectury.hooks.level.entity.EntityHooks;
import dev.architectury.registry.block.BlockProperties;
import dev.architectury.registry.registries.DeferredRegister;
import dev.architectury.registry.registries.RegistrySupplier;
import dev.architectury.test.entity.TestEntity;
import dev.architectury.test.registry.objects.EquippableTickingItem;
import dev.architectury.test.tab.TestCreativeTabs;
import dev.architectury.test.TestMod;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.BlockGetter;
@@ -37,11 +39,12 @@ import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import static me.shedaniel.architectury.test.TestMod.SINK;
import static dev.architectury.test.TestMod.SINK;
public class TestRegistries {
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(TestMod.MOD_ID, Registry.ITEM_REGISTRY);
public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(TestMod.MOD_ID, Registry.BLOCK_REGISTRY);
public static final DeferredRegister<EntityType<?>> ENTITY_TYPES = DeferredRegister.create(TestMod.MOD_ID, Registry.ENTITY_TYPE_REGISTRY);
public static final RegistrySupplier<Item> TEST_ITEM = ITEMS.register("test_item", () ->
new Item(new Item.Properties().tab(TestCreativeTabs.TEST_TAB)));
@@ -64,8 +67,11 @@ public class TestRegistries {
public static final RegistrySupplier<Item> COLLISION_BLOCK_ITEM = ITEMS.register("collision_block", () ->
new BlockItem(COLLISION_BLOCK.get(), new Item.Properties().tab(TestCreativeTabs.TEST_TAB)));
public static final RegistrySupplier<EntityType<TestEntity>> TEST_ENTITY = ENTITY_TYPES.register("test_entity", () -> TestEntity.TYPE);
public static void initialize() {
BLOCKS.register();
ITEMS.register();
ENTITY_TYPES.register();
}
}

View File

@@ -17,12 +17,12 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package me.shedaniel.architectury.test.registry.client;
package dev.architectury.test.registry.client;
import com.mojang.blaze3d.platform.InputConstants;
import me.shedaniel.architectury.event.events.client.ClientTickEvent;
import me.shedaniel.architectury.registry.KeyBindings;
import me.shedaniel.architectury.test.TestMod;
import dev.architectury.event.events.client.ClientTickEvent;
import dev.architectury.registry.client.keymappings.KeyMappingRegistry;
import dev.architectury.test.TestMod;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.KeyMapping;
@@ -32,8 +32,8 @@ import org.lwjgl.glfw.GLFW;
public class TestKeybinds {
@Environment(EnvType.CLIENT)
public static void initialize() {
KeyMapping mapping = new KeyMapping("key.architectury-test.test", InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_O, "category.architectury-test");
KeyBindings.registerKeyBinding(mapping);
var mapping = new KeyMapping("key.architectury-test.test", InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_O, "category.architectury-test");
KeyMappingRegistry.register(mapping);
ClientTickEvent.CLIENT_POST.register(instance -> {
while (mapping.consumeClick()) {
TestMod.SINK.accept("Key \"%s\" pressed!", I18n.get("key.architectury-test.test"));

View File

@@ -17,10 +17,10 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package me.shedaniel.architectury.test.registry.objects;
package dev.architectury.test.registry.objects;
import me.shedaniel.architectury.extensions.ItemExtension;
import me.shedaniel.architectury.test.TestMod;
import dev.architectury.extensions.ItemExtension;
import dev.architectury.test.TestMod;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.player.Player;

View File

@@ -17,16 +17,16 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package me.shedaniel.architectury.test.tab;
package dev.architectury.test.tab;
import me.shedaniel.architectury.registry.CreativeTabs;
import me.shedaniel.architectury.test.TestMod;
import me.shedaniel.architectury.test.registry.TestRegistries;
import dev.architectury.registry.CreativeTabRegistry;
import dev.architectury.test.TestMod;
import dev.architectury.test.registry.TestRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.ItemStack;
public class TestCreativeTabs {
public static final CreativeModeTab TEST_TAB = CreativeTabs.create(new ResourceLocation(TestMod.MOD_ID, "test_tab"),
public static final CreativeModeTab TEST_TAB = CreativeTabRegistry.create(new ResourceLocation(TestMod.MOD_ID, "test_tab"),
() -> new ItemStack(TestRegistries.TEST_ITEM.get()));
}

View File

@@ -17,31 +17,31 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package me.shedaniel.architectury.test.tags;
package dev.architectury.test.tags;
import me.shedaniel.architectury.event.events.BlockEvent;
import me.shedaniel.architectury.hooks.TagHooks;
import me.shedaniel.architectury.test.TestMod;
import dev.architectury.event.EventResult;
import dev.architectury.event.events.common.BlockEvent;
import dev.architectury.hooks.tags.TagHooks;
import dev.architectury.test.TestMod;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.tags.Tag;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.level.block.Block;
public class TestTags {
public static void initialize() {
// This will not be present, but it should return an empty tag
Tag.Named<Block> heartParticles = TagHooks.getBlockOptional(new ResourceLocation(TestMod.MOD_ID, "heart_particles"));
var heartParticles = TagHooks.optionalBlock(new ResourceLocation(TestMod.MOD_ID, "heart_particles"));
// This will act like a normal tag, we have emerald block here
Tag.Named<Block> heartParticles2 = TagHooks.getBlockOptional(new ResourceLocation(TestMod.MOD_ID, "heart_particles2"));
var heartParticles2 = TagHooks.optionalBlock(new ResourceLocation(TestMod.MOD_ID, "heart_particles2"));
BlockEvent.BREAK.register((world, pos, state, player, xp) -> {
if (player != null && !world.isClientSide() && (state.is(heartParticles) || state.is(heartParticles2))) {
((ServerLevel) world).sendParticles(player, ParticleTypes.HEART, false, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, 10, 0.0, 0.0, 0.0, 0.0);
}
return InteractionResult.PASS;
return EventResult.pass();
});
}
}

View File

@@ -17,10 +17,10 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package me.shedaniel.architectury.test.trade;
package dev.architectury.test.trade;
import me.shedaniel.architectury.registry.trade.SimpleTrade;
import me.shedaniel.architectury.registry.trade.TradeRegistry;
import dev.architectury.registry.level.entity.trade.SimpleTrade;
import dev.architectury.registry.level.entity.trade.TradeRegistry;
import net.minecraft.core.Registry;
import net.minecraft.world.entity.npc.VillagerProfession;
import net.minecraft.world.entity.npc.VillagerTrades;
@@ -29,14 +29,14 @@ import net.minecraft.world.item.Items;
public class TestTrades {
public static void init() {
for (VillagerProfession villagerProfession : Registry.VILLAGER_PROFESSION) {
for (var villagerProfession : Registry.VILLAGER_PROFESSION) {
TradeRegistry.registerVillagerTrade(villagerProfession, 1, TestTrades.createTrades());
}
TradeRegistry.registerTradeForWanderingTrader(false, TestTrades.createTrades());
}
private static VillagerTrades.ItemListing[] createTrades() {
SimpleTrade trade = new SimpleTrade(Items.APPLE.getDefaultInstance(), ItemStack.EMPTY, Items.ACACIA_BOAT.getDefaultInstance(), 1, 0, 1.0F);
var trade = new SimpleTrade(Items.APPLE.getDefaultInstance(), ItemStack.EMPTY, Items.ACACIA_BOAT.getDefaultInstance(), 1, 0, 1.0F);
return new VillagerTrades.ItemListing[]{trade};
}
}

View File

@@ -1,337 +0,0 @@
/*
* This file is part of architectury.
* Copyright (C) 2020, 2021 architectury
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package me.shedaniel.architectury.test.events;
import com.mojang.blaze3d.platform.InputConstants;
import me.shedaniel.architectury.event.CompoundEventResult;
import me.shedaniel.architectury.event.EventResult;
import me.shedaniel.architectury.event.events.*;
import me.shedaniel.architectury.event.events.client.*;
import me.shedaniel.architectury.hooks.ExplosionHooks;
import me.shedaniel.architectury.platform.Platform;
import me.shedaniel.architectury.utils.Env;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.screens.inventory.AnvilScreen;
import net.minecraft.core.Position;
import net.minecraft.core.Vec3i;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import java.util.Optional;
import static me.shedaniel.architectury.test.TestMod.SINK;
public class DebugEvents {
public static void initialize() {
debugEvents();
if (Platform.getEnvironment() == Env.CLIENT)
debugEventsClient();
}
public static void debugEvents() {
BlockEvent.BREAK.register((world, pos, state, player, xp) -> {
SINK.accept(player.getScoreboardName() + " breaks " + toShortString(pos) + logSide(player.level));
return InteractionResult.PASS;
});
BlockEvent.PLACE.register((world, pos, state, placer) -> {
SINK.accept(Optional.ofNullable(placer).map(Entity::getScoreboardName).orElse("null") + " places block at " + toShortString(pos) + logSide(world));
return InteractionResult.PASS;
});
ChatEvent.SERVER.register((player, message, component) -> {
SINK.accept("Server chat received: " + message.getRaw());
return InteractionResult.PASS;
});
CommandPerformEvent.EVENT.register(event -> {
SINK.accept("Server command performed: " + event.getResults().getReader().getString());
return InteractionResult.PASS;
});
CommandRegistrationEvent.EVENT.register((dispatcher, selection) -> {
SINK.accept("Server commands registers");
});
EntityEvent.LIVING_DEATH.register((entity, source) -> {
if (entity instanceof Player) {
SINK.accept(entity.getScoreboardName() + " died to " + source.getMsgId() + logSide(entity.level));
}
return InteractionResult.PASS;
});
EntityEvent.LIVING_ATTACK.register((entity, source, amount) -> {
if (source.getDirectEntity() instanceof Player) {
SINK.accept(source.getDirectEntity().getScoreboardName() + " deals %.2f damage" + logSide(entity.level), amount);
}
return InteractionResult.PASS;
});
EntityEvent.ADD.register((entity, level) -> {
if (entity instanceof Player) {
SINK.accept(entity.getScoreboardName() + " was added to " + level.dimension().location().toString() + logSide(level));
}
return InteractionResult.PASS;
});
EntityEvent.ENTER_SECTION.register(((entity, nx, ny, nz, ox, oy, oz) -> {
if (entity instanceof Player) {
Player player = (Player) entity;
SINK.accept("%s switched section: %s => %s", entity.getScoreboardName(), sectionPos(ox, oy, oz), sectionPos(nx, oy, nz));
player.displayClientMessage(new TextComponent("Entering chunk: " + sectionPos(nx, ny, nz)), true);
}
}));
EntityEvent.LIVING_CHECK_SPAWN.register(((entity, level, x, y, z, type, spawner) -> {
StringBuilder sb = new StringBuilder();
sb.append(entity.getType());
sb.append(" is trying to spawn");
sb.append(" at ");
sb.append(toShortString(new Vec3(x, y, z)));
if (level instanceof Level) {
sb.append(" in world ");
sb.append(((Level) level).dimension().location());
}
sb.append(" from cause ");
sb.append(type.name());
if (spawner != null) {
sb.append(" (");
sb.append(spawner);
sb.append(") ");
}
SINK.accept(sb.toString());
return EventResult.pass();
}));
ExplosionEvent.DETONATE.register((world, explosion, affectedEntities) -> {
SINK.accept(world.dimension().location() + " explodes at " + toShortString(ExplosionHooks.getPosition(explosion)) + logSide(world));
});
InteractionEvent.LEFT_CLICK_BLOCK.register((player, hand, pos, face) -> {
SINK.accept(player.getScoreboardName() + " left clicks " + toShortString(pos) + logSide(player.level));
return InteractionResult.PASS;
});
InteractionEvent.RIGHT_CLICK_BLOCK.register((player, hand, pos, face) -> {
SINK.accept(player.getScoreboardName() + " right clicks " + toShortString(pos) + logSide(player.level));
return InteractionResult.PASS;
});
InteractionEvent.RIGHT_CLICK_ITEM.register((player, hand) -> {
SINK.accept(player.getScoreboardName() + " uses " + (hand == InteractionHand.MAIN_HAND ? "main hand" : "off hand") + logSide(player.level));
return InteractionResultHolder.pass(player.getItemInHand(hand));
});
InteractionEvent.INTERACT_ENTITY.register((player, entity, hand) -> {
SINK.accept(player.getScoreboardName() + " interacts with " + entity.getScoreboardName() + " using " + (hand == InteractionHand.MAIN_HAND ? "main hand" : "off hand") + logSide(player.level));
return InteractionResult.PASS;
});
InteractionEvent.FARMLAND_TRAMPLE.register((level, pos, state, distance, entity) -> {
if (entity instanceof Player && ((Player) entity).getItemBySlot(EquipmentSlot.FEET).getItem() == Items.DIAMOND_BOOTS) {
return EventResult.interrupt(false);
}
SINK.accept("%s trampled farmland (%s) at %s in %s (Fall height: %f blocks)", entity, state, pos, level, distance);
return EventResult.pass();
});
LifecycleEvent.SERVER_BEFORE_START.register(instance -> {
SINK.accept("Server ready to start");
});
LifecycleEvent.SERVER_STARTING.register(instance -> {
SINK.accept("Server starting");
});
LifecycleEvent.SERVER_STARTED.register(instance -> {
SINK.accept("Server started");
});
LifecycleEvent.SERVER_STOPPING.register(instance -> {
SINK.accept("Server stopping");
});
LifecycleEvent.SERVER_STOPPED.register(instance -> {
SINK.accept("Server stopped");
});
LifecycleEvent.SERVER_WORLD_LOAD.register(instance -> {
SINK.accept("Server world loaded: " + instance.dimension().location());
});
LifecycleEvent.SERVER_WORLD_UNLOAD.register(instance -> {
SINK.accept("Server world unloaded: " + instance.dimension().location());
});
LifecycleEvent.SERVER_WORLD_SAVE.register(instance -> {
SINK.accept("Server world saved: " + instance.dimension().location());
});
PlayerEvent.PLAYER_JOIN.register(player -> {
SINK.accept(player.getScoreboardName() + " joined" + logSide(player.level));
});
PlayerEvent.PLAYER_QUIT.register(player -> {
SINK.accept(player.getScoreboardName() + " quit" + logSide(player.level));
});
PlayerEvent.PLAYER_RESPAWN.register((player, conqueredEnd) -> {
if (!conqueredEnd) {
SINK.accept(player.getScoreboardName() + " respawns " + logSide(player.level));
}
});
PlayerEvent.PLAYER_CLONE.register((oldPlayer, newPlayer, wonGame) -> {
SINK.accept("Player cloned: " + newPlayer.getScoreboardName() + logSide(newPlayer.level));
});
PlayerEvent.PLAYER_ADVANCEMENT.register((player, advancement) -> {
SINK.accept(player.getScoreboardName() + " was awarded with %s" + logSide(player.level), advancement.getChatComponent().getString());
});
PlayerEvent.CRAFT_ITEM.register((player, constructed, inventory) -> {
SINK.accept(player.getScoreboardName() + " crafts " + new TranslatableComponent(constructed.getDescriptionId()).getString() + logSide(player.level));
});
PlayerEvent.SMELT_ITEM.register((player, smelted) -> {
SINK.accept(player.getScoreboardName() + " smelts " + new TranslatableComponent(smelted.getDescriptionId()).getString() + logSide(player.level));
});
PlayerEvent.PICKUP_ITEM_POST.register((player, entity, stack) -> {
SINK.accept(player.getScoreboardName() + " picks up " + new TranslatableComponent(stack.getDescriptionId()).getString() + logSide(player.level));
});
PlayerEvent.DROP_ITEM.register((player, entity) -> {
SINK.accept(player.getScoreboardName() + " drops " + new TranslatableComponent(entity.getItem().getDescriptionId()).getString() + logSide(player.level));
return InteractionResult.PASS;
});
PlayerEvent.OPEN_MENU.register((player, menu) -> {
SINK.accept(player.getScoreboardName() + " opens " + toSimpleName(menu) + logSide(player.level));
});
PlayerEvent.CLOSE_MENU.register((player, menu) -> {
SINK.accept(player.getScoreboardName() + " closes " + toSimpleName(menu) + logSide(player.level));
});
PlayerEvent.CHANGE_DIMENSION.register((player, oldLevel, newLevel) -> {
SINK.accept(player.getScoreboardName() + " switched from " + oldLevel.location() + " to " + newLevel.location() + logSide(player.level));
});
PlayerEvent.FILL_BUCKET.register(((player, level, stack, target) -> {
SINK.accept("%s used a bucket (%s) in %s%s while looking at %s", player.getScoreboardName(), stack, level.dimension().location(), logSide(level), target == null ? "nothing" : target.getLocation());
return CompoundEventResult.pass();
}));
LightningEvent.STRIKE.register((bolt, level, pos, toStrike) -> {
SINK.accept(bolt.getScoreboardName() + " struck at " + toShortString(pos) + logSide(level));
});
}
public static String toShortString(Vec3i pos) {
return pos.getX() + ", " + pos.getY() + ", " + pos.getZ();
}
public static String toShortString(Position pos) {
return pos.x() + ", " + pos.y() + ", " + pos.z();
}
public static String logSide(Level level) {
if (level.isClientSide())
return " (client)";
return " (server)";
}
@Environment(EnvType.CLIENT)
public static void debugEventsClient() {
ClientChatEvent.CLIENT.register(message -> {
SINK.accept("Client chat sent: " + message);
return InteractionResultHolder.pass(message);
});
ClientChatEvent.CLIENT_RECEIVED.register((type, message, sender) -> {
SINK.accept("Client chat received: " + message.getString());
return InteractionResultHolder.pass(message);
});
ClientLifecycleEvent.CLIENT_WORLD_LOAD.register(world -> {
SINK.accept("Client world loaded: " + world.dimension().location().toString());
});
ClientPlayerEvent.CLIENT_PLAYER_JOIN.register(player -> {
SINK.accept(player.getScoreboardName() + " joined (client)");
});
ClientPlayerEvent.CLIENT_PLAYER_QUIT.register(player -> {
if (player != null) {
SINK.accept(player.getScoreboardName() + " quit (client)");
}
});
ClientPlayerEvent.CLIENT_PLAYER_RESPAWN.register((oldPlayer, newPlayer) -> {
SINK.accept(newPlayer.getScoreboardName() + " respawned (client)");
});
GuiEvent.INIT_PRE.register((screen, access) -> {
SINK.accept(toSimpleName(screen) + " initializes");
return InteractionResult.PASS;
});
InteractionEvent.CLIENT_LEFT_CLICK_AIR.register((player, hand) -> {
SINK.accept(player.getScoreboardName() + " left clicks air" + logSide(player.level));
});
InteractionEvent.CLIENT_RIGHT_CLICK_AIR.register((player, hand) -> {
SINK.accept(player.getScoreboardName() + " right clicks air" + logSide(player.level));
});
RecipeUpdateEvent.EVENT.register(recipeManager -> {
SINK.accept("Client recipes received");
});
TextureStitchEvent.POST.register(atlas -> {
SINK.accept("Client texture stitched: " + atlas.location());
});
ClientScreenInputEvent.MOUSE_SCROLLED_PRE.register((client, screen, mouseX, mouseY, amount) -> {
SINK.accept("Screen Mouse scrolled: %.2f distance", amount);
return InteractionResult.PASS;
});
ClientScreenInputEvent.MOUSE_CLICKED_PRE.register((client, screen, mouseX, mouseY, button) -> {
SINK.accept("Screen Mouse clicked: " + button);
return InteractionResult.PASS;
});
ClientScreenInputEvent.MOUSE_RELEASED_PRE.register((client, screen, mouseX, mouseY, button) -> {
SINK.accept("Screen Mouse released: " + button);
return InteractionResult.PASS;
});
ClientScreenInputEvent.MOUSE_DRAGGED_PRE.register((client, screen, mouseX1, mouseY1, button, mouseX2, mouseY2) -> {
SINK.accept("Screen Mouse dragged: %d (%d,%d) by (%d,%d)", button, (int) mouseX1, (int) mouseY1, (int) mouseX2, (int) mouseY2);
return InteractionResult.PASS;
});
ClientScreenInputEvent.CHAR_TYPED_PRE.register((client, screen, character, keyCode) -> {
SINK.accept("Screen Char typed: " + character);
return InteractionResult.PASS;
});
ClientScreenInputEvent.KEY_PRESSED_PRE.register((client, screen, keyCode, scanCode, modifiers) -> {
SINK.accept("Screen Key pressed: " + InputConstants.getKey(keyCode, scanCode).getDisplayName().getString());
return InteractionResult.PASS;
});
ClientScreenInputEvent.KEY_RELEASED_PRE.register((client, screen, keyCode, scanCode, modifiers) -> {
SINK.accept("Screen Key released: " + InputConstants.getKey(keyCode, scanCode).getDisplayName().getString());
return InteractionResult.PASS;
});
ClientRawInputEvent.MOUSE_SCROLLED.register((client, amount) -> {
SINK.accept("Raw Mouse scrolled: %.2f distance", amount);
return InteractionResult.PASS;
});
ClientRawInputEvent.MOUSE_CLICKED_PRE.register((client, button, action, mods) -> {
SINK.accept("Raw Mouse clicked: " + button);
return InteractionResult.PASS;
});
ClientRawInputEvent.KEY_PRESSED.register((client, keyCode, scanCode, action, modifiers) -> {
SINK.accept("Raw Key pressed: " + InputConstants.getKey(keyCode, scanCode).getDisplayName().getString());
return InteractionResult.PASS;
});
GuiEvent.SET_SCREEN.register(screen -> {
if (screen instanceof AnvilScreen) {
return InteractionResultHolder.fail(screen);
}
SINK.accept("Screen has been changed to " + toSimpleName(screen));
return InteractionResultHolder.pass(screen);
});
}
private static String chunkPos(int x, int z) {
return "[" + x + ", " + z + "]";
}
private static String sectionPos(int x, int y, int z) {
return "[" + x + ", " + y + ", " + z + "]";
}
private static String toSimpleName(Object o) {
return o == null ? "null" : o.getClass().getSimpleName() + "@" + Integer.toHexString(o.hashCode());
}
}