mirror of
https://gitlab.com/cable-mc/cobblemon.git
synced 2026-12-04 14:08:54 -05:00
Redstone functionality
This commit is contained in:
1 parent
1f5bb78684
commit
0725fa83d6
6 files changed
+46
-4
No files matched your search
@@ -14,6 +14,8 @@ import com.mojang.serialization.codecs.RecordCodecBuilder
|
||||
import net.minecraft.core.BlockPos
|
||||
import net.minecraft.core.Direction
|
||||
import net.minecraft.server.level.ServerLevel
|
||||
import net.minecraft.sounds.SoundEvents
|
||||
import net.minecraft.sounds.SoundSource
|
||||
import net.minecraft.util.RandomSource
|
||||
import net.minecraft.world.InteractionResult
|
||||
import net.minecraft.world.entity.player.Player
|
||||
@@ -71,7 +73,10 @@ open class CopperFanBlock(settings: Properties) : HorizontalDirectionalBlock(set
|
||||
player: Player,
|
||||
hitResult: BlockHitResult
|
||||
): InteractionResult {
|
||||
if (!level.isClientSide) level.setBlockAndUpdate(pos, state.setValue(PUSH, !state.getValue(PUSH)))
|
||||
if (!level.isClientSide) {
|
||||
level.setBlockAndUpdate(pos, state.setValue(PUSH, !state.getValue(PUSH)))
|
||||
level.playSound(null, pos, SoundEvents.STONE_BUTTON_CLICK_ON, SoundSource.BLOCKS)
|
||||
}
|
||||
return InteractionResult.SUCCESS
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -227,7 +227,8 @@ open class CopperFridgeBlock(settings: Properties) : BaseEntityBlock(settings),
|
||||
}
|
||||
|
||||
override fun getAnalogOutputSignal(state: BlockState, level: Level, pos: BlockPos): Int {
|
||||
return when ((level.getBlockEntity(pos) as CopperFridgeBlockEntity).theItem.item) {
|
||||
if (level.isClientSide) return 0
|
||||
return when (getBlockEntity(level as ServerLevel, pos).theItem.item) {
|
||||
Items.WATER_BUCKET -> 1
|
||||
Items.ICE -> 2
|
||||
else -> 0
|
||||
|
||||
+2
-1
@@ -22,7 +22,7 @@ class CopperFridgeBlockEntity(val pos: BlockPos, val state: BlockState) : BlockE
|
||||
if (!level!!.getBlockState(pos).getValue(CopperFridgeBlock.POWERED)) return
|
||||
if (timer > 0) timer--
|
||||
if (timer == 0 && item.item == Items.WATER_BUCKET) {
|
||||
item = Items.ICE.defaultInstance
|
||||
theItem = Items.ICE.defaultInstance
|
||||
timer = -1
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,7 @@ class CopperFridgeBlockEntity(val pos: BlockPos, val state: BlockState) : BlockE
|
||||
|
||||
override fun setTheItem(item: ItemStack) {
|
||||
this.item = item
|
||||
level?.updateNeighborsAt(pos, state.block)
|
||||
}
|
||||
|
||||
override fun canTakeItem(target: Container, slot: Int, stack: ItemStack): Boolean {
|
||||
|
||||
@@ -14,6 +14,8 @@ import com.mojang.serialization.MapCodec
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder
|
||||
import net.minecraft.core.BlockPos
|
||||
import net.minecraft.core.Direction
|
||||
import net.minecraft.sounds.SoundEvents
|
||||
import net.minecraft.sounds.SoundSource
|
||||
import net.minecraft.world.InteractionHand
|
||||
import net.minecraft.world.ItemInteractionResult
|
||||
import net.minecraft.world.entity.item.ItemEntity
|
||||
@@ -123,6 +125,7 @@ open class CopperWasherBlock(settings: Properties) : BaseEntityBlock(settings),
|
||||
itemEntity.deltaMovement = Vec3(facing.stepX.toDouble(), 0.0, facing.stepZ.toDouble()).scale(0.2)
|
||||
level.addFreshEntity(itemEntity)
|
||||
entity.theItem = ItemStack.EMPTY
|
||||
level.playSound(null, pos, SoundEvents.ITEM_FRAME_REMOVE_ITEM, SoundSource.BLOCKS)
|
||||
}
|
||||
return ItemInteractionResult.SUCCESS
|
||||
}
|
||||
|
||||
+5
-1
@@ -3,6 +3,7 @@ package com.cobblemon.mod.common.block.appliances
|
||||
import com.cobblemon.mod.common.CobblemonBlockEntities
|
||||
import com.cobblemon.mod.common.CobblemonRecipeTypes
|
||||
import com.cobblemon.mod.common.item.crafting.washer.WasherInput
|
||||
import com.cobblemon.mod.common.util.isServerSide
|
||||
import net.minecraft.core.BlockPos
|
||||
import net.minecraft.world.item.ItemStack
|
||||
import net.minecraft.world.level.block.entity.BlockEntity
|
||||
@@ -18,7 +19,10 @@ class CopperWasherBlockEntity(val pos: BlockPos, val state: BlockState): BlockEn
|
||||
|
||||
override fun getContainerBlockEntity() = this
|
||||
override fun getTheItem() = item
|
||||
override fun setTheItem(item: ItemStack) { this.item = item }
|
||||
override fun setTheItem(item: ItemStack) {
|
||||
this.item = item
|
||||
level?.updateNeighborsAt(pos, state.block)
|
||||
}
|
||||
|
||||
fun craft() {
|
||||
val level = level ?: return
|
||||
|
||||
+28
@@ -11,8 +11,11 @@ package com.cobblemon.mod.common.block.dispenser
|
||||
import com.cobblemon.mod.common.block.SaccharineLeafBlock
|
||||
import com.cobblemon.mod.common.block.SaccharineLogBlock
|
||||
import com.cobblemon.mod.common.block.SaccharineLogSlatheredBlock
|
||||
import com.cobblemon.mod.common.block.appliances.CopperFridgeBlock
|
||||
import com.cobblemon.mod.common.mixin.accessor.DispenserBlockAccessor
|
||||
import net.minecraft.core.dispenser.DispenseItemBehavior
|
||||
import net.minecraft.sounds.SoundEvents
|
||||
import net.minecraft.sounds.SoundSource
|
||||
import net.minecraft.world.item.Item
|
||||
import net.minecraft.world.item.Items
|
||||
import net.minecraft.world.item.alchemy.PotionContents
|
||||
@@ -86,5 +89,30 @@ object DispenserBehaviorRegistry {
|
||||
).item
|
||||
)
|
||||
)
|
||||
register(
|
||||
{ dispenseWaterBucketIntoFridge() },
|
||||
items = listOf(Items.WATER_BUCKET)
|
||||
)
|
||||
}
|
||||
|
||||
private fun dispenseWaterBucketIntoFridge(): DispenseItemBehavior =
|
||||
DispenseItemBehavior { source, stack ->
|
||||
val level = source.level
|
||||
val pos = source.pos.relative(source.state.getValue(DispenserBlock.FACING))
|
||||
val fridge = level.getBlockState(pos).block as? CopperFridgeBlock
|
||||
|
||||
if (fridge == null) {
|
||||
stack
|
||||
} else {
|
||||
val fridgeEntity = fridge.getBlockEntity(level, pos)
|
||||
if (!fridgeEntity.theItem.isEmpty) {
|
||||
stack
|
||||
} else {
|
||||
fridgeEntity.theItem = Items.WATER_BUCKET.defaultInstance
|
||||
fridgeEntity.timer = 100
|
||||
level.playSound(null, pos, SoundEvents.BUCKET_EMPTY, SoundSource.BLOCKS, 1.0f, 1.0f)
|
||||
Items.BUCKET.defaultInstance
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user