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());
});
}
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;
}
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());
}
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;
}
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;
}
Aggregations