Skip to content

Commit

Permalink
Document miscellaneous functions in General.kt that could be useful t…
Browse files Browse the repository at this point in the history
…o someone else someday

Rename RayMarching to Raycasting
  • Loading branch information
ATPStorages committed Aug 19, 2024
1 parent 2e724ff commit 44ae840
Show file tree
Hide file tree
Showing 5 changed files with 566 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import breadmod.item.tool_gun.IToolGunMode.Companion.playModeSound
import breadmod.item.tool_gun.IToolGunMode.Companion.playToolGunSound
import breadmod.network.PacketHandler.NETWORK
import breadmod.network.client.BeamPacket
import breadmod.util.RayMarchResult.Companion.rayMarchBlock
import breadmod.util.RaycastResult.Companion.blockRaycast
import breadmod.util.render.minecraft
import com.mojang.blaze3d.vertex.PoseStack
import net.minecraft.client.renderer.MultiBufferSource
Expand All @@ -37,7 +37,12 @@ internal class ToolGunExplodeMode: IToolGunMode {
if(pControl.id == "use") {
val settings = pGunStack.orCreateTag.getCompound(pControl.categoryKey)

pLevel.rayMarchBlock(pPlayer.eyePosition, Vec3.directionFromRotation(pPlayer.xRot, pPlayer.yRot), 1000.0, settings.getBoolean("hitFluid"))?.let {
pLevel.blockRaycast(
pPlayer.eyePosition,
Vec3.directionFromRotation(pPlayer.xRot, pPlayer.yRot),
1000.0,
settings.getBoolean("hitFluid")
)?.let {
NETWORK.send(
PacketDistributor.TRACKING_CHUNK.with { pLevel.getChunkAt(pPlayer.blockPosition()) },
BeamPacket(it.startPosition.toVector3f(), it.endPosition.toVector3f(), 1.0f)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import breadmod.item.tool_gun.IToolGunMode.Companion.playToolGunSound
import breadmod.network.PacketHandler.NETWORK
import breadmod.network.client.BeamPacket
import breadmod.network.tool_gun.SDPacket
import breadmod.util.RayMarchResult.Companion.rayMarchEntity
import breadmod.util.RaycastResult.Companion.entityRaycast
import net.minecraft.ChatFormatting
import net.minecraft.core.particles.ParticleTypes
import net.minecraft.server.level.ServerLevel
Expand All @@ -28,7 +28,8 @@ internal class ToolGunRemoverMode: IToolGunMode {
pControl: BreadModToolGunModeProvider.Control
) {
if(pLevel is ServerLevel) {
pLevel.rayMarchEntity(pPlayer, pPlayer.eyePosition, Vec3.directionFromRotation(pPlayer.xRot, pPlayer.yRot), 1000.0)?.let {
pLevel.entityRaycast(pPlayer, pPlayer.eyePosition, Vec3.directionFromRotation(pPlayer.xRot, pPlayer.yRot), 1000.0)
?.let {
fun rand() = (pPlayer.random.nextDouble() - 0.5)*1.2
pLevel.sendParticles(ParticleTypes.END_ROD, it.entity.x, it.entity.y, it.entity.z, 60, rand(), pPlayer.random.nextDouble(), rand(), 1.0)
playToolGunSound(pLevel, pPlayer.blockPosition())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import breadmod.datagen.tool_gun.BreadModToolGunModeProvider.Companion.TOOL_GUN_
import breadmod.item.tool_gun.IToolGunMode
import breadmod.item.tool_gun.IToolGunMode.Companion.playToolGunSound
import breadmod.menu.item.ToolGunCreatorMenu
import breadmod.util.RayMarchResult.Companion.rayMarchBlock
import breadmod.util.RaycastResult.Companion.blockRaycast
import com.google.gson.Gson
import com.google.gson.JsonElement
import com.google.gson.JsonObject
Expand Down Expand Up @@ -127,7 +127,7 @@ internal class ToolGunCreatorMode : IToolGunMode, MenuProvider {
if (pControl.id == "screen" && !pLevel.isClientSide) {
NetworkHooks.openScreen(pPlayer as ServerPlayer, this, pPlayer.blockPosition())
} else if (pLevel is ServerLevel && pControl.id == "use") {
pLevel.rayMarchBlock(
pLevel.blockRaycast(
pPlayer.eyePosition,
Vec3.directionFromRotation(pPlayer.xRot, pPlayer.yRot),
100.0, false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class SimpleFluidEnergyRecipeSerializer<T: FluidEnergyRecipe>(
val requiredItems = inputs.getAsJsonObject(ITEMS_KEY)
val outputs = p1.getAsJsonObject(OUTPUT_KEY)
return factory(
ResourceLocation(p1.get(ENTRY_ID_KEY).asString),
ResourceLocation(p1.get(ENTRY_ID).asString),
p1.get(TIME_KEY).asInt,
inputs.get(ENERGY_KEY)?.asInt,
requiredFluids?.getAsJsonArray(CERTAIN_KEY)?.extractJsonFluidList(),
Expand All @@ -59,7 +59,7 @@ class SimpleFluidEnergyRecipeSerializer<T: FluidEnergyRecipe>(
itemsRequired: List<ItemStack>?, itemsRequiredTagged: List<Pair<TagKey<T>, Int>>?,
itemsOutput: List<ItemStack>?, fluidsOutput: List<FluidStack>?
) = to.also {
it.addProperty(ENTRY_ID_KEY, id.toString())
it.addProperty(ENTRY_ID, id.toString())
it.addProperty(TIME_KEY, time)
it.add(INPUT_KEY, JsonObject().also { required ->
if(energy != null) required.addProperty(ENERGY_KEY, energy)
Expand Down
Loading

0 comments on commit 44ae840

Please sign in to comment.