Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
Thepigcat76 committed Dec 16, 2024
2 parents 49fd167 + 8c53b0d commit 8c6efb5
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 1 deletion.
24 changes: 24 additions & 0 deletions src/main/java/com/portingdeadmods/nautec/NTConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,21 @@ public final class NTConfig {
.comment("Set to false to disable the rendering of augments, this can improve performance")
.define("allowAugmentRendering", true);

private static final ModConfigSpec.IntValue FISHER_LASER_LEVEL = BUILDER
.comment("The amount laser power required to have the fisher work")
.defineInRange("fisherLaserLevel", 1, 0, Integer.MAX_VALUE);

private static final ModConfigSpec.IntValue FISHER_DURATION = BUILDER
.comment("The amount of ticks the fisher takes to make a new item")
.defineInRange("fisherRunDuration", 40, 0, Integer.MAX_VALUE);
private static final ModConfigSpec.IntValue FISHER_RADIUS = BUILDER
.comment("The radius on the x and z plane the fisher checks for the water")
.defineInRange("fisherRadius", 2, 1, Integer.MAX_VALUE);

private static final ModConfigSpec.IntValue FISHER_DEPTH = BUILDER
.comment("The y depth the fisher checks for water")
.defineInRange("fisherDepth", 2, 1, Integer.MAX_VALUE);

static final ModConfigSpec SPEC = BUILDER.build();

public static int kelpHeight;
Expand All @@ -83,6 +98,10 @@ public final class NTConfig {
public static int guardianAugmentDamage;
public static boolean allowAugmentRendering;

public static int fisherLaserLevel;
public static int fisherRunDuration;
public static int fisherRadius;
public static int fisherDepth;
@SubscribeEvent
static void onLoad(final ModConfigEvent event) {
kelpHeight = KELP_HEIGHT.get();
Expand All @@ -105,6 +124,11 @@ static void onLoad(final ModConfigEvent event) {

guardianAugmentDamage = GUARDIAN_AUGMENT_DAMAGE.get();
allowAugmentRendering = ALLOW_AUGMENT_RENDERING.get();

fisherLaserLevel = FISHER_LASER_LEVEL.getAsInt();
fisherRunDuration = FISHER_DURATION.getAsInt();
fisherDepth = FISHER_DEPTH.getAsInt();
fisherRadius = FISHER_RADIUS.getAsInt();
}

}
Original file line number Diff line number Diff line change
@@ -1,19 +1,35 @@
package com.portingdeadmods.nautec.content.blockentities;

import com.portingdeadmods.nautec.NTConfig;
import com.portingdeadmods.nautec.api.blockentities.LaserBlockEntity;
import com.portingdeadmods.nautec.capabilities.IOActions;
import com.portingdeadmods.nautec.registries.NTBlockEntityTypes;
import it.unimi.dsi.fastutil.Pair;
import it.unimi.dsi.fastutil.objects.ObjectSet;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.BuiltInLootTables;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.LootParams;
import net.minecraft.world.level.storage.loot.LootTable;
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.world.phys.Vec3;
import net.neoforged.neoforge.capabilities.BlockCapability;
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.Map;

public class FishingStationBlockEntity extends LaserBlockEntity {
private boolean running;
private int counter;
public FishingStationBlockEntity(BlockPos blockPos, BlockState blockState) {
super(NTBlockEntityTypes.FISHING_STATION.get(), blockPos, blockState);
}
Expand All @@ -32,4 +48,40 @@ public ObjectSet<Direction> getLaserOutputs() {
public <T> Map<Direction, Pair<IOActions, int[]>> getSidedInteractions(BlockCapability<T, @Nullable Direction> capability) {
return Map.of();
}
}

private boolean canRun(){
BlockPos start = worldPosition.offset(-NTConfig.fisherRadius,-NTConfig.fisherDepth,-NTConfig.fisherRadius);
BlockPos end = worldPosition.offset(NTConfig.fisherRadius,-1,NTConfig.fisherRadius);
for (BlockPos pos: BlockPos.betweenClosed(start,end)) {
if (!level.getBlockState(pos).is(Blocks.WATER)) return false;
}
return true;
}

@Override
public void commonTick() {
super.commonTick();
if (level instanceof ServerLevel && getPower() >= NTConfig.fisherLaserLevel){
if (running) {
if (counter >= NTConfig.fisherRunDuration) {
counter = 0;
running = false;
spawnLoot();
}
counter++;
} else running = canRun();
}
}

private void spawnLoot() {
LootTable lootTable = level.getServer().reloadableRegistries().getLootTable(BuiltInLootTables.FISHING);
List<ItemStack> loot = lootTable.getRandomItems(new LootParams.Builder((ServerLevel) level).withParameter(LootContextParams.ORIGIN, Vec3.atCenterOf(worldPosition)).withParameter(LootContextParams.TOOL, Items.FISHING_ROD.getDefaultInstance()).create(LootContextParamSets.FISHING));
for (ItemStack stack : loot) {
Vec3 pos = getItemSpawnPos();
ItemEntity itemEntity = new ItemEntity(level, pos.x, pos.y, pos.z, stack);
level.addFreshEntity(itemEntity);
}
}
private Vec3 getItemSpawnPos(){
return new Vec3(worldPosition.getX() + 0.5, worldPosition.getY() + 1.5, worldPosition.getZ() + 0.5);
}}

0 comments on commit 8c6efb5

Please sign in to comment.