Skip to content

Commit

Permalink
The Leacher extracts only one resource from vein #170
Browse files Browse the repository at this point in the history
  • Loading branch information
igentuman committed Mar 9, 2025
1 parent eee3b23 commit 6e1a1e6
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 17 deletions.
20 changes: 11 additions & 9 deletions src/main/java/igentuman/nc/block/entity/processor/LeacherBE.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public LeacherBE(BlockPos pPos, BlockState pBlockState) {

protected PumpBE[] pumps = new PumpBE[4];

protected byte pumpValidationTimeout = 40;
protected byte pumpValidationTimeout = 80;

@Override
public String getName() {
Expand Down Expand Up @@ -113,7 +113,7 @@ public void tickServer() {
private void handleState() {
pumpValidationTimeout--;
if(pumpValidationTimeout <= 0) {
pumpValidationTimeout = 40;
pumpValidationTimeout = 80;
clearHighligts();
validatePumps();
}
Expand Down Expand Up @@ -162,8 +162,8 @@ public void tickClient() {
}

public boolean isPumpValid(NCBlockPos pos, int id) {
for (int y = 0; y < 20; y++) {
BlockEntity be = getLevel().getBlockEntity( pos.below());
for (int y = 0; y < 2; y++) {
BlockEntity be = getLevel().getBlockEntity(pos.below());
if (be instanceof PumpBE) {
pumps[id] = (PumpBE) be;
return pumps[id].isInSituValid();
Expand All @@ -176,7 +176,7 @@ public void validatePumps() {
ChunkPos chunkPos = new ChunkPos(getBlockPos());
boolean isClientSide = Objects.requireNonNull(getLevel()).isClientSide;
pumpsAreValid = isPumpValid(
new NCBlockPos(chunkPos.getMinBlockX(), worldPosition.getY()+5, chunkPos.getMinBlockZ()),
new NCBlockPos(chunkPos.getMinBlockX(), worldPosition.getY()+1, chunkPos.getMinBlockZ()),
0
);
if(!pumpsAreValid) {
Expand All @@ -185,7 +185,7 @@ public void validatePumps() {
}
}
if(!isPumpValid(
new NCBlockPos(chunkPos.getMinBlockX(), worldPosition.getY()+5, chunkPos.getMaxBlockZ()),
new NCBlockPos(chunkPos.getMinBlockX(), worldPosition.getY()+1, chunkPos.getMaxBlockZ()),
1
)) {
pumpsAreValid = false;
Expand All @@ -195,7 +195,7 @@ public void validatePumps() {
}

if(!isPumpValid(
new NCBlockPos(chunkPos.getMaxBlockX(), worldPosition.getY()+5, chunkPos.getMaxBlockZ()),
new NCBlockPos(chunkPos.getMaxBlockX(), worldPosition.getY()+1, chunkPos.getMaxBlockZ()),
2
)) {
if(isClientSide) {
Expand All @@ -205,7 +205,7 @@ public void validatePumps() {
}

if(!isPumpValid(
new NCBlockPos(chunkPos.getMaxBlockX(), worldPosition.getY()+5, chunkPos.getMinBlockZ()),
new NCBlockPos(chunkPos.getMaxBlockX(), worldPosition.getY()+1, chunkPos.getMinBlockZ()),
3
)) {
if(isClientSide) {
Expand All @@ -232,6 +232,9 @@ protected void updateRecipe() {

public void gatherOre()
{
if(!contentHandler.itemHandler.getStackInSlot(0).isEmpty()) {
return;
}
if(!hasCatalyst()) {
catalyst = ItemStack.EMPTY;
return;
Expand Down Expand Up @@ -283,7 +286,6 @@ protected ItemStack useResearchPaper() {

int currentMiningTimeout = 0;
protected ItemStack useMapCatalyst() {

MapItemSavedData mapData = ((MapItem)catalyst.getItem()).getSavedData(catalyst, getLevel());
if(mapData == null) return ItemStack.EMPTY;
if(worldPosition.getX() < mapData.centerX-64 || worldPosition.getX() > mapData.centerX+64 &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected void updateRecipe() {
//just check if it has solid blocks below and is not busy on other recipes
public boolean isInSituValid() {
NCBlockPos pos = NCBlockPos.of(getBlockPos());
for (int i = 0; i < 4; i++) {
for (int i = 0; i < 2; i++) {
if (!level.getBlockState(pos.below()).isSolidRender(level, pos)) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public static void register(FMLClientSetupEvent event) {
@SubscribeEvent
public static void onRenderWorldEvent(RenderLevelStageEvent e) {
final GameRenderer gameRenderer = Minecraft.getInstance().gameRenderer;

Player player = Minecraft.getInstance().player;
if(e.getStage().equals(RenderLevelStageEvent.Stage.AFTER_SOLID_BLOCKS)) {
for(BlockPos pos: fusionReactors) {
Expand Down
39 changes: 32 additions & 7 deletions src/main/java/igentuman/nc/recipes/type/OreVeinRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,32 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraftforge.fluids.FluidStack;
import org.jetbrains.annotations.NotNull;

import java.util.HashMap;
import java.util.Random;

import static igentuman.nc.setup.registration.NCItems.NC_PARTS;

public class OreVeinRecipe extends NcRecipe {
public OreVeinRecipe(ResourceLocation id, ItemStackIngredient[] input, ItemStackIngredient[] output, FluidStackIngredient[] inputFluids, FluidStackIngredient[] outputFluids, double timeModifier, double powerModifier, double radiation, double rarityModifier) {
super(id, input, output, timeModifier, powerModifier, radiation, rarityModifier);
}

private HashMap<ItemStackIngredient, Integer> itemsPool = new HashMap<>();
private int roll;

public HashMap<ItemStackIngredient, Integer> getItemsPool() {
if(itemsPool.isEmpty()) {
for(ItemStackIngredient item : inputItems) {
itemsPool.put(item, item.getAmount());
}
}
return itemsPool;
}

@Override
public @NotNull String getGroup() {
return codeId;
Expand All @@ -27,18 +43,27 @@ public OreVeinRecipe(ResourceLocation id, ItemStackIngredient[] input, ItemStack
return new ItemStack(NC_PARTS.get("research_paper").get());
}

private int gameTimeSeed(ServerLevel level) {
Random rand = new Random(level.getGameTime());
return rand.nextInt();
}

public ItemStack getRandomOre(ServerLevel level, int x, int z, int id) {
int score = OreVeinProvider.get(level).rand(x, z, id).nextInt(100);
return getOreByScore(score, level, x, z);
int score = OreVeinProvider.get(level).rand(x, z, id, gameTimeSeed(level)).nextInt(100);
roll = 1;
ItemStack ore = getOreByScore(score, level, x, z).copy();
ore.setCount(1);
return ore;
}

public ItemStack getOreByScore(int score, ServerLevel level, int x, int z) {
int id = OreVeinProvider.get(level).rand(x, z, score).nextInt(inputItems.length);
for(int i = id; i < inputItems.length; i++) {
if(score <= inputItems[i].getRepresentations().get(0).getCount()) {
return inputItems[i].getRepresentations().get(0);
for (ItemStackIngredient item: getItemsPool().keySet()) {
if (score <= getItemsPool().get(item) && OreVeinProvider.get(level).rand(x, z, score, gameTimeSeed(level)).nextInt(10)>roll) {
return item.getRepresentations().get(0);
}
score -= inputItems[i].getRepresentations().get(0).getCount();
roll++;
roll = Math.min(roll, 8);
score -= getItemsPool().get(item)/2;
}
return getOreByScore(score, level, x, z);
}
Expand Down

0 comments on commit 6e1a1e6

Please sign in to comment.