Search in sources :

Example 11 with ServerPlayerEntity

use of net.minecraft.entity.player.ServerPlayerEntity in project Overloaded by CJ-MC-Mods.

the class PlayerMessageHandler method accept.

@Override
public void accept(T message, Supplier<NetworkEvent.Context> ctx) {
    ServerPlayerEntity player = ctx.get().getSender();
    if (player == null) {
        return;
    }
    ctx.get().enqueueWork(() -> method.handleMessage(player, message));
    ctx.get().setPacketHandled(true);
}
Also used : ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity)

Example 12 with ServerPlayerEntity

use of net.minecraft.entity.player.ServerPlayerEntity in project NetherEx by LogicTechCorp.

the class PlayerHandler method onPlayerRespawn.

@SubscribeEvent
public static void onPlayerRespawn(PlayerEvent.PlayerRespawnEvent event) {
    World world = event.getPlayer().getEntityWorld();
    PlayerEntity player = event.getPlayer();
    PlayerInventory playerInventory = player.inventory;
    if (!world.isRemote) {
        ItemStack mirrorStack = ItemStack.EMPTY;
        for (int i = 0; i < playerInventory.getSizeInventory(); i++) {
            ItemStack stack = playerInventory.getStackInSlot(i);
            if (stack.getItem() == NetherExItems.DULL_MIRROR.get()) {
                mirrorStack = stack;
                break;
            }
        }
        if (!mirrorStack.isEmpty()) {
            if (mirrorStack.getDamage() < mirrorStack.getMaxDamage() - 1) {
                CompoundNBT compound = NBTHelper.ensureTagExists(mirrorStack);
                if (compound.contains("SpawnDimension") && compound.contains("SpawnPoint")) {
                    DimensionType spawnDimension = DimensionType.byName(new ResourceLocation(compound.getString("SpawnDimension")));
                    if (spawnDimension != null && player.dimension != spawnDimension) {
                        MinecraftServer server = world.getServer();
                        if (server != null) {
                            BlockPos spawnPoint = NBTUtil.readBlockPos(compound.getCompound("SpawnPoint"));
                            ((ServerPlayerEntity) player).teleport(server.getWorld(spawnDimension), spawnPoint.getX() + 0.5D, spawnPoint.getY(), spawnPoint.getZ() + 0.5D, player.rotationYaw, player.rotationPitch);
                        }
                    }
                }
            }
        }
    }
}
Also used : DimensionType(net.minecraft.world.dimension.DimensionType) CompoundNBT(net.minecraft.nbt.CompoundNBT) ResourceLocation(net.minecraft.util.ResourceLocation) BlockPos(net.minecraft.util.math.BlockPos) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) PlayerInventory(net.minecraft.entity.player.PlayerInventory) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) MinecraftServer(net.minecraft.server.MinecraftServer) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 13 with ServerPlayerEntity

use of net.minecraft.entity.player.ServerPlayerEntity in project AgriCraft by AgriCraft.

the class JsonSyncHandler method onConnect.

@SubscribeEvent
@SuppressWarnings("unused")
public void onConnect(PlayerEvent.PlayerLoggedInEvent event) {
    if (event.getPlayer() instanceof ServerPlayerEntity) {
        ServerPlayerEntity player = (ServerPlayerEntity) event.getPlayer();
        MinecraftServer server = player.getServer();
        if (server != null) {
            if (server.isDedicatedServer()) {
                // always sync on dedicated servers
                this.syncJsons(player);
            } else if (server.getPublic()) {
                // only sync when the server is open to LAN on integrated servers
                this.syncJsons(player);
            }
        }
    }
}
Also used : ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) MinecraftServer(net.minecraft.server.MinecraftServer) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 14 with ServerPlayerEntity

use of net.minecraft.entity.player.ServerPlayerEntity in project AgriCraft by AgriCraft.

the class GuiPlugin method onSeedAnalyzerRightClick.

public void onSeedAnalyzerRightClick(PlayerInteractEvent.RightClickBlock event) {
    BlockPos pos = event.getPos();
    BlockState state = event.getWorld().getBlockState(pos);
    if (event.getPlayer().isSneaking()) {
        return;
    }
    if (state.getBlock() != AgriCraft.instance.getModBlockRegistry().seed_analyzer.getBlock()) {
        return;
    }
    event.setCancellationResult(ActionResultType.SUCCESS);
    event.setCanceled(true);
    if (event.getPlayer().world.isRemote) {
        return;
    }
    INamedContainerProvider containerProvider = new INamedContainerProvider() {

        @Nonnull
        @Override
        public ITextComponent getDisplayName() {
            return new TranslationTextComponent("screen.agricraft.seed_analyzer");
        }

        @Override
        public Container createMenu(int id, @Nonnull PlayerInventory playerInventory, @Nonnull PlayerEntity player) {
            return new SeedAnalyzerContainer(id, event.getWorld(), playerInventory, pos);
        }
    };
    NetworkHooks.openGui((ServerPlayerEntity) event.getPlayer(), containerProvider, pos);
}
Also used : BlockState(net.minecraft.block.BlockState) Nonnull(javax.annotation.Nonnull) SeedAnalyzerContainer(com.infinityraider.agricraft.plugins.agrigui.analyzer.SeedAnalyzerContainer) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos) INamedContainerProvider(net.minecraft.inventory.container.INamedContainerProvider) PlayerInventory(net.minecraft.entity.player.PlayerInventory) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity)

Example 15 with ServerPlayerEntity

use of net.minecraft.entity.player.ServerPlayerEntity 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);
            }
        }
    }
}
Also used : PotionEffect(com.viste.realisticarmortiers.data.PotionEffect) ArrayList(java.util.ArrayList) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) IArmor(com.viste.realisticarmortiers.capability.IArmor) MinecraftServer(net.minecraft.server.MinecraftServer) ResourceLocation(net.minecraft.util.ResourceLocation) Effect(net.minecraft.potion.Effect) PotionEffect(com.viste.realisticarmortiers.data.PotionEffect) ItemStack(net.minecraft.item.ItemStack) EffectInstance(net.minecraft.potion.EffectInstance) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Aggregations

ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)16 ItemStack (net.minecraft.item.ItemStack)8 PlayerEntity (net.minecraft.entity.player.PlayerEntity)4 MinecraftServer (net.minecraft.server.MinecraftServer)3 ResourceLocation (net.minecraft.util.ResourceLocation)3 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)3 Nullable (javax.annotation.Nullable)2 PlayerInventory (net.minecraft.entity.player.PlayerInventory)2 Container (net.minecraft.inventory.container.Container)2 BlockPos (net.minecraft.util.math.BlockPos)2 Vector3d (net.minecraft.util.math.vector.Vector3d)2 StringTextComponent (net.minecraft.util.text.StringTextComponent)2 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)2 NetworkEvent (net.minecraftforge.fml.network.NetworkEvent)2 IGuiButtonSensitive (com.bluepowermod.client.gui.IGuiButtonSensitive)1 ContainerDataMessage (com.cjm721.overloaded.network.packets.ContainerDataMessage)1 NoClipStatusMessage (com.cjm721.overloaded.network.packets.NoClipStatusMessage)1 IGenericDataStorage (com.cjm721.overloaded.storage.IGenericDataStorage)1 JsonObject (com.google.gson.JsonObject)1 SeedAnalyzerContainer (com.infinityraider.agricraft.plugins.agrigui.analyzer.SeedAnalyzerContainer)1