use of net.minecraft.world.phys.BlockHitResult in project BuildingGadgets by Direwolf20-MC.
the class GadgetDestruction method use.
@Override
public InteractionResultHolder<ItemStack> use(Level world, Player player, InteractionHand hand) {
ItemStack stack = player.getItemInHand(hand);
player.startUsingItem(hand);
if (!world.isClientSide) {
if (!player.isShiftKeyDown()) {
BlockPos anchorPos = getAnchor(stack);
Direction anchorSide = getAnchorSide(stack);
if (anchorPos != null && anchorSide != null) {
clearArea(world, anchorPos, anchorSide, (ServerPlayer) player, stack);
onAnchorRemoved(stack, player);
return new InteractionResultHolder<>(InteractionResult.SUCCESS, stack);
}
BlockHitResult lookingAt = VectorHelper.getLookingAt(player, stack);
if (!world.isEmptyBlock(lookingAt.getBlockPos())) {
clearArea(world, lookingAt.getBlockPos(), lookingAt.getDirection(), (ServerPlayer) player, stack);
onAnchorRemoved(stack, player);
return new InteractionResultHolder<>(InteractionResult.SUCCESS, stack);
}
return new InteractionResultHolder<>(InteractionResult.FAIL, stack);
}
} else if (player.isShiftKeyDown()) {
GuiMod.DESTRUCTION.openScreen(player);
}
return new InteractionResultHolder<>(InteractionResult.SUCCESS, stack);
}
use of net.minecraft.world.phys.BlockHitResult in project Silent-Gear by SilentChaos512.
the class DebugOverlay method getDebugText.
@Nonnull
@Override
public List<String> getDebugText() {
List<String> list = new ArrayList<>();
Minecraft mc = Minecraft.getInstance();
LocalPlayer player = mc.player;
if (player == null)
return list;
// addAttributeInfo(list, player, SharedMonsterAttributes.LUCK);
ItemStack heldItem = player.getItemInHand(InteractionHand.MAIN_HAND);
if (heldItem.isEmpty())
return list;
Item item = heldItem.getItem();
// Crossbow debugging
if (item instanceof GearCrossbowItem) {
float pull = ModelPropertiesHelper.getValue(heldItem, new ResourceLocation("pull"), mc.level, player);
float pulling = ModelPropertiesHelper.getValue(heldItem, new ResourceLocation("pulling"), mc.level, player);
float charged = ModelPropertiesHelper.getValue(heldItem, new ResourceLocation("charged"), mc.level, player);
float firework = ModelPropertiesHelper.getValue(heldItem, new ResourceLocation("firework"), mc.level, player);
list.add(String.format("pull=%.1f", pull));
list.add(String.format("pulling=%.1f", pulling));
list.add(String.format("charged=%.1f", charged));
list.add(String.format("firework=%.1f", firework));
list.add(String.format("chargeTime=%d", GearCrossbowItem.getChargeTime(heldItem)));
return list;
}
// Harvest level checks
HitResult rt = mc.hitResult;
if (rt != null && rt.getType() == HitResult.Type.BLOCK) {
BlockHitResult brt = (BlockHitResult) rt;
Entity renderViewEntity = mc.getCameraEntity();
if (renderViewEntity != null) {
BlockPos pos = brt.getBlockPos();
BlockState state = renderViewEntity.level.getBlockState(pos);
/*if (item instanceof ICoreTool) {
ToolType toolClass = state.getBlock().getHarvestTool(state);
final int blockLevel = state.getBlock().getHarvestLevel(state);
final int toolLevel = item.getHarvestLevel(heldItem, toolClass, player, state);
final boolean canHarvest = toolLevel >= blockLevel;
ChatFormatting format = canHarvest ? ChatFormatting.GREEN : ChatFormatting.RED;
String name = toolClass == null ? "null" : toolClass.getName();
list.add(format + String.format("%s=%d (%d)", name, blockLevel, toolLevel));
final float destroySpeed = heldItem.getDestroySpeed(state);
if (canHarvest) {
int level = TraitHelper.getTraitLevel(heldItem, Const.Traits.LUSTROUS);
int light = GearEvents.getLightForLustrousTrait(player.level, player.blockPosition());
final float newSpeed = destroySpeed + GearEvents.getLustrousSpeedBonus(level, light);
list.add(String.format("speed = %.1f", newSpeed));
} else {
list.add(String.format("speed = %.1f", destroySpeed));
}
}*/
}
} else if (rt != null && rt.getType() == HitResult.Type.ENTITY) {
EntityHitResult ert = (EntityHitResult) rt;
Entity entity = ert.getEntity();
if (entity instanceof LivingEntity) {
list.add(String.format("%s", entity.getScoreboardName()));
list.add(String.format("health = %.3f", ((LivingEntity) entity).getHealth()));
}
}
return list;
}
use of net.minecraft.world.phys.BlockHitResult in project BuildingGadgets by Direwolf20-MC.
the class GadgetUtils method linkToInventory.
public static void linkToInventory(ItemStack stack, Player player) {
Level world = player.level;
BlockHitResult lookingAt = VectorHelper.getLookingAt(player, AbstractGadget.shouldRayTraceFluid(stack) ? ClipContext.Fluid.ANY : ClipContext.Fluid.NONE);
if (world.getBlockState(VectorHelper.getLookingAt(player, stack).getBlockPos()) == Blocks.AIR.defaultBlockState())
return;
InventoryLinker.Result result = InventoryLinker.linkInventory(player.level, stack, lookingAt);
player.displayClientMessage(result.getI18n().componentTranslation(), true);
}
use of net.minecraft.world.phys.BlockHitResult in project EvilCraft by CyclopsMC.
the class EntityBiomeExtract method onHit.
@Override
protected void onHit(final HitResult movingobjectposition) {
if (!level.isClientSide() && movingobjectposition.getType() == HitResult.Type.BLOCK) {
ItemStack itemStack = getItem();
final Biome biome = ItemBiomeExtract.getBiome(itemStack);
if (biome != null) {
// Update biome in organic spread
Set<ChunkPos> updatedChunks = Sets.newHashSet();
OrganicSpread spread = new OrganicSpread(level, 2, 5, new OrganicSpread.IOrganicSpreadable() {
@Override
public boolean isDone(Level world, BlockPos location) {
return world.getBiome(location) == biome;
}
@Override
public void spreadTo(Level world, BlockPos location) {
setBiome((ServerLevel) world, location, biome);
updatedChunks.add(new ChunkPos(location));
// int color = biome.getFoliageColor(); // Only accessible client-side, so we copy and modify its implementation...
int color = biome.specialEffects.getFoliageColorOverride().orElseGet(() -> {
double d0 = (double) Mth.clamp(biome.climateSettings.temperature, 0.0F, 1.0F);
double d1 = (double) Mth.clamp(biome.climateSettings.downfall, 0.0F, 1.0F);
// return FoliageColors.get(d0, d1);
return Helpers.RGBToInt(20, 200, 20);
});
showChangedBiome((ServerLevel) world, new BlockPos(location.getX(), ((BlockHitResult) movingobjectposition).getBlockPos().getY(), location.getZ()), color);
}
});
BlockPos pos = new BlockPos(movingobjectposition.getLocation());
for (int i = 0; i < 50; i++) {
spread.spreadTick(pos);
}
// Send chunk biome data to all players, and reset their grass colors
if (!level.isClientSide()) {
for (ChunkPos chunkPos : updatedChunks) {
updateChunkAfterBiomeChange(level, chunkPos);
}
}
}
// Play sound and show particles of splash potion of harming
this.level.globalLevelEvent(2002, blockPosition(), 16428);
remove(RemovalReason.DISCARDED);
}
}
use of net.minecraft.world.phys.BlockHitResult in project EvilCraft by CyclopsMC.
the class ItemBloodContainer method use.
@Override
public InteractionResultHolder<ItemStack> use(Level world, Player player, InteractionHand hand) {
ItemStack itemStack = player.getItemInHand(hand);
IFluidHandlerItemCapacity fluidHandler = FluidHelpers.getFluidHandlerItemCapacity(itemStack).orElse(null);
FluidStack fluidStack = FluidUtil.getFluidContained(itemStack).orElse(FluidStack.EMPTY);
FluidStack drained = fluidHandler.drain(FluidHelpers.BUCKET_VOLUME, IFluidHandler.FluidAction.SIMULATE);
boolean hasBucket = !drained.isEmpty() && (drained.getAmount() == FluidHelpers.BUCKET_VOLUME);
boolean hasSpace = fluidStack.isEmpty() || (fluidStack.getAmount() + FluidHelpers.BUCKET_VOLUME <= fluidHandler.getCapacity());
BlockHitResult movingobjectpositionDrain = (BlockHitResult) this.getPlayerPOVHitResult(world, player, ClipContext.Fluid.NONE);
BlockHitResult movingobjectpositionFill = (BlockHitResult) this.getPlayerPOVHitResult(world, player, ClipContext.Fluid.SOURCE_ONLY);
if (movingobjectpositionDrain != null && movingobjectpositionFill != null) {
if (isPickupFluids() && movingobjectpositionFill.getType() == HitResult.Type.BLOCK) {
// Fill the container and remove fluid blockState
BlockPos blockPos = movingobjectpositionFill.getBlockPos();
BlockState blockState = world.getBlockState(blockPos);
if (blockState.getBlock() instanceof LiquidBlock && ((LiquidBlock) blockState.getBlock()).getFluid() == getFluid() && blockState.getValue(LiquidBlock.LEVEL) == 0) {
if (hasSpace) {
world.setBlock(blockPos, Blocks.AIR.defaultBlockState(), 3);
fluidHandler.fill(new FluidStack(getFluid(), FluidHelpers.BUCKET_VOLUME), IFluidHandler.FluidAction.EXECUTE);
}
return MinecraftHelpers.successAction(itemStack);
}
}
// Drain container and place fluid blockState
if (hasBucket && isPlaceFluids() && movingobjectpositionDrain.getType() == HitResult.Type.BLOCK) {
BlockPos blockPos = movingobjectpositionFill.getBlockPos();
Direction direction = movingobjectpositionDrain.getDirection();
blockPos = blockPos.offset(direction.getNormal());
if (this.tryPlaceContainedLiquid(world, blockPos, true)) {
fluidHandler.drain(FluidHelpers.BUCKET_VOLUME, IFluidHandler.FluidAction.EXECUTE);
return MinecraftHelpers.successAction(itemStack);
}
}
}
return MinecraftHelpers.successAction(itemStack);
}
Aggregations