Skip to content

Commit

Permalink
同步更新
Browse files Browse the repository at this point in the history
  • Loading branch information
TartaricAcid committed Apr 7, 2024
1 parent 413993a commit 4533ff6
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
import com.github.tartaricacid.touhoulittlemaid.init.InitItems;
import net.minecraft.Util;
import net.minecraft.client.Minecraft;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtUtils;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.syncher.SynchedEntityData;
Expand Down Expand Up @@ -200,15 +198,8 @@ public InteractionResult interact(Player player, InteractionHand hand) {
if (this.getPassengers().size() > 1) {
return InteractionResult.sidedSuccess(this.level.isClientSide);
}
if (player.getUUID().equals(this.getOwnerUUID())) {
if (!level.isClientSide) {
player.startRiding(this);
}
} else {
if (hand == InteractionHand.MAIN_HAND && this.level.isClientSide) {
player.sendMessage(new TranslatableComponent("message.touhou_little_maid.broom.not_the_owner"), Util.NIL_UUID);
}
return InteractionResult.FAIL;
if (!level.isClientSide) {
player.startRiding(this);
}
return InteractionResult.sidedSuccess(this.level.isClientSide);
}
Expand Down Expand Up @@ -237,7 +228,7 @@ public double getPassengersRidingOffset() {

@Override
protected boolean canKillEntity(Player player) {
return player.getUUID().equals(this.getOwnerUUID());
return true;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,13 @@
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.ServerLevelAccessor;
import net.minecraft.world.level.block.BaseFireBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.LevelEvent;
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.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.pathfinder.BlockPathTypes;
import net.minecraft.world.level.pathfinder.Path;
import net.minecraft.world.phys.AABB;
Expand Down Expand Up @@ -1683,7 +1689,41 @@ public boolean destroyBlock(BlockPos pos) {
}

public boolean destroyBlock(BlockPos pos, boolean dropBlock) {
return canDestroyBlock(pos) && level.destroyBlock(pos, dropBlock, this);
return canDestroyBlock(pos) && destroyBlock(level, pos, dropBlock, this);
}

public boolean destroyBlock(Level level, BlockPos blockPos, boolean dropBlock, @Nullable Entity entity) {
BlockState blockState = level.getBlockState(blockPos);
if (blockState.isAir()) {
return false;
} else {
FluidState fluidState = level.getFluidState(blockPos);
if (!(blockState.getBlock() instanceof BaseFireBlock)) {
level.levelEvent(LevelEvent.PARTICLES_DESTROY_BLOCK, blockPos, Block.getId(blockState));
}
if (dropBlock) {
BlockEntity blockEntity = blockState.hasBlockEntity() ? level.getBlockEntity(blockPos) : null;
dropResourcesToMaidInv(blockState, level, blockPos, blockEntity, this, ItemStack.EMPTY);
}
boolean setResult = level.setBlock(blockPos, fluidState.createLegacyBlock(), Block.UPDATE_ALL);
if (setResult) {
level.gameEvent(entity, GameEvent.BLOCK_DESTROY, blockPos);
}
return setResult;
}
}

public void dropResourcesToMaidInv(BlockState state, Level level, BlockPos pos, @Nullable BlockEntity blockEntity, EntityMaid maid, ItemStack tool) {
if (level instanceof ServerLevel serverLevel) {
CombinedInvWrapper availableInv = this.getAvailableInv(false);
Block.getDrops(state, serverLevel, pos, blockEntity, maid, tool).forEach(stack -> {
ItemStack remindItemStack = ItemHandlerHelper.insertItemStacked(availableInv, stack, false);
if (!remindItemStack.isEmpty()) {
Block.popResource(level, pos, remindItemStack);
}
});
state.spawnAfterBreak(serverLevel, pos, tool);
}
}

public boolean placeItemBlock(InteractionHand hand, BlockPos placePos, Direction direction, ItemStack stack) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.item.*;
import net.minecraft.world.level.EmptyBlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
Expand All @@ -19,8 +17,6 @@
import net.minecraftforge.items.ItemHandlerHelper;
import net.minecraftforge.items.wrapper.CombinedInvWrapper;

import javax.annotation.Nullable;

public class TaskNormalFarm implements IFarmTask {
private static final ResourceLocation NAME = new ResourceLocation(TouhouLittleMaid.MOD_ID, "farm");

Expand Down Expand Up @@ -73,7 +69,7 @@ public void harvest(EntityMaid maid, BlockPos cropPos, BlockState cropState) {
if (cropBlock instanceof CropBlock) {
CropBlock crop = (CropBlock) cropBlock;
BlockEntity blockEntity = cropState.hasBlockEntity() ? maid.level.getBlockEntity(cropPos) : null;
dropResourcesToMaidInv(cropState, maid.level, cropPos, blockEntity, maid, maid.getMainHandItem(), availableInv);
maid.dropResourcesToMaidInv(cropState, maid.level, cropPos, blockEntity, maid, maid.getMainHandItem());
maid.level.setBlock(cropPos, crop.defaultBlockState(), Block.UPDATE_ALL);
maid.level.gameEvent(maid, GameEvent.BLOCK_CHANGE, cropPos);
return;
Expand Down Expand Up @@ -119,16 +115,4 @@ public ItemStack plant(EntityMaid maid, BlockPos basePos, BlockState baseState,
}
return seed;
}

private void dropResourcesToMaidInv(BlockState state, Level level, BlockPos pos, @Nullable BlockEntity blockEntity, EntityMaid maid, ItemStack tool, CombinedInvWrapper invWrapper) {
if (level instanceof ServerLevel serverLevel) {
Block.getDrops(state, serverLevel, pos, blockEntity, maid, tool).forEach(stack -> {
ItemStack remindItemStack = ItemHandlerHelper.insertItemStacked(invWrapper, stack, false);
if (!remindItemStack.isEmpty()) {
Block.popResource(level, pos, remindItemStack);
}
});
state.spawnAfterBreak(serverLevel, pos, tool);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
package com.github.tartaricacid.touhoulittlemaid.item;

import com.github.tartaricacid.touhoulittlemaid.entity.item.EntityBroom;
import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.MobSpawnType;
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.item.context.UseOnContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;

import javax.annotation.Nullable;
import java.util.List;

import static com.github.tartaricacid.touhoulittlemaid.item.MaidGroup.MAIN_TAB;

public class ItemBroom extends Item {
Expand Down Expand Up @@ -53,4 +59,9 @@ public InteractionResult useOn(UseOnContext context) {
}
return InteractionResult.FAIL;
}

@Override
public void appendHoverText(ItemStack stack, @Nullable Level level, List<Component> tooltipComponents, TooltipFlag isAdvanced) {
tooltipComponents.add(new TranslatableComponent("tooltips.touhou_little_maid.broom.desc").withStyle(ChatFormatting.GRAY));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
"tooltips.touhou_little_maid.tank_backpack.fluid": "%s: %d mB",
"tooltips.touhou_little_maid.tank_backpack.capacity": "Capacity: %d mB",
"tooltips.touhou_little_maid.item_container.empty": "Empty",
"tooltips.touhou_little_maid.broom.desc": "Right click on the block to place the broom",
"overlay.touhou_little_maid.compass.tips": "Right click to display the maid's task area",
"overlay.touhou_little_maid.golden_apple.tips": "Golden apple shift click can be fed to maid",
"overlay.touhou_little_maid.potion.tips": "Potion shift click can be fed to maid",
Expand Down Expand Up @@ -293,7 +294,6 @@
"message.touhou_little_maid.script_book.remove": "Successfully clear the maid's chat bubble script",
"message.touhou_little_maid.script_book.install": "Successfully install the maid's chat bubble script",
"message.touhou_little_maid.script_book.copy": "Successfully copy the maid's chat bubble script",
"message.touhou_little_maid.broom.not_the_owner": "You are not the owner of this broom!",
"message.touhou_little_maid.broom.unable_fly": "You need a maid to sit on your broom before you can use it",
"commands.touhou_little_maid.pack.reload.info": "All model pack have been reloaded!",
"commands.touhou_little_maid.power.handle.info": "%d players's power point is changed",
Expand Down
10 changes: 5 additions & 5 deletions src/main/resources/assets/touhou_little_maid/lang/zh_cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
"tooltips.touhou_little_maid.tank_backpack.fluid": "%s: %d mB",
"tooltips.touhou_little_maid.tank_backpack.capacity": "容量:%d mB",
"tooltips.touhou_little_maid.item_container.empty": "",
"tooltips.touhou_little_maid.broom.desc": "右击方块来放置扫帚",
"overlay.touhou_little_maid.compass.tips": "右击可以显示女仆的任务区域",
"overlay.touhou_little_maid.golden_apple.tips": "金苹果可以 Shfit 右击喂给女仆",
"overlay.touhou_little_maid.potion.tips": "药水可以 Shift 右击喂给女仆",
Expand Down Expand Up @@ -151,8 +152,8 @@
"gui.touhou_little_maid.skin.button.close": "关闭",
"gui.touhou_little_maid.skin.tooltips.show_details": "Shift 点击打开详情界面",
"gui.touhou_little_maid.skin.tooltips.maid_use_sound_pack_id": "使用声音包:%s",
"gui.touhou_little_maid.button.home.true": "Home 模式已开启",
"gui.touhou_little_maid.button.home.false": "Home 模式已关闭",
"gui.touhou_little_maid.button.home.true": "Home 模式已开启(不跟随玩家)",
"gui.touhou_little_maid.button.home.false": "Home 模式已关闭(跟随玩家)",
"gui.touhou_little_maid.button.home.desc": "§7点击此按钮可以设置女仆是否跟随玩家",
"gui.touhou_little_maid.button.pickup.true": "拾物模式已开启",
"gui.touhou_little_maid.button.pickup.false": "拾物模式已关闭",
Expand Down Expand Up @@ -293,7 +294,6 @@
"message.touhou_little_maid.script_book.remove": "成功清除女仆的聊天气泡台本",
"message.touhou_little_maid.script_book.install": "成功写入女仆的聊天气泡台本",
"message.touhou_little_maid.script_book.copy": "成功复制女仆的聊天气泡台本",
"message.touhou_little_maid.broom.not_the_owner": "你不是这个扫帚的主人!",
"message.touhou_little_maid.broom.unable_fly": "你需要一个女仆也坐在扫帚上才能使用它",
"commands.touhou_little_maid.pack.reload.info": "所有的模型包已经重载!",
"commands.touhou_little_maid.power.handle.info": "修改了 %d 位玩家的 P 点",
Expand All @@ -316,8 +316,8 @@
"config.touhou_little_maid.maid.maid_idle_range.desc": "女仆处于休息模式时的最大范围",
"config.touhou_little_maid.maid.maid_sleep_range.name": "女仆睡觉范围",
"config.touhou_little_maid.maid.maid_sleep_range.desc": "女仆处于睡觉模式时的最大范围",
"config.touhou_little_maid.maid.maid_non_home_range.name": "女仆非 Home 模式范围",
"config.touhou_little_maid.maid.maid_non_home_range.desc": "当女仆处于非 Home 模式时的最大范围",
"config.touhou_little_maid.maid.maid_non_home_range.name": "女仆跟随范围",
"config.touhou_little_maid.maid.maid_non_home_range.desc": "当女仆处于跟随情况下时的活动范围",
"config.touhou_little_maid.maid.feed_animal_max_number.name": "繁殖动物的最大数量",
"config.touhou_little_maid.maid.feed_animal_max_number.desc": "女仆处于繁殖动物模式时,周围最大可以繁殖的动物数量",
"config.touhou_little_maid.maid.maid_change_model.name": "女仆能否切换模型",
Expand Down

0 comments on commit 4533ff6

Please sign in to comment.