2018-10-16 11:49:30 +02:00
|
|
|
package de.ellpeck.naturesaura.blocks;
|
|
|
|
|
2018-10-18 13:34:37 +02:00
|
|
|
import de.ellpeck.naturesaura.Helper;
|
2018-11-14 19:14:03 +01:00
|
|
|
import de.ellpeck.naturesaura.blocks.multi.Multiblocks;
|
2021-12-04 15:40:09 +01:00
|
|
|
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityWoodStand;
|
2021-12-15 14:26:42 +01:00
|
|
|
import de.ellpeck.naturesaura.blocks.tiles.ModTileEntities;
|
2018-11-21 20:36:55 +01:00
|
|
|
import de.ellpeck.naturesaura.blocks.tiles.render.RenderWoodStand;
|
2020-01-29 00:40:28 +01:00
|
|
|
import de.ellpeck.naturesaura.data.BlockStateGenerator;
|
2021-01-14 23:15:02 +01:00
|
|
|
import de.ellpeck.naturesaura.recipes.ModRecipes;
|
|
|
|
import de.ellpeck.naturesaura.recipes.TreeRitualRecipe;
|
2020-01-29 00:40:28 +01:00
|
|
|
import de.ellpeck.naturesaura.reg.ICustomBlockState;
|
2018-11-21 20:36:55 +01:00
|
|
|
import de.ellpeck.naturesaura.reg.ITESRProvider;
|
2021-12-15 14:26:42 +01:00
|
|
|
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
|
|
|
|
import net.minecraft.core.BlockPos;
|
2018-11-21 20:36:55 +01:00
|
|
|
import net.minecraft.util.Tuple;
|
2021-12-15 14:26:42 +01:00
|
|
|
import net.minecraft.world.InteractionHand;
|
|
|
|
import net.minecraft.world.InteractionResult;
|
|
|
|
import net.minecraft.world.entity.player.Player;
|
|
|
|
import net.minecraft.world.item.ItemStack;
|
|
|
|
import net.minecraft.world.item.crafting.Ingredient;
|
|
|
|
import net.minecraft.world.level.BlockGetter;
|
|
|
|
import net.minecraft.world.level.Level;
|
|
|
|
import net.minecraft.world.level.LevelAccessor;
|
|
|
|
import net.minecraft.world.level.block.SoundType;
|
|
|
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
|
|
|
import net.minecraft.world.level.block.entity.BlockEntityType;
|
|
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
|
|
import net.minecraft.world.level.material.Material;
|
|
|
|
import net.minecraft.world.phys.BlockHitResult;
|
|
|
|
import net.minecraft.world.phys.shapes.CollisionContext;
|
|
|
|
import net.minecraft.world.phys.shapes.Shapes;
|
|
|
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
2018-11-14 19:14:03 +01:00
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
2021-12-15 14:26:42 +01:00
|
|
|
import net.minecraftforge.event.world.SaplingGrowTreeEvent;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
2018-11-14 19:14:03 +01:00
|
|
|
import org.apache.commons.lang3.mutable.MutableObject;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.List;
|
2020-01-28 20:36:08 +01:00
|
|
|
import java.util.function.Supplier;
|
2018-10-16 11:49:30 +02:00
|
|
|
|
2021-12-04 15:40:09 +01:00
|
|
|
public class BlockWoodStand extends BlockContainerImpl implements ITESRProvider<BlockEntityWoodStand>, ICustomBlockState {
|
2018-10-16 11:49:30 +02:00
|
|
|
|
2021-12-04 15:40:09 +01:00
|
|
|
private static final VoxelShape SHAPE = Shapes.create(3 / 16F, 0F, 3 / 16F, 13 / 16F, 13 / 16F, 13 / 16F);
|
2018-10-16 11:49:30 +02:00
|
|
|
|
|
|
|
public BlockWoodStand() {
|
2021-12-15 14:26:42 +01:00
|
|
|
super("wood_stand", BlockEntityWoodStand::new, Properties.of(Material.WOOD).strength(1.5F).sound(SoundType.WOOD));
|
2020-01-21 21:04:44 +01:00
|
|
|
MinecraftForge.EVENT_BUS.register(this);
|
2018-11-14 19:14:03 +01:00
|
|
|
}
|
|
|
|
|
2020-02-05 14:30:17 +01:00
|
|
|
@Override
|
|
|
|
protected boolean hasWaterlogging() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-01-23 16:05:52 +01:00
|
|
|
@Override
|
2021-12-15 14:26:42 +01:00
|
|
|
public VoxelShape getShape(BlockState state, BlockGetter levelIn, BlockPos pos, CollisionContext context) {
|
2020-01-23 16:05:52 +01:00
|
|
|
return SHAPE;
|
|
|
|
}
|
|
|
|
|
2018-11-14 19:14:03 +01:00
|
|
|
@SubscribeEvent
|
|
|
|
public void onTreeGrow(SaplingGrowTreeEvent event) {
|
2021-12-15 14:26:42 +01:00
|
|
|
LevelAccessor level = event.getWorld();
|
2018-11-14 19:14:03 +01:00
|
|
|
BlockPos pos = event.getPos();
|
2021-12-04 15:40:09 +01:00
|
|
|
if (!level.isClientSide() && level instanceof Level) {
|
|
|
|
if (Multiblocks.TREE_RITUAL.isComplete((Level) level, pos)) {
|
|
|
|
BlockState sapling = level.getBlockState(pos);
|
2021-12-15 14:26:42 +01:00
|
|
|
ItemStack saplingStack = sapling.getBlock().getCloneItemStack(level, pos, sapling);
|
2018-11-14 19:14:03 +01:00
|
|
|
if (!saplingStack.isEmpty()) {
|
2021-12-15 14:26:42 +01:00
|
|
|
for (TreeRitualRecipe recipe : ((Level) level).getRecipeManager().getRecipesFor(ModRecipes.TREE_RITUAL_TYPE, null, null)) {
|
2020-01-21 21:04:44 +01:00
|
|
|
if (recipe.saplingType.test(saplingStack)) {
|
2018-11-20 11:44:07 +01:00
|
|
|
List<Ingredient> required = new ArrayList<>(Arrays.asList(recipe.ingredients));
|
2021-12-04 15:40:09 +01:00
|
|
|
MutableObject<BlockEntityWoodStand> toPick = new MutableObject<>();
|
2018-11-14 19:14:03 +01:00
|
|
|
|
|
|
|
boolean fine = Multiblocks.TREE_RITUAL.forEach(pos, 'W', (tilePos, matcher) -> {
|
2021-12-04 15:40:09 +01:00
|
|
|
BlockEntity tile = level.getBlockEntity(tilePos);
|
2021-12-15 14:26:42 +01:00
|
|
|
if (tile instanceof BlockEntityWoodStand stand) {
|
2018-11-14 19:14:03 +01:00
|
|
|
ItemStack stack = stand.items.getStackInSlot(0);
|
|
|
|
if (!stack.isEmpty()) {
|
2018-11-19 21:55:00 +01:00
|
|
|
for (int i = required.size() - 1; i >= 0; i--) {
|
2018-11-20 11:44:07 +01:00
|
|
|
Ingredient req = required.get(i);
|
2020-01-21 21:04:44 +01:00
|
|
|
if (req.test(stack)) {
|
2018-11-19 21:55:00 +01:00
|
|
|
required.remove(i);
|
2018-11-14 19:14:03 +01:00
|
|
|
|
2018-11-19 21:55:00 +01:00
|
|
|
if (toPick.getValue() == null) {
|
|
|
|
toPick.setValue(stand);
|
|
|
|
}
|
|
|
|
return true;
|
2018-11-14 19:14:03 +01:00
|
|
|
}
|
|
|
|
}
|
2018-11-19 21:55:00 +01:00
|
|
|
return false;
|
2018-11-14 19:14:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (fine && required.isEmpty()) {
|
|
|
|
toPick.getValue().setRitual(pos, recipe);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-10-16 11:49:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-12-15 14:26:42 +01:00
|
|
|
public InteractionResult use(BlockState state, Level levelIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult hit) {
|
2020-01-21 21:04:44 +01:00
|
|
|
return Helper.putStackOnTile(player, handIn, pos, 0, true);
|
2018-10-16 11:49:30 +02:00
|
|
|
}
|
|
|
|
|
2018-11-21 20:36:55 +01:00
|
|
|
@Override
|
2021-12-15 14:26:42 +01:00
|
|
|
public Tuple<BlockEntityType<? extends BlockEntityWoodStand>, Supplier<BlockEntityRendererProvider<BlockEntityWoodStand>>> getTESR() {
|
2020-01-28 20:36:08 +01:00
|
|
|
return new Tuple<>(ModTileEntities.WOOD_STAND, () -> RenderWoodStand::new);
|
2018-11-21 20:36:55 +01:00
|
|
|
}
|
2020-01-29 00:40:28 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void generateCustomBlockState(BlockStateGenerator generator) {
|
|
|
|
generator.simpleBlock(this, generator.models().getExistingFile(generator.modLoc(this.getBaseName())));
|
|
|
|
}
|
2021-12-15 14:26:42 +01:00
|
|
|
|
2018-10-16 11:49:30 +02:00
|
|
|
}
|