-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
68 changed files
with
1,226 additions
and
468 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/main/java/com/cstav/genshinstrument/block/LyreInstrumentBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/cstav/genshinstrument/block/ModBlockEntities.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
26
src/main/java/com/cstav/genshinstrument/block/ModBlocks.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
85 changes: 85 additions & 0 deletions
85
src/main/java/com/cstav/genshinstrument/block/partial/AbstractInstrumentBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/cstav/genshinstrument/block/partial/InstrumentBlockEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/main/java/com/cstav/genshinstrument/client/ModArmPose.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.