Skip to content

Commit

Permalink
Merge branch 'dev' into 1.20
Browse files Browse the repository at this point in the history
  • Loading branch information
StavWasPlayZ committed Aug 5, 2023
2 parents 95e228f + cee14ee commit 0088ed5
Show file tree
Hide file tree
Showing 68 changed files with 1,226 additions and 468 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ parchment_mappings=1.20.1:2023.07.02
loader_version=0.14.21

# Mod Properties
mod_version=3.1
mod_version=3.2.2
maven_group=com.cstav.genshinstrument
archives_base_name=genshinstrument

Expand Down
10 changes: 8 additions & 2 deletions src/main/java/com/cstav/genshinstrument/GInstrumentMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.cstav.genshinstrument.block.ModBlockEntities;
import com.cstav.genshinstrument.block.ModBlocks;
import com.cstav.genshinstrument.criteria.ModCriteria;
import com.cstav.genshinstrument.item.ModItems;
import com.cstav.genshinstrument.networking.ModPacketHandler;
Expand All @@ -19,10 +21,14 @@ public void onInitialize() {
ModPacketHandler.registerServerPackets();
ModCriteria.register();

ModSounds.regsiter();
ModSounds.load();


ModBlocks.load();
ModBlockEntities.load();

ModCreativeModeTabs.regsiter();
ModItems.register();
ModItems.load();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@

public class ModCreativeModeTabs {

public static final CreativeModeTab INSTRUMENTS = FabricItemGroup.builder()
public static final CreativeModeTab INSTRUMENTS_TAB = FabricItemGroup.builder()
.icon(() -> new ItemStack(ModItems.FLORAL_ZITHER))
.title(Component.translatable("genshinstrument.itemGroup.instruments"))
.build();

public static void regsiter() {
Registry.register(BuiltInRegistries.CREATIVE_MODE_TAB, new ResourceLocation(GInstrumentMod.MODID, "instruments_group"), INSTRUMENTS);
Registry.register(BuiltInRegistries.CREATIVE_MODE_TAB, new ResourceLocation(GInstrumentMod.MODID, "instruments_group"), INSTRUMENTS_TAB);

}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.cstav.genshinstrument.block;

import com.cstav.genshinstrument.block.partial.AbstractInstrumentBlock;
import com.cstav.genshinstrument.block.partial.InstrumentBlockEntity;
import com.cstav.genshinstrument.networking.OpenInstrumentPacketSender;
import com.cstav.genshinstrument.util.ServerUtil;

import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.state.BlockState;


//TODO remove after tests
public class LyreInstrumentBlock extends AbstractInstrumentBlock {

public LyreInstrumentBlock(Properties pProperties) {
super(pProperties);
}

@Override
public InstrumentBlockEntity newBlockEntity(BlockPos pPos, BlockState pState) {
return new InstrumentBlockEntity(pPos, pState);
}

@Override
protected OpenInstrumentPacketSender instrumentPacketSender() {
return (player, hand) -> ServerUtil.sendInternalOpenPacket(player, hand, "windsong_lyre");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.cstav.genshinstrument.block;

import com.cstav.genshinstrument.GInstrumentMod;
import com.cstav.genshinstrument.block.partial.InstrumentBlockEntity;

import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;

public abstract class ModBlockEntities {
public static void load() {};

public static final BlockEntityType<InstrumentBlockEntity> INSTRUMENT_BE = regsiter("instrument_be",
BlockEntityType.Builder.of((pos, state) -> new InstrumentBlockEntity(pos, state), ModBlocks.LYRE_BLOCK)
.build(null)
);

private static <T extends BlockEntity> BlockEntityType<T> regsiter(final String name, final BlockEntityType<T> bet) {
Registry.register(BuiltInRegistries.BLOCK_ENTITY_TYPE, new ResourceLocation(GInstrumentMod.MODID, name), bet);
return bet;
}
}
26 changes: 26 additions & 0 deletions src/main/java/com/cstav/genshinstrument/block/ModBlocks.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.cstav.genshinstrument.block;

import com.cstav.genshinstrument.GInstrumentMod;

import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockBehaviour.Properties;

public abstract class ModBlocks {
public static void load() {};

//NOTE for testing purposes
public static final Block
LYRE_BLOCK = register("lyre_block", new LyreInstrumentBlock(Properties.copy(Blocks.OAK_WOOD)))
;


private static Block register(final String name, final Block block) {
Registry.register(BuiltInRegistries.BLOCK, new ResourceLocation(GInstrumentMod.MODID, name), block);
return block;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.cstav.genshinstrument.block.partial;

import com.cstav.genshinstrument.client.ModArmPose;
import com.cstav.genshinstrument.event.PosePlayerArmEvent.PosePlayerArmEventArgs;
import com.cstav.genshinstrument.networking.ModPacketHandler;
import com.cstav.genshinstrument.networking.OpenInstrumentPacketSender;
import com.cstav.genshinstrument.networking.packets.instrument.NotifyInstrumentOpenPacket;
import com.cstav.genshinstrument.util.ModEntityData;
import com.cstav.genshinstrument.util.ServerUtil;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.BaseEntityBlock;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;

public abstract class AbstractInstrumentBlock extends BaseEntityBlock {

/**
* @param onOpenRequest A server-side event fired when the player has requested to interact
* with the instrument.
* It should should send a packet to the given player for opening this instrument's screen.
*/
public AbstractInstrumentBlock(Properties pProperties) {
super(pProperties);
}


// Abstract implementations
protected abstract OpenInstrumentPacketSender instrumentPacketSender();
@Override
public abstract InstrumentBlockEntity newBlockEntity(BlockPos pPos, BlockState pState);


@Override
public InteractionResult use(BlockState pState, Level pLevel, BlockPos pPos, Player pPlayer, InteractionHand pHand,
BlockHitResult pHit) {
if (pLevel.isClientSide)
return InteractionResult.CONSUME;


final BlockEntity be = pLevel.getBlockEntity(pPos);
if (!(be instanceof InstrumentBlockEntity))
return InteractionResult.FAIL;

if (ServerUtil.sendOpenPacket((ServerPlayer)pPlayer, instrumentPacketSender(), pPos)) {
((InstrumentBlockEntity)be).users.add(pPlayer.getUUID());
return InteractionResult.SUCCESS;
}

return InteractionResult.FAIL;
}


@Override
public void onRemove(BlockState pState, Level pLevel, BlockPos pPos, BlockState pNewState, boolean pMovedByPiston) {
final BlockEntity be = pLevel.getBlockEntity(pPos);
if (!(be instanceof InstrumentBlockEntity))
return;


final InstrumentBlockEntity ibe = (InstrumentBlockEntity)be;

for (final Player player : pLevel.players()) {
ibe.users.forEach((user) -> {
ModEntityData.setInstrumentClosed(pLevel.getPlayerByUUID(user));
ModPacketHandler.sendToClient(new NotifyInstrumentOpenPacket(user, false), (ServerPlayer)player);
});
}
}


@Environment(EnvType.CLIENT)
public void onPosePlayerArm(PosePlayerArmEventArgs args) {
ModArmPose.poseForBlockInstrument(args);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.cstav.genshinstrument.block.partial;

import java.util.HashSet;
import java.util.Set;
import java.util.UUID;

import com.cstav.genshinstrument.block.ModBlockEntities;

import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;

public class InstrumentBlockEntity extends BlockEntity {

public Set<UUID> users = new HashSet<UUID>();

public InstrumentBlockEntity(BlockEntityType<?> pType, BlockPos pPos, BlockState pBlockState) {
super(pType, pPos, pBlockState);
}

//TODO remove after tests
public InstrumentBlockEntity(BlockPos pPos, BlockState pBlockState) {
super(ModBlockEntities.INSTRUMENT_BE, pPos, pBlockState);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.cstav.genshinstrument.client.gui.screens.instrument.drum.AratakisGreatAndGloriousDrumScreen;
import com.cstav.genshinstrument.client.gui.screens.instrument.floralzither.FloralZitherScreen;
import com.cstav.genshinstrument.client.gui.screens.instrument.partial.InstrumentThemeLoader;
import com.cstav.genshinstrument.client.gui.screens.instrument.test.banjo.BanjoInstrumentScreen;
import com.cstav.genshinstrument.client.gui.screens.instrument.vintagelyre.VintageLyreScreen;
import com.cstav.genshinstrument.client.gui.screens.instrument.windsonglyre.WindsongLyreScreen;
import com.cstav.genshinstrument.event.ClientEvents;
Expand All @@ -20,8 +21,11 @@
public class ClientInitiator implements ClientModInitializer {

private static final List<Class<?>> LOAD_ME = List.of(
AratakisGreatAndGloriousDrumScreen.class, FloralZitherScreen.class, VintageLyreScreen.class,
WindsongLyreScreen.class
WindsongLyreScreen.class, VintageLyreScreen.class,
FloralZitherScreen.class, AratakisGreatAndGloriousDrumScreen.class,

//TODO remove after tests
BanjoInstrumentScreen.class
);


Expand Down
37 changes: 37 additions & 0 deletions src/main/java/com/cstav/genshinstrument/client/ModArmPose.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.cstav.genshinstrument.client;

import com.cstav.genshinstrument.event.PosePlayerArmEvent.HandType;
import com.cstav.genshinstrument.event.PosePlayerArmEvent.PosePlayerArmEventArgs;
import com.cstav.genshinstrument.util.ModEntityData;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.model.geom.ModelPart;

@Environment(EnvType.CLIENT)
public abstract class ModArmPose {
public static final float HAND_HEIGHT_ROT = .9f;

public static void poseForItemInstrument(final PosePlayerArmEventArgs args) {
if (!ModEntityData.isInstrumentOpen(args.player) || !ModEntityData.isInstrumentItem(args.player))
return;

final ModelPart arm = args.arm;
if (args.hand == HandType.LEFT) {
arm.xRot = -HAND_HEIGHT_ROT;
arm.zRot = 0.85f;
} else {
arm.xRot = -HAND_HEIGHT_ROT;
arm.zRot = -0.35f;
}

args.setCanceled(true);
}

public static void poseForBlockInstrument(final PosePlayerArmEventArgs args) {
args.arm.xRot = -HAND_HEIGHT_ROT;

args.setCanceled(true);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class ModClientConfigs {
public static final EnumValue<NoteGridLabel> GRID_LABEL_TYPE;
public static final EnumValue<InstrumentChannelType> CHANNEL_TYPE;
public static final BooleanValue STOP_MUSIC_ON_PLAY, EMIT_RING_ANIMATION, SHARED_INSTRUMENT,
RENDER_BACKGROUND, ACCEPTED_GENSHIN_CONSENT, ACCURATE_ACCIDENTALS;
RENDER_BACKGROUND, ACCEPTED_GENSHIN_CONSENT, ACCURATE_NOTES;

public static final EnumValue<ZitherSoundType> ZITHER_SOUND_TYPE;
public static final EnumValue<DrumNoteLabel> DRUM_LABEL_TYPE;
Expand All @@ -45,7 +45,7 @@ public class ModClientConfigs {
SHARED_INSTRUMENT = configBuilder.comment("Defines whether you will see others playing on your instrument's screen")
.define("display_other_players", true);
RENDER_BACKGROUND = configBuilder.define("render_background", true);
ACCURATE_ACCIDENTALS = configBuilder.define("accurate_accidentals", true);
ACCURATE_NOTES = configBuilder.define("accurate_notes", true);

ACCEPTED_GENSHIN_CONSENT = configBuilder.define("accepted_genshin_consent", false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
import com.cstav.genshinstrument.sound.ModSounds;
import com.cstav.genshinstrument.sound.NoteSound;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;

@Environment(EnvType.CLIENT)
public enum ZitherSoundType {
OLD(() -> ModSounds.ZITHER_OLD_NOTE_SOUNDS),
NEW(() -> ModSounds.ZITHER_NEW_NOTE_SOUNDS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public enum NoteGridLabel implements INoteLabel {
).append(LabelUtil.getCutNoteName(ng(note)).substring(1))
),
ABC_1((note) -> Component.literal(
LabelUtil.ABC[ng(note).row] + (gs(note).columns() - ng(note).column)
String.valueOf(LabelUtil.ABC[ng(note).row]) + (gs(note).columns() - ng(note).column)
)),
ABC_2((note) -> Component.literal(
(
Expand Down
Loading

0 comments on commit 0088ed5

Please sign in to comment.