Search in sources :

Example 1 with Contract

use of moriyashiine.bewitchment.api.registry.Contract in project bewitchment by MoriyaShiine.

the class BaphometEntity method getOffers.

@Override
public List<DemonEntity.DemonTradeOffer> getOffers() {
    if (offers.isEmpty()) {
        List<Contract> availableContracts = BWRegistries.CONTRACTS.stream().collect(Collectors.toList());
        for (int i = 0; i < 5; i++) {
            Contract contract = availableContracts.get(random.nextInt(availableContracts.size()));
            offers.add(new DemonEntity.DemonTradeOffer(contract, 72000, 2 + random.nextInt(2) * 2));
            availableContracts.remove(contract);
        }
    }
    return offers;
}
Also used : Contract(moriyashiine.bewitchment.api.registry.Contract)

Example 2 with Contract

use of moriyashiine.bewitchment.api.registry.Contract in project bewitchment by MoriyaShiine.

the class DemonEntity method getOffers.

@Override
public List<DemonEntity.DemonTradeOffer> getOffers() {
    if (offers.isEmpty()) {
        List<Contract> availableContracts = BWRegistries.CONTRACTS.stream().collect(Collectors.toList());
        for (int i = 0; i < 3; i++) {
            Contract contract = availableContracts.get(random.nextInt(availableContracts.size()));
            offers.add(new DemonTradeOffer(contract, 168000, MathHelper.nextInt(random, 3, 6)));
            availableContracts.remove(contract);
        }
    }
    return offers;
}
Also used : Contract(moriyashiine.bewitchment.api.registry.Contract)

Example 3 with Contract

use of moriyashiine.bewitchment.api.registry.Contract in project bewitchment by MoriyaShiine.

the class ContractsComponent method readFromNbt.

@Override
public void readFromNbt(NbtCompound tag) {
    NbtList contractsList = tag.getList("Contracts", NbtType.COMPOUND);
    for (int i = 0; i < contractsList.size(); i++) {
        NbtCompound contractCompound = contractsList.getCompound(i);
        addContract(new Contract.Instance(BWRegistries.CONTRACTS.get(new Identifier(contractCompound.getString("Contract"))), contractCompound.getInt("Duration"), contractCompound.getInt("Cost")));
    }
}
Also used : Identifier(net.minecraft.util.Identifier) NbtCompound(net.minecraft.nbt.NbtCompound) NbtList(net.minecraft.nbt.NbtList) Contract(moriyashiine.bewitchment.api.registry.Contract)

Example 4 with Contract

use of moriyashiine.bewitchment.api.registry.Contract in project bewitchment by MoriyaShiine.

the class ContractsComponent method toNbtContract.

@SuppressWarnings("ConstantConditions")
public NbtList toNbtContract() {
    NbtList contractsTag = new NbtList();
    for (Contract.Instance instance : getContracts()) {
        NbtCompound contractCompound = new NbtCompound();
        contractCompound.putString("Contract", BWRegistries.CONTRACTS.getId(instance.contract).toString());
        contractCompound.putInt("Duration", instance.duration);
        contractCompound.putInt("Cost", instance.cost);
        contractsTag.add(contractCompound);
    }
    return contractsTag;
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound) NbtList(net.minecraft.nbt.NbtList) Contract(moriyashiine.bewitchment.api.registry.Contract)

Example 5 with Contract

use of moriyashiine.bewitchment.api.registry.Contract in project bewitchment by MoriyaShiine.

the class SyncContractsPacket method handle.

public static void handle(MinecraftClient client, ClientPlayNetworkHandler network, PacketByteBuf buf, PacketSender sender) {
    NbtCompound contractsCompound = buf.readNbt();
    client.execute(new Runnable() {

        @Override
        public void run() {
            if (client.player != null) {
                BWComponents.CONTRACTS_COMPONENT.maybeGet(client.player).ifPresent(contractsComponent -> {
                    contractsComponent.getContracts().clear();
                    NbtList contractsList = contractsCompound.getList("Contracts", NbtType.COMPOUND);
                    for (int i = 0; i < contractsList.size(); i++) {
                        NbtCompound contractCompound = contractsList.getCompound(i);
                        contractsComponent.addContract(new Contract.Instance(BWRegistries.CONTRACTS.get(new Identifier(contractCompound.getString("Contract"))), contractCompound.getInt("Duration"), contractCompound.getInt("Cost")));
                    }
                });
            }
        }
    });
}
Also used : PacketSender(net.fabricmc.fabric.api.networking.v1.PacketSender) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Contract(moriyashiine.bewitchment.api.registry.Contract) NbtList(net.minecraft.nbt.NbtList) PacketByteBuf(net.minecraft.network.PacketByteBuf) Unpooled(io.netty.buffer.Unpooled) BWRegistries(moriyashiine.bewitchment.common.registry.BWRegistries) NbtCompound(net.minecraft.nbt.NbtCompound) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) NbtType(net.fabricmc.fabric.api.util.NbtType) ServerPlayNetworking(net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking) BWComponents(moriyashiine.bewitchment.common.registry.BWComponents) Identifier(net.minecraft.util.Identifier) MinecraftClient(net.minecraft.client.MinecraftClient) ClientPlayNetworkHandler(net.minecraft.client.network.ClientPlayNetworkHandler) Bewitchment(moriyashiine.bewitchment.common.Bewitchment) Identifier(net.minecraft.util.Identifier) NbtCompound(net.minecraft.nbt.NbtCompound) NbtList(net.minecraft.nbt.NbtList)

Aggregations

Contract (moriyashiine.bewitchment.api.registry.Contract)5 NbtCompound (net.minecraft.nbt.NbtCompound)3 NbtList (net.minecraft.nbt.NbtList)3 Identifier (net.minecraft.util.Identifier)2 Unpooled (io.netty.buffer.Unpooled)1 Bewitchment (moriyashiine.bewitchment.common.Bewitchment)1 BWComponents (moriyashiine.bewitchment.common.registry.BWComponents)1 BWRegistries (moriyashiine.bewitchment.common.registry.BWRegistries)1 PacketSender (net.fabricmc.fabric.api.networking.v1.PacketSender)1 ServerPlayNetworking (net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking)1 NbtType (net.fabricmc.fabric.api.util.NbtType)1 MinecraftClient (net.minecraft.client.MinecraftClient)1 ClientPlayNetworkHandler (net.minecraft.client.network.ClientPlayNetworkHandler)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1 PacketByteBuf (net.minecraft.network.PacketByteBuf)1 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)1