Skip to content

Commit

Permalink
If redstone is supplied by neighbors dont accpet energy
Browse files Browse the repository at this point in the history
  • Loading branch information
citpo committed Mar 18, 2024
1 parent 5465780 commit 9cc9c5f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ public boolean canExtract() {

@Override
public boolean canReceive() {

//Abort if redstone enabled
if(parent.getIsRedstoneDisabled())
return false;

if (parent.getMode() == MODE.CONSUMER) {
return parent.getSideConfig().get(side) == IO_SETTING.IN;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public enum Constants {
public static final String IO_SCREEN_ID = "screen";
public static final String INTERVAL_ID = "interval";
public static final String THRESHOLD_ID = "threshold";

public static final String REDSTONE_DISABLED_ID = "redstone_disabled";
/**
* Decimal color values to ensure consistent color values.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import net.minecraft.world.phys.BlockHitResult;
import net.minecraftforge.network.NetworkHooks;


import javax.annotation.Nullable;

import static com.github.almostreliable.energymeter.core.Constants.IO_STATE_ID;
Expand Down Expand Up @@ -75,6 +76,10 @@ public void neighborChanged(
// resolve tile entity from block position
if (!state.hasBlockEntity()) return;
if (level.getBlockEntity(pos) instanceof MeterEntity entity) {
//Check neighbor redstone level
var isDisabled = level.hasNeighborSignal(pos);
entity.setIsRedstoneDisabled(isDisabled);

// ensure valid neighbor
var neighborState = level.getBlockState(neighbor);
// noinspection deprecation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public class MeterEntity extends BlockEntity implements MenuProvider {
private int threshold = REFRESH_RATE;
private double zeroThreshold;

private boolean isRedstoneDisabled = false;

@SuppressWarnings("ThisEscapedInObjectConstruction")
public MeterEntity(BlockPos pos, BlockState state) {
super(Entities.METER.get(), pos, state);
Expand Down Expand Up @@ -171,6 +173,8 @@ public void load(CompoundTag tag) {
if (tag.contains(ACCURACY_ID)) accuracy = ACCURACY.values()[tag.getInt(ACCURACY_ID)];
if (tag.contains(INTERVAL_ID)) interval = tag.getInt(INTERVAL_ID);
if (tag.contains(THRESHOLD_ID)) threshold = tag.getInt(THRESHOLD_ID);
if (tag.contains(REDSTONE_DISABLED_ID)) isRedstoneDisabled = tag.getBoolean(REDSTONE_DISABLED_ID);

}

@Override
Expand All @@ -182,6 +186,7 @@ public void saveAdditional(CompoundTag tag) {
tag.putInt(ACCURACY_ID, accuracy.ordinal());
tag.putInt(INTERVAL_ID, interval);
tag.putInt(THRESHOLD_ID, threshold);
tag.putBoolean(REDSTONE_DISABLED_ID, isRedstoneDisabled);
}

@Override
Expand All @@ -195,6 +200,7 @@ public CompoundTag getUpdateTag() {
tag.putInt(ACCURACY_ID, accuracy.ordinal());
tag.putInt(INTERVAL_ID, interval);
tag.putInt(THRESHOLD_ID, threshold);
tag.putBoolean(REDSTONE_DISABLED_ID, isRedstoneDisabled);
return tag;
}

Expand All @@ -216,6 +222,7 @@ public void handleUpdateTag(CompoundTag tag) {
accuracy = ACCURACY.values()[tag.getInt(ACCURACY_ID)];
interval = tag.getInt(INTERVAL_ID);
threshold = tag.getInt(THRESHOLD_ID);
isRedstoneDisabled = tag.getBoolean(REDSTONE_DISABLED_ID);
}

public int receiveEnergy(int energy, boolean simulate) {
Expand Down Expand Up @@ -583,4 +590,12 @@ public void setMode(MODE mode) {
public Component getDisplayName() {
return TextUtils.translate(TRANSLATE_TYPE.CONTAINER, METER_ID);
}

public void setIsRedstoneDisabled(boolean isDisabled) {
isRedstoneDisabled = isDisabled;
}

public boolean getIsRedstoneDisabled() {
return isRedstoneDisabled;
}
}

0 comments on commit 9cc9c5f

Please sign in to comment.