Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* MIT License
*
* Copyright (c) 2020 Azercoco & Technici4n
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package aztech.modern_industrialization.api.energy;

public interface CableTierHolder {
CableTier getCableTier();
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
package aztech.modern_industrialization.machines.blockentities;

import aztech.modern_industrialization.MICapabilities;
import aztech.modern_industrialization.api.energy.CableTier;
import aztech.modern_industrialization.api.energy.CableTierHolder;
import aztech.modern_industrialization.api.energy.EnergyApi;
import aztech.modern_industrialization.api.energy.MIEnergyStorage;
import aztech.modern_industrialization.api.machine.holder.EnergyComponentHolder;
Expand All @@ -44,7 +46,7 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.block.entity.BlockEntityType;

public class ElectricCraftingMachineBlockEntity extends AbstractCraftingMachineBlockEntity implements EnergyComponentHolder {
public class ElectricCraftingMachineBlockEntity extends AbstractCraftingMachineBlockEntity implements EnergyComponentHolder, CableTierHolder {

public ElectricCraftingMachineBlockEntity(BEP bep, MachineRecipeType recipeType, MachineInventoryComponent inventory,
MachineGuiParameters guiParams, EnergyBar.Parameters energyBarParams, ProgressBar.Parameters progressBarParams,
Expand Down Expand Up @@ -132,4 +134,9 @@ public boolean isOverdriving() {
public EnergyComponent getEnergyComponent() {
return energy;
}

@Override
public CableTier getCableTier() {
return casing.getCableTier();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import aztech.modern_industrialization.MICapabilities;
import aztech.modern_industrialization.api.energy.CableTier;
import aztech.modern_industrialization.api.energy.CableTierHolder;
import aztech.modern_industrialization.api.energy.EnergyApi;
import aztech.modern_industrialization.api.energy.MIEnergyStorage;
import aztech.modern_industrialization.api.machine.holder.EnergyComponentHolder;
Expand All @@ -43,7 +44,7 @@
import net.minecraft.world.level.material.Fluids;
import net.neoforged.neoforge.fluids.FluidType;

public class ElectricWaterPumpBlockEntity extends AbstractWaterPumpBlockEntity implements EnergyComponentHolder {
public class ElectricWaterPumpBlockEntity extends AbstractWaterPumpBlockEntity implements EnergyComponentHolder, CableTierHolder {
public ElectricWaterPumpBlockEntity(BEP bep) {
super(bep, "electric_water_pump");

Expand Down Expand Up @@ -105,4 +106,9 @@ public static void registerEnergyApi(BlockEntityType<?> bet) {
event.registerBlockEntity(EnergyApi.SIDED, bet, (be, direction) -> ((ElectricWaterPumpBlockEntity) be).insertable);
});
}

@Override
public CableTier getCableTier() {
return CableTier.LV;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import aztech.modern_industrialization.MICapabilities;
import aztech.modern_industrialization.api.energy.CableTier;
import aztech.modern_industrialization.api.energy.CableTierHolder;
import aztech.modern_industrialization.api.energy.EnergyApi;
import aztech.modern_industrialization.api.energy.MIEnergyStorage;
import aztech.modern_industrialization.api.machine.holder.EnergyComponentHolder;
Expand All @@ -50,7 +51,7 @@
import net.minecraft.network.chat.Component;
import net.minecraft.world.level.block.entity.BlockEntityType;

public class GeneratorMachineBlockEntity extends MachineBlockEntity implements Tickable, EnergyComponentHolder {
public class GeneratorMachineBlockEntity extends MachineBlockEntity implements Tickable, EnergyComponentHolder, CableTierHolder {

private final CableTier outputTier;
private final MIEnergyStorage extractable;
Expand Down Expand Up @@ -212,4 +213,9 @@ public static void registerEnergyApi(BlockEntityType<?> bet) {
public List<Component> getTooltips() {
return fluidItemConsumer.getTooltips();
}

@Override
public CableTier getCableTier() {
return outputTier;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@
package aztech.modern_industrialization.machines.blockentities;

import aztech.modern_industrialization.api.energy.CableTier;
import aztech.modern_industrialization.api.energy.CableTierHolder;
import aztech.modern_industrialization.machines.BEP;
import net.minecraft.util.Mth;

public class StorageMachineBlockEntity extends AbstractStorageMachineBlockEntity {
public class StorageMachineBlockEntity extends AbstractStorageMachineBlockEntity implements CableTierHolder {

public StorageMachineBlockEntity(BEP bep, CableTier tier, String name, long eu_capacity) {
super(bep, tier, tier, name, eu_capacity);
Expand All @@ -43,4 +44,9 @@ protected int getComparatorOutput() {
double fillPercentage = (double) energy.getEu() / energy.getCapacity();
return Mth.floor(fillPercentage * 14) + (energy.getEu() > 0 ? 1 : 0);
}

@Override
public CableTier getCableTier() {
return to;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import aztech.modern_industrialization.MICapabilities;
import aztech.modern_industrialization.api.energy.CableTier;
import aztech.modern_industrialization.api.energy.CableTierHolder;
import aztech.modern_industrialization.api.energy.EnergyApi;
import aztech.modern_industrialization.api.energy.MIEnergyStorage;
import aztech.modern_industrialization.api.machine.holder.EnergyComponentHolder;
Expand All @@ -39,12 +40,13 @@
import java.util.List;
import net.minecraft.world.level.block.entity.BlockEntityType;

public class EnergyHatch extends HatchBlockEntity implements EnergyComponentHolder {
public class EnergyHatch extends HatchBlockEntity implements EnergyComponentHolder, CableTierHolder {

public EnergyHatch(BEP bep, String name, boolean input, CableTier tier) {
super(bep, new MachineGuiParameters.Builder(name, false).build(), new OrientationComponent.Params(!input, false, false));

this.input = input;
this.tier = tier;

this.energy = new EnergyComponent(this, 30 * 20 * tier.getEu());
insertable = energy.buildInsertable((CableTier tier2) -> tier2 == tier);
Expand All @@ -56,10 +58,11 @@ public EnergyHatch(BEP bep, String name, boolean input, CableTier tier) {
}

private final boolean input;
private final CableTier tier;

protected final EnergyComponent energy;
protected final MIEnergyStorage insertable;
protected final MIEnergyStorage extractable;
private final EnergyComponent energy;
private final MIEnergyStorage insertable;
private final MIEnergyStorage extractable;

@Override
public HatchType getHatchType() {
Expand All @@ -71,6 +74,11 @@ public boolean upgradesToSteel() {
return false;
}

@Override
public CableTier getCableTier() {
return tier;
}

@Override
public MIInventory getInventory() {
return MIInventory.EMPTY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,25 @@

public class CasingComponent implements IComponent, DropableComponent {

@FunctionalInterface
public interface UpdatedCallback {
void onUpdated(CableTier from, CableTier to);
}

@Nullable
private final UpdatedCallback callback;

private ItemStack casingStack = ItemStack.EMPTY;
private CableTier currentTier = CableTier.LV;

public CasingComponent(@Nullable UpdatedCallback callback) {
this.callback = callback;
}

public CasingComponent() {
this(null);
}

/**
* Sets the current casing stack and update {@link #currentTier} accordingly.
*/
Expand Down Expand Up @@ -80,13 +96,18 @@ public void readClientNbt(CompoundTag tag, HolderLookup.Provider registries) {
currentTier = CableTier.getTier(tag.getString("casing"));
}

public CableTier getCableTier() {
return currentTier;
}

public void dropCasing(Level world, BlockPos pos) {
Containers.dropItemStack(world, pos.getX(), pos.getY(), pos.getZ(), casingStack);
}

public ItemInteractionResult onUse(MachineBlockEntity be, Player player, InteractionHand hand) {
ItemStack stackInHand = player.getItemInHand(hand);
if (stackInHand.getCount() >= 1) {
var previousTier = currentTier;
var newTier = getCasingTier(stackInHand.getItem());
if (newTier != null && newTier != currentTier) {
if (currentTier != CableTier.LV) {
Expand All @@ -103,6 +124,9 @@ public ItemInteractionResult onUse(MachineBlockEntity be, Player player, Interac
be.getLevel().updateNeighborsAt(be.getBlockPos(), Blocks.AIR);
// Play a nice sound :)
playCasingPlaceSound(be);
if (callback != null) {
callback.onUpdated(previousTier, currentTier);
}
return ItemInteractionResult.sidedSuccess(be.getLevel().isClientSide);
}
}
Expand Down Expand Up @@ -142,11 +166,15 @@ public ItemStack getDrop() {
}

public void setCasingServer(MachineBlockEntity be, ItemStack casing) {
var previousTier = currentTier;
setCasingStack(casing);
be.setChanged();
be.sync();
be.getLevel().updateNeighborsAt(be.getBlockPos(), Blocks.AIR);
playCasingPlaceSound(be);
if (callback != null && previousTier != currentTier) {
callback.onUpdated(previousTier, currentTier);
}
}

public MachineCasing getCasing() {
Expand Down
Loading