Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -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 @@ -55,7 +57,8 @@ public EnergyHatch(BEP bep, String name, boolean input, CableTier tier) {
this.registerComponents(energy);
}

private final boolean input;
protected final boolean input;
protected final CableTier tier;

protected final EnergyComponent energy;
protected final MIEnergyStorage insertable;
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 @@ -24,6 +24,7 @@
package aztech.modern_industrialization.machines.components;

import aztech.modern_industrialization.api.energy.CableTier;
import aztech.modern_industrialization.api.energy.CableTierHolder;
import aztech.modern_industrialization.machines.IComponent;
import aztech.modern_industrialization.machines.MachineBlockEntity;
import aztech.modern_industrialization.machines.models.MachineCasing;
Expand All @@ -42,15 +43,15 @@
import net.minecraft.world.level.block.Blocks;
import org.jetbrains.annotations.Nullable;

public class CasingComponent implements IComponent, DropableComponent {
public class CasingComponent implements IComponent, DropableComponent, CableTierHolder {

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

/**
* Sets the current casing stack and update {@link #currentTier} accordingly.
*/
private void setCasingStack(ItemStack stack) {
protected void setCasingStack(ItemStack stack) {
casingStack = stack;

// Compute tier
Expand Down Expand Up @@ -80,6 +81,11 @@ public void readClientNbt(CompoundTag tag, HolderLookup.Provider registries) {
currentTier = CableTier.getTier(tag.getString("casing"));
}

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

public void dropCasing(Level world, BlockPos pos) {
Containers.dropItemStack(world, pos.getX(), pos.getY(), pos.getZ(), casingStack);
}
Expand Down Expand Up @@ -109,7 +115,7 @@ public ItemInteractionResult onUse(MachineBlockEntity be, Player player, Interac
return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
}

private void playCasingPlaceSound(MachineBlockEntity be) {
protected void playCasingPlaceSound(MachineBlockEntity be) {
var blockKey = currentTier.itemKey;
if (blockKey == null) {
return; // no sound for LV
Expand Down
Loading