Skip to content

Commit

Permalink
yarrhahhahar more thingies
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfieboy09 committed Oct 29, 2024
1 parent 777a4a9 commit d213bc9
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,6 @@ public int getMaxEnergyStored() {
return this.energyStorage.getMaxEnergyStored();
}

@Override
protected void loadAdditional(CompoundTag tag, HolderLookup.Provider registries) {
super.loadAdditional(tag, registries);
if (tag.contains("Energy")) {
this.energyStorage.deserializeNBT(registries, tag.get("Energy"));
}
}

@Override
public int receiveEnergy(int i, boolean b) {
return this.energyStorage.receiveEnergy(i, b);
Expand All @@ -104,24 +96,67 @@ public int extractEnergy(int i, boolean b) {
return this.energyStorage.extractEnergy(i, b);
}

// optional functions for blocks

/**
* Gets called from {@link #saveAdditional}
* @param tag
* @param registries
*/
public void saveExtra(CompoundTag tag, HolderLookup.Provider registries) {}

/**
* Gets called from {@link #loadAdditional}
* @param tag
* @param registries
*/
protected void loadExtra(CompoundTag tag, HolderLookup.Provider registries) {}

/**
* Gets called from {@link #getUpdateTag}
* @param tag
* @param lookupProvider
* @return
*/
public CompoundTag updateTag(CompoundTag tag, HolderLookup.Provider lookupProvider) { return tag; }

/**
* Gets called from {@link #handleUpdateTag}
* @param tag
* @param lookupProvider
*/
public void handleUpdate(CompoundTag tag, HolderLookup.Provider lookupProvider) {}


@Override
protected void saveAdditional(CompoundTag tag, HolderLookup.Provider registries) {
super.saveAdditional(tag, registries);
tag.put("Energy", this.energyStorage.serializeNBT(registries));
saveExtra(tag, registries);
}

@Override
public @NotNull CompoundTag getUpdateTag(HolderLookup.Provider registries) {
CompoundTag tag = super.getUpdateTag(registries);
CompoundTag tag = updateTag(super.getUpdateTag(registries), registries);
tag.put("Energy", this.energyStorage.serializeNBT(registries));
return tag;
}

@Override
protected void loadAdditional(CompoundTag tag, HolderLookup.Provider registries) {
super.loadAdditional(tag, registries);
if (tag.contains("Energy")) {
this.energyStorage.deserializeNBT(registries, tag.get("Energy"));
}
loadExtra(tag, registries);
}

@Override
public void handleUpdateTag(@NotNull CompoundTag tag, @NotNull HolderLookup.Provider lookupProvider) {
Tag energyTag = tag.get("Energy");
if (energyTag == null) return;
this.energyStorage.deserializeNBT(lookupProvider, energyTag);
handleUpdate(tag, lookupProvider);
}

public void syncToClient() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import dev.wolfieboy09.qstorage.registries.QSBlockEntities;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.HolderLookup;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.SimpleContainer;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
Expand All @@ -12,8 +14,10 @@
import net.neoforged.neoforge.items.ItemStackHandler;
import org.jetbrains.annotations.Nullable;

import javax.annotation.ParametersAreNonnullByDefault;
import java.util.Objects;

@ParametersAreNonnullByDefault
public class DiskAssemblerBlockEntity extends AbstractEnergyBlockEntity {
private int progress = 0;
private int crafting_ticks = 0;
Expand Down Expand Up @@ -114,4 +118,34 @@ public SimpleContainer getOutputContainer() {
container.setItem(8, inventory.getStackInSlot(8));
return container;
}

@Override
public void saveExtra(CompoundTag tag, HolderLookup.Provider registries) {
super.saveExtra(tag, registries);
tag.putInt("energy_required", this.energy_required);
tag.putInt("crafting_ticks", this.crafting_ticks);
tag.put("inventory", this.inventory.serializeNBT(registries));
}

@Override
protected void loadExtra(CompoundTag tag, HolderLookup.Provider registries) {
super.loadExtra(tag, registries);
this.energy_required = tag.getInt("energy_required");
this.crafting_ticks = tag.getInt("crafting_ticks");
this.inventory.deserializeNBT(registries, tag.getCompound("inventory"));
}

@Override
public CompoundTag updateTag(CompoundTag tag, HolderLookup.Provider lookupProvider) {
tag.putInt("energy_required", this.energy_required);
tag.putInt("crafting_ticks", this.crafting_ticks);
return super.updateTag(tag, lookupProvider);
}

@Override
public void handleUpdate(CompoundTag tag, HolderLookup.Provider lookupProvider) {
super.handleUpdate(tag, lookupProvider);
this.energy_required = tag.getInt("energy_required");
this.crafting_ticks = tag.getInt("crafting_ticks");
}
}

0 comments on commit d213bc9

Please sign in to comment.