Skip to content

Commit

Permalink
bug fix bacterial analyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
Thepigcat76 committed Dec 22, 2024
1 parent 5d60573 commit 5a102ee
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/portingdeadmods/nautec/NTRegistries.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ public final class NTRegistries {
public static final Registry<AugmentSlot> AUGMENT_SLOT = new RegistryBuilder<>(AUGMENT_SLOT_KEY).create();
public static final Registry<Multiblock> MULTIBLOCK = new RegistryBuilder<>(MULTIBLOCK_KEY).create();
public static final Registry<BacteriaSerializer<?>> BACTERIA_SERIALIZER = new RegistryBuilder<>(BACTERIA_SERIALIZER_KEY).create();
public static final Registry<BacteriaStatsSerializer<?>> BACTERIA_STATS_SERIALIZER = new RegistryBuilder<>(BACTERIA_STATS_SERIALIZER_KEY).create();
public static final Registry<BacteriaStatsSerializer<?>> BACTERIA_STATS_SERIALIZER = new RegistryBuilder<>(BACTERIA_STATS_SERIALIZER_KEY).sync(true).create();
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,8 @@ public BacteriaStats getStats() {
public BacteriaInstance copy() {
return new BacteriaInstance(this.bacteria, amount, this.stats.copy());
}

public boolean isEmpty() {
return bacteria == NTBacterias.EMPTY;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,43 @@ public int getSlots() {
};
}

private static int getStackLimit(IItemHandler itemHandler, int slot, ItemStack stack) {
return Math.min(itemHandler.getSlotLimit(slot), stack.getMaxStackSize());
}

public ItemStack forceInsertItem(int slot, ItemStack stack, boolean simulate) {
if (stack.isEmpty())
return ItemStack.EMPTY;

ItemStack existing = getItemHandler().getStackInSlot(slot);

int limit = getStackLimit(getItemHandler(), slot, stack);

if (!existing.isEmpty()) {
if (!ItemStack.isSameItemSameComponents(stack, existing))
return stack;

limit -= existing.getCount();
}

if (limit <= 0)
return stack;

boolean reachedLimit = stack.getCount() > limit;

if (!simulate) {
if (existing.isEmpty()) {
getItemStackHandler().setStackInSlot(slot, reachedLimit ? stack.copyWithCount(limit) : stack);
} else {
existing.grow(reachedLimit ? limit : stack.getCount());
}
onItemsChanged(slot);
}

return reachedLimit ? stack.copyWithCount(stack.getCount() - limit) : ItemStack.EMPTY;
}


protected final void addFluidTank(int capacityInMb) {
addFluidTank(capacityInMb, ignored -> true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.portingdeadmods.nautec.api.blockentities.LaserBlockEntity;
import com.portingdeadmods.nautec.capabilities.IOActions;
import com.portingdeadmods.nautec.capabilities.NTCapabilities;
import com.portingdeadmods.nautec.capabilities.bacteria.IBacteriaStorage;
import com.portingdeadmods.nautec.content.items.PetriDishItem;
import com.portingdeadmods.nautec.content.menus.BacterialAnalyzerMenu;
import com.portingdeadmods.nautec.data.NTDataComponents;
Expand Down Expand Up @@ -33,7 +34,7 @@ public class BacterialAnalyzerBlockEntity extends LaserBlockEntity implements Me

public BacterialAnalyzerBlockEntity(BlockPos blockPos, BlockState blockState) {
super(NTBlockEntityTypes.BACTERIAL_ANALYZER.get(), blockPos, blockState);
addItemHandler(2, 1, (slot, stack) -> (slot == 0 && stack.getItem() instanceof PetriDishItem) || slot == 1);
addItemHandler(2, 1, (slot, stack) -> (slot == 0 && stack.getItem() instanceof PetriDishItem));
}

@Override
Expand All @@ -42,7 +43,9 @@ protected void onItemsChanged(int slot) {

ItemStack stack = getItemHandler().getStackInSlot(0);
ItemStack resultStack = getItemHandler().getStackInSlot(1);
this.hasRecipe = stack.getCapability(NTCapabilities.BacteriaStorage.ITEM) != null
IBacteriaStorage iBacteriaStorage = stack.getCapability(NTCapabilities.BacteriaStorage.ITEM);
this.hasRecipe = iBacteriaStorage != null
&& !iBacteriaStorage.getBacteria(0).isEmpty()
&& Boolean.FALSE.equals(stack.get(NTDataComponents.ANALYZED))
&& resultStack.isEmpty();
}
Expand All @@ -59,7 +62,8 @@ public void commonTick() {
ItemStack result = extracted.copy();
result.set(NTDataComponents.ANALYZED, true);

getItemHandler().insertItem(1, result, false);
forceInsertItem(1, result, false);

} else {
progress++;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package com.portingdeadmods.nautec.content.blockentities;

import com.portingdeadmods.nautec.NTConfig;
import com.portingdeadmods.nautec.api.bacteria.Bacteria;
import com.portingdeadmods.nautec.api.blockentities.LaserBlockEntity;
import com.portingdeadmods.nautec.capabilities.IOActions;
import com.portingdeadmods.nautec.capabilities.NTCapabilities;
import com.portingdeadmods.nautec.content.items.PetriDishItem;
import com.portingdeadmods.nautec.content.menus.MutatorMenu;
import com.portingdeadmods.nautec.data.NTDataComponents;
import com.portingdeadmods.nautec.data.components.ComponentBacteriaStorage;
import com.portingdeadmods.nautec.registries.NTBacterias;
import com.portingdeadmods.nautec.registries.NTBlockEntityTypes;
import com.portingdeadmods.nautec.utils.BacteriaHelper;
import it.unimi.dsi.fastutil.Pair;
import it.unimi.dsi.fastutil.objects.ObjectSet;
import net.minecraft.core.BlockPos;
Expand Down Expand Up @@ -62,13 +67,13 @@ public void commonTick() {

ItemStack result = extracted.copy();

Bacteria bacteria = BacteriaHelper.getBacteria(getLevel().getServer().registryAccess(), extracted.get(NTDataComponents.BACTERIA).bacteria());
bacteria.stats().rollStats();

result.set(NTDataComponents.BACTERIA, new ComponentBacteriaStorage(
NTBacterias.EMPTY,
1
));
// Bacteria bacteria = BacteriaHelper.getBacteria(getLevel().getServer().registryAccess(), extracted.get(NTDataComponents.BACTERIA).bacteria());
// bacteria.stats().rollStats();
//
// result.set(NTDataComponents.BACTERIA, new ComponentBacteriaStorage(
// NTBacterias.EMPTY,
// 1
// ));

getItemHandler().insertItem(1, result, false);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
package com.portingdeadmods.nautec.content.blocks;

import com.portingdeadmods.nautec.content.blockentities.BacterialAnalyzerBlockEntity;
import com.portingdeadmods.nautec.registries.NTBlocks;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.DirectionProperty;
import net.minecraft.world.level.material.PushReaction;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
Expand Down Expand Up @@ -58,13 +62,19 @@ public BacterialAnalyzerTopBlock(Properties properties) {

@Override
protected InteractionResult useWithoutItem(BlockState state, Level level, BlockPos pos, Player player, BlockHitResult hitResult) {
if (level.getBlockEntity(pos.below()) instanceof BacterialAnalyzerBlockEntity be) {
player.openMenu(be, pos.below());
BlockPos below = pos.below();
if (level.getBlockEntity(below) instanceof BacterialAnalyzerBlockEntity be) {
player.openMenu(be, below);
return InteractionResult.SUCCESS;
}
return super.useWithoutItem(state, level, pos, player, hitResult);
}

@Override
public ItemStack getCloneItemStack(BlockState state, HitResult target, LevelReader level, BlockPos pos, Player player) {
return NTBlocks.BACTERIAL_ANALYZER.toStack();
}

@Override
protected VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
return switch (state.getValue(FACING)) {
Expand All @@ -85,11 +95,13 @@ protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockSt
public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean movedByPiston) {
super.onRemove(state, level, pos, newState, movedByPiston);

level.removeBlock(pos.below(), false);
if (!state.is(newState.getBlock())) {
level.removeBlock(pos.below(), false);
}
}

@Override
public @Nullable PushReaction getPistonPushReaction(BlockState state) {
return PushReaction.IGNORE;
return PushReaction.BLOCK;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ protected void buildRecipes(@NotNull RecipeOutput pRecipeOutput) {

brownPolymerRecipes(pRecipeOutput);



ShapelessRecipeBuilder.shapeless(RecipeCategory.MISC, NTItems.NAUTEC_GUIDE.get(), 1)
.requires(Items.BOOK)
.requires(NTItems.CAST_IRON_NUGGET.get(), 1)
Expand Down Expand Up @@ -120,14 +118,11 @@ private static void aquaticCatalystRecipes(@NotNull RecipeOutput pRecipeOutput)
private static void aquarineSteelRecipes(@NotNull RecipeOutput pRecipeOutput) {
ItemTransformationRecipeBuilder.newRecipe(new ItemStack(NTItems.AQUARINE_STEEL_INGOT.get(), 1))
.ingredient(new ItemStack(NTItems.AQUARINE_STEEL_COMPOUND.get()))
.purity(3)
.purity(0)
.duration(100)
.save(pRecipeOutput, Nautec.rl("aquarine_steel_ingot"));

ShapelessRecipeBuilder.shapeless(RecipeCategory.MISC, NTBlocks.AQUARINE_STEEL_BLOCK.asItem(), 1)
.requires(NTItems.AQUARINE_STEEL_INGOT, 9)
.unlockedBy("has_item", has(NTItems.AQUARINE_STEEL_INGOT))
.save(pRecipeOutput, Nautec.rl( "cast_iron_ingot_from_blasting"));
nineBlockStorageRecipes(pRecipeOutput, RecipeCategory.MISC, NTItems.AQUARINE_STEEL_INGOT.get(), RecipeCategory.BUILDING_BLOCKS, NTBlocks.AQUARINE_STEEL_BLOCK.get());
}

private static void augmentationStationRecipes(@NotNull RecipeOutput pRecipeOutput) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

@EventBusSubscriber(modid = Nautec.MODID, value = Dist.CLIENT)
public final class AugmentClientEvents {

// TODO: CACHING
@SubscribeEvent
public static void renderPlayerPart(RenderPlayerEvent.Pre event) {
AugmentSlotsRenderer.render(event);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/resources/assets/nautec/textures/item/dolphin_fin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5a102ee

Please sign in to comment.