Skip to content

Commit

Permalink
Revert "Progress on recipe system for Sculk spreading."
Browse files Browse the repository at this point in the history
This reverts commit 5b3bb3d.
  • Loading branch information
nitrodynamite18 committed Mar 21, 2023
1 parent 0b91e1a commit 9c054db
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 104 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
package com.kyanite.deeperdarker.mixin.misc;

import com.kyanite.deeperdarker.miscellaneous.DDRecipeTypes;
import com.kyanite.deeperdarker.miscellaneous.SculkSpreadingRecipe;
import com.kyanite.deeperdarker.miscellaneous.DDTags;
import com.kyanite.deeperdarker.registry.blocks.DDBlocks;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.tags.BlockTags;
import net.minecraft.tags.TagKey;
import net.minecraft.util.RandomSource;
import net.minecraft.world.SimpleContainer;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.RecipeManager;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.state.BlockState;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.Optional;

@Mixin(SculkVeinBlock.class)
public abstract class SculkSpreadMixin extends MultifaceBlock {
@Shadow
Expand All @@ -37,47 +33,61 @@ public SculkSpreadMixin(Properties pProperties) {
@Shadow
public abstract void onDischarged(LevelAccessor levelAccessor, BlockState state, BlockPos pos, RandomSource randomSource);

public BlockState getBlockState(BlockState state) {

if(state.is(Blocks.STONE)) return DDBlocks.SCULK_STONE.get().defaultBlockState();
if(state.is(BlockTags.LOGS)) return DDBlocks.ECHO_LOG.get().defaultBlockState().setValue(RotatedPillarBlock.AXIS, state.getValue(RotatedPillarBlock.AXIS));
if(state.is(DDTags.Blocks.STRIPPED_LOGS)) return DDBlocks.STRIPPED_ECHO_LOG.get().defaultBlockState().setValue(RotatedPillarBlock.AXIS, state.getValue(RotatedPillarBlock.AXIS));
if(state.is(DDTags.Blocks.WOOD)) return DDBlocks.ECHO_WOOD.get().defaultBlockState().setValue(RotatedPillarBlock.AXIS, state.getValue(RotatedPillarBlock.AXIS));
if(state.is(DDTags.Blocks.STRIPPED_WOOD)) return DDBlocks.STRIPPED_ECHO_WOOD.get().defaultBlockState().setValue(RotatedPillarBlock.AXIS, state.getValue(RotatedPillarBlock.AXIS));
if(state.is(BlockTags.LEAVES)) return DDBlocks.ECHO_LEAVES.get().defaultBlockState().setValue(LeavesBlock.DISTANCE, state.getValue(LeavesBlock.DISTANCE)).setValue(LeavesBlock.PERSISTENT, state.getValue(LeavesBlock.PERSISTENT)).setValue(LeavesBlock.WATERLOGGED, state.getValue(LeavesBlock.WATERLOGGED));
if(state == Blocks.SHROOMLIGHT.defaultBlockState()) return DDBlocks.SCULK_GLEAM.get().defaultBlockState();
if(state == Blocks.WEEPING_VINES.defaultBlockState()) return DDBlocks.SCULK_VINES.get().defaultBlockState();
if(state == Blocks.WEEPING_VINES_PLANT.defaultBlockState()) return DDBlocks.SCULK_VINES_PLANT.get().defaultBlockState();
if(state == Blocks.TWISTING_VINES.defaultBlockState()) return DDBlocks.SCULK_TENDRILS.get().defaultBlockState();
if(state == Blocks.TWISTING_VINES_PLANT.defaultBlockState()) return DDBlocks.SCULK_TENDRILS_PLANT.get().defaultBlockState();

return Blocks.SCULK.defaultBlockState();
}

@Inject(method = "attemptPlaceSculk", cancellable = true, at = @At("HEAD"))
public void attemptSculk(SculkSpreader sculkSpreader, LevelAccessor levelAccessor, BlockPos pos, RandomSource randomSource, CallbackInfoReturnable<Boolean> cir) {
cir.cancel();
BlockState state = levelAccessor.getBlockState(pos);
TagKey<Block> replaceable = sculkSpreader.replaceableBlocks();

for (Direction direction : Direction.allShuffled(randomSource)) {
if (hasFace(state, direction)) {
for(Direction direction : Direction.allShuffled(randomSource)) {
if(hasFace(state, direction)) {
BlockPos relativePos = pos.relative(direction);
BlockState relativeState = levelAccessor.getBlockState(relativePos);
if (relativeState.is(replaceable)) {
RecipeManager recipeManager = levelAccessor.getServer().getRecipeManager();
Optional<SculkSpreadingRecipe> optionalRecipe = recipeManager.getRecipeFor(DDRecipeTypes.SCULK_SPREADING, new SimpleContainer(1), (Level) levelAccessor.getLevelData());
if (optionalRecipe.isPresent()) {
SculkSpreadingRecipe recipe = optionalRecipe.get();
ItemStack output = recipe.getResultItem();
if (!output.isEmpty()) {
BlockState outputState = Block.byItem(output.getItem()).defaultBlockState();
levelAccessor.setBlock(relativePos, outputState, 3);
Block.pushEntitiesUp(relativeState, outputState, levelAccessor, relativePos);
levelAccessor.playSound(null, relativePos, SoundEvents.SCULK_BLOCK_SPREAD, SoundSource.BLOCKS, 1.0F, 1.0F);
this.veinSpreader.spreadAll(outputState, levelAccessor, relativePos, sculkSpreader.isWorldGeneration());
Direction direction1 = direction.getOpposite();
if(relativeState.is(replaceable)) {
BlockState blockState = getBlockState(relativeState);
levelAccessor.setBlock(relativePos, blockState, 3);
Block.pushEntitiesUp(relativeState, blockState, levelAccessor, relativePos);
levelAccessor.playSound(null, relativePos, SoundEvents.SCULK_BLOCK_SPREAD, SoundSource.BLOCKS, 1.0F, 1.0F);
this.veinSpreader.spreadAll(blockState, levelAccessor, relativePos, sculkSpreader.isWorldGeneration());
Direction direction1 = direction.getOpposite();

for (Direction direction2 : DIRECTIONS) {
if (direction2 != direction1) {
BlockPos blockPos = relativePos.relative(direction2);
BlockState checkState = levelAccessor.getBlockState(blockPos);
if (checkState.is(this)) {
this.onDischarged(levelAccessor, checkState, blockPos, randomSource);
}
}
for(Direction direction2 : DIRECTIONS) {
if(direction2 != direction1) {
BlockPos blockPos = relativePos.relative(direction2);
BlockState checkState = levelAccessor.getBlockState(blockPos);
if(checkState.is(this)) {
this.onDischarged(levelAccessor, checkState, blockPos, randomSource);
}

cir.setReturnValue(true);
}
}
}

cir.setReturnValue(false);
cir.setReturnValue(true);
}
}
}

cir.setReturnValue(false);
}

@Override
public @NotNull MultifaceSpreader getSpreader() {
return veinSpreader;
}
}

0 comments on commit 9c054db

Please sign in to comment.