Skip to content

Commit

Permalink
bits n bobs
Browse files Browse the repository at this point in the history
  • Loading branch information
afamiliarquiet committed Nov 1, 2024
1 parent 7cac54e commit 6a15680
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,17 @@ public class FamiliarBlocks {

public static final DeferredBlock<CandleBlock> ENCHANTED_CANDLE_BLOCK = registerBlockWithItem(
"enchanted_candle",
() -> new EnchantedCandleBlock(BlockBehaviour.Properties.ofFullCopy(Blocks.CANDLE)) // maybe toy with properties later
() -> new EnchantedCandleBlock(BlockBehaviour.Properties.ofFullCopy(Blocks.CANDLE)
.mapColor(MapColor.COLOR_ORANGE)
) // maybe toy with properties later
);

public static final DeferredBlock<SummoningTableBlock> SUMMONING_TABLE_BLOCK = registerBlockWithItem(
"summoning_table",
() -> new SummoningTableBlock(BlockBehaviour.Properties.of()
.mapColor(MapColor.COLOR_PURPLE)
.instrument(NoteBlockInstrument.BASEDRUM)
.requiresCorrectToolForDrops() // hmm good point. i should fix this by adding this to stone pick tag or whatever
.requiresCorrectToolForDrops()
.lightLevel(state -> state.getValue(SummoningTableBlock.SUMMONING_TABLE_STATE).lightLevel())
.strength(5.0F, 1200.0F)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ protected void tick(BlockState state, ServerLevel level, BlockPos pos, RandomSou

@Override
public void animateTick(BlockState state, Level level, BlockPos pos, RandomSource random) {
if (state.getValue(SUMMONING_TABLE_STATE) == SummoningTableState.SUMMONING) {
SummoningTableState tableState = state.getValue(SUMMONING_TABLE_STATE);
if (tableState == SummoningTableState.SUMMONING) {
if (random.nextInt(100) == 0) {
// truly just ripping this whole thing from respawn anchor. as usual, might change sound later. unlikely
level.playLocalSound(pos, SoundEvents.RESPAWN_ANCHOR_AMBIENT, SoundSource.BLOCKS, 1.0F, 1.0F, false);
Expand All @@ -185,6 +186,21 @@ public void animateTick(BlockState state, Level level, BlockPos pos, RandomSourc
double d2 = (double)pos.getZ() + 0.5 + (0.5 - random.nextDouble());
double d3 = (double)random.nextFloat() * 0.04;
level.addParticle(ParticleTypes.REVERSE_PORTAL, d0, d1, d2, 0.0, d3, 0.0);
} else if (tableState == SummoningTableState.BURNING) {
if (random.nextInt(31) == 0) {
level.playLocalSound(pos, SoundEvents.CAMPFIRE_CRACKLE, SoundSource.BLOCKS, 1, 1, false);
}

if (random.nextInt(2) == 0) {
double x = pos.getX() + 0.5 + 0.5 * (0.5 - random.nextDouble());
double y = pos.getY() + 0.8375;
double z = pos.getZ() + 0.5 + 0.5 * (0.5 - random.nextDouble());
level.addParticle(
random.nextInt(6) == 0 ? ParticleTypes.FLAME : ParticleTypes.SMOKE,
x, y, z,
0.0, 0.0, 0.0
);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.LockCode;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.Nameable;
Expand All @@ -37,6 +39,7 @@
import net.minecraft.world.level.block.entity.BaseContainerBlockEntity;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.gameevent.GameEvent;
import net.neoforged.neoforge.items.IItemHandler;
import net.neoforged.neoforge.items.IItemHandlerModifiable;
import net.neoforged.neoforge.items.ItemStackHandler;
Expand Down Expand Up @@ -135,11 +138,12 @@ public SummoningTableBlockEntity(BlockPos pos, BlockState blockState) {

public BlockState startSummoning(BlockState state, boolean simulate) {
// todo - check for unlits, then blow out candles on summoning start
if (this.level instanceof ServerLevel serverLevel) {
if (!this.anyUnlit() && this.level instanceof ServerLevel serverLevel) {
LivingEntity livingTarget = findTargetByUuid(this.getCandleTarget(), serverLevel.getServer());
if (livingTarget != null) {
if (!simulate) {
this.summoningTimer = FamiliarTricks.SUMMONING_TIME_SECONDS;
//this.unlightAll();

if (livingTarget instanceof ServerPlayer player) {
SummoningRequestData requestData = new SummoningRequestData(
Expand Down Expand Up @@ -210,7 +214,7 @@ public void cancelSummoning() {

public void acceptSummoning(LivingEntity livingTarget) {
if (this.level == null) {
// this really shouldn't ever be real
// this really shouldn't ever be real. also this should always be on server side?
return;
}
if (livingTarget.getUUID().equals(this.getCandleTarget()) && this.getBlockState().getValue(SummoningTableBlock.SUMMONING_TABLE_STATE) == SummoningTableState.SUMMONING) {
Expand All @@ -221,6 +225,10 @@ public void acceptSummoning(LivingEntity livingTarget) {
pathfindermob.getNavigation().stop();
}

level.gameEvent(GameEvent.TELEPORT, livingTarget.position(), GameEvent.Context.of(livingTarget));
level.broadcastEntityEvent(livingTarget, (byte)46);
level.playSound(null, this.getBlockPos(), SoundEvents.PLAYER_TELEPORT, SoundSource.BLOCKS, 1, 1);

// todo - replace these with more happy variants, and also give offerings to accepting player
cancelSummoning();
SummoningTableBlock.extinguish(null, this.getBlockState(), this.level, this.getBlockPos());
Expand Down Expand Up @@ -303,6 +311,25 @@ public boolean anyUnlit() {
return false;
}

private void unlightAll() {
if (this.level == null) {
return;
}

for (int i = 0; i < 32; i++) {
// boldly unchecked because this should only be called when all the things are there... err i should check actually
BlockPos targetPos = this.getBlockPos().offset(CANDLE_COLUMN_OFFSETS[2*i], 0, CANDLE_COLUMN_OFFSETS[2*i+1]);
targetPos = targetPos.offset(0, ((this.targetFromCandlesInNybbles[i] >> 2) & 0b11) + 1, 0);
BlockState targetState = this.level.getBlockState(targetPos);
if (targetState.is(FamiliarBlocks.ENCHANTED_CANDLE_BLOCK)) {
this.level.setBlock(targetPos, targetState.setValue(EnchantedCandleBlock.LIT, false), Block.UPDATE_CLIENTS);
}
}

// todo - custom sound/event
level.playSound(null, this.getBlockPos(), SoundEvents.BREEZE_LAND, SoundSource.BLOCKS, 1, 1);
}

// written with the aid of our lady luna :innocent:
private static byte[] processCandles(Level level, BlockPos pos) {
byte[] nybbles = new byte[32];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

import io.github.afamiliarquiet.familiar_magic.data.SummoningRequestData;
import io.netty.buffer.ByteBuf;
import net.minecraft.client.Minecraft;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.entity.player.Player;
import net.neoforged.neoforge.network.handling.IPayloadContext;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -42,6 +43,7 @@ public static void ayeAyeRequestReceived(final SummoningRequestPayload summoning
} else {
// also set like, request time? to 30? and fade screen in and out at the ends
setRequest(hehehe, summoningRequestPayload.requestData);
hehehe.level().playLocalSound(hehehe, SoundEvents.UI_CARTOGRAPHY_TABLE_TAKE_RESULT, SoundSource.BLOCKS, 1, 1);
}
}
}

0 comments on commit 6a15680

Please sign in to comment.