message on sleep
Sendet eine nachricht, wenn sich der Client schlafen legt. Vorstufe zum testen, dass der event-caller auch funktioniert
This commit is contained in:
parent
88ba212779
commit
f58ffa9b65
|
@ -1,11 +1,20 @@
|
||||||
package modchest;
|
package modchest;
|
||||||
|
|
||||||
import modchest.block.modBlocks;
|
|
||||||
import net.fabricmc.api.ClientModInitializer;
|
import net.fabricmc.api.ClientModInitializer;
|
||||||
|
import net.minecraft.client.MinecraftClient;
|
||||||
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
|
||||||
public class REServerModClient implements ClientModInitializer {
|
public class REServerModClient implements ClientModInitializer {
|
||||||
@Override
|
@Override
|
||||||
public void onInitializeClient() {
|
public void onInitializeClient() {
|
||||||
// This entrypoint is suitable for setting up client-specific logic, such as rendering.
|
// This entrypoint is suitable for setting up client-specific logic, such as rendering.
|
||||||
|
//EntitySleepEvents.START_SLEEPING.register(new entitySleepStartSleepingEventHandler());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void writeMessage(String text) { //holt den Spieler dieses Clients und sendet ihm eine Nachricht
|
||||||
|
PlayerEntity thisPlayer = MinecraftClient.getInstance().player;
|
||||||
|
assert thisPlayer != null;
|
||||||
|
thisPlayer.sendMessage(Text.literal(text));
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,10 +2,11 @@ package modchest;
|
||||||
|
|
||||||
import modchest.block.entity.modBlockEntities;
|
import modchest.block.entity.modBlockEntities;
|
||||||
import modchest.block.modBlocks;
|
import modchest.block.modBlocks;
|
||||||
|
import modchest.event.entitySleepStartSleepingEventHandler;
|
||||||
import modchest.item.modItemGroup;
|
import modchest.item.modItemGroup;
|
||||||
import modchest.item.modItems;
|
import modchest.item.modItems;
|
||||||
import net.fabricmc.api.ModInitializer;
|
import net.fabricmc.api.ModInitializer;
|
||||||
|
import net.fabricmc.fabric.api.entity.event.v1.EntitySleepEvents;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -21,6 +22,7 @@ public class REServerMod implements ModInitializer {
|
||||||
modItems.setItems(); // die Items werden erstellt
|
modItems.setItems(); // die Items werden erstellt
|
||||||
modBlocks.setBlocks(); // Hier werden die Blöcke erstellt
|
modBlocks.setBlocks(); // Hier werden die Blöcke erstellt
|
||||||
modBlockEntities.registerBlockEntities(); // Die Interaktionsmenüs für die Blöcke werden erstellt
|
modBlockEntities.registerBlockEntities(); // Die Interaktionsmenüs für die Blöcke werden erstellt
|
||||||
|
EntitySleepEvents.START_SLEEPING.register(new entitySleepStartSleepingEventHandler());
|
||||||
|
|
||||||
LOGGER.info("Modchest erfolgreich geladen!");
|
LOGGER.info("Modchest erfolgreich geladen!");
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
package modchest.event;
|
||||||
|
|
||||||
|
import net.fabricmc.fabric.api.entity.event.v1.EntitySleepEvents;
|
||||||
|
import net.minecraft.entity.LivingEntity;
|
||||||
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
|
public class entitySleepStartSleepingEventHandler implements EntitySleepEvents.StartSleeping {
|
||||||
|
@Override
|
||||||
|
public void onStartSleeping(LivingEntity entity, BlockPos sleepingPos) { //Methode die aufgerufen wird, wenn sich ein entity Hinlegt
|
||||||
|
if (entity instanceof PlayerEntity) { //ueberprueft ob das Entity ein Spieler ist
|
||||||
|
entity.sendMessage(Text.of("Schlafmütze!"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue