Skip to content

Commit

Permalink
energy requirement for blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Thepigcat76 committed Sep 28, 2024
1 parent a34800c commit 0339fb1
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 38 deletions.
6 changes: 6 additions & 0 deletions src/main/java/com/portingdeadmods/nautec/NTConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ public final class NTConfig {
private static final ModConfigSpec.IntValue KELP_HEIGHT = BUILDER
.comment("The height of kelp to be able to grow.")
.defineInRange("kelpHeight", 40, 25, Integer.MAX_VALUE);
private static final ModConfigSpec.IntValue MIXER_POWER_REQUIREMENT = BUILDER
.comment("The amount of power required by the mixer each tick.")
.defineInRange("mixerPowerRequirement", 15, 0, Integer.MAX_VALUE);
private static final ModConfigSpec.IntValue AUGMENTATION_STATION_REQUIREMENT = BUILDER
.comment("The amount of power required by the Augmentation Station each tick.")
.defineInRange("mixerPowerRequirement", 50, 0, Integer.MAX_VALUE);


static final ModConfigSpec SPEC = BUILDER.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@ public void render(T blockEntity, float partialTick, PoseStack poseStack, MultiB
Object2IntMap<Direction> laserDistances = blockEntity.getLaserDistances();
for (Direction direction : blockEntity.getLaserOutputs()) {
int laserDistance = laserDistances.getOrDefault(direction, 0);
Nautec.LOGGER.debug("Distance: {}", laserDistance);

BlockPos originPos = blockEntity.getBlockPos();
BlockPos targetPos = originPos.relative(direction, laserDistance - 1);
Nautec.LOGGER.debug("origin: {}, target: {}", originPos, targetPos);
BlockState state = blockEntity.getLevel().getBlockState(targetPos.relative(direction));
if (laserDistance > 0 && blockEntity.shouldRender(direction)) {
VoxelShape shape = state.getShape(blockEntity.getLevel(), targetPos.relative(direction), CollisionContext.empty());
Expand Down Expand Up @@ -70,6 +68,7 @@ public void render(T blockEntity, float partialTick, PoseStack poseStack, MultiB
}

if (direction == Direction.UP) {
offset = 1;
offset2 = 1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,21 @@ public void commonTick() {
}

private void performRecipe() {
if (recipe != null) {
if (recipe != null && getPower() > 20) {
this.running = true;
if (duration >= recipe.duration()) {
duration = 0;
this.running = false;
setOutputs(recipe);
removeInputs(recipe);
duration = 0;
this.recipe = getRecipe().orElse(null);
} else {
duration++;
}
} else {
this.running = false;
duration = 0;
this.recipe = null;
}
}

Expand Down Expand Up @@ -208,12 +212,14 @@ public float getIndependentAngle(float partialTicks) {
protected void loadData(CompoundTag tag, HolderLookup.Provider provider) {
super.loadData(tag, provider);
this.duration = tag.getInt("duration");
this.independentAngle = tag.getFloat("independentAngle");
}

@Override
protected void saveData(CompoundTag tag, HolderLookup.Provider provider) {
super.saveData(tag, provider);
tag.putInt("duration", this.duration);
tag.putFloat("independentAngle", this.independentAngle);
}

public FluidStack getInputFluid() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ public void startAugmentation(Player player, AugmentSlot augmentSlot) {
for (BlockPos pos : augmentItems.keySet()) {
AugmentationStationExtensionBlockEntity be = (AugmentationStationExtensionBlockEntity) level.getBlockEntity(pos);

if (be.getPower() < 15) {
return;
}

be.equipAugment();
}

Expand Down Expand Up @@ -136,6 +140,17 @@ public void commonTick() {
if (duration > 0) {
duration--;

for (BlockPos pos : augmentItems.keySet()) {
AugmentationStationExtensionBlockEntity be = (AugmentationStationExtensionBlockEntity) level.getBlockEntity(pos);

if (be.getPower() < 15) {
this.duration = 0;
this.isRunning = false;
restorePlayerAttributes();
return;
}
}

if (duration == 0) {
this.isRunning = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public class AugmentationStationExtensionBlockEntity extends LaserBlockEntity im
private int animationInterval;
private Animation animation;

private boolean hasRobotArm;
private BlockPos controllerPos;

public AugmentationStationExtensionBlockEntity(BlockPos blockPos, BlockState blockState) {
Expand Down Expand Up @@ -134,17 +133,9 @@ public float getTipIndependentAngle(float partialTicks) {
return animationRunning ? (tipIndependentAngle + partialTicks) / 360 : 0;
}

public boolean hasRobotArm() {
return hasRobotArm;
}

public void setHasRobotArm(boolean hasRobotArm) {
this.hasRobotArm = hasRobotArm;
}

@Override
public ObjectSet<Direction> getLaserInputs() {
return ObjectSet.of();
return ObjectSet.of(Direction.DOWN);
}

@Override
Expand Down Expand Up @@ -177,7 +168,6 @@ public void onLoad() {
protected void loadData(CompoundTag tag, HolderLookup.Provider provider) {
super.loadData(tag, provider);
this.controllerPos = BlockPos.of(tag.getLong("controllerPos"));
this.hasRobotArm = tag.getBoolean("hasRobotArm");
}

@Override
Expand All @@ -186,7 +176,6 @@ protected void saveData(CompoundTag tag, HolderLookup.Provider provider) {
if (controllerPos != null) {
tag.putLong("controllerPos", controllerPos.asLong());
}
tag.putBoolean("hasRobotArm", hasRobotArm);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,26 +104,6 @@ protected MapCodec<? extends BaseEntityBlock> codec() {
return super.useItemOn(stack, state, level, pos, player, hand, hitResult);
}

@Override
public List<Component> displayText(Level level, BlockPos blockPos, Player player) {
MixerBlockEntity mixerBE = (MixerBlockEntity) level.getBlockEntity(blockPos);
List<Component> list = new ArrayList<>(super.displayText(level, blockPos, player));
list.add(literal("Input:"));
StringBuilder builder = new StringBuilder();
IItemHandler handler = mixerBE.getItemHandler();
IFluidHandler fluidHandler = mixerBE.getFluidHandler();
IFluidHandler secondaryHandler = mixerBE.getSecondaryFluidHandler();
for (int i = 0; i < handler.getSlots()-1; i++) {
builder.append(handler.getStackInSlot(i)+"; ");
}
list.add(literal(builder.toString()));
list.add(literal(fluidHandler.getFluidInTank(0).toString()));
list.add(literal("Output:"));
list.add(literal(handler.getStackInSlot(MixerBlockEntity.OUTPUT_SLOT).toString()));
list.add(literal(secondaryHandler.getFluidInTank(0).toString()));
return list;
}

private static Component literal(String text) {
return Component.literal(text).withStyle(ChatFormatting.WHITE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ protected void addTranslations() {
add("augment_slot.nautec.left_arm", "Left Arm");
add("augment_slot.nautec.right_arm", "Right Arm");
add("augment_slot.nautec.heart", "Heart");

add("augment_type.nautec.drowned_lung", "Drowned Lung");
add("augment_type.nautec.guardian_eye", "Guardian Eye");
add("augment_type.nautec.dolphin_fin", "Dolphin Fin");
}

private void addFluidType(Supplier<? extends FluidType> fluidType, String val) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ public static <T extends LaserBlockEntity> void renderOuterBeam(T blockEntity, B
offset = 0;
} else if (direction == Direction.DOWN) {
poseStack.translate(0.5F, 1, 0.5F);
offset = 1;
offset = 0;
} else {
poseStack.translate(0.5F, 1, 0.5F);
offset = 1;
}
Vec3 vec3 = vec3Relative(targetPos.relative(direction, -offset).getCenter(), direction, targetOffset - (direction != Direction.DOWN ? 0.9d : 0.9d));
Vec3 vec3 = vec3Relative(targetPos.relative(direction, -offset).getCenter(), direction, targetOffset - (direction != Direction.DOWN ? 0.9d : -0.1d));
Vec3 vec31 = originPos.relative(direction, offset2).getCenter();
Vec3 vec32 = vec3.subtract(vec31);
float f4 = (float) (vec32.length() + 1.0);
Expand Down

0 comments on commit 0339fb1

Please sign in to comment.