Skip to content

Commit

Permalink
Merge pull request #16 from Crystal1921/dev/1.21
Browse files Browse the repository at this point in the history
添加转向电话
  • Loading branch information
Yuqi154 authored Oct 30, 2024
2 parents df34265 + f480352 commit 8479f57
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 57 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ run

# Files from Forge MDK
forge*changelog.txt
/src/generated/resources/.cache/
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
{
"variants": {
"": {
"facing=east": {
"model": "mystias_izakaya:block/telephone",
"y": 90
},
"facing=north": {
"model": "mystias_izakaya:block/telephone"
},
"facing=south": {
"model": "mystias_izakaya:block/telephone",
"y": 180
},
"facing=west": {
"model": "mystias_izakaya:block/telephone",
"y": 270
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

package org.hiedacamellia.mystiasizakaya.content.common.block.blocks;

import io.netty.buffer.Unpooled;
Expand All @@ -16,11 +15,14 @@
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
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.SoundType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.NoteBlockInstrument;
import net.minecraft.world.level.storage.loot.LootParams;
import net.minecraft.world.phys.BlockHitResult;
Expand All @@ -38,68 +40,78 @@
import java.util.List;

public class Telephone extends Block {
public Telephone() {
super(Properties.of().instrument(NoteBlockInstrument.BASEDRUM).sound(SoundType.METAL).strength(1f, 10f).noOcclusion());
}
public Telephone() {
super(Properties.of().instrument(NoteBlockInstrument.BASEDRUM).sound(SoundType.METAL).strength(1f, 10f).noOcclusion());
}

@Override
@OnlyIn(Dist.CLIENT)
public void appendHoverText(ItemStack itemstack, Item.TooltipContext context, List<Component> list, TooltipFlag flag) {
super.appendHoverText(itemstack, context, list, flag);
if (!Screen.hasShiftDown()) {
list.add(Component.literal(
"§7§o" + Component.translatable("tooltip.mystias_izakaya.press_shift").getString() + "§r"));
} else {
String[] description = Component.translatable("tooltip.mystias_izakaya.telephone").getString().split("§n");
for (String line : description) {
list.add(Component.literal(line));
}
}
}

@Override
@OnlyIn(Dist.CLIENT)
public void appendHoverText(ItemStack itemstack, Item.TooltipContext context, List<Component> list, TooltipFlag flag) {
super.appendHoverText(itemstack, context, list, flag);
if (!Screen.hasShiftDown()) {
list.add(Component.literal(
"§7§o" + Component.translatable("tooltip.mystias_izakaya.press_shift").getString() + "§r"));
} else {
String[] description = Component.translatable("tooltip.mystias_izakaya.telephone").getString().split("§n");
for (String line : description) {
list.add(Component.literal(line));
}
}
}
@Override
public int getLightBlock(BlockState state, BlockGetter worldIn, BlockPos pos) {
return 15;
}

@Override
public int getLightBlock(BlockState state, BlockGetter worldIn, BlockPos pos) {
return 15;
}
@Override
public List<ItemStack> getDrops(BlockState state, LootParams.Builder builder) {
List<ItemStack> dropsOriginal = super.getDrops(state, builder);
if (!dropsOriginal.isEmpty())
return dropsOriginal;
return Collections.singletonList(new ItemStack(this, 1));
}

@Override
public List<ItemStack> getDrops(BlockState state, LootParams.Builder builder) {
List<ItemStack> dropsOriginal = super.getDrops(state, builder);
if (!dropsOriginal.isEmpty())
return dropsOriginal;
return Collections.singletonList(new ItemStack(this, 1));
}
@Override
public @NotNull InteractionResult useWithoutItem(@NotNull BlockState blockstate, @NotNull Level world, @NotNull BlockPos pos, @NotNull Player entity, @NotNull BlockHitResult hit) {
super.useWithoutItem(blockstate, world, pos, entity, hit);

@Override
public @NotNull InteractionResult useWithoutItem(@NotNull BlockState blockstate, @NotNull Level world, @NotNull BlockPos pos, @NotNull Player entity, @NotNull BlockHitResult hit) {
super.useWithoutItem(blockstate, world, pos, entity, hit);

int tick = entity.getData(MIAttachment.MI_TELE_COLDDOWN).tick();
if (tick > 0) {
entity.sendSystemMessage(Component.translatable("message.mystiasizakaya.telephone.colddown", tick / 20).withStyle(ChatFormatting.RED));
return InteractionResult.FAIL;
}

int tick = entity.getData(MIAttachment.MI_TELE_COLDDOWN).tick();
if(tick>0){
entity.sendSystemMessage(Component.translatable("message.mystiasizakaya.telephone.colddown",tick/20).withStyle(ChatFormatting.RED));
return InteractionResult.FAIL;
}
if (entity instanceof ServerPlayer player) {
player.openMenu(new MenuProvider() {
@Override
public @NotNull Component getDisplayName() {
return Component.literal("Telephone");
}

if (entity instanceof ServerPlayer player) {
player.openMenu(new MenuProvider() {
@Override
public @NotNull Component getDisplayName() {
return Component.literal("Telephone");
}
@Override
public AbstractContainerMenu createMenu(int id, @NotNull Inventory inventory, @NotNull Player player) {
return new TelephoneUiMenu(id, inventory, new FriendlyByteBuf(Unpooled.buffer()).writeBlockPos(pos));
}
}, pos);
}
return InteractionResult.SUCCESS;
}

@Override
public AbstractContainerMenu createMenu(int id, @NotNull Inventory inventory, @NotNull Player player) {
return new TelephoneUiMenu(id, inventory, new FriendlyByteBuf(Unpooled.buffer()).writeBlockPos(pos));
}
}, pos);
}
return InteractionResult.SUCCESS;
}
@Override
public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) {
return Shapes.join(box(4, 0, 4, 12, 4, 12), box(0, 0, 0, 0, 0, 0), BooleanOp.ONLY_FIRST);
}

@Override
public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) {
return Shapes.join(box(4, 0, 4, 12, 4, 12), box(0,0,0,0,0,0), BooleanOp.ONLY_FIRST);
}
@Override
public BlockState getStateForPlacement(BlockPlaceContext pContext) {
return defaultBlockState()
.setValue(HorizontalDirectionalBlock.FACING, pContext.getHorizontalDirection().getOpposite());
}

@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> pBuilder) {
pBuilder.add(HorizontalDirectionalBlock.FACING);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ protected void registerStatesAndModels() {
simpleBlock(MIBlock.STEAMER.get(),models().getExistingFile(modLoc("block/steamer")));
simpleBlock(MIBlock.FRYING_PAN.get(),models().getExistingFile(modLoc("block/frying_pan")));

simpleBlockWithItem(MIBlock.TELEPHONE.get(),models().getExistingFile(modLoc("block/telephone")));
horizontalBlock(MIBlock.TELEPHONE.get(),models().getExistingFile(modLoc("block/telephone")));
simpleBlockWithItem(MIBlock.TABLE.get(),models().getExistingFile(modLoc("block/table")));
}
}

0 comments on commit 8479f57

Please sign in to comment.