more client things and fixing up actions

This commit is contained in:
gamma-delta 2022-05-06 11:40:33 -05:00
parent 67a2bc24a3
commit fbf5f003c8
25 changed files with 258 additions and 186 deletions

View file

@ -9,7 +9,7 @@ archivesBaseName = "${modID}-common-${minecraftVersion}"
minecraft {
version(minecraftVersion)
runs {
if (project.hasProperty('common_runs_enabled') ? project.findProperty('common_runs_enabled').toBoolean() : true) {
server(project.hasProperty('common_server_run_name') ? project.findProperty('common_server_run_name') : 'vanilla_server') {
@ -26,6 +26,8 @@ dependencies {
compileOnly group: 'org.spongepowered', name: 'mixin', version: '0.8.5'
implementation group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.1'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
compileOnly "vazkii.patchouli:Patchouli-xplat:$minecraftVersion-$patchouliVersion"
}
processResources {

View file

@ -1,10 +1,10 @@
package at.petrak.hexcasting.api.spell
import at.petrak.hexcasting.api.misc.FrozenColorizer
import at.petrak.hexcasting.api.mod.HexApiMessages
import at.petrak.hexcasting.common.network.MsgCastParticleAck
import at.petrak.hexcasting.xplat.IXplatAbstractions
import net.minecraft.server.level.ServerLevel
import net.minecraft.world.phys.Vec3
import net.minecraftforge.network.PacketDistributor
data class ParticleSpray(val pos: Vec3, val vel: Vec3, val fuzziness: Double, val spread: Double, val count: Int = 20) {
companion object {
@ -20,14 +20,6 @@ data class ParticleSpray(val pos: Vec3, val vel: Vec3, val fuzziness: Double, va
}
fun sprayParticles(world: ServerLevel, color: FrozenColorizer) {
HexApiMessages.getChannel().send(PacketDistributor.NEAR.with {
PacketDistributor.TargetPoint(
this.pos.x,
this.pos.y,
this.pos.z,
128.0 * 128.0,
world.dimension()
)
}, HexApiMessages.getParticleSprayMessage(this, color))
IXplatAbstractions.INSTANCE.sendPacketNear(this.pos, 128.0, world, MsgCastParticleAck(this, color))
}
}

View file

@ -1,12 +1,12 @@
package at.petrak.hexcasting.api.spell.casting
import at.petrak.hexcasting.api.mod.HexConfig
import at.petrak.hexcasting.api.player.HexPlayerDataHelper
import at.petrak.hexcasting.api.spell.Operator
import at.petrak.hexcasting.api.spell.mishaps.MishapEntityTooFarAway
import at.petrak.hexcasting.api.spell.mishaps.MishapEvalTooDeep
import at.petrak.hexcasting.api.spell.mishaps.MishapLocationTooFarAway
import at.petrak.hexcasting.api.utils.HexUtils
import at.petrak.hexcasting.xplat.IXplatAbstractions
import net.minecraft.resources.ResourceLocation
import net.minecraft.server.level.ServerLevel
import net.minecraft.server.level.ServerPlayer
@ -52,7 +52,7 @@ data class CastingContext(
*/
fun incDepth() {
this.depth++
val maxAllowedDepth = HexConfig.Server.maxRecurseDepth.get()
val maxAllowedDepth = HexConfig.server().maxRecurseDepth()
if (this.depth > maxAllowedDepth) {
throw MishapEvalTooDeep()
}
@ -77,7 +77,7 @@ data class CastingContext(
}
fun isVecInRange(vec: Vec3): Boolean {
val sentinel = HexPlayerDataHelper.getSentinel(caster)
val sentinel = IXplatAbstractions.INSTANCE.getSentinel(caster)
if (sentinel.hasSentinel
&& sentinel.extendsRange
&& world.dimension() == sentinel.dimension

View file

@ -1,6 +1,6 @@
package at.petrak.hexcasting.api.utils
import at.petrak.hexcasting.forge.cap.HexCapabilities
import at.petrak.hexcasting.xplat.IXplatAbstractions
import net.minecraft.util.Mth
import net.minecraft.world.item.ItemStack
import kotlin.math.roundToInt
@ -8,8 +8,8 @@ import kotlin.math.roundToInt
object ManaHelper {
@JvmStatic
fun isManaItem(stack: ItemStack): Boolean {
return stack.getCapability(at.petrak.hexcasting.forge.cap.HexCapabilities.MANA).map { it.canProvide() }
.orElse(false) && extractMana(stack, simulate = true) > 0
val manaHolder = IXplatAbstractions.INSTANCE.findManaHolder(stack) ?: return false
return manaHolder.withdrawMana(-1, true) > 0
}
/**
@ -28,30 +28,25 @@ object ManaHelper {
drainForBatteries: Boolean = false,
simulate: Boolean = false
): Int {
val manaCapability = stack.getCapability(at.petrak.hexcasting.forge.cap.HexCapabilities.MANA).resolve()
val manaHolder = IXplatAbstractions.INSTANCE.findManaHolder(stack) ?: return 0
if (!manaCapability.isPresent)
if (drainForBatteries && !manaHolder.canConstructBattery())
return 0
val manaReservoir = manaCapability.get()
if (drainForBatteries && !manaReservoir.canConstructBattery())
return 0
return manaReservoir.withdrawMana(cost, simulate)
return manaHolder.withdrawMana(cost, simulate)
}
/**
* Sorted from least important to most important
*/
fun compare(astack: ItemStack, bstack: ItemStack): Int {
val aMana = astack.getCapability(at.petrak.hexcasting.forge.cap.HexCapabilities.MANA).resolve()
val bMana = bstack.getCapability(at.petrak.hexcasting.forge.cap.HexCapabilities.MANA).resolve()
val aMana = IXplatAbstractions.INSTANCE.findManaHolder(astack)
val bMana = IXplatAbstractions.INSTANCE.findManaHolder(bstack)
return if (astack.item != bstack.item) {
aMana.map { it.consumptionPriority }.orElse(0) - bMana.map { it.consumptionPriority }.orElse(0)
} else if (aMana.isPresent && bMana.isPresent) {
aMana.get().mana - bMana.get().mana
(aMana?.consumptionPriority ?: 0) - (bMana?.consumptionPriority ?: 0)
} else if (aMana != null && bMana != null) {
aMana.mana - bMana.mana
} else {
astack.count - bstack.count
}

View file

@ -29,6 +29,7 @@ import at.petrak.hexcasting.xplat.IClientXplatAbstractions;
import com.mojang.datafixers.util.Pair;
import net.minecraft.ChatFormatting;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.core.Direction;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.chat.TranslatableComponent;
@ -39,9 +40,10 @@ import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.ComparatorBlock;
import net.minecraft.world.level.block.RedStoneWireBlock;
import net.minecraft.world.level.block.RepeaterBlock;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.properties.ComparatorMode;
import net.minecraftforge.client.event.EntityRenderersEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import org.jetbrains.annotations.NotNull;
import java.util.Locale;
@ -234,16 +236,21 @@ public class RegisterClientStuff {
public static void registerParticles() {
// rip particle man
IClientXplatAbstractions.INSTANCE.registerParticleType(HexParticles.LIGHT_PARTICLE.get(),
IClientXplatAbstractions.INSTANCE.registerParticleType(HexParticles.LIGHT_PARTICLE,
ConjureParticle.Provider::new);
IClientXplatAbstractions.INSTANCE.registerParticleType(HexParticles.CONJURE_PARTICLE.get(),
IClientXplatAbstractions.INSTANCE.registerParticleType(HexParticles.CONJURE_PARTICLE,
ConjureParticle.Provider::new);
}
@SubscribeEvent
public static void registerRenderers(EntityRenderersEvent.RegisterRenderers evt) {
evt.registerBlockEntityRenderer(HexBlockEntities.SLATE_TILE.get(), BlockEntitySlateRenderer::new);
evt.registerBlockEntityRenderer(HexBlockEntities.AKASHIC_BOOKSHELF_TILE.get(),
public static void registerBlockEntityRenderers(@NotNull BlockEntityRendererRegisterererer registerer) {
registerer.registerBlockEntityRenderer(HexBlockEntities.SLATE_TILE, BlockEntitySlateRenderer::new);
registerer.registerBlockEntityRenderer(HexBlockEntities.AKASHIC_BOOKSHELF_TILE,
BlockEntityAkashicBookshelfRenderer::new);
}
@FunctionalInterface
public interface BlockEntityRendererRegisterererer {
<T extends BlockEntity> void registerBlockEntityRenderer(BlockEntityType<T> type,
BlockEntityRendererProvider<? super T> berp);
}
}

View file

@ -1,23 +1,23 @@
package at.petrak.hexcasting.client.gui
import at.petrak.hexcasting.api.utils.HexUtils
import at.petrak.hexcasting.api.utils.HexUtils.TAU
import at.petrak.hexcasting.client.RenderLib
import at.petrak.hexcasting.client.sound.GridSoundInstance
import at.petrak.hexcasting.api.mod.HexItemTags
import at.petrak.hexcasting.api.spell.casting.ControllerInfo
import at.petrak.hexcasting.api.spell.casting.ResolvedPattern
import at.petrak.hexcasting.api.spell.casting.ResolvedPatternValidity
import at.petrak.hexcasting.common.lib.HexItems
import at.petrak.hexcasting.common.items.ItemSpellbook
import at.petrak.hexcasting.common.lib.HexSounds
import at.petrak.hexcasting.common.lib.HexMessages
import at.petrak.hexcasting.common.network.MsgNewSpellPatternSyn
import at.petrak.hexcasting.common.network.MsgShiftScrollSyn
import at.petrak.hexcasting.api.spell.math.HexAngle
import at.petrak.hexcasting.api.spell.math.HexCoord
import at.petrak.hexcasting.api.spell.math.HexDir
import at.petrak.hexcasting.api.spell.math.HexPattern
import at.petrak.hexcasting.api.mod.HexItemTags
import at.petrak.hexcasting.api.utils.HexUtils
import at.petrak.hexcasting.api.utils.HexUtils.TAU
import at.petrak.hexcasting.client.RenderLib
import at.petrak.hexcasting.client.sound.GridSoundInstance
import at.petrak.hexcasting.common.items.ItemSpellbook
import at.petrak.hexcasting.common.lib.HexItems
import at.petrak.hexcasting.common.lib.HexSounds
import at.petrak.hexcasting.common.network.MsgNewSpellPatternSyn
import at.petrak.hexcasting.common.network.MsgShiftScrollSyn
import at.petrak.hexcasting.xplat.IClientXplatAbstractions
import com.mojang.blaze3d.systems.RenderSystem
import com.mojang.blaze3d.vertex.PoseStack
import net.minecraft.client.Minecraft
@ -61,7 +61,7 @@ class GuiSpellcasting(
if (!info.wasPrevPatternInvalid) {
Minecraft.getInstance().soundManager.play(
SimpleSoundInstance(
HexSounds.ADD_PATTERN.get(),
HexSounds.ADD_PATTERN,
SoundSource.PLAYERS,
0.5f,
1f + (Math.random().toFloat() - 0.5f) * 0.1f,
@ -76,7 +76,7 @@ class GuiSpellcasting(
override fun init() {
val minecraft = Minecraft.getInstance()
val soundManager = minecraft.soundManager
soundManager.stop(HexSounds.CASTING_AMBIANCE.id, null)
soundManager.stop(HexSounds.CASTING_AMBIANCE.location, null)
val player = minecraft.player
if (player != null) {
this.ambianceSoundInstance = GridSoundInstance(player)
@ -107,7 +107,7 @@ class GuiSpellcasting(
this.drawState = PatternDrawState.JustStarted(coord)
Minecraft.getInstance().soundManager.play(
SimpleSoundInstance(
HexSounds.START_PATTERN.get(),
HexSounds.START_PATTERN,
SoundSource.PLAYERS,
0.25f,
1f,
@ -180,7 +180,7 @@ class GuiSpellcasting(
if (playSound) {
Minecraft.getInstance().soundManager.play(
SimpleSoundInstance(
HexSounds.ADD_LINE.get(),
HexSounds.ADD_LINE,
SoundSource.PLAYERS,
0.25f,
1f + (Math.random().toFloat() - 0.5f) * 0.1f,
@ -208,7 +208,7 @@ class GuiSpellcasting(
this.drawState = PatternDrawState.BetweenPatterns
if (this.patterns.isEmpty()) {
Minecraft.getInstance().setScreen(null)
Minecraft.getInstance().soundManager.stop(HexSounds.CASTING_AMBIANCE.id, null)
Minecraft.getInstance().soundManager.stop(HexSounds.CASTING_AMBIANCE.location, null)
}
}
is PatternDrawState.Drawing -> {
@ -218,7 +218,7 @@ class GuiSpellcasting(
this.usedSpots.addAll(pat.positions(start))
HexMessages.getNetwork().sendToServer(
IClientXplatAbstractions.INSTANCE.sendPacketToServer(
MsgNewSpellPatternSyn(
this.handOpenedWith,
pat,
@ -236,13 +236,19 @@ class GuiSpellcasting(
val otherHand = HexUtils.OtherHand(this.handOpenedWith)
if (Minecraft.getInstance().player!!.getItemInHand(otherHand).item is ItemSpellbook)
HexMessages.getNetwork().sendToServer(MsgShiftScrollSyn(otherHand, pDelta, Screen.hasControlDown()))
IClientXplatAbstractions.INSTANCE.sendPacketToServer(
MsgShiftScrollSyn(
otherHand,
pDelta,
Screen.hasControlDown()
)
)
return true
}
override fun onClose() {
Minecraft.getInstance().soundManager.stop(HexSounds.CASTING_AMBIANCE.id, null)
Minecraft.getInstance().soundManager.stop(HexSounds.CASTING_AMBIANCE.location, null)
super.onClose()
}
@ -345,7 +351,7 @@ class GuiSpellcasting(
/** Distance between adjacent hex centers */
fun hexSize(): Float {
val hasLens = Minecraft.getInstance().player!!
.getItemInHand(HexUtils.OtherHand(this.handOpenedWith)).`is`(HexItems.SCRYING_LENS.get())
.getItemInHand(HexUtils.OtherHand(this.handOpenedWith)).`is`(HexItems.SCRYING_LENS)
return this.width.toFloat() / if (hasLens) 48.0f else 32.0f
}

View file

@ -1,6 +1,6 @@
package at.petrak.hexcasting.client.particles;
import at.petrak.hexcasting.HexMod;
import at.petrak.hexcasting.api.HexAPI;
import at.petrak.hexcasting.common.particles.ConjureParticleOptions;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.BufferBuilder;
@ -99,6 +99,9 @@ public class ConjureParticle extends TextureSheetParticle {
// pretty sure this prevents the gross culling
// https://github.com/VazkiiMods/Psi/blob/1.18/src/main/java/vazkii/psi/client/fx/FXWisp.java
private record ConjureRenderType(boolean light) implements ParticleRenderType {
private static boolean prevBlur;
private static boolean prevMipmap;
@Override
public void begin(BufferBuilder buf, TextureManager texMan) {
Minecraft.getInstance().gameRenderer.lightTexture().turnOnLightLayer();
@ -116,17 +119,17 @@ public class ConjureParticle extends TextureSheetParticle {
@Override
public void end(Tesselator tess) {
tess.end();
Minecraft.getInstance()
.getTextureManager()
.getTexture(TextureAtlas.LOCATION_PARTICLES)
.restoreLastBlurMipmap();
// Minecraft.getInstance()
// .getTextureManager()
// .getTexture(TextureAtlas.LOCATION_PARTICLES)
// .restoreLastBlurMipmap();
RenderSystem.disableBlend();
RenderSystem.depthMask(true);
}
@Override
public String toString() {
return HexMod.MOD_ID + (light ? ":light" : ":conjure");
return HexAPI.MOD_ID + (light ? ":light" : ":conjure");
}
}

View file

@ -13,7 +13,8 @@ import net.minecraftforge.api.distmarker.Dist
import net.minecraftforge.api.distmarker.OnlyIn
@OnlyIn(Dist.CLIENT)
class GridSoundInstance(val player: Player) : AbstractTickableSoundInstance(HexSounds.CASTING_AMBIANCE.get(), SoundSource.PLAYERS) {
class GridSoundInstance(val player: Player) :
AbstractTickableSoundInstance(HexSounds.CASTING_AMBIANCE, SoundSource.PLAYERS) {
var mousePosX: Double = 0.5
var mousePosY: Double = 0.5

View file

@ -1,5 +1,6 @@
package at.petrak.hexcasting.common.blocks;
import at.petrak.hexcasting.annotations.SoftImplement;
import at.petrak.hexcasting.api.misc.FrozenColorizer;
import at.petrak.hexcasting.common.blocks.entity.BlockEntityConjured;
import net.minecraft.core.BlockPos;
@ -56,12 +57,6 @@ public class BlockConjured extends Block implements EntityBlock {
}
}
@Override
public ItemStack getCloneItemStack(BlockState state, HitResult target, BlockGetter level, BlockPos pos,
Player player) {
return ItemStack.EMPTY;
}
@Override
public void stepOn(Level pLevel, @NotNull BlockPos pPos, @NotNull BlockState pState, @NotNull Entity pEntity) {
BlockEntity tile = pLevel.getBlockEntity(pPos);
@ -117,14 +112,22 @@ public class BlockConjured extends Block implements EntityBlock {
// NO-OP
}
@Override
// TODO figure out how to impl these in fabric
@SoftImplement("forge")
public boolean addLandingEffects(BlockState state1, ServerLevel worldserver, BlockPos pos, BlockState state2,
LivingEntity entity, int numberOfParticles) {
BlockEntity tile = worldserver.getBlockEntity(pos);
if (tile instanceof BlockEntityConjured) {
((BlockEntityConjured) tile).landParticle(entity, numberOfParticles);
if (tile instanceof BlockEntityConjured bec) {
bec.landParticle(entity, numberOfParticles);
}
return true;
}
@SoftImplement("forge")
public ItemStack getCloneItemStack(BlockState state, HitResult target, BlockGetter level, BlockPos pos,
Player player) {
return ItemStack.EMPTY;
}
}

View file

@ -1,5 +1,6 @@
package at.petrak.hexcasting.common.blocks.circles;
import at.petrak.hexcasting.annotations.SoftImplement;
import at.petrak.hexcasting.api.block.circle.BlockCircleComponent;
import at.petrak.hexcasting.api.spell.SpellDatum;
import at.petrak.hexcasting.api.spell.math.HexPattern;
@ -94,19 +95,19 @@ public class BlockSlate extends BlockCircleComponent implements EntityBlock, Sim
}
}
@Override
@SoftImplement("forge")
public ItemStack getCloneItemStack(BlockState state, HitResult target, BlockGetter level, BlockPos pos,
Player player) {
BlockEntity be = level.getBlockEntity(pos);
if (be instanceof BlockEntitySlate slate) {
ItemStack stack = new ItemStack(HexItems.SLATE.get());
ItemStack stack = new ItemStack(HexItems.SLATE);
if (slate.pattern != null) {
HexItems.SLATE.get().writeDatum(stack, SpellDatum.make(slate.pattern));
HexItems.SLATE.writeDatum(stack, SpellDatum.make(slate.pattern));
}
return stack;
}
return super.getCloneItemStack(state, target, level, pos, player);
return new ItemStack(this);
}
@Override

View file

@ -5,12 +5,12 @@ import at.petrak.hexcasting.api.spell.ParticleSpray
import at.petrak.hexcasting.api.spell.RenderedSpell
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.SpellOperator
import at.petrak.hexcasting.common.blocks.akashic.BlockEntityAkashicRecord
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.math.HexPattern
import at.petrak.hexcasting.api.spell.mishaps.MishapNoAkashicRecord
import at.petrak.hexcasting.api.spell.mishaps.MishapOthersName
import at.petrak.hexcasting.common.blocks.akashic.BlockEntityAkashicRecord
import at.petrak.hexcasting.common.lib.HexSounds
import at.petrak.hexcasting.api.spell.math.HexPattern
import net.minecraft.core.BlockPos
import net.minecraft.sounds.SoundSource
import net.minecraft.world.phys.Vec3
@ -51,7 +51,7 @@ object OpAkashicWrite : SpellOperator {
record.addNewDatum(key, datum)
ctx.world.playSound(
null, record.blockPos, HexSounds.SCROLL_SCRIBBLE.get(), SoundSource.BLOCKS,
null, record.blockPos, HexSounds.SCROLL_SCRIBBLE, SoundSource.BLOCKS,
1f, 0.8f
)

View file

@ -6,12 +6,10 @@ import at.petrak.hexcasting.api.spell.RenderedSpell
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.SpellOperator
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.common.lib.HexMessages
import at.petrak.hexcasting.common.network.MsgBeepAck
import at.petrak.hexcasting.xplat.IXplatAbstractions
import net.minecraft.world.level.block.state.properties.NoteBlockInstrument
import net.minecraft.world.phys.Vec3
import net.minecraftforge.network.PacketDistributor
import net.minecraftforge.network.PacketDistributor.TargetPoint
object OpBeep : SpellOperator {
override val argc = 3
@ -37,12 +35,7 @@ object OpBeep : SpellOperator {
private data class Spell(val target: Vec3, val note: Int, val instrument: NoteBlockInstrument) : RenderedSpell {
override fun cast(ctx: CastingContext) {
HexMessages.getNetwork().send(PacketDistributor.NEAR.with {
TargetPoint(
target.x, target.y, target.z,
128.0 * 128.0, ctx.world.dimension()
)
}, MsgBeepAck(target, note, instrument))
IXplatAbstractions.INSTANCE.sendPacketNear(target, 128.0, ctx.world, MsgBeepAck(target, note, instrument))
}
}
}

View file

@ -7,12 +7,11 @@ import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.SpellOperator
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.mishaps.MishapImmuneEntity
import at.petrak.hexcasting.common.lib.HexMessages
import at.petrak.hexcasting.common.network.MsgBlinkAck
import at.petrak.hexcasting.xplat.IXplatAbstractions
import net.minecraft.server.level.ServerPlayer
import net.minecraft.world.entity.Entity
import net.minecraft.world.phys.Vec3
import net.minecraftforge.network.PacketDistributor
import kotlin.math.max
import kotlin.math.roundToInt
@ -52,7 +51,7 @@ object OpBlink : SpellOperator {
target.setPos(target.position().add(dvec))
if (target is ServerPlayer) {
target.connection.resetPosition()
HexMessages.getNetwork().send(PacketDistributor.PLAYER.with { target }, MsgBlinkAck(dvec))
IXplatAbstractions.INSTANCE.sendPacketToPlayer(target, MsgBlinkAck(dvec))
}
}
}

View file

@ -7,9 +7,9 @@ import at.petrak.hexcasting.api.spell.RenderedSpell
import at.petrak.hexcasting.api.spell.SpellDatum
import at.petrak.hexcasting.api.spell.SpellOperator
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.xplat.IXplatAbstractions
import net.minecraft.core.BlockPos
import net.minecraft.world.phys.Vec3
import net.minecraftforge.common.TierSortingRegistry
object OpBreakBlock : SpellOperator {
override val argc: Int
@ -39,13 +39,12 @@ object OpBreakBlock : SpellOperator {
val blockstate = ctx.world.getBlockState(pos)
val tier =
HexConfig.Server.getOpBreakHarvestLevelBecauseForgeThoughtItWasAGoodIdeaToImplementHarvestTiersUsingAnHonestToGodTopoSort()
HexConfig.server().opBreakHarvestLevel()
if (
!blockstate.isAir
&& blockstate.getDestroySpeed(ctx.world, pos) >= 0f // fix being able to break bedrock &c
&& (!blockstate.requiresCorrectToolForDrops()
|| TierSortingRegistry.isCorrectTierForDrops(tier, blockstate))
&& IXplatAbstractions.INSTANCE.isCorrectTierForDrops(tier, blockstate)
) {
ctx.world.destroyBlock(pos, true, ctx.caster)
}

View file

@ -7,18 +7,25 @@ import net.minecraft.resources.ResourceLocation;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.function.BiConsumer;
import static at.petrak.hexcasting.api.HexAPI.modLoc;
public class HexParticles {
public static void registerParticles(BiConsumer<ParticleType<?>, ResourceLocation> r) {
for (var e : PARTICLES.entrySet()) {
r.accept(e.getValue(), e.getKey());
}
}
private static final Map<ResourceLocation, ParticleType<?>> PARTICLES = new LinkedHashMap<>();
public static final ConjureParticleOptions.Type CONJURE_PARTICLE = register(
"conjure_block_particle", new ConjureParticleOptions.Type(false));
public static final ConjureParticleOptions.Type LIGHT_PARTICLE = register(
"conjure_light_particle", () -> new ConjureParticleOptions.Type(false));
"conjure_light_particle", new ConjureParticleOptions.Type(false));
private static <T extends ParticleOptions> ParticleType<T> register(String id, ParticleType<T> particle) {
private static <O extends ParticleOptions, T extends ParticleType<O>> T register(String id, T particle) {
var old = PARTICLES.put(modLoc(id), particle);
if (old != null) {
throw new IllegalArgumentException("Typo? Duplicate id " + id);

View file

@ -14,7 +14,7 @@ import java.util.Locale;
public record ConjureParticleOptions(int color, boolean isLight) implements ParticleOptions {
@Override
public ParticleType<?> getType() {
return (this.isLight ? HexParticles.LIGHT_PARTICLE : HexParticles.CONJURE_PARTICLE).get();
return (this.isLight ? HexParticles.LIGHT_PARTICLE : HexParticles.CONJURE_PARTICLE);
}
@Override

View file

@ -3,35 +3,22 @@ package at.petrak.hexcasting.common.recipe;
import at.petrak.hexcasting.common.lib.HexBlocks;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.level.block.ComposterBlock;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.registries.RegistryObject;
public final class HexComposting {
@SubscribeEvent
public static void setup(FMLCommonSetupEvent evt) {
compostBlock(HexBlocks.AKASHIC_LEAVES1, 0.3F);
compostBlock(HexBlocks.AKASHIC_LEAVES2, 0.3F);
compostBlock(HexBlocks.AKASHIC_LEAVES3, 0.3F);
public static void setup() {
compost(HexBlocks.AKASHIC_LEAVES1, 0.3F);
compost(HexBlocks.AKASHIC_LEAVES2, 0.3F);
compost(HexBlocks.AKASHIC_LEAVES3, 0.3F);
}
private static <T extends Item> void compostItem(RegistryObject<T> itemHolder, float chance) {
T item = itemHolder.get();
private static void compost(ItemLike itemLike, float chance) {
Item item = itemLike.asItem();
if (item != Items.AIR) {
ComposterBlock.COMPOSTABLES.put(item, chance);
}
}
private static <T extends Block> void compostBlock(RegistryObject<T> blockHolder, float chance) {
T block = blockHolder.get();
Item item = block.asItem();
if (item != Items.AIR) {
ComposterBlock.COMPOSTABLES.put(item, chance);
}
if (item != Items.AIR) {
ComposterBlock.COMPOSTABLES.put(item, chance);
}
}
}

View file

@ -4,24 +4,21 @@ import at.petrak.hexcasting.api.HexAPI;
import at.petrak.hexcasting.api.addldata.DataHolder;
import at.petrak.hexcasting.api.addldata.HexHolder;
import at.petrak.hexcasting.api.addldata.ManaHolder;
import at.petrak.hexcasting.api.advancements.HexAdvancementTriggers;
import at.petrak.hexcasting.api.misc.FrozenColorizer;
import at.petrak.hexcasting.api.player.FlightAbility;
import at.petrak.hexcasting.api.player.Sentinel;
import at.petrak.hexcasting.api.spell.casting.CastingHarness;
import at.petrak.hexcasting.api.spell.casting.ResolvedPattern;
import at.petrak.hexcasting.common.casting.RegisterPatterns;
import at.petrak.hexcasting.common.command.PatternResLocArgument;
import at.petrak.hexcasting.common.network.IMessage;
import net.minecraft.commands.synchronization.ArgumentTypes;
import net.minecraft.commands.synchronization.EmptyArgumentSerializer;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Tier;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
@ -45,6 +42,8 @@ public interface IXplatAbstractions {
void sendPacketToPlayer(ServerPlayer target, IMessage packet);
void sendPacketNear(Vec3 pos, double radius, ServerLevel dimension, IMessage packet);
// Things that used to be caps
/**
@ -99,17 +98,7 @@ public interface IXplatAbstractions {
CreativeModeTab getTab();
default void init() {
HexAPI.LOGGER.info("Hello Hexcasting! This is {}!", this.platform());
ArgumentTypes.register(
"hexcasting:pattern",
PatternResLocArgument.class,
new EmptyArgumentSerializer<>(PatternResLocArgument::id)
);
RegisterPatterns.registerPatterns();
HexAdvancementTriggers.registerTriggers();
}
boolean isCorrectTierForDrops(Tier tier, BlockState bs);
IXplatAbstractions INSTANCE = find();

View file

@ -1,4 +1,5 @@
import at.petrak.hexcasting.client.HexAdditionalRenderers
import at.petrak.hexcasting.client.RegisterClientStuff
import at.petrak.hexcasting.fabric.network.FabricPacketHandler
import net.fabricmc.api.ClientModInitializer
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback
@ -12,5 +13,8 @@ object FabricHexClientInitializer : ClientModInitializer {
HexAdditionalRenderers.overlayLevel(ctx.matrixStack(), ctx.tickDelta())
}
HudRenderCallback.EVENT.register(HexAdditionalRenderers::overlayGui)
RegisterClientStuff.init()
RegisterClientStuff.registerParticles()
}
}

View file

@ -1,27 +1,37 @@
import at.petrak.hexcasting.common.lib.HexBlockEntities
import at.petrak.hexcasting.common.lib.HexBlocks
import at.petrak.hexcasting.common.lib.HexItems
import at.petrak.hexcasting.common.lib.HexSounds
import at.petrak.hexcasting.api.advancements.HexAdvancementTriggers
import at.petrak.hexcasting.common.casting.RegisterPatterns
import at.petrak.hexcasting.common.command.PatternResLocArgument
import at.petrak.hexcasting.common.lib.*
import at.petrak.hexcasting.common.misc.Brainsweeping
import at.petrak.hexcasting.common.recipe.HexComposting
import at.petrak.hexcasting.fabric.FabricHexConfig
import at.petrak.hexcasting.fabric.event.VillagerConversionCallback
import at.petrak.hexcasting.fabric.network.FabricPacketHandler
import at.petrak.hexcasting.xplat.IXplatAbstractions
import net.fabricmc.api.ModInitializer
import net.fabricmc.fabric.api.event.player.UseEntityCallback
import net.minecraft.commands.synchronization.ArgumentTypes
import net.minecraft.commands.synchronization.EmptyArgumentSerializer
import net.minecraft.core.Registry
import net.minecraft.resources.ResourceLocation
import java.util.function.BiConsumer
object FabricHexInitializer : ModInitializer {
override fun onInitialize() {
IXplatAbstractions.INSTANCE.init()
FabricPacketHandler.init()
FabricHexConfig.setup()
FabricPacketHandler.init()
initListeners()
initRegistries()
ArgumentTypes.register(
"hexcasting:pattern",
PatternResLocArgument::class.java,
EmptyArgumentSerializer { PatternResLocArgument.id() }
)
RegisterPatterns.registerPatterns()
HexAdvancementTriggers.registerTriggers()
HexComposting.setup()
}
fun initListeners() {
@ -35,6 +45,8 @@ object FabricHexInitializer : ModInitializer {
HexBlocks.registerBlockItems(bind(Registry.ITEM))
HexItems.registerItems(bind(Registry.ITEM))
HexBlockEntities.registerTiles(bind(Registry.BLOCK_ENTITY_TYPE))
HexParticles.registerParticles(bind(Registry.PARTICLE_TYPE))
}
private fun <T> bind(registry: Registry<in T>): BiConsumer<T, ResourceLocation> =

View file

@ -4,6 +4,7 @@ import at.petrak.hexcasting.api.addldata.DataHolder;
import at.petrak.hexcasting.api.addldata.HexHolder;
import at.petrak.hexcasting.api.addldata.ManaHolder;
import at.petrak.hexcasting.api.misc.FrozenColorizer;
import at.petrak.hexcasting.api.mod.HexConfig;
import at.petrak.hexcasting.api.player.FlightAbility;
import at.petrak.hexcasting.api.player.Sentinel;
import at.petrak.hexcasting.api.spell.casting.CastingHarness;
@ -15,17 +16,18 @@ import at.petrak.hexcasting.xplat.IXplatAbstractions;
import at.petrak.hexcasting.xplat.Platform;
import net.fabricmc.api.EnvType;
import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder;
import net.fabricmc.fabric.api.networking.v1.PlayerLookup;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder;
import net.fabricmc.fabric.api.registry.FlammableBlockRegistry;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.*;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
@ -36,6 +38,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.function.BiFunction;
import java.util.stream.Stream;
import static at.petrak.hexcasting.api.HexAPI.modLoc;
@ -55,6 +58,15 @@ public class FabricXplatImpl implements IXplatAbstractions {
ServerPlayNetworking.send(target, packet.getFabricId(), packet.toBuf());
}
@Override
public void sendPacketNear(Vec3 pos, double radius, ServerLevel dimension, IMessage packet) {
var pkt = ServerPlayNetworking.createS2CPacket(packet.getFabricId(), packet.toBuf());
var nears = PlayerLookup.around(dimension, pos, radius);
for (var p : nears) {
p.connection.send(pkt);
}
}
@Override
public void brainsweep(Mob mob) {
var cc = HexCardinalComponents.BRAINSWEPT.get(mob);
@ -193,4 +205,32 @@ public class FabricXplatImpl implements IXplatAbstractions {
return TAB;
}
// do a stupid hack from botania
private static List<ItemStack> stacks(Item... items) {
return Stream.of(items).map(ItemStack::new).toList();
}
private static final List<List<ItemStack>> HARVEST_TOOLS_BY_LEVEL = List.of(
stacks(Items.WOODEN_PICKAXE, Items.WOODEN_AXE, Items.WOODEN_HOE, Items.WOODEN_SHOVEL),
stacks(Items.STONE_PICKAXE, Items.STONE_AXE, Items.STONE_HOE, Items.STONE_SHOVEL),
stacks(Items.IRON_PICKAXE, Items.IRON_AXE, Items.IRON_HOE, Items.IRON_SHOVEL),
stacks(Items.DIAMOND_PICKAXE, Items.DIAMOND_AXE, Items.DIAMOND_HOE, Items.DIAMOND_SHOVEL),
stacks(Items.NETHERITE_PICKAXE, Items.NETHERITE_AXE, Items.NETHERITE_HOE, Items.NETHERITE_SHOVEL)
);
@Override
public boolean isCorrectTierForDrops(Tier tier, BlockState bs) {
if (!bs.requiresCorrectToolForDrops())
return true;
int level = HexConfig.server()
.opBreakHarvestLevelBecauseForgeThoughtItWasAGoodIdeaToImplementHarvestTiersUsingAnHonestToGodTopoSort();
for (var tool : HARVEST_TOOLS_BY_LEVEL.get(level)) {
if (tool.isCorrectToolForDrops(bs))
return true;
}
return false;
}
}

View file

@ -0,0 +1,34 @@
package at.petrak.hexcasting;
import at.petrak.hexcasting.client.HexAdditionalRenderers;
import at.petrak.hexcasting.client.RegisterClientStuff;
import net.minecraftforge.client.event.EntityRenderersEvent;
import net.minecraftforge.client.event.ParticleFactoryRegisterEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.RenderLevelLastEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
// This is Java because I can't kotlin-fu some of the consumers
public class ForgeHexClientInitializer {
@SubscribeEvent
public static void clientInit(FMLClientSetupEvent evt) {
RegisterClientStuff.init();
var evBus = MinecraftForge.EVENT_BUS;
evBus.addListener(
(RenderLevelLastEvent e) -> HexAdditionalRenderers.overlayLevel(e.getPoseStack(), e.getPartialTick()));
evBus.addListener((RenderGameOverlayEvent.PreLayer e) ->
HexAdditionalRenderers.overlayGui(e.getMatrixStack(), e.getPartialTicks()));
evBus.addListener(EventPriority.LOWEST, (ParticleFactoryRegisterEvent e) ->
RegisterClientStuff.registerParticles());
}
@SubscribeEvent
public static void registerEntityRenderers(EntityRenderersEvent.RegisterRenderers evt) {
RegisterClientStuff.registerBlockEntityRenderers(evt::registerBlockEntityRenderer);
}
}

View file

@ -2,34 +2,27 @@ package at.petrak.hexcasting
import at.petrak.hexcasting.api.HexAPI
import at.petrak.hexcasting.api.PatternRegistry
import at.petrak.hexcasting.api.advancements.HexAdvancementTriggers
import at.petrak.hexcasting.api.mod.HexConfig
import at.petrak.hexcasting.client.HexAdditionalRenderers
import at.petrak.hexcasting.client.RegisterClientStuff
import at.petrak.hexcasting.common.lib.HexBlockEntities
import at.petrak.hexcasting.common.lib.HexBlocks
import at.petrak.hexcasting.common.lib.HexItems
import at.petrak.hexcasting.common.lib.HexSounds
import at.petrak.hexcasting.common.casting.RegisterPatterns
import at.petrak.hexcasting.common.command.PatternResLocArgument
import at.petrak.hexcasting.common.lib.*
import at.petrak.hexcasting.common.misc.Brainsweeping
import at.petrak.hexcasting.common.recipe.HexComposting
import at.petrak.hexcasting.forge.ForgeHexConfig
import at.petrak.hexcasting.forge.ForgeOnlyEvents
import at.petrak.hexcasting.forge.cap.CapSyncers
import at.petrak.hexcasting.forge.network.ForgePacketHandler
import at.petrak.hexcasting.xplat.IXplatAbstractions
import net.minecraft.commands.synchronization.ArgumentTypes
import net.minecraft.commands.synchronization.EmptyArgumentSerializer
import net.minecraft.resources.ResourceLocation
import net.minecraftforge.api.distmarker.Dist
import net.minecraftforge.client.event.ParticleFactoryRegisterEvent
import net.minecraftforge.client.event.RenderGameOverlayEvent
import net.minecraftforge.client.event.RenderLevelLastEvent
import net.minecraftforge.common.ForgeConfigSpec
import net.minecraftforge.event.RegistryEvent
import net.minecraftforge.event.entity.living.LivingConversionEvent
import net.minecraftforge.event.entity.player.PlayerInteractEvent.EntityInteract
import net.minecraftforge.eventbus.api.EventPriority
import net.minecraftforge.fml.DistExecutor
import net.minecraftforge.fml.ModLoadingContext
import net.minecraftforge.fml.common.Mod
import net.minecraftforge.fml.config.ModConfig
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent
import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext
@ -44,12 +37,18 @@ import java.util.function.Consumer
@Mod(HexAPI.MOD_ID)
object ForgeHexInitializer {
init {
IXplatAbstractions.INSTANCE.init()
initConfig()
initRegistry()
initListeners()
ArgumentTypes.register(
"hexcasting:pattern",
PatternResLocArgument::class.java,
EmptyArgumentSerializer { PatternResLocArgument.id() }
)
RegisterPatterns.registerPatterns()
HexAdvancementTriggers.registerTriggers()
}
fun initConfig() {
@ -73,6 +72,8 @@ object ForgeHexInitializer {
bind(ForgeRegistries.ITEMS, HexBlocks::registerBlockItems)
bind(ForgeRegistries.BLOCK_ENTITIES, HexBlockEntities::registerTiles)
bind(ForgeRegistries.ITEMS, HexItems::registerItems)
bind(ForgeRegistries.PARTICLE_TYPES, HexParticles::registerParticles)
}
fun initListeners() {
@ -81,15 +82,12 @@ object ForgeHexInitializer {
// game events
val evBus = thedarkcolour.kotlinforforge.forge.FORGE_BUS
modBus.register(ForgeHexClientInitializer::class.java)
modBus.addListener { evt: FMLCommonSetupEvent ->
evt.enqueueWork {
ForgePacketHandler.init()
}
}
modBus.addListener { evt: FMLClientSetupEvent ->
evt.enqueueWork {
RegisterClientStuff.init()
HexComposting.setup()
}
}
@ -117,20 +115,6 @@ object ForgeHexInitializer {
evBus.register(CapSyncers::class.java)
evBus.register(ForgeOnlyEvents::class.java)
DistExecutor.unsafeRunWhenOn(Dist.CLIENT) {
Runnable {
evBus.addListener { evt: RenderLevelLastEvent ->
HexAdditionalRenderers.overlayLevel(evt.poseStack, evt.partialTick)
}
evBus.addListener { evt: RenderGameOverlayEvent.PreLayer ->
HexAdditionalRenderers.overlayGui(evt.matrixStack, evt.partialTicks)
}
evBus.addListener(EventPriority.LOWEST) { _: ParticleFactoryRegisterEvent ->
RegisterClientStuff.registerParticles()
}
}
}
}
private fun <T : IForgeRegistryEntry<T>> bind(

View file

@ -37,6 +37,7 @@ import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Tier;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
@ -44,6 +45,7 @@ import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.common.TierSortingRegistry;
import net.minecraftforge.fml.loading.FMLLoader;
import net.minecraftforge.network.PacketDistributor;
import org.jetbrains.annotations.Nullable;
@ -242,6 +244,13 @@ public class ForgeXplatImpl implements IXplatAbstractions {
ForgePacketHandler.getNetwork().send(PacketDistributor.PLAYER.with(() -> target), packet);
}
@Override
public void sendPacketNear(Vec3 pos, double radius, ServerLevel dimension, IMessage packet) {
ForgePacketHandler.getNetwork().send(PacketDistributor.NEAR.with(() -> new PacketDistributor.TargetPoint(
pos.x, pos.y, pos.z, radius * radius, dimension.dimension()
)), packet);
}
@Override
public <T extends BlockEntity> BlockEntityType<T> createBlockEntityType(BiFunction<BlockPos, BlockState, T> func,
Block... blocks) {
@ -275,6 +284,11 @@ public class ForgeXplatImpl implements IXplatAbstractions {
return TAB;
}
@Override
public boolean isCorrectTierForDrops(Tier tier, BlockState bs) {
return !bs.requiresCorrectToolForDrops() || TierSortingRegistry.isCorrectTierForDrops(tier, bs);
}
public static final String TAG_BRAINSWEPT = "hexcasting:brainswept";
public static final String TAG_SENTINEL_EXISTS = "hexcasting:sentinel_exists";
public static final String TAG_SENTINEL_GREATER = "hexcasting:sentinel_extends_range";

View file

@ -10,7 +10,7 @@ minecraftVersion=1.18.2
modVersion=0.8.0
paucalVersion=0.3.4
patchouliVersion=66
patchouliVersion=67
jeiVersion=9.5.3.143
forgeVersion=40.1.0