-
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.
Migrate instruments to Fabric, leave out looper
- Loading branch information
1 parent
351ad40
commit 6bba75a
Showing
45 changed files
with
2,718 additions
and
25 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
26 changes: 26 additions & 0 deletions
26
src/main/java/com/cstav/evenmoreinstruments/EMIModCreativeModeTabs.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.evenmoreinstruments; | ||
|
||
import com.cstav.evenmoreinstruments.item.ModItems; | ||
|
||
import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup; | ||
import net.minecraft.core.Registry; | ||
import net.minecraft.core.registries.BuiltInRegistries; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.item.CreativeModeTab; | ||
import net.minecraft.world.item.ItemStack; | ||
|
||
public abstract class EMIModCreativeModeTabs { | ||
|
||
public static final CreativeModeTab INSTRUMENT_ACCESSORY_TAB = FabricItemGroup.builder() | ||
.icon(() -> new ItemStack(ModItems.KEYBOARD_STAND)) | ||
.title(Component.translatable("itemGroup.evenmoreinstruments.instrument_accessories")) | ||
.build(); | ||
|
||
public static void regsiter() { | ||
Registry.register(BuiltInRegistries.CREATIVE_MODE_TAB, | ||
new ResourceLocation(Main.MODID, "instruments_tab"), INSTRUMENT_ACCESSORY_TAB | ||
); | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -1,15 +1,43 @@ | ||
package com.cstav.evenmoreinstruments; | ||
|
||
import net.fabricmc.api.ModInitializer; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.cstav.evenmoreinstruments.block.ModBlocks; | ||
import com.cstav.evenmoreinstruments.block.blockentity.ModBlockEntities; | ||
import com.cstav.evenmoreinstruments.gamerule.ModGameRules; | ||
import com.cstav.evenmoreinstruments.item.ModItems; | ||
import com.cstav.evenmoreinstruments.networking.ModPacketHandler; | ||
import com.cstav.evenmoreinstruments.sound.ModSounds; | ||
|
||
import net.fabricmc.api.ModInitializer; | ||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.world.item.ItemStack; | ||
|
||
public class Main implements ModInitializer { | ||
public static final Logger LOGGER = LoggerFactory.getLogger("evenmoreinstruments"); | ||
public static final String MODID = "evenmoreinstruments"; | ||
public static final Logger LOGGER = LoggerFactory.getLogger(MODID); | ||
|
||
public static CompoundTag modTag(final ItemStack item) { | ||
return item.getOrCreateTagElement(MODID); | ||
} | ||
//TODO implement getPersistentData for BlockEntities | ||
// public static CompoundTag modTag(final BlockEntity be) { | ||
// return CommonUtil.getOrCreateElementTag(be.getPersistentData(), MODID); | ||
// } | ||
|
||
@Override | ||
public void onInitialize() { | ||
ModPacketHandler.registerServerPackets(); | ||
EMIModCreativeModeTabs.regsiter(); | ||
|
||
ModSounds.load(); | ||
ModGameRules.load(); | ||
|
||
|
||
ModBlocks.load(); | ||
ModBlockEntities.load(); | ||
|
||
@Override | ||
public void onInitialize() { | ||
LOGGER.info("Hello Fabric world!"); | ||
} | ||
} | ||
ModItems.load(); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/cstav/evenmoreinstruments/block/IDoubleBlock.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,9 @@ | ||
package com.cstav.evenmoreinstruments.block; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
|
||
public interface IDoubleBlock { | ||
BlockPos getOtherBlock(final BlockState state, final BlockPos blockPos, final Level level); | ||
} |
153 changes: 153 additions & 0 deletions
153
src/main/java/com/cstav/evenmoreinstruments/block/KeyboardBlock.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,153 @@ | ||
package com.cstav.evenmoreinstruments.block; | ||
|
||
import com.cstav.evenmoreinstruments.block.blockentity.ModInstrumentBlockEntity; | ||
import com.cstav.evenmoreinstruments.networking.ModPacketHandler; | ||
import com.cstav.evenmoreinstruments.networking.packet.ModOpenInstrumentPacket; | ||
import com.cstav.evenmoreinstruments.util.CommonUtil; | ||
import com.cstav.genshinstrument.block.partial.AbstractInstrumentBlock; | ||
import com.cstav.genshinstrument.block.partial.InstrumentBlockEntity; | ||
import com.cstav.genshinstrument.networking.OpenInstrumentPacketSender; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.Direction; | ||
import net.minecraft.util.StringRepresentable; | ||
import net.minecraft.world.entity.LivingEntity; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.item.context.BlockPlaceContext; | ||
import net.minecraft.world.level.BlockGetter; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.block.Block; | ||
import net.minecraft.world.level.block.Blocks; | ||
import net.minecraft.world.level.block.HorizontalDirectionalBlock; | ||
import net.minecraft.world.level.block.RenderShape; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.level.block.state.StateDefinition.Builder; | ||
import net.minecraft.world.level.block.state.properties.DirectionProperty; | ||
import net.minecraft.world.level.block.state.properties.EnumProperty; | ||
import net.minecraft.world.phys.shapes.CollisionContext; | ||
import net.minecraft.world.phys.shapes.VoxelShape; | ||
|
||
public class KeyboardBlock extends AbstractInstrumentBlock implements IDoubleBlock { | ||
public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING; | ||
public static final EnumProperty<KeyboardBlock.KeyboardPart> PART = EnumProperty.create("part", KeyboardPart.class); | ||
|
||
public static final VoxelShape | ||
SHAPE_LEFT_SOUTH = Block.box(0.0D, 0.0D, 4.0D, 15.65D, 4.4D, 12.8D), | ||
SHAPE_RIGHT_SOUTH = Block.box(0.3D, 0.0D, 4D, 16.0D, 4.4D, 12.8D), | ||
|
||
SHAPE_LEFT_EAST = Block.box(3.5D, 0.0D, 0.0D, 12D, 4.4D, 15.65D), | ||
SHAPE_RIGHT_EAST = Block.box(3.5D, 0.0D, 0.3D, 12D, 4.4D, 16D); | ||
; | ||
|
||
|
||
public KeyboardBlock(Properties pProperties) { | ||
super(pProperties); | ||
registerDefaultState(defaultBlockState() | ||
.setValue(FACING, Direction.NORTH) | ||
.setValue(PART, KeyboardPart.LEFT) | ||
); | ||
} | ||
|
||
@Override | ||
public VoxelShape getShape(BlockState pState, BlockGetter pLevel, BlockPos pPos, CollisionContext pContext) { | ||
final Direction facing = pState.getValue(FACING); | ||
final boolean southOrNorth = (facing == Direction.SOUTH) || (facing == Direction.NORTH); | ||
|
||
return (pState.getValue(PART) == KeyboardPart.LEFT) | ||
? (southOrNorth ? SHAPE_LEFT_SOUTH : SHAPE_LEFT_EAST) | ||
: (southOrNorth ? SHAPE_RIGHT_SOUTH : SHAPE_RIGHT_EAST); | ||
} | ||
|
||
public RenderShape getRenderShape(BlockState pState) { | ||
return RenderShape.MODEL; | ||
} | ||
|
||
|
||
@Override | ||
protected OpenInstrumentPacketSender instrumentPacketSender() { | ||
return (player, hand) -> ModPacketHandler.sendToClient(new ModOpenInstrumentPacket("keyboard", hand), player); | ||
} | ||
|
||
@Override | ||
public InstrumentBlockEntity newBlockEntity(BlockPos arg0, BlockState arg1) { | ||
return new ModInstrumentBlockEntity(arg0, arg1); | ||
} | ||
|
||
|
||
// Handle 2 blocks | ||
@Override | ||
public void setPlacedBy(Level pLevel, BlockPos pPos, BlockState pState, LivingEntity pPlacer, ItemStack pStack) { | ||
super.setPlacedBy(pLevel, pPos, pState, pPlacer, pStack); | ||
if (pLevel.isClientSide) | ||
return; | ||
|
||
final BlockPos sidePos = pPos.relative(CommonUtil.getRight(pState.getValue(FACING))); | ||
|
||
pLevel.setBlock(sidePos, | ||
pState.setValue(PART, KeyboardPart.RIGHT) | ||
, 3); | ||
pLevel.blockUpdated(pPos, Blocks.AIR); | ||
pLevel.blockUpdated(sidePos, Blocks.AIR); | ||
pState.updateNeighbourShapes(pLevel, pPos, 3); | ||
} | ||
|
||
@Override | ||
public void onRemove(BlockState pState, Level pLevel, BlockPos pPos, BlockState pNewState, boolean pMovedByPiston) { | ||
if (pLevel.isClientSide) | ||
return; | ||
|
||
final BlockPos sideBlock = getOtherBlock(pState, pPos, pLevel); | ||
if (sideBlock == null) | ||
return; | ||
|
||
pLevel.setBlock(sideBlock, | ||
Blocks.AIR.defaultBlockState() | ||
, 1|2|4); | ||
pLevel.blockUpdated(pPos, Blocks.AIR); | ||
pState.updateNeighbourShapes(pLevel, pPos, 1|2|4); | ||
} | ||
|
||
|
||
@Override | ||
public BlockState getStateForPlacement(BlockPlaceContext pContext) { | ||
final Direction direction = pContext.getHorizontalDirection(); | ||
final BlockPos pos = pContext.getClickedPos(); | ||
final BlockPos sidePos = pos.relative(CommonUtil.getLeft(direction)); | ||
|
||
final Level level = pContext.getLevel(); | ||
|
||
return ( | ||
level.getBlockState(sidePos).canBeReplaced(pContext) && level.getWorldBorder().isWithinBounds(sidePos) | ||
&& (level.getBlockState(pos.below(1)).canOcclude() || level.getBlockState(sidePos.below(1)).canOcclude()) | ||
) | ||
? defaultBlockState().setValue(FACING, pContext.getHorizontalDirection().getOpposite()) | ||
: null; | ||
} | ||
|
||
@Override | ||
protected void createBlockStateDefinition(Builder<Block, BlockState> pBuilder) { | ||
pBuilder.add(FACING, PART); | ||
} | ||
|
||
|
||
public static enum KeyboardPart implements StringRepresentable { | ||
LEFT, RIGHT; | ||
|
||
@Override | ||
public String getSerializedName() { | ||
return toString().toLowerCase(); | ||
} | ||
} | ||
|
||
|
||
@Override | ||
public BlockPos getOtherBlock(final BlockState state, BlockPos blockPos, Level level) { | ||
final BlockPos sideBlock = blockPos.relative((state.getValue(PART) == KeyboardPart.LEFT) | ||
? CommonUtil.getRight(state.getValue(FACING)) | ||
: CommonUtil.getLeft(state.getValue(FACING)) | ||
); | ||
|
||
return (!level.getBlockState(sideBlock).is(ModBlocks.KEYBOARD)) ? null : sideBlock; | ||
} | ||
|
||
} |
100 changes: 100 additions & 0 deletions
100
src/main/java/com/cstav/evenmoreinstruments/block/KeyboardStandBlock.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,100 @@ | ||
package com.cstav.evenmoreinstruments.block; | ||
|
||
import com.cstav.evenmoreinstruments.block.blockentity.ModInstrumentBlockEntity; | ||
import com.cstav.evenmoreinstruments.item.ModItems; | ||
import com.cstav.evenmoreinstruments.networking.ModPacketHandler; | ||
import com.cstav.evenmoreinstruments.networking.packet.ModOpenInstrumentPacket; | ||
import com.cstav.genshinstrument.block.partial.AbstractInstrumentBlock; | ||
import com.cstav.genshinstrument.block.partial.InstrumentBlockEntity; | ||
import com.cstav.genshinstrument.networking.OpenInstrumentPacketSender; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.Direction; | ||
import net.minecraft.world.InteractionHand; | ||
import net.minecraft.world.InteractionResult; | ||
import net.minecraft.world.entity.item.ItemEntity; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.item.context.BlockPlaceContext; | ||
import net.minecraft.world.level.BlockGetter; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.block.Block; | ||
import net.minecraft.world.level.block.HorizontalDirectionalBlock; | ||
import net.minecraft.world.level.block.RenderShape; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.level.block.state.StateDefinition.Builder; | ||
import net.minecraft.world.level.block.state.properties.BooleanProperty; | ||
import net.minecraft.world.level.block.state.properties.DirectionProperty; | ||
import net.minecraft.world.phys.BlockHitResult; | ||
import net.minecraft.world.phys.shapes.CollisionContext; | ||
import net.minecraft.world.phys.shapes.VoxelShape; | ||
|
||
public class KeyboardStandBlock extends AbstractInstrumentBlock { | ||
public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING; | ||
public static final BooleanProperty HAS_KEYBOARD = BooleanProperty.create("has_keyboard"); | ||
|
||
|
||
public static final VoxelShape BASE_SHAPE = Block.box(0.0D, 0.0D, 0.0D, 16.0D, 9.0D, 16.0D), | ||
WITH_KEYBOARD_SHAPE = Block.box(0.0D, 0.0D, 0.0D, 16.0D, 12.0D, 16.0D); | ||
|
||
@Override | ||
public VoxelShape getShape(BlockState pState, BlockGetter pLevel, BlockPos pPos, CollisionContext pContext) { | ||
return pState.getValue(HAS_KEYBOARD) ? WITH_KEYBOARD_SHAPE : BASE_SHAPE; | ||
} | ||
|
||
public KeyboardStandBlock(Properties pProperties) { | ||
super(pProperties); | ||
registerDefaultState(defaultBlockState() | ||
.setValue(FACING, Direction.NORTH) | ||
.setValue(HAS_KEYBOARD, false) | ||
); | ||
} | ||
|
||
@Override | ||
public InteractionResult use(BlockState pState, Level pLevel, BlockPos pPos, Player pPlayer, InteractionHand pHand, | ||
BlockHitResult pHit) { | ||
if (!pState.getValue(HAS_KEYBOARD)) | ||
return InteractionResult.FAIL; | ||
|
||
return super.use(pState, pLevel, pPos, pPlayer, pHand, pHit); | ||
} | ||
|
||
@Override | ||
public void onRemove(BlockState arg0, Level arg1, BlockPos arg2, BlockState arg3, boolean arg4) { | ||
//NOTE: Does not check for creative, because no context is given | ||
if (!arg1.isClientSide && arg0.getValue(HAS_KEYBOARD)) | ||
arg1.addFreshEntity( | ||
new ItemEntity(arg1, arg2.getX(), arg2.getY(), arg2.getZ(), new ItemStack(ModItems.KEYBOARD)) | ||
); | ||
|
||
super.onRemove(arg0, arg1, arg2, arg3, arg4); | ||
} | ||
|
||
|
||
@Override | ||
protected OpenInstrumentPacketSender instrumentPacketSender() { | ||
return (player, hand) -> ModPacketHandler.sendToClient(new ModOpenInstrumentPacket("keyboard", hand), player); | ||
} | ||
|
||
@Override | ||
public RenderShape getRenderShape(BlockState pState) { | ||
return RenderShape.MODEL; | ||
} | ||
|
||
|
||
@Override | ||
public BlockState getStateForPlacement(BlockPlaceContext pContext) { | ||
return defaultBlockState().setValue(FACING, pContext.getHorizontalDirection().getOpposite()); | ||
} | ||
|
||
@Override | ||
public InstrumentBlockEntity newBlockEntity(BlockPos arg0, BlockState arg1) { | ||
return new ModInstrumentBlockEntity(arg0, arg1); | ||
} | ||
|
||
@Override | ||
protected void createBlockStateDefinition(Builder<Block, BlockState> pBuilder) { | ||
pBuilder.add(FACING, HAS_KEYBOARD); | ||
} | ||
|
||
} |
Oops, something went wrong.