use of net.minecraftforge.eventbus.api.SubscribeEvent in project MC-Prefab by Brian-Wuest.
the class StructureEventHandler method PlayerLoggedIn.
/**
* This event is used to determine if the player should be given the starting house item when they log in.
*
* @param event The event object.
*/
@SubscribeEvent
public static void PlayerLoggedIn(PlayerLoggedInEvent event) {
if (!event.getPlayer().level.isClientSide() && event.getPlayer() instanceof ServerPlayer) {
ServerPlayer player = (ServerPlayer) event.getPlayer();
EntityPlayerConfiguration playerConfig = EntityPlayerConfiguration.loadFromEntityData(player);
String startingItem = CommonProxy.proxyConfiguration.serverConfiguration.startingItem;
if (!playerConfig.givenHouseBuilder && startingItem != null) {
ItemStack stack = ItemStack.EMPTY;
switch(startingItem.toLowerCase()) {
case "starting house":
{
stack = new ItemStack(ModRegistry.StartHouse.get());
break;
}
case "moderate house":
{
stack = new ItemStack(ModRegistry.ModerateHouse.get());
break;
}
}
if (!stack.isEmpty()) {
System.out.println(player.getDisplayName().getString() + " joined the game for the first time. Giving them starting item.");
player.getInventory().add(stack);
player.containerMenu.broadcastChanges();
// Make sure to set the tag for this player so they don't get the item again.
playerConfig.givenHouseBuilder = true;
playerConfig.saveToPlayer(player);
}
}
// Send the tag to the client.
Prefab.network.sendTo(new PlayerEntityTagMessage(playerConfig.getModIsPlayerNewTag(player)), ((ServerPlayer) event.getPlayer()).connection.connection, NetworkDirection.PLAY_TO_CLIENT);
}
}
use of net.minecraftforge.eventbus.api.SubscribeEvent in project MC-Prefab by Brian-Wuest.
the class ClientEventHandler method KeyInput.
@SubscribeEvent(priority = EventPriority.NORMAL)
@OnlyIn(Dist.CLIENT)
public static void KeyInput(InputEvent.KeyInputEvent event) {
for (KeyMapping binding : ClientEventHandler.keyBindings) {
if (binding.isDown()) {
if (StructureRenderHandler.currentStructure != null) {
ItemStack mainHandStack = Minecraft.getInstance().player.getMainHandItem();
ItemStack offHandStack = Minecraft.getInstance().player.getOffhandItem();
boolean foundCorrectStructureItem = false;
if (mainHandStack != ItemStack.EMPTY || offHandStack != ItemStack.EMPTY) {
StructureTagMessage.EnumStructureConfiguration structureConfigurationEnum = StructureTagMessage.EnumStructureConfiguration.getByConfigurationInstance(StructureRenderHandler.currentConfiguration);
if (mainHandStack != ItemStack.EMPTY && mainHandStack.getItem() instanceof StructureItem) {
// Check main hand.
foundCorrectStructureItem = ClientEventHandler.checkIfStackIsCorrectGui(structureConfigurationEnum, mainHandStack);
}
if (!foundCorrectStructureItem && offHandStack != ItemStack.EMPTY && offHandStack.getItem() instanceof StructureItem) {
// Main hand is not correct item; check off-hand
foundCorrectStructureItem = ClientEventHandler.checkIfStackIsCorrectGui(structureConfigurationEnum, offHandStack);
}
}
if (foundCorrectStructureItem) {
Prefab.network.sendToServer(new StructureTagMessage(StructureRenderHandler.currentConfiguration.WriteToCompoundTag(), StructureTagMessage.EnumStructureConfiguration.getByConfigurationInstance(StructureRenderHandler.currentConfiguration)));
}
StructureRenderHandler.currentStructure = null;
}
break;
}
}
}
use of net.minecraftforge.eventbus.api.SubscribeEvent in project RealisticArmorTiers by IsakViste.
the class EventEquipmentSets method onServerTick.
@SubscribeEvent
public void onServerTick(TickEvent.ServerTickEvent evt) {
MinecraftServer server = ServerLifecycleHooks.getCurrentServer();
List<ServerPlayerEntity> playerList = Lists.newArrayList(server.getPlayerList().getPlayers());
IArmor armors = null;
List<PotionEffect> setEffects = new ArrayList<>();
boolean foundWhole = false;
for (ServerPlayerEntity serverPlayerEntity : playerList) {
int m;
List<ItemStack> stacks;
if (serverPlayerEntity.getCapability(ArmorProvider.Armor).isPresent()) {
armors = (IArmor) serverPlayerEntity.getCapability(ArmorProvider.Armor);
stacks = (List<ItemStack>) serverPlayerEntity.getArmorSlots();
int numberOfStack = 0;
for (ItemStack stack : stacks) {
if (!stack.isEmpty()) {
numberOfStack++;
}
}
if (numberOfStack == armors.getItems().size()) {
foundWhole = true;
for (ItemStack stack : stacks) {
boolean found = false;
if (!stack.isEmpty()) {
for (int l = 0; l < armors.getItems().size(); l++) {
if (stack.getItem().equals(armors.getItems().get(l).getItem())) {
found = true;
break;
}
}
if (!found) {
foundWhole = false;
break;
}
}
}
}
}
if (foundWhole) {
setEffects = armors.getPotionEffects();
} else {
if (serverPlayerEntity.getCapability(ArmorProvider.Armor).isPresent()) {
if (armors != null) {
m = 0;
setEffects = armors.getPotionEffects();
while (m < setEffects.size()) {
RegistryObject<Effect> potionEffect = RegistryObject.of(new ResourceLocation(setEffects.get(m).id), ForgeRegistries.POTIONS);
if (potionEffect.isPresent()) {
serverPlayerEntity.removeEffect(potionEffect.get());
}
m++;
}
armors.removeAllItems();
Collection<EffectInstance> potionEffectsPlayer = serverPlayerEntity.getActiveEffects();
Iterator<EffectInstance> potionEffects = potionEffectsPlayer.iterator();
while (potionEffects.hasNext()) {
EffectInstance o = potionEffects.next();
ResourceLocation effectResLoc = o.getEffect().getRegistryName();
if (effectResLoc == null) {
RealisticArmorTiers.LOGGER.warn("Could not find ResourceLocation of " + o.getDescriptionId());
continue;
}
PotionEffect usedPotion = new PotionEffect(effectResLoc.getNamespace() + ":" + o.getEffect().getRegistryName().getPath(), o.getAmplifier(), o.getDuration());
armors.addUsedPotionEffect(usedPotion);
potionEffects.remove();
}
stacks = (List<ItemStack>) serverPlayerEntity.getArmorSlots();
for (ItemStack stack : stacks) {
if (!stack.isEmpty()) {
armors.addItem(stack.copy());
}
}
}
} else {
serverPlayerEntity.removeAllEffects();
}
int setNumber = sets.armors.checkIfSet(serverPlayerEntity);
if (setNumber != -1) {
setEffects = sets.armors.getPotionEffects(setNumber);
}
if (serverPlayerEntity.getCapability(ArmorProvider.Armor).isPresent()) {
if (setEffects != null && armors != null) {
armors.addPotionEffectList(setEffects);
}
}
}
if (armors != null) {
if (setEffects != null) {
m = 0;
while (m < setEffects.size()) {
Equiped.addPotionEffect(serverPlayerEntity, armors.getPotionEffects().get(m));
m++;
}
}
if (!foundWhole) {
setEffects = armors.getUsedPotionEffects();
Equiped.addUsedPotionEffect(serverPlayerEntity, setEffects, armors);
}
}
}
}
use of net.minecraftforge.eventbus.api.SubscribeEvent in project Overloaded by CJ-MC-Mods.
the class RenderMultiToolAssist method onMouseEvent.
@SubscribeEvent
public static void onMouseEvent(InputEvent.MouseScrollEvent event) {
ClientPlayerEntity player = Minecraft.getInstance().player;
if (event.getScrollDelta() != 0 && player != null && player.isShiftKeyDown()) {
ItemStack stack = player.getMainHandItem();
if (player.isShiftKeyDown() && !stack.isEmpty() && stack.getItem() == ModItems.multiTool) {
changeHelpMode((int) Math.round(event.getScrollDelta()));
player.displayClientMessage(new StringTextComponent("Assist Mode: " + getAssistMode().getName()), true);
event.setCanceled(true);
}
}
}
use of net.minecraftforge.eventbus.api.SubscribeEvent in project MinecraftForge by MinecraftForge.
the class ForgeMod method registerLootData.
// ModBus
@SubscribeEvent
// automatically called by Forge
@SuppressWarnings("unused")
public void registerLootData(RegistryEvent.Register<GlobalLootModifierSerializer<?>> event) {
// Ignore the event itself: this is done only not to statically initialize our custom LootConditionType
Registry.register(Registry.LOOT_CONDITION_TYPE, new ResourceLocation("forge:loot_table_id"), LootTableIdCondition.LOOT_TABLE_ID);
Registry.register(Registry.LOOT_CONDITION_TYPE, new ResourceLocation("forge:can_tool_perform_action"), CanToolPerformAction.LOOT_CONDITION_TYPE);
}
Aggregations