Skip to content

Commit 07da29e

Browse files
committed
Make CableTier more accessible
1 parent a52a091 commit 07da29e

File tree

3 files changed

+49
-7
lines changed

3 files changed

+49
-7
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2020 Azercoco & Technici4n
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package aztech.modern_industrialization.api.energy;
25+
26+
public interface CableTierHolder {
27+
CableTier getCableTier();
28+
}

src/main/java/aztech/modern_industrialization/machines/blockentities/hatches/EnergyHatch.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import aztech.modern_industrialization.MICapabilities;
2727
import aztech.modern_industrialization.api.energy.CableTier;
28+
import aztech.modern_industrialization.api.energy.CableTierHolder;
2829
import aztech.modern_industrialization.api.energy.EnergyApi;
2930
import aztech.modern_industrialization.api.energy.MIEnergyStorage;
3031
import aztech.modern_industrialization.api.machine.holder.EnergyComponentHolder;
@@ -39,12 +40,13 @@
3940
import java.util.List;
4041
import net.minecraft.world.level.block.entity.BlockEntityType;
4142

42-
public class EnergyHatch extends HatchBlockEntity implements EnergyComponentHolder {
43+
public class EnergyHatch extends HatchBlockEntity implements EnergyComponentHolder, CableTierHolder {
4344

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

4748
this.input = input;
49+
this.tier = tier;
4850

4951
this.energy = new EnergyComponent(this, 30 * 20 * tier.getEu());
5052
insertable = energy.buildInsertable((CableTier tier2) -> tier2 == tier);
@@ -55,7 +57,8 @@ public EnergyHatch(BEP bep, String name, boolean input, CableTier tier) {
5557
this.registerComponents(energy);
5658
}
5759

58-
private final boolean input;
60+
protected final boolean input;
61+
protected final CableTier tier;
5962

6063
protected final EnergyComponent energy;
6164
protected final MIEnergyStorage insertable;
@@ -71,6 +74,11 @@ public boolean upgradesToSteel() {
7174
return false;
7275
}
7376

77+
@Override
78+
public CableTier getCableTier() {
79+
return tier;
80+
}
81+
7482
@Override
7583
public MIInventory getInventory() {
7684
return MIInventory.EMPTY;

src/main/java/aztech/modern_industrialization/machines/components/CasingComponent.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
package aztech.modern_industrialization.machines.components;
2525

2626
import aztech.modern_industrialization.api.energy.CableTier;
27+
import aztech.modern_industrialization.api.energy.CableTierHolder;
2728
import aztech.modern_industrialization.machines.IComponent;
2829
import aztech.modern_industrialization.machines.MachineBlockEntity;
2930
import aztech.modern_industrialization.machines.models.MachineCasing;
@@ -42,15 +43,15 @@
4243
import net.minecraft.world.level.block.Blocks;
4344
import org.jetbrains.annotations.Nullable;
4445

45-
public class CasingComponent implements IComponent, DropableComponent {
46+
public class CasingComponent implements IComponent, DropableComponent, CableTierHolder {
4647

47-
private ItemStack casingStack = ItemStack.EMPTY;
48-
private CableTier currentTier = CableTier.LV;
48+
protected ItemStack casingStack = ItemStack.EMPTY;
49+
protected CableTier currentTier = CableTier.LV;
4950

5051
/**
5152
* Sets the current casing stack and update {@link #currentTier} accordingly.
5253
*/
53-
private void setCasingStack(ItemStack stack) {
54+
protected void setCasingStack(ItemStack stack) {
5455
casingStack = stack;
5556

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

84+
@Override
85+
public CableTier getCableTier() {
86+
return currentTier;
87+
}
88+
8389
public void dropCasing(Level world, BlockPos pos) {
8490
Containers.dropItemStack(world, pos.getX(), pos.getY(), pos.getZ(), casingStack);
8591
}
@@ -109,7 +115,7 @@ public ItemInteractionResult onUse(MachineBlockEntity be, Player player, Interac
109115
return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
110116
}
111117

112-
private void playCasingPlaceSound(MachineBlockEntity be) {
118+
protected void playCasingPlaceSound(MachineBlockEntity be) {
113119
var blockKey = currentTier.itemKey;
114120
if (blockKey == null) {
115121
return; // no sound for LV

0 commit comments

Comments
 (0)