Skip to content

Commit

Permalink
fix bugs (#17)
Browse files Browse the repository at this point in the history
* remove template license

* fix issue #6: 禁止复合食物作为三明治成分

* fix issue #9:现在空的三明治会不渲染(就像空气一样)而不会导致崩溃

* fix issue #10:重构方块掉落逻辑,使其符合原版

* 更改错误的翻译

* fix issue #12: 现在进食模组食物也会受伤

* fix issue #14: 已翻译

* remove useless code

* fix issue #15:现在牛奶不能移除标记为milk_irremovable的效果
  • Loading branch information
FCWYzzr authored Aug 25, 2024
1 parent e98dc5a commit 31562e2
Show file tree
Hide file tree
Showing 14 changed files with 105 additions and 165 deletions.
24 changes: 0 additions & 24 deletions TEMPLATE_LICENSE.txt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ private void use_mixin(Level level, Player player, InteractionHand usedHand, Cal
if (!cir.getReturnValue().getResult().equals(InteractionResult.CONSUME))
return;
final var item = player.getItemInHand(usedHand);
if (! CompoundFood.Companion.isFood(item))
if (! CompoundFood.Companion.isFood(item, false))
return;

if (!Anorexia.INSTANCE.canEat(item, player))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ abstract class CompoundFood(
fun chewTick(stack: ItemStack) = (stack.components[FoodItemProperties.type]!!.chewSeconds * FoodTalks.TPS).toInt()
fun bites(stack: ItemStack) = stack.maxDamage
override fun getUseAnimation(stack: ItemStack) = UseAnim.EAT
// override fun getUseDuration(stack: ItemStack, entity: LivingEntity) =
// (stack.components[FoodItemProperties.type]!!.chewSeconds * FoodTalks.TPS).toInt()

override fun getUseDuration(stack: ItemStack, entity: LivingEntity) = 5 + chewTick(stack)
override fun use(level: Level, player: Player, usedHand: InteractionHand): InteractionResultHolder<ItemStack> {
Expand Down Expand Up @@ -65,8 +63,15 @@ abstract class CompoundFood(
}

companion object{
fun isFood(itemStack: ItemStack): Boolean{
return itemStack.components.has(DataComponents.FOOD) || itemStack.item is CompoundFood
fun isFood(itemStack: ItemStack, notCompound: Boolean = false): Boolean{
return if (notCompound)
isVanillaFood(itemStack) && itemStack.item !is CompoundFood
else
isVanillaFood(itemStack) || itemStack.item is CompoundFood
}

private fun isVanillaFood(itemStack: ItemStack): Boolean{
return itemStack.components.has(DataComponents.FOOD)
}

fun containerOrNull(itemStack: ItemStack): ItemStack? {
Expand All @@ -82,8 +87,8 @@ abstract class CompoundFood(
}?.getOrNull()
}

fun isHandHoldFood(itemStack: ItemStack): Boolean{
return isFood(itemStack) && containerOrNull(itemStack) == null
fun isHandHoldFood(itemStack: ItemStack, notCompound: Boolean = false): Boolean{
return isFood(itemStack, notCompound) && containerOrNull(itemStack) == null
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ object PlateRenderer: BlockEntityRenderer<PlateBlockEntity> {
)
else{
poseStack.pushPose()
poseStack.translate(0.5, 2.5 / 16, 0.5)
poseStack.translate(0.5, 2.0 / 16, 0.5)
poseStack.mulPose(Axis.XP.rotationDegrees(90F))
poseStack.scale(1F, 1F, 3F)
Minecraft.getInstance().itemRenderer.renderStatic(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ object SandwichRenderer {
light: Int,
overlay: Int
){
if (layer.isEmpty())
return

val itemRenderer = Minecraft
.getInstance()
.itemRenderer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import net.minecraft.core.Registry
import net.minecraft.core.component.DataComponents
import net.minecraft.core.registries.BuiltInRegistries
import net.minecraft.resources.ResourceKey
import net.minecraft.server.level.ServerLevel
import net.minecraft.world.InteractionHand
import net.minecraft.world.InteractionResult
import net.minecraft.world.ItemInteractionResult
Expand All @@ -20,16 +21,20 @@ import net.minecraft.world.item.ItemStack
import net.minecraft.world.item.ItemUtils
import net.minecraft.world.item.Items
import net.minecraft.world.item.alchemy.PotionContents
import net.minecraft.world.level.*
import net.minecraft.world.level.BlockGetter
import net.minecraft.world.level.Level
import net.minecraft.world.level.LevelAccessor
import net.minecraft.world.level.LevelReader
import net.minecraft.world.level.block.Block
import net.minecraft.world.level.block.Blocks
import net.minecraft.world.level.block.EntityBlock
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.IntegerProperty
import net.minecraft.world.level.material.FluidState
import net.minecraft.world.level.material.PushReaction
import net.minecraft.world.level.storage.loot.LootParams
import net.minecraft.world.level.storage.loot.parameters.LootContextParams
import net.minecraft.world.phys.BlockHitResult
import net.minecraft.world.phys.HitResult
import net.minecraft.world.phys.shapes.CollisionContext
Expand Down Expand Up @@ -81,23 +86,6 @@ class BottleBlock private constructor(): Block(Properties.of().apply {
return canSupportCenter(pLevel, pPos.below(), Direction.UP)
}

override fun onDestroyedByPlayer(
state: BlockState,
level: Level,
pos: BlockPos,
player: Player,
willHarvest: Boolean,
fluid: FluidState
): Boolean {
val entity = level.getBlockEntity(pos) as BottleBlockEntity

if (level.gameRules.getBoolean(GameRules.RULE_DOBLOCKDROPS) && ! player.hasInfiniteMaterials())
doDestroyDrop(level, entity, state.getValue(PROPERTY_FILL_LEVEL))
super.onDestroyedByPlayer(state, level, pos, player, willHarvest, fluid)

return true
}

override fun updateShape(
state: BlockState,
direction: Direction,
Expand All @@ -111,7 +99,8 @@ class BottleBlock private constructor(): Block(Properties.of().apply {
level,
pos
)
) Blocks.AIR.defaultBlockState() else
) Blocks.AIR.defaultBlockState()
else
super.updateShape(
state,
direction,
Expand All @@ -122,9 +111,10 @@ class BottleBlock private constructor(): Block(Properties.of().apply {
)
}

private fun doDestroyDrop(level: Level, entity: BottleBlockEntity, fillLevel: Int){
val itemStack = Cocktail.buildFromBottle(entity, fillLevel)
popResource(level, entity.blockPos, itemStack)
override fun getDrops(state: BlockState, params: LootParams.Builder): MutableList<ItemStack> {
val entity = params.getParameter(LootContextParams.BLOCK_ENTITY) as BottleBlockEntity
val fillLevel = state.getValue(PROPERTY_FILL_LEVEL)
return mutableListOf(Cocktail.buildFromBottle(entity, fillLevel))
}

/**
Expand All @@ -140,14 +130,13 @@ class BottleBlock private constructor(): Block(Properties.of().apply {
if (! player.isShiftKeyDown)
return InteractionResult.PASS

doDestroyDrop(
level,
level.getBlockEntity(pos) as BottleBlockEntity,
state.getValue(PROPERTY_FILL_LEVEL)
)

if (!player.hasInfiniteMaterials())
level.setBlockAndUpdate(pos, Blocks.AIR.defaultBlockState())
if (player.hasInfiniteMaterials() && level is ServerLevel)
getDrops(state, level, pos, level.getBlockEntity(pos)).forEach {
popResource(level, pos, it)
}
else if (level is ServerLevel)
level.destroyBlock(pos, true)

return InteractionResult.SUCCESS
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ package indi.fcwyzzr.minecraft.food_talks.common.block

import indi.fcwyzzr.minecraft.f_lib.registry.FRegistry
import indi.fcwyzzr.minecraft.food_talks.common.block.entity.PlateBlockEntity
import indi.fcwyzzr.minecraft.food_talks.common.item.Plate
import indi.fcwyzzr.minecraft.food_talks.common.item.Sandwich
import indi.fcwyzzr.minecraft.food_talks.toRegistryName
import indi.fcwyzzr.minecraft.food_talks.toResourceLocation
import net.minecraft.core.BlockPos
import net.minecraft.core.Direction
import net.minecraft.core.Holder
import net.minecraft.core.Registry
import net.minecraft.core.component.DataComponentMap
import net.minecraft.core.registries.BuiltInRegistries
import net.minecraft.resources.ResourceKey
import net.minecraft.server.level.ServerLevel
import net.minecraft.sounds.SoundEvents
import net.minecraft.sounds.SoundSource
import net.minecraft.world.InteractionHand
Expand All @@ -20,17 +21,20 @@ import net.minecraft.world.ItemInteractionResult
import net.minecraft.world.entity.Entity
import net.minecraft.world.entity.item.ItemEntity
import net.minecraft.world.entity.player.Player
import net.minecraft.world.item.Item
import net.minecraft.world.item.ItemStack
import net.minecraft.world.level.*
import net.minecraft.world.level.BlockGetter
import net.minecraft.world.level.Level
import net.minecraft.world.level.LevelAccessor
import net.minecraft.world.level.LevelReader
import net.minecraft.world.level.block.Block
import net.minecraft.world.level.block.Blocks
import net.minecraft.world.level.block.EntityBlock
import net.minecraft.world.level.block.SoundType
import net.minecraft.world.level.block.entity.BlockEntity
import net.minecraft.world.level.block.state.BlockState
import net.minecraft.world.level.material.FluidState
import net.minecraft.world.level.material.PushReaction
import net.minecraft.world.level.storage.loot.LootParams
import net.minecraft.world.level.storage.loot.parameters.LootContextParams
import net.minecraft.world.phys.BlockHitResult
import net.minecraft.world.phys.shapes.CollisionContext
import net.minecraft.world.phys.shapes.VoxelShape
Expand Down Expand Up @@ -93,11 +97,11 @@ class PlateBlock private constructor(): Block(Properties.of().apply {
): InteractionResult {
val entity = level.getBlockEntity(pos) as PlateBlockEntity
if (player.isShiftKeyDown){
if (!player.hasInfiniteMaterials() && level.gameRules.getBoolean(GameRules.RULE_DOBLOCKDROPS))
doIngredientsDrop(level, pos, false)
else
entity.clear()
if (!player.hasInfiniteMaterials()
&& level is ServerLevel)
entity.forEachFoldedContent { popResource(level, pos, this) }

entity.clear()

return InteractionResult.SUCCESS
}
Expand Down Expand Up @@ -152,82 +156,15 @@ class PlateBlock private constructor(): Block(Properties.of().apply {
}
}

override fun onDestroyedByPlayer(
state: BlockState,
level: Level,
pos: BlockPos,
player: Player,
willHarvest: Boolean,
fluid: FluidState
): Boolean {
if (level.gameRules.getBoolean(GameRules.RULE_DOBLOCKDROPS))
doIngredientsDrop(
level,
pos,
!player.hasInfiniteMaterials()
)
return super.onDestroyedByPlayer(state, level, pos, player, willHarvest, fluid)
}
override fun getDrops(state: BlockState, params: LootParams.Builder) = buildList {
val breaker: Entity? = params.getOptionalParameter(LootContextParams.THIS_ENTITY)
if (breaker !is Player || !breaker.hasInfiniteMaterials())
add(Plate.defaultInstance)

override fun onDestroyedByPushReaction(
state: BlockState,
level: Level,
pos: BlockPos,
pushDirection: Direction,
fluid: FluidState
) {
if (level.gameRules.getBoolean(GameRules.RULE_DOBLOCKDROPS))
doIngredientsDrop(
level,
pos,
true
)
super.onDestroyedByPushReaction(state, level, pos, pushDirection, fluid)
val entity = params.getParameter(LootContextParams.BLOCK_ENTITY) as PlateBlockEntity
entity.forEachFoldedContent(::add)
}

private fun doIngredientsDrop(
level: Level,
pos: BlockPos,
dropSelf: Boolean
){
val entity = level.getBlockEntity(pos) as PlateBlockEntity

if (dropSelf)
popResource(level, pos, ItemStack(instance))


entity
.popDisplay()
?.apply{
popResource(level, pos, this)
}
?: run {
entity
.readOnlyIngredient
.fold(mutableMapOf<Item, MutableMap<DataComponentMap, ItemStack>>()) { map, itemStack ->
if (itemStack.item !in map) {
map[itemStack.item] = mutableMapOf(itemStack.components to itemStack)
return@fold map
}

val itemSet = map[itemStack.item]!!
if (itemStack.components !in itemSet) {
itemSet[itemStack.components] = itemStack
return@fold map
}

itemSet[itemStack.components]!!.grow(itemStack.count)

map
}
.flatMap { it.value.values }
.forEach{
popResource(level, pos, it)
}

entity.clear()
}
}


companion object: FRegistry<Block> {
Expand Down
Loading

0 comments on commit 31562e2

Please sign in to comment.