Search in sources :

Example 41 with ResourceLocation

use of net.minecraft.resources.ResourceLocation in project MyPet by xXKeyleXx.

the class EntityRegistry method registerEntityType.

protected void registerEntityType(MyPetType petType, String key, DefaultedRegistry<EntityType<?>> entityRegistry) {
    EntityDimensions size = entityRegistry.get(new ResourceLocation(key.toLowerCase())).getDimensions();
    entityTypes.put(petType, Registry.register(entityRegistry, "mypet_" + key.toLowerCase(), EntityType.Builder.createNothing(MobCategory.CREATURE).noSave().noSummon().sized(size.width, size.height).build(key)));
    EntityType<? extends LivingEntity> types = (EntityType<? extends LivingEntity>) entityRegistry.get(new ResourceLocation(key));
    registerDefaultAttributes(entityTypes.get(petType), types);
    overwriteEntityID(entityTypes.get(petType), getEntityTypeId(petType, entityRegistry), entityRegistry);
}
Also used : EntityType(net.minecraft.world.entity.EntityType) LivingEntity(net.minecraft.world.entity.LivingEntity) EntityDimensions(net.minecraft.world.entity.EntityDimensions) ResourceLocation(net.minecraft.resources.ResourceLocation)

Example 42 with ResourceLocation

use of net.minecraft.resources.ResourceLocation in project MyPet by xXKeyleXx.

the class PlatformHelper method playParticleEffect.

/**
 * @param location   the {@link Location} around which players must be to see the effect
 * @param effectName list of effects: https://gist.github.com/riking/5759002
 * @param offsetX    the amount to be randomly offset by in the X axis
 * @param offsetY    the amount to be randomly offset by in the Y axis
 * @param offsetZ    the amount to be randomly offset by in the Z axis
 * @param speed      the speed of the particles
 * @param count      the number of particles
 * @param radius     the radius around the location
 */
@Override
public void playParticleEffect(Location location, String effectName, float offsetX, float offsetY, float offsetZ, float speed, int count, int radius, de.Keyle.MyPet.api.compat.Compat<Object> data) {
    ParticleType effect = Registry.PARTICLE_TYPE.get(new ResourceLocation(effectName));
    Validate.notNull(location, "Location cannot be null");
    Validate.notNull(effect, "Effect cannot be null");
    Validate.notNull(location.getWorld(), "World cannot be null");
    ParticleOptions particle = null;
    if (effect.getDeserializer() != null && data != null) {
        try {
            particle = effect.getDeserializer().fromCommand(effect, new StringReader(" " + data.get().toString()));
        } catch (CommandSyntaxException e) {
            e.printStackTrace();
        }
    } else if (effect instanceof SimpleParticleType) {
        particle = (SimpleParticleType) effect;
    }
    if (particle == null) {
        return;
    }
    ClientboundLevelParticlesPacket packet = new ClientboundLevelParticlesPacket(particle, false, (float) location.getX(), (float) location.getY(), (float) location.getZ(), offsetX, offsetY, offsetZ, speed, count);
    radius = radius * radius;
    for (Player player : location.getWorld().getPlayers()) {
        if ((int) MyPetApi.getPlatformHelper().distanceSquared(player.getLocation(), location) <= radius) {
            ((CraftPlayer) player).getHandle().connection.send(packet);
        }
    }
}
Also used : CraftPlayer(org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer) MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) ParticleOptions(net.minecraft.core.particles.ParticleOptions) ResourceLocation(net.minecraft.resources.ResourceLocation) StringReader(com.mojang.brigadier.StringReader) ParticleType(net.minecraft.core.particles.ParticleType) SimpleParticleType(net.minecraft.core.particles.SimpleParticleType) ClientboundLevelParticlesPacket(net.minecraft.network.protocol.game.ClientboundLevelParticlesPacket) CraftPlayer(org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer) SimpleParticleType(net.minecraft.core.particles.SimpleParticleType) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException)

Example 43 with ResourceLocation

use of net.minecraft.resources.ResourceLocation in project MyPet by xXKeyleXx.

the class PlatformHelper method playParticleEffect.

/**
 * @param location   the {@link Location} around which players must be to see the effect
 * @param effectName list of effects: https://gist.github.com/riking/5759002
 * @param offsetX    the amount to be randomly offset by in the X axis
 * @param offsetY    the amount to be randomly offset by in the Y axis
 * @param offsetZ    the amount to be randomly offset by in the Z axis
 * @param speed      the speed of the particles
 * @param count      the number of particles
 * @param radius     the radius around the location
 */
@Override
public void playParticleEffect(Player player, Location location, String effectName, float offsetX, float offsetY, float offsetZ, float speed, int count, int radius, de.Keyle.MyPet.api.compat.Compat<Object> data) {
    ParticleType effect = Registry.PARTICLE_TYPE.get(new ResourceLocation(effectName));
    Validate.notNull(location, "Location cannot be null");
    Validate.notNull(effect, "Effect cannot be null");
    Validate.notNull(location.getWorld(), "World cannot be null");
    ParticleOptions particle = null;
    if (effect.getDeserializer() != null && data != null) {
        try {
            particle = effect.getDeserializer().fromCommand(effect, new StringReader(" " + data.get().toString()));
        } catch (CommandSyntaxException e) {
            e.printStackTrace();
        }
    } else if (effect instanceof SimpleParticleType) {
        particle = (SimpleParticleType) effect;
    }
    if (particle == null) {
        return;
    }
    ClientboundLevelParticlesPacket packet = new ClientboundLevelParticlesPacket(particle, false, (float) location.getX(), (float) location.getY(), (float) location.getZ(), offsetX, offsetY, offsetZ, speed, count);
    if (MyPetApi.getPlatformHelper().distanceSquared(player.getLocation(), location) <= radius) {
        ((CraftPlayer) player).getHandle().connection.send(packet);
    }
}
Also used : ParticleOptions(net.minecraft.core.particles.ParticleOptions) ResourceLocation(net.minecraft.resources.ResourceLocation) StringReader(com.mojang.brigadier.StringReader) ParticleType(net.minecraft.core.particles.ParticleType) SimpleParticleType(net.minecraft.core.particles.SimpleParticleType) ClientboundLevelParticlesPacket(net.minecraft.network.protocol.game.ClientboundLevelParticlesPacket) CraftPlayer(org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer) SimpleParticleType(net.minecraft.core.particles.SimpleParticleType) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException)

Example 44 with ResourceLocation

use of net.minecraft.resources.ResourceLocation in project MyPet by xXKeyleXx.

the class EntityRegistry method registerEntityType.

protected void registerEntityType(MyPetType petType, String key, DefaultedRegistry<EntityType<?>> entityRegistry) {
    EntityDimensions size = entityRegistry.get(new ResourceLocation(key.toLowerCase())).getDimensions();
    entityTypes.put(petType, Registry.register(entityRegistry, "mypet_" + key.toLowerCase(), EntityType.Builder.createNothing(MobCategory.CREATURE).noSave().noSummon().sized(size.width, size.height).build(key)));
    EntityType<? extends LivingEntity> types = (EntityType<? extends LivingEntity>) entityRegistry.get(new ResourceLocation(key));
    registerDefaultAttributes(entityTypes.get(petType), types);
    overwriteEntityID(entityTypes.get(petType), getEntityTypeId(petType, entityRegistry), entityRegistry);
}
Also used : EntityType(net.minecraft.world.entity.EntityType) LivingEntity(net.minecraft.world.entity.LivingEntity) EntityDimensions(net.minecraft.world.entity.EntityDimensions) ResourceLocation(net.minecraft.resources.ResourceLocation)

Example 45 with ResourceLocation

use of net.minecraft.resources.ResourceLocation in project SpongeCommon by SpongePowered.

the class PhaseTracker method validateBlockForNeighborNotification.

public static Block validateBlockForNeighborNotification(final ServerLevel worldServer, final BlockPos pos, @Nullable Block blockIn, final BlockPos otherPos, final LevelChunk chunk) {
    if (blockIn == null) {
        // If the block is null, check with the PhaseState to see if it can perform a safe way
        final PhaseContext<?> currentContext = PhaseTracker.getInstance().getPhaseContext();
        final PhaseTrackerCategory trackerConfig = SpongeConfigs.getCommon().get().phaseTracker;
        if (currentContext.state == TickPhase.Tick.TILE_ENTITY) {
            // Try to save ourselves
            @Nullable final BlockEntity source = (BlockEntity) currentContext.getSource();
            @Nullable final BlockEntityType<?> type = Optional.ofNullable(source).map(BlockEntity::getType).orElse(null);
            if (type != null) {
                @Nullable ResourceLocation id = BlockEntityType.getKey(type);
                if (id == null) {
                    id = new ResourceLocation(source.getClass().getCanonicalName());
                }
                final Map<String, Boolean> autoFixedTiles = trackerConfig.autoFixNullSourceBlockProvidingBlockEntities;
                final boolean contained = autoFixedTiles.containsKey(type.toString());
                // based on whether the source is the same as the TileEntity.
                if (!contained) {
                    autoFixedTiles.put(id.toString(), pos.equals(source.getBlockPos()));
                }
                final boolean useTile = contained && autoFixedTiles.get(id.toString());
                if (useTile) {
                    blockIn = source.getBlockState().getBlock();
                } else {
                    blockIn = (pos.getX() >> 4 == chunk.getPos().x && pos.getZ() >> 4 == chunk.getPos().z) ? chunk.getBlockState(pos).getBlock() : worldServer.getBlockState(pos).getBlock();
                }
                if (!contained && trackerConfig.reportNullSourceBlocksOnNeighborNotifications) {
                    PhasePrinter.printNullSourceBlockWithTile(pos, blockIn, otherPos, id, useTile, new NullPointerException("Null Source Block For TileEntity Neighbor Notification"));
                }
            } else {
                blockIn = (pos.getX() >> 4 == chunk.getPos().x && pos.getZ() >> 4 == chunk.getPos().z) ? chunk.getBlockState(pos).getBlock() : worldServer.getBlockState(pos).getBlock();
                if (trackerConfig.reportNullSourceBlocksOnNeighborNotifications) {
                    PhasePrinter.printNullSourceBlockNeighborNotificationWithNoTileSource(pos, blockIn, otherPos, new NullPointerException("Null Source Block For Neighbor Notification"));
                }
            }
        } else {
            blockIn = (pos.getX() >> 4 == chunk.getPos().x && pos.getZ() >> 4 == chunk.getPos().z) ? chunk.getBlockState(pos).getBlock() : worldServer.getBlockState(pos).getBlock();
            if (trackerConfig.reportNullSourceBlocksOnNeighborNotifications) {
                PhasePrinter.printNullSourceForBlock(worldServer, pos, blockIn, otherPos, new NullPointerException("Null Source Block For Neighbor Notification"));
            }
        }
    }
    return blockIn;
}
Also used : PhaseTrackerCategory(org.spongepowered.common.applaunch.config.common.PhaseTrackerCategory) ResourceLocation(net.minecraft.resources.ResourceLocation) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Nullable(org.checkerframework.checker.nullness.qual.Nullable) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Aggregations

ResourceLocation (net.minecraft.resources.ResourceLocation)130 Map (java.util.Map)12 IOException (java.io.IOException)11 ArrayList (java.util.ArrayList)11 CompoundTag (net.minecraft.nbt.CompoundTag)11 List (java.util.List)10 BlockPos (net.minecraft.core.BlockPos)9 Collectors (java.util.stream.Collectors)7 Block (net.minecraft.world.level.block.Block)7 LogManager (org.apache.logging.log4j.LogManager)7 Logger (org.apache.logging.log4j.Logger)7 JsonObject (com.google.gson.JsonObject)6 HashMap (java.util.HashMap)6 FriendlyByteBuf (net.minecraft.network.FriendlyByteBuf)6 LivingEntity (net.minecraft.world.entity.LivingEntity)6 JsonElement (com.google.gson.JsonElement)5 CommandSyntaxException (com.mojang.brigadier.exceptions.CommandSyntaxException)5 Registry (net.minecraft.core.Registry)5 ServerLevel (net.minecraft.server.level.ServerLevel)5 InputStream (java.io.InputStream)4