Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If redstone is supplied dont accept energy #33

Closed
wants to merge 1 commit into from
Closed
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
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;
}
}
Loading