Search in sources :

Example 1 with CapabilityTrait

use of com.lowdragmc.multiblocked.api.capability.trait.CapabilityTrait in project Multiblocked by Low-Drag-MC.

the class ComponentTileEntity method initTrait.

protected void initTrait() {
    for (Map.Entry<String, JsonElement> entry : this.definition.traits.entrySet()) {
        MultiblockCapability<?> capability = MbdCapabilities.get(entry.getKey());
        if (capability != null && capability.hasTrait()) {
            CapabilityTrait trait = capability.createTrait();
            trait.serialize(entry.getValue());
            trait.setComponent(this);
            traits.put(capability, trait);
        }
    }
}
Also used : JsonElement(com.google.gson.JsonElement) CapabilityTrait(com.lowdragmc.multiblocked.api.capability.trait.CapabilityTrait) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with CapabilityTrait

use of com.lowdragmc.multiblocked.api.capability.trait.CapabilityTrait in project Multiblocked by Low-Drag-MC.

the class ComponentTileEntity method save.

@Nonnull
@Override
public CompoundNBT save(@Nonnull CompoundNBT compound) {
    super.save(compound);
    compound.putString("loc", definition.location.toString());
    if (this.owner != null) {
        compound.putUUID("owner", this.owner);
    }
    compound.putString("mbd_def", definition.location.toString());
    CompoundNBT traitTag = new CompoundNBT();
    for (Map.Entry<MultiblockCapability<?>, CapabilityTrait> entry : traits.entrySet()) {
        CompoundNBT tag = new CompoundNBT();
        entry.getValue().writeToNBT(tag);
        traitTag.put(entry.getKey().name, tag);
    }
    compound.put("trait", traitTag);
    if (persistedData != null) {
        compound.put("persisted", persistedData);
    }
    return compound;
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) MultiblockCapability(com.lowdragmc.multiblocked.api.capability.MultiblockCapability) CapabilityTrait(com.lowdragmc.multiblocked.api.capability.trait.CapabilityTrait) Map(java.util.Map) HashMap(java.util.HashMap) Nonnull(javax.annotation.Nonnull)

Example 3 with CapabilityTrait

use of com.lowdragmc.multiblocked.api.capability.trait.CapabilityTrait in project Multiblocked by Low-Drag-MC.

the class ComponentTileEntity method initTraitUI.

protected void initTraitUI(TabContainer tabContainer, PlayerEntity PlayerEntity) {
    WidgetGroup group = new WidgetGroup(20, 0, 176, 256);
    tabContainer.addTab(new TabButton(0, tabContainer.containerGroup.widgets.size() * 20, 20, 20).setTexture(new ResourceTexture("multiblocked:textures/gui/custom_gui_tab_button.png").getSubTexture(0, 0, 1, 0.5), new ResourceTexture("multiblocked:textures/gui/custom_gui_tab_button.png").getSubTexture(0, 0.5, 1, 0.5)), group);
    group.addWidget(new ImageWidget(0, 0, 176, 256, new ResourceTexture(JSONUtils.getAsString(definition.traits, "background", "multiblocked:textures/gui/custom_gui.png"))));
    if (traits.size() > 0) {
        for (int row = 0; row < 3; row++) {
            for (int col = 0; col < 9; col++) {
                group.addWidget(new SlotWidget(PlayerEntity.inventory, col + (row + 1) * 9, 7 + col * 18, 173 + row * 18).setLocationInfo(true, false));
            }
        }
        for (int slot = 0; slot < 9; slot++) {
            group.addWidget(new SlotWidget(PlayerEntity.inventory, slot, 7 + slot * 18, 231).setLocationInfo(true, true));
        }
    }
    for (CapabilityTrait trait : traits.values()) {
        trait.createUI(this, group, PlayerEntity);
    }
}
Also used : SlotWidget(com.lowdragmc.lowdraglib.gui.widget.SlotWidget) ResourceTexture(com.lowdragmc.lowdraglib.gui.texture.ResourceTexture) TabButton(com.lowdragmc.lowdraglib.gui.widget.TabButton) CapabilityTrait(com.lowdragmc.multiblocked.api.capability.trait.CapabilityTrait) WidgetGroup(com.lowdragmc.lowdraglib.gui.widget.WidgetGroup) ImageWidget(com.lowdragmc.lowdraglib.gui.widget.ImageWidget)

Example 4 with CapabilityTrait

use of com.lowdragmc.multiblocked.api.capability.trait.CapabilityTrait in project Multiblocked by Low-Drag-MC.

the class ComponentTileEntity method load.

@Override
public void load(@Nonnull BlockState blockState, @Nonnull CompoundNBT compound) {
    super.load(blockState, compound);
    if (needAlwaysUpdate()) {
        MultiblockWorldSavedData.getOrCreate(level).addLoading(this);
    }
    if (compound.contains("owner")) {
        this.owner = compound.getUUID("owner");
    }
    CompoundNBT traitTag = compound.getCompound("trait");
    for (Map.Entry<MultiblockCapability<?>, CapabilityTrait> entry : traits.entrySet()) {
        entry.getValue().readFromNBT(traitTag.getCompound(entry.getKey().name));
    }
    if (compound.contains("persisted")) {
        persistedData = compound.get("persisted");
    }
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) MultiblockCapability(com.lowdragmc.multiblocked.api.capability.MultiblockCapability) CapabilityTrait(com.lowdragmc.multiblocked.api.capability.trait.CapabilityTrait) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

CapabilityTrait (com.lowdragmc.multiblocked.api.capability.trait.CapabilityTrait)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 MultiblockCapability (com.lowdragmc.multiblocked.api.capability.MultiblockCapability)2 CompoundNBT (net.minecraft.nbt.CompoundNBT)2 JsonElement (com.google.gson.JsonElement)1 ResourceTexture (com.lowdragmc.lowdraglib.gui.texture.ResourceTexture)1 ImageWidget (com.lowdragmc.lowdraglib.gui.widget.ImageWidget)1 SlotWidget (com.lowdragmc.lowdraglib.gui.widget.SlotWidget)1 TabButton (com.lowdragmc.lowdraglib.gui.widget.TabButton)1 WidgetGroup (com.lowdragmc.lowdraglib.gui.widget.WidgetGroup)1 Nonnull (javax.annotation.Nonnull)1