use of net.minecraft.world.phys.BlockHitResult in project Cyclic by Lothrazar.
the class EventRender method onRenderWorldLast.
@SubscribeEvent
public void onRenderWorldLast(RenderLevelLastEvent event) {
Player player = Minecraft.getInstance().player;
if (player == null) {
return;
}
Level world = player.level;
double range = 6F;
float alpha = 0.125F * 2;
Map<BlockPos, Color> renderCubes = new HashMap<>();
// /////////////////// BuilderItem
ItemStack stack = BuilderItem.getIfHeld(player);
if (stack.getItem() instanceof BuilderItem) {
BlockHitResult lookingAt = (BlockHitResult) player.pick(range, 0F, false);
if (!world.isEmptyBlock(lookingAt.getBlockPos())) {
BlockPos pos = lookingAt.getBlockPos();
BuildStyle buildStyle = ((BuilderItem) stack.getItem()).style;
if (buildStyle.isOffset() && lookingAt.getDirection() != null) {
pos = pos.relative(lookingAt.getDirection());
}
alpha = 0.4F;
// now the item has a build area
List<BlockPos> coordinates = PacketSwapBlock.getSelectedBlocks(world, pos, BuilderItem.getActionType(stack), lookingAt.getDirection(), buildStyle);
for (BlockPos coordinate : coordinates) {
renderCubes.put(coordinate, ClientConfigCyclic.getColor(stack));
}
}
}
// /////////////////// RandomizerItem
stack = RandomizerItem.getIfHeld(player);
if (stack.getItem() instanceof RandomizerItem) {
BlockHitResult lookingAt = UtilRender.getLookingAt(player, (int) range);
if (player.level.getBlockState(lookingAt.getBlockPos()) == Blocks.AIR.defaultBlockState()) {
return;
}
List<BlockPos> coords = RandomizerItem.getPlaces(lookingAt.getBlockPos(), lookingAt.getDirection());
for (BlockPos e : coords) {
renderCubes.put(e, RandomizerItem.canMove(player.level.getBlockState(e), player.level, e) ? ClientConfigCyclic.getColor(stack) : Color.RED);
}
}
stack = OreProspector.getIfHeld(player);
if (stack.getItem() instanceof OreProspector) {
List<BlockPosDim> coords = OreProspector.getPosition(stack);
for (BlockPosDim loc : coords) {
if (loc != null) {
if (loc.getDimension() == null || loc.getDimension().equalsIgnoreCase(UtilWorld.dimensionToString(world))) {
UtilRender.createBox(event.getPoseStack(), loc.getPos());
}
}
}
}
// /////////////////// LocationGpsItem
stack = player.getMainHandItem();
if (stack.getItem() instanceof LocationGpsCard) {
BlockPosDim loc = LocationGpsCard.getPosition(stack);
if (loc != null) {
if (loc.getDimension() == null || loc.getDimension().equalsIgnoreCase(UtilWorld.dimensionToString(world))) {
renderCubes.put(loc.getPos(), ClientConfigCyclic.getColor(stack));
}
}
}
// /////////////////////////////////////ShapeCard
if (stack.getItem() instanceof ShapeCard) {
RelativeShape shape = RelativeShape.read(stack);
if (shape != null) {
BlockPos here = player.blockPosition();
for (BlockPos s : shape.getShape()) {
renderCubes.put(here.offset(s), ClientConfigCyclic.getColor(stack));
}
}
}
// render the pos->colour map
if (renderCubes.keySet().size() > 0) {
UtilRender.renderColourCubes(event, renderCubes, alpha);
}
}
use of net.minecraft.world.phys.BlockHitResult in project Cyclic by Lothrazar.
the class TeleporterWandItem method releaseUsing.
@Override
public void releaseUsing(ItemStack stack, Level world, LivingEntity entity, int chargeTimer) {
if (!(entity instanceof Player)) {
return;
}
float percentageCharged = getChargedPercent(stack, chargeTimer);
if (percentageCharged >= 0.98) {
// full charge with a bit of buffer room
Player player = (Player) entity;
HitResult trace = player.pick(RANGE.get(), 0, true);
if (trace.getType() == HitResult.Type.BLOCK) {
BlockHitResult blockRayTraceResult = (BlockHitResult) trace;
Direction face = blockRayTraceResult.getDirection();
BlockPos newPos = blockRayTraceResult.getBlockPos().relative(face);
BlockPos oldPos = player.blockPosition();
if (UtilEntity.enderTeleportEvent(player, world, newPos)) {
// && player.getPosition() != currentPlayerPos
UtilItemStack.damageItem(player, stack);
if (world.isClientSide) {
UtilParticle.spawnParticleBeam(world, ParticleTypes.PORTAL, oldPos, newPos, RANGE.get());
UtilSound.playSound(player, SoundRegistry.WARP_ECHO);
}
}
}
}
}
use of net.minecraft.world.phys.BlockHitResult in project Cyclic by Lothrazar.
the class MattockItem method onBlockStartBreak.
@Override
public boolean onBlockStartBreak(ItemStack stack, BlockPos pos, Player player) {
Level world = player.level;
// this.getTier()
HitResult ray = getPlayerPOVHitResult(world, player, ClipContext.Fluid.NONE);
int yoff = 0;
if (radius == 2 && player.isCrouching()) {
yoff = 1;
}
if (ray != null && ray.getType() == HitResult.Type.BLOCK) {
BlockHitResult brt = (BlockHitResult) ray;
Direction sideHit = brt.getDirection();
List<BlockPos> shape;
if (sideHit == Direction.UP || sideHit == Direction.DOWN) {
shape = UtilShape.squareHorizontalHollow(pos, radius);
if (radius == 2) {
shape.addAll(UtilShape.squareHorizontalHollow(pos, radius - 1));
}
} else if (sideHit == Direction.EAST || sideHit == Direction.WEST) {
int y = 1 + radius - yoff;
int z = radius;
shape = UtilShape.squareVerticalZ(pos, y, z);
} else {
// has to be NORTHSOUTH
int x = radius;
int y = 1 + radius - yoff;
shape = UtilShape.squareVerticalX(pos, x, y);
}
for (BlockPos posCurrent : shape) {
BlockState bsCurrent = world.getBlockState(posCurrent);
if (bsCurrent.isAir()) {
continue;
}
if (// -1 is unbreakable
bsCurrent.destroySpeed >= 0 && player.mayUseItemAt(posCurrent, sideHit, stack) && ForgeEventFactory.doPlayerHarvestCheck(player, bsCurrent, true) && this.getDestroySpeed(stack, bsCurrent) > 1 && (bsCurrent.canHarvestBlock(world, pos, player) || bsCurrent.getBlock().builtInRegistryHolder().is(this.getTier().getTag()))) // end of OR
{
stack.mineBlock(world, bsCurrent, posCurrent, player);
Block blockCurrent = bsCurrent.getBlock();
if (world.isClientSide) {
world.levelEvent(2001, posCurrent, Block.getId(bsCurrent));
// removedByPlayer
if (blockCurrent.onDestroyedByPlayer(bsCurrent, world, posCurrent, player, true, bsCurrent.getFluidState())) {
blockCurrent.destroy(world, posCurrent, bsCurrent);
}
// stack.onBlockDestroyed(world, bsCurrent, posCurrent, player);//update tool damage
} else if (player instanceof ServerPlayer) {
// Server side, so this works
ServerPlayer mp = (ServerPlayer) player;
int xpGivenOnDrop = ForgeHooks.onBlockBreakEvent(world, ((ServerPlayer) player).gameMode.getGameModeForPlayer(), (ServerPlayer) player, posCurrent);
if (xpGivenOnDrop >= 0) {
if (blockCurrent.onDestroyedByPlayer(bsCurrent, world, posCurrent, player, true, bsCurrent.getFluidState()) && world instanceof ServerLevel) {
BlockEntity tile = world.getBlockEntity(posCurrent);
blockCurrent.destroy(world, posCurrent, bsCurrent);
blockCurrent.playerDestroy(world, player, posCurrent, bsCurrent, tile, stack);
blockCurrent.popExperience((ServerLevel) world, posCurrent, xpGivenOnDrop);
}
mp.connection.send(new ClientboundBlockUpdatePacket(world, posCurrent));
}
}
}
}
}
return super.onBlockStartBreak(stack, pos, player);
}
use of net.minecraft.world.phys.BlockHitResult in project Cyclic by Lothrazar.
the class FireEntity method onHit.
@Override
protected void onHit(HitResult result) {
HitResult.Type type = result.getType();
if (type == HitResult.Type.ENTITY) {
// damage entity by zero
// drop torch
EntityHitResult entityRayTrace = (EntityHitResult) result;
Entity target = entityRayTrace.getEntity();
if (target.isAlive()) {
target.hurt(DamageSource.thrown(this, this.getOwner()), Mth.nextInt(level.random, 2, 6));
if (!target.level.isClientSide && target.isOnFire() == false && target instanceof LivingEntity) {
target.hurt(DamageSource.IN_FIRE, Mth.nextInt(level.random, 3, 5));
LivingEntity living = (LivingEntity) target;
living.addEffect(new MobEffectInstance(PotionRegistry.PotionEffects.STUN, Const.TICKS_PER_SEC * 4, 1));
living.setSecondsOnFire(Mth.nextInt(level.random, 1, 5));
}
}
} else if (type == HitResult.Type.BLOCK) {
BlockHitResult ray = (BlockHitResult) result;
if (ray.getBlockPos() == null) {
return;
}
// BlockPos pos = ray.getPos();//.offset(ray.getFace());
// Block blockHere = world.getBlockState(pos).getBlock();
// if (blockHere == Blocks.SNOW
// || blockHere == Blocks.SNOW_BLOCK
// || blockHere == Blocks.SNOW
// || blockHere == Blocks.ICE) {
// this.world.setBlockState(pos, Blocks.AIR.getDefaultState());
// }
}
this.remove(RemovalReason.DISCARDED);
}
use of net.minecraft.world.phys.BlockHitResult in project Electrona-Project by Max094Reikeb.
the class NuclearBomb method use.
@Override
public InteractionResult use(BlockState state, Level worldIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult hit) {
if (!worldIn.isClientSide) {
BlockEntity tile = worldIn.getBlockEntity(pos);
if (player.isCrouching() && player.getItemInHand(handIn).isEmpty()) {
player.setItemInHand(handIn, new ItemStack(this, 1));
worldIn.removeBlock(pos, true);
return InteractionResult.SUCCESS;
} else if (player.getItemInHand(handIn).getItem() == Items.FLINT_AND_STEEL) {
if (tile instanceof TileNuclearBomb) {
if (((TileNuclearBomb) tile).isCharged() && worldIn.getLevelData().getGameRules().getBoolean(Gamerules.DO_NUCLEAR_BOMBS_EXPLODE)) {
if (!player.isCreative()) {
player.getItemInHand(handIn).hurtAndBreak(1, player, (p_220287_1_) -> {
p_220287_1_.broadcastBreakEvent(handIn);
});
}
new NuclearExplosion(worldIn, pos.getX(), pos.getY(), pos.getZ(), ((TileNuclearBomb) tile).getNuclearCharge());
return InteractionResult.SUCCESS;
}
}
} else {
if (tile instanceof TileNuclearBomb) {
NetworkHooks.openGui((ServerPlayer) player, (MenuProvider) tile, pos);
return InteractionResult.SUCCESS;
}
}
}
return InteractionResult.SUCCESS;
}
Aggregations