Search in sources :

Example 6 with ResourceLocation

use of net.minecraft.resources.ResourceLocation in project MinecraftForge by MinecraftForge.

the class LoginWrapper method wrapperReceived.

private <T extends NetworkEvent> void wrapperReceived(final T packet) {
    // we don't care about channel registration change events on this channel
    if (packet instanceof NetworkEvent.ChannelRegistrationChangeEvent)
        return;
    final NetworkEvent.Context wrappedContext = packet.getSource().get();
    final FriendlyByteBuf payload = packet.getPayload();
    ResourceLocation targetNetworkReceiver = NetworkConstants.FML_HANDSHAKE_RESOURCE;
    FriendlyByteBuf data = null;
    if (payload != null) {
        targetNetworkReceiver = payload.readResourceLocation();
        final int payloadLength = payload.readVarInt();
        data = new FriendlyByteBuf(payload.readBytes(payloadLength));
    }
    final int loginSequence = packet.getLoginIndex();
    LOGGER.debug(HandshakeHandler.FMLHSMARKER, "Recieved login wrapper packet event for channel {} with index {}", targetNetworkReceiver, loginSequence);
    final NetworkEvent.Context context = new NetworkEvent.Context(wrappedContext.getNetworkManager(), wrappedContext.getDirection(), (rl, buf) -> {
        LOGGER.debug(HandshakeHandler.FMLHSMARKER, "Dispatching wrapped packet reply for channel {} with index {}", rl, loginSequence);
        wrappedContext.getPacketDispatcher().sendPacket(WRAPPER, this.wrapPacket(rl, buf));
    });
    final NetworkEvent.LoginPayloadEvent loginPayloadEvent = new NetworkEvent.LoginPayloadEvent(data, () -> context, loginSequence);
    NetworkRegistry.findTarget(targetNetworkReceiver).ifPresent(ni -> {
        ni.dispatchLoginPacket(loginPayloadEvent);
        wrappedContext.setPacketHandled(context.getPacketHandled());
    });
}
Also used : FriendlyByteBuf(net.minecraft.network.FriendlyByteBuf) ResourceLocation(net.minecraft.resources.ResourceLocation)

Example 7 with ResourceLocation

use of net.minecraft.resources.ResourceLocation in project MinecraftForge by MinecraftForge.

the class DeferredRegister method register.

/**
 * Adds a new supplier to the list of entries to be registered, and returns a RegistryObject that will be populated with the created entry automatically.
 *
 * @param name The new entry's name, it will automatically have the modid prefixed.
 * @param sup A factory for the new entry, it should return a new instance every time it is called.
 * @return A RegistryObject that will be updated with when the entries in the registry change.
 */
@SuppressWarnings("unchecked")
public <I extends T> RegistryObject<I> register(final String name, final Supplier<? extends I> sup) {
    if (seenRegisterEvent)
        throw new IllegalStateException("Cannot register new entries to DeferredRegister after RegistryEvent.Register has been fired.");
    Objects.requireNonNull(name);
    Objects.requireNonNull(sup);
    final ResourceLocation key = new ResourceLocation(modid, name);
    RegistryObject<I> ret;
    if (this.type != null)
        ret = RegistryObject.of(key, this.type);
    else if (this.superType != null)
        ret = RegistryObject.of(key, this.superType, this.modid);
    else
        throw new IllegalStateException("Could not create RegistryObject in DeferredRegister");
    if (entries.putIfAbsent((RegistryObject<T>) ret, () -> sup.get().setRegistryName(key)) != null) {
        throw new IllegalArgumentException("Duplicate registration " + name);
    }
    return ret;
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation)

Example 8 with ResourceLocation

use of net.minecraft.resources.ResourceLocation in project MinecraftForge by MinecraftForge.

the class RegistryObjectTest method commonSetup.

public void commonSetup(FMLCommonSetupEvent event) {
    LOGGER.info("Stone 1: {}", RegistryObject.of(new ResourceLocation("minecraft", "stone"), ForgeRegistries.BLOCKS).get());
    LOGGER.info("Stone 2: {}", RegistryObject.of(new ResourceLocation("minecraft", "stone"), Block.class, MODID).get());
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation)

Example 9 with ResourceLocation

use of net.minecraft.resources.ResourceLocation in project MinecraftForge by MinecraftForge.

the class FluidStack method loadFluidStackFromNBT.

/**
 * This provides a safe method for retrieving a FluidStack - if the Fluid is invalid, the stack
 * will return as null.
 */
public static FluidStack loadFluidStackFromNBT(CompoundTag nbt) {
    if (nbt == null) {
        return EMPTY;
    }
    if (!nbt.contains("FluidName", Tag.TAG_STRING)) {
        return EMPTY;
    }
    ResourceLocation fluidName = new ResourceLocation(nbt.getString("FluidName"));
    Fluid fluid = ForgeRegistries.FLUIDS.getValue(fluidName);
    if (fluid == null) {
        return EMPTY;
    }
    FluidStack stack = new FluidStack(fluid, nbt.getInt("Amount"));
    if (nbt.contains("Tag", Tag.TAG_COMPOUND)) {
        stack.tag = nbt.getCompound("Tag");
    }
    return stack;
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) Fluid(net.minecraft.world.level.material.Fluid)

Example 10 with ResourceLocation

use of net.minecraft.resources.ResourceLocation in project MinecraftForge by MinecraftForge.

the class ForgeWorldPreset method getDefaultWorldPreset.

public static ForgeWorldPreset getDefaultWorldPreset() {
    String defaultWorldType = ForgeConfig.COMMON.defaultWorldType.get();
    if (StringUtil.isNullOrEmpty(defaultWorldType) || "default".equals(defaultWorldType))
        // use vanilla
        return null;
    ForgeWorldPreset def = ForgeRegistries.WORLD_TYPES.getValue(new ResourceLocation(defaultWorldType));
    if (def == null) {
        LOGGER.error("The defaultWorldType '{}' specified in the forge config has not been registered. The vanilla default generator will be used.", defaultWorldType);
    }
    return def;
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation)

Aggregations

ResourceLocation (net.minecraft.resources.ResourceLocation)86 ArrayList (java.util.ArrayList)7 Map (java.util.Map)7 LogManager (org.apache.logging.log4j.LogManager)7 Logger (org.apache.logging.log4j.Logger)7 List (java.util.List)6 FriendlyByteBuf (net.minecraft.network.FriendlyByteBuf)6 JsonObject (com.google.gson.JsonObject)5 CommandSyntaxException (com.mojang.brigadier.exceptions.CommandSyntaxException)5 IOException (java.io.IOException)5 Collectors (java.util.stream.Collectors)5 StringReader (com.mojang.brigadier.StringReader)4 CompoundTag (net.minecraft.nbt.CompoundTag)4 CraftServer (org.bukkit.craftbukkit.v1_17_R1.CraftServer)4 ItemStack (org.bukkit.inventory.ItemStack)4 InputStream (java.io.InputStream)3 Collections (java.util.Collections)3 Set (java.util.Set)3 Function (java.util.function.Function)3 Nullable (javax.annotation.Nullable)3