use of com.simibubi.create.content.curiosities.tools.SandPaperItem in project Create by Creators-of-Create.
the class DeployerHandler method activateInner.
private static void activateInner(DeployerFakePlayer player, Vec3 vec, BlockPos clickedPos, Vec3 extensionVector, Mode mode) {
Vec3 rayOrigin = vec.add(extensionVector.scale(3 / 2f + 1 / 64f));
Vec3 rayTarget = vec.add(extensionVector.scale(5 / 2f - 1 / 64f));
player.setPos(rayOrigin.x, rayOrigin.y, rayOrigin.z);
BlockPos pos = new BlockPos(vec);
ItemStack stack = player.getMainHandItem();
Item item = stack.getItem();
// Check for entities
final ServerLevel world = player.getLevel();
List<Entity> entities = world.getEntitiesOfClass(Entity.class, new AABB(clickedPos)).stream().filter(e -> !(e instanceof AbstractContraptionEntity)).collect(Collectors.toList());
InteractionHand hand = InteractionHand.MAIN_HAND;
if (!entities.isEmpty()) {
Entity entity = entities.get(world.random.nextInt(entities.size()));
List<ItemEntity> capturedDrops = new ArrayList<>();
boolean success = false;
entity.captureDrops(capturedDrops);
// Use on entity
if (mode == Mode.USE) {
InteractionResult cancelResult = ForgeHooks.onInteractEntity(player, entity, hand);
if (cancelResult == InteractionResult.FAIL) {
entity.captureDrops(null);
return;
}
if (cancelResult == null) {
if (entity.interact(player, hand).consumesAction()) {
if (entity instanceof AbstractVillager) {
AbstractVillager villager = ((AbstractVillager) entity);
if (villager.getTradingPlayer() instanceof DeployerFakePlayer)
villager.setTradingPlayer(null);
}
success = true;
} else if (entity instanceof LivingEntity && stack.interactLivingEntity(player, (LivingEntity) entity, hand).consumesAction())
success = true;
}
if (!success && stack.isEdible() && entity instanceof Player) {
Player playerEntity = (Player) entity;
if (playerEntity.canEat(item.getFoodProperties().canAlwaysEat())) {
playerEntity.eat(world, stack);
player.spawnedItemEffects = stack.copy();
success = true;
}
}
}
// Punch entity
if (mode == Mode.PUNCH) {
player.resetAttackStrengthTicker();
player.attack(entity);
success = true;
}
entity.captureDrops(null);
capturedDrops.forEach(e -> player.getInventory().placeItemBackInInventory(e.getItem()));
if (success)
return;
}
// Shoot ray
ClipContext rayTraceContext = new ClipContext(rayOrigin, rayTarget, ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, player);
BlockHitResult result = world.clip(rayTraceContext);
if (result.getBlockPos() != clickedPos)
result = new BlockHitResult(result.getLocation(), result.getDirection(), clickedPos, result.isInside());
BlockState clickedState = world.getBlockState(clickedPos);
Direction face = result.getDirection();
if (face == null)
face = Direction.getNearest(extensionVector.x, extensionVector.y, extensionVector.z).getOpposite();
// Left click
if (mode == Mode.PUNCH) {
if (!world.mayInteract(player, clickedPos))
return;
if (clickedState.getShape(world, clickedPos).isEmpty()) {
player.blockBreakingProgress = null;
return;
}
LeftClickBlock event = ForgeHooks.onLeftClickBlock(player, clickedPos, face);
if (event.isCanceled())
return;
if (// FIXME: is there an equivalent in world,
BlockHelper.extinguishFire(world, player, clickedPos, face))
// as there was in 1.15?
return;
if (event.getUseBlock() != DENY)
clickedState.attack(world, clickedPos, player);
if (stack.isEmpty())
return;
float progress = clickedState.getDestroyProgress(player, world, clickedPos) * 16;
float before = 0;
Pair<BlockPos, Float> blockBreakingProgress = player.blockBreakingProgress;
if (blockBreakingProgress != null)
before = blockBreakingProgress.getValue();
progress += before;
world.playSound(null, clickedPos, clickedState.getSoundType().getHitSound(), SoundSource.NEUTRAL, .25f, 1);
if (progress >= 1) {
tryHarvestBlock(player, player.gameMode, clickedPos);
world.destroyBlockProgress(player.getId(), clickedPos, -1);
player.blockBreakingProgress = null;
return;
}
if (progress <= 0) {
player.blockBreakingProgress = null;
return;
}
if ((int) (before * 10) != (int) (progress * 10))
world.destroyBlockProgress(player.getId(), clickedPos, (int) (progress * 10));
player.blockBreakingProgress = Pair.of(clickedPos, progress);
return;
}
// Right click
UseOnContext itemusecontext = new UseOnContext(player, hand, result);
Event.Result useBlock = DEFAULT;
Event.Result useItem = DEFAULT;
if (!clickedState.getShape(world, clickedPos).isEmpty()) {
RightClickBlock event = ForgeHooks.onRightClickBlock(player, hand, clickedPos, result);
useBlock = event.getUseBlock();
useItem = event.getUseItem();
}
// Item has custom active use
if (useItem != DENY) {
InteractionResult actionresult = stack.onItemUseFirst(itemusecontext);
if (actionresult != InteractionResult.PASS)
return;
}
boolean holdingSomething = !player.getMainHandItem().isEmpty();
boolean flag1 = !(player.isShiftKeyDown() && holdingSomething) || (stack.doesSneakBypassUse(world, clickedPos, player));
// Use on block
if (useBlock != DENY && flag1 && safeOnUse(clickedState, world, clickedPos, player, hand, result).consumesAction())
return;
if (stack.isEmpty())
return;
if (useItem == DENY)
return;
if (item instanceof BlockItem && !(item instanceof CartAssemblerBlockItem) && !clickedState.canBeReplaced(new BlockPlaceContext(itemusecontext)))
return;
// Reposition fire placement for convenience
if (item == Items.FLINT_AND_STEEL) {
Direction newFace = result.getDirection();
BlockPos newPos = result.getBlockPos();
if (!BaseFireBlock.canBePlacedAt(world, clickedPos, newFace))
newFace = Direction.UP;
if (clickedState.getMaterial() == Material.AIR)
newPos = newPos.relative(face.getOpposite());
result = new BlockHitResult(result.getLocation(), newFace, newPos, result.isInside());
itemusecontext = new UseOnContext(player, hand, result);
}
// 'Inert' item use behaviour & block placement
InteractionResult onItemUse = stack.useOn(itemusecontext);
if (onItemUse.consumesAction())
return;
if (item == Items.ENDER_PEARL)
return;
// buckets create their own ray, We use a fake wall to contain the active area
Level itemUseWorld = world;
if (item instanceof BucketItem || item instanceof SandPaperItem)
itemUseWorld = new ItemUseWorld(world, face, pos);
InteractionResultHolder<ItemStack> onItemRightClick = item.use(itemUseWorld, player, hand);
ItemStack resultStack = onItemRightClick.getObject();
if (resultStack != stack || resultStack.getCount() != stack.getCount() || resultStack.getUseDuration() > 0 || resultStack.getDamageValue() != stack.getDamageValue()) {
player.setItemInHand(hand, onItemRightClick.getObject());
}
CompoundTag tag = stack.getTag();
if (tag != null && stack.getItem() instanceof SandPaperItem && tag.contains("Polishing")) {
player.spawnedItemEffects = ItemStack.of(tag.getCompound("Polishing"));
AllSoundEvents.SANDING_SHORT.playOnServer(world, pos, .25f, 1f);
}
if (!player.getUseItem().isEmpty())
player.setItemInHand(hand, stack.finishUsingItem(world, player));
player.stopUsingItem();
}
use of com.simibubi.create.content.curiosities.tools.SandPaperItem in project Create by Creators-of-Create.
the class DeployerTileEntity method getRecipe.
@Nullable
public Recipe<? extends Container> getRecipe(ItemStack stack) {
// safety checks
if (player == null || level == null)
return null;
// sandpaper = op
ItemStack heldItemMainhand = player.getMainHandItem();
if (heldItemMainhand.getItem() instanceof SandPaperItem) {
sandpaperInv.setItem(0, stack);
return AllRecipeTypes.SANDPAPER_POLISHING.find(sandpaperInv, level).orElse(null);
}
// inventory
recipeInv.setItem(0, stack);
recipeInv.setItem(1, heldItemMainhand);
// event nonsense
DeployerRecipeSearchEvent event = new DeployerRecipeSearchEvent(this, recipeInv);
// creates deployer recipes
event.addRecipe(() -> SequencedAssemblyRecipe.getRecipe(level, event.getInventory(), AllRecipeTypes.DEPLOYING.getType(), DeployerApplicationRecipe.class), 100);
event.addRecipe(() -> AllRecipeTypes.DEPLOYING.find(event.getInventory(), level), 50);
// post the event, get result
MinecraftForge.EVENT_BUS.post(event);
return event.getRecipe();
}
Aggregations