Silk moth AI upgrade, silk harvesting, hives

This commit is contained in:
paulevsGitch 2021-03-18 16:53:25 +03:00
parent 2f2b6dc654
commit 778977a869
15 changed files with 237 additions and 14 deletions

View file

@ -5,11 +5,13 @@ import java.util.List;
import java.util.Random;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.Material;
import net.minecraft.block.ShapeContext;
import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack;
@ -24,8 +26,11 @@ import net.minecraft.state.property.DirectionProperty;
import net.minecraft.state.property.IntProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.tag.BlockTags;
import net.minecraft.util.ActionResult;
import net.minecraft.util.BlockMirror;
import net.minecraft.util.BlockRotation;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Direction;
@ -39,7 +44,9 @@ import ru.betterend.client.render.ERenderLayer;
import ru.betterend.entity.SilkMothEntity;
import ru.betterend.interfaces.IRenderTypeable;
import ru.betterend.registry.EndEntities;
import ru.betterend.registry.EndItems;
import ru.betterend.util.BlocksHelper;
import ru.betterend.util.MHelper;
public class SilkMothNestBlock extends BlockBase implements IRenderTypeable {
public static final BooleanProperty ACTIVE = BlockProperties.ACTIVE;
@ -128,7 +135,7 @@ public class SilkMothNestBlock extends BlockBase implements IRenderTypeable {
return;
}
int count = world.getEntitiesByType(EndEntities.SILK_MOTH, new Box(pos).expand(16), (entity) -> { return true; }).size();
if (count > 8) {
if (count > 6) {
return;
}
SilkMothEntity moth = new SilkMothEntity(EndEntities.SILK_MOTH, world);
@ -138,4 +145,29 @@ public class SilkMothNestBlock extends BlockBase implements IRenderTypeable {
world.spawnEntity(moth);
world.playSound(null, pos, SoundEvents.BLOCK_BEEHIVE_EXIT, SoundCategory.BLOCKS, 1, 1);
}
@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (hand == Hand.MAIN_HAND) {
ItemStack stack = player.getMainHandStack();
if (stack.getItem().isIn(FabricToolTags.SHEARS) && state.get(ACTIVE) && state.get(FULLNESS) == 3) {
BlocksHelper.setWithUpdate(world, pos, state.with(FULLNESS, 0));
Direction dir = state.get(FACING);
double px = pos.getX() + dir.getOffsetX() + 0.5;
double py = pos.getY() + dir.getOffsetY() + 0.5;
double pz = pos.getZ() + dir.getOffsetZ() + 0.5;
ItemStack drop = new ItemStack(EndItems.SILK_FIBER, MHelper.randRange(1, 4, world.getRandom()));
ItemEntity entity = new ItemEntity(world, px, py, pz, drop);
world.spawnEntity(entity);
drop = new ItemStack(EndItems.SILK_MOTH_MATRIX, MHelper.randRange(1, 3, world.getRandom()));
entity = new ItemEntity(world, px, py, pz, drop);
world.spawnEntity(entity);
if (!player.isCreative()) {
stack.setDamage(stack.getDamage() + 1);
}
return ActionResult.SUCCESS;
}
}
return ActionResult.FAIL;
}
}