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