Holo sign test

This commit is contained in:
DBotThePony 2023-01-23 23:37:03 +07:00
parent f9b5a673e2
commit 48bda405cd
Signed by: DBot
GPG Key ID: DCC23B5715498507
17 changed files with 156 additions and 0 deletions

View File

@ -372,6 +372,7 @@ private fun blocks(provider: MatteryLanguageProvider) {
add(MBlocks.BLACK_HOLE, "Local Anomalous Singular Gravitation Field")
add(MBlocks.ENGINE, "Ship Engine")
add(MBlocks.HOLO_SIGN, "Holo Sign")
add(MBlocks.TRITANIUM_INGOT_BLOCK, "Tritanium Plating Block")

View File

@ -377,6 +377,7 @@ private fun blocks(provider: MatteryLanguageProvider) {
add(MBlocks.BLACK_HOLE, "Локализированное Аномальное Сингулярное Гравитационное Поле")
add(MBlocks.ENGINE, "Двигатель Корабля")
add(MBlocks.HOLO_SIGN, "Голографическая Табличка")
add(MBlocks.TRITANIUM_INGOT_BLOCK, "Блок Слитков Тритана")

View File

@ -12,6 +12,7 @@ import ru.dbotthepony.mc.otm.block.entity.MatteryBlockEntity.Companion.ENERGY_KE
import ru.dbotthepony.mc.otm.block.entity.MatteryBlockEntity.Companion.MATTER_STORAGE_KEY
import ru.dbotthepony.mc.otm.block.entity.MatteryBlockEntity.Companion.REDSTONE_SETTING_KEY
import ru.dbotthepony.mc.otm.block.entity.MatteryBlockEntity.Companion.REDSTONE_SIGNAL_KEY
import ru.dbotthepony.mc.otm.block.entity.decorative.HoloSignBlockEntity
import ru.dbotthepony.mc.otm.block.entity.matter.MatterBottlerBlockEntity
import ru.dbotthepony.mc.otm.block.entity.storage.AbstractStorageImportExport.Companion.FILTER_KEY
import ru.dbotthepony.mc.otm.block.entity.storage.StoragePowerSupplierBlockEntity
@ -145,6 +146,8 @@ fun addLootTables(lootTables: LootTables) {
REDSTONE_SETTING_KEY,
)
lootTables.tile(MBlocks.HOLO_SIGN, HoloSignBlockEntity.TEXT_KEY)
lootTables.dropsSelf(MBlocks.STORAGE_CABLE)
lootTables.poweredTile(MBlocks.ANDROID_STATION)
lootTables.basicTile(MBlocks.BATTERY_BANK)

View File

@ -48,6 +48,11 @@ fun addCraftingTableRecipes(consumer: Consumer<FinishedRecipe>) {
.unlockedBy(MItems.ENERGY_COUNTER)
.save(consumer, modLocation("energy_counter_reset"))
ShapelessRecipeBuilder(machinesCategory, MItems.HOLO_SIGN, 1)
.requires(MItems.HOLO_SIGN)
.unlockedBy(MItems.HOLO_SIGN)
.save(consumer, modLocation("holo_sign_reset"))
MatteryRecipe(MBlocks.PLATE_PRESS, category = machinesCategory)
.row(MItems.ELECTRIC_PARTS, MItems.ENERGY_BUS, MItems.ELECTRIC_PARTS)
.row(MItemTags.TRITANIUM_INGOTS, Items.BLAST_FURNACE, MItemTags.TRITANIUM_INGOTS)

View File

@ -144,6 +144,7 @@ fun addTags(tagsProvider: TagsProvider) {
MBlocks.TRITANIUM_INGOT_BLOCK,
MBlocks.ENGINE,
MBlocks.HOLO_SIGN,
), Tiers.IRON)
tagsProvider.requiresPickaxe(MBlocks.TRITANIUM_ORE, Tiers.IRON)

View File

@ -0,0 +1,17 @@
package ru.dbotthepony.mc.otm.block.decorative
import net.minecraft.core.BlockPos
import net.minecraft.world.level.block.EntityBlock
import net.minecraft.world.level.block.entity.BlockEntity
import net.minecraft.world.level.block.state.BlockState
import ru.dbotthepony.mc.otm.block.RotatableMatteryBlock
import ru.dbotthepony.mc.otm.block.entity.decorative.HoloSignBlockEntity
class HoloSignBlock : RotatableMatteryBlock(), EntityBlock {
override val hasFreeRotation: Boolean
get() = true
override fun newBlockEntity(p_153215_: BlockPos, p_153216_: BlockState): BlockEntity {
return HoloSignBlockEntity(p_153215_, p_153216_)
}
}

View File

@ -0,0 +1,41 @@
package ru.dbotthepony.mc.otm.block.entity.decorative
import net.minecraft.core.BlockPos
import net.minecraft.nbt.CompoundTag
import net.minecraft.network.chat.Component
import net.minecraft.world.MenuProvider
import net.minecraft.world.entity.player.Inventory
import net.minecraft.world.entity.player.Player
import net.minecraft.world.inventory.AbstractContainerMenu
import net.minecraft.world.level.block.state.BlockState
import ru.dbotthepony.mc.otm.block.entity.SynchronizedBlockEntity
import ru.dbotthepony.mc.otm.core.nbt.set
import ru.dbotthepony.mc.otm.menu.HoloSignMenu
import ru.dbotthepony.mc.otm.registry.MBlockEntities
import ru.dbotthepony.mc.otm.registry.MBlocks
class HoloSignBlockEntity(blockPos: BlockPos, blockState: BlockState) : SynchronizedBlockEntity(MBlockEntities.HOLO_SIGN, blockPos, blockState), MenuProvider {
var text by synchronizer.string("АМОГУС", name = "text")
override fun createMenu(p_39954_: Int, p_39955_: Inventory, p_39956_: Player): AbstractContainerMenu {
return HoloSignMenu(p_39954_, p_39955_, this)
}
override fun getDisplayName(): Component {
return MBlocks.HOLO_SIGN.name
}
override fun saveAdditional(p_187471_: CompoundTag) {
super.saveAdditional(p_187471_)
p_187471_[TEXT_KEY] = text
}
override fun load(p_155245_: CompoundTag) {
super.load(p_155245_)
text = p_155245_.getString(TEXT_KEY)
}
companion object {
const val TEXT_KEY = "SignText"
}
}

View File

@ -0,0 +1,36 @@
package ru.dbotthepony.mc.otm.client.render.blockentity
import com.mojang.blaze3d.vertex.PoseStack
import net.minecraft.client.renderer.MultiBufferSource
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider
import ru.dbotthepony.mc.otm.block.entity.decorative.HoloSignBlockEntity
import ru.dbotthepony.mc.otm.client.font
import ru.dbotthepony.mc.otm.client.render.DynamicBufferSource
import ru.dbotthepony.mc.otm.client.render.TextAlign
import ru.dbotthepony.mc.otm.client.render.drawAligned
import ru.dbotthepony.mc.otm.core.math.RGBAColor
import ru.dbotthepony.mc.otm.core.math.rotateX
import ru.dbotthepony.mc.otm.core.math.rotateY
class HoloSignRenderer(private val context: BlockEntityRendererProvider.Context) : BlockEntityRenderer<HoloSignBlockEntity> {
override fun render(
tile: HoloSignBlockEntity,
partialTick: Float,
poseStack: PoseStack,
badSorse: MultiBufferSource,
p_112311_: Int,
p_112312_: Int
) {
poseStack.pushPose()
poseStack.translate(0.5f, 0.5f, -0.1f)
poseStack.rotateX(Math.PI.toFloat())
poseStack.rotateY(Math.PI.toFloat())
poseStack.scale(0.01f, 0.01f, 0.01f)
val sorse = DynamicBufferSource.WORLD
font.drawAligned(poseStack = poseStack, buffer = sorse, text = tile.text, align = TextAlign.CENTER_CENTER, x = 0f, y = 0f, color = RGBAColor.BLUE.toInt())
poseStack.popPose()
}
}

View File

@ -73,6 +73,7 @@ val BigDecimalValueCodec = StreamCodec(DataInputStream::readBigDecimal, DataOutp
val UUIDValueCodec = StreamCodec({ s -> UUID(s.readLong(), s.readLong()) }, { s, v -> s.writeLong(v.mostSignificantBits); s.writeLong(v.leastSignificantBits) })
val VarIntValueCodec = StreamCodec(DataInputStream::readVarIntLE, DataOutputStream::writeVarIntLE)
val VarLongValueCodec = StreamCodec(DataInputStream::readVarLongLE, DataOutputStream::writeVarLongLE)
val BinaryStringCodec = StreamCodec(DataInputStream::readBinaryString, DataOutputStream::writeBinaryString)
class EnumValueCodec<V : Enum<V>>(private val clazz: Class<out V>) : IStreamCodec<V> {
private val values = clazz.enumConstants
@ -248,6 +249,19 @@ fun OutputStream.writeVarLongLE(value: Long) {
}
}
fun InputStream.readBinaryString(): String {
val size = readVarIntLE()
val bytes = ByteArray(size)
read(bytes)
return bytes.decodeToString()
}
fun OutputStream.writeBinaryString(input: String) {
val bytes = input.encodeToByteArray()
writeVarIntLE(bytes.size)
write(bytes)
}
private data class IndexedStreamCodec<T>(
val condition: Predicate<Any?>,
val id: Int,
@ -282,6 +296,7 @@ private val codecs: List<IndexedStreamCodec<*>> = com.google.common.collect.Immu
it.add(IndexedStreamCodec(codecID++, ImpreciseFractionValueCodec))
it.add(IndexedStreamCodec(codecID++, BigDecimalValueCodec))
it.add(IndexedStreamCodec(codecID++, UUIDValueCodec))
it.add(IndexedStreamCodec(codecID++, BinaryStringCodec))
it.build()
}

View File

@ -0,0 +1,15 @@
package ru.dbotthepony.mc.otm.menu
import net.minecraft.world.entity.player.Inventory
import net.minecraft.world.inventory.Slot
import ru.dbotthepony.mc.otm.block.entity.decorative.HoloSignBlockEntity
import ru.dbotthepony.mc.otm.registry.MMenus
class HoloSignMenu @JvmOverloads constructor(
containerId: Int,
inventory: Inventory,
tile: HoloSignBlockEntity? = null
) : MatteryMenu(MMenus.HOLO_SIGN, containerId, inventory, tile) {
override val storageSlots: Collection<Slot>
get() = listOf()
}

View File

@ -14,6 +14,7 @@ import ru.dbotthepony.mc.otm.core.*
import ru.dbotthepony.mc.otm.core.collect.ProxiedMap
import ru.dbotthepony.mc.otm.core.math.Decimal
import ru.dbotthepony.mc.otm.core.util.BigDecimalValueCodec
import ru.dbotthepony.mc.otm.core.util.BinaryStringCodec
import ru.dbotthepony.mc.otm.core.util.BooleanValueCodec
import ru.dbotthepony.mc.otm.core.util.ByteValueCodec
import ru.dbotthepony.mc.otm.core.util.DoubleValueCodec
@ -289,6 +290,15 @@ class FieldSynchronizer(private val callback: Runnable, private val alwaysCallCa
return Field(value, VarIntValueCodec, getter, setter, name = name)
}
fun string(
value: String = "",
getter: FieldGetter<String>? = null,
setter: FieldSetter<String>? = null,
name: String = nextFieldName(),
): Field<String> {
return Field(value, BinaryStringCodec, getter, setter, name = name)
}
fun fixedInt(
value: Int = 0,
getter: FieldGetter<Int>? = null,

View File

@ -102,6 +102,7 @@ internal fun addMainCreativeTabItems(consumer: CreativeModeTab.Output) {
accept(MItems.MACHINES)
accept(MRegistry.CARGO_CRATES.item)
accept(MItems.HOLO_SIGN)
base(MItems.TRITANIUM_DOOR)
base(MItems.TRITANIUM_TRAPDOOR)

View File

@ -13,6 +13,7 @@ import ru.dbotthepony.mc.otm.block.entity.blackhole.BlackHoleBlockEntity
import ru.dbotthepony.mc.otm.block.entity.blackhole.BlockEntityExplosionDebugger
import ru.dbotthepony.mc.otm.block.entity.blackhole.BlockEntitySphereDebugger
import ru.dbotthepony.mc.otm.block.entity.decorative.CargoCrateBlockEntity
import ru.dbotthepony.mc.otm.block.entity.decorative.HoloSignBlockEntity
import ru.dbotthepony.mc.otm.block.entity.matter.*
import ru.dbotthepony.mc.otm.block.entity.storage.*
import ru.dbotthepony.mc.otm.block.entity.tech.AndroidStationBlockEntity
@ -24,6 +25,7 @@ import ru.dbotthepony.mc.otm.client.render.blockentity.BatteryBankRenderer
import ru.dbotthepony.mc.otm.client.render.blockentity.BlackHoleRenderer
import ru.dbotthepony.mc.otm.client.render.blockentity.EnergyCounterRenderer
import ru.dbotthepony.mc.otm.client.render.blockentity.GravitationStabilizerRenderer
import ru.dbotthepony.mc.otm.client.render.blockentity.HoloSignRenderer
import ru.dbotthepony.mc.otm.client.render.blockentity.MatterBatteryBankRenderer
import ru.dbotthepony.mc.otm.client.render.blockentity.MatterReplicatorRenderer
@ -62,6 +64,8 @@ object MBlockEntities {
val STORAGE_EXPORTER: BlockEntityType<*> by registry.register(MNames.STORAGE_EXPORTER) { BlockEntityType.Builder.of(::StorageExporterBlockEntity, MBlocks.STORAGE_EXPORTER).build(null) }
val STORAGE_POWER_SUPPLIER: BlockEntityType<*> by registry.register(MNames.STORAGE_POWER_SUPPLIER) { BlockEntityType.Builder.of(::StoragePowerSupplierBlockEntity, MBlocks.STORAGE_POWER_SUPPLIER).build(null) }
val HOLO_SIGN: BlockEntityType<HoloSignBlockEntity> by registry.register(MNames.HOLO_SIGN) { BlockEntityType.Builder.of(::HoloSignBlockEntity, MBlocks.HOLO_SIGN).build(null) }
val DEBUG_EXPLOSION_SMALL: BlockEntityType<*> by registry.register(MNames.DEBUG_EXPLOSION_SMALL) { BlockEntityType.Builder.of(::BlockEntityExplosionDebugger, MBlocks.DEBUG_EXPLOSION_SMALL).build(null) }
val DEBUG_SPHERE_POINTS: BlockEntityType<*> by registry.register(MNames.DEBUG_SPHERE_POINTS) { BlockEntityType.Builder.of(::BlockEntitySphereDebugger, MBlocks.DEBUG_SPHERE_POINTS).build(null) }
@ -79,6 +83,7 @@ object MBlockEntities {
BlockEntityRenderers.register(BATTERY_BANK as BlockEntityType<BatteryBankBlockEntity>, ::BatteryBankRenderer)
BlockEntityRenderers.register(MATTER_CAPACITOR_BANK as BlockEntityType<MatterCapacitorBankBlockEntity>, ::MatterBatteryBankRenderer)
BlockEntityRenderers.register(MATTER_REPLICATOR as BlockEntityType<MatterReplicatorBlockEntity>, ::MatterReplicatorRenderer)
BlockEntityRenderers.register(HOLO_SIGN, ::HoloSignRenderer)
}
}
}

View File

@ -44,6 +44,7 @@ import ru.dbotthepony.mc.otm.block.tech.PhantomAttractorBlock
import ru.dbotthepony.mc.otm.block.tech.PlatePressBlock
import ru.dbotthepony.mc.otm.block.StorageCableBlock
import ru.dbotthepony.mc.otm.block.decorative.EngineBlock
import ru.dbotthepony.mc.otm.block.decorative.HoloSignBlock
import ru.dbotthepony.mc.otm.block.matter.MatterBottlerBlock
import ru.dbotthepony.mc.otm.block.matter.MatterCapacitorBankBlock
import ru.dbotthepony.mc.otm.block.matter.MatterDecomposerBlock
@ -133,6 +134,7 @@ object MBlocks {
val DANGER_STRIPE_BLOCK: Block by registry.register(MNames.DANGER_STRIPE_BLOCK) { Block(BlockBehaviour.Properties.of(Material.METAL, DyeColor.GRAY).explosionResistance(6f).destroyTime(1.5f).requiresCorrectToolForDrops()) }
val METAL_BEAM: Block by registry.register(MNames.METAL_BEAM) { Block(BlockBehaviour.Properties.of(Material.METAL, DyeColor.GRAY).explosionResistance(14f).destroyTime(2.5f).requiresCorrectToolForDrops()) }
val ENGINE: Block by registry.register(MNames.ENGINE) { EngineBlock() }
val HOLO_SIGN: Block by registry.register(MNames.HOLO_SIGN) { HoloSignBlock() }
val TRITANIUM_DOOR = registry.allColored(MNames.TRITANIUM_DOOR) { color, _ ->
object : DoorBlock(Properties.of(Material.METAL, color ?: DyeColor.LIGHT_BLUE).explosionResistance(80f).noOcclusion().destroyTime(3f).requiresCorrectToolForDrops(), SoundEvents.IRON_DOOR_CLOSE, SoundEvents.IRON_DOOR_OPEN) {

View File

@ -266,6 +266,7 @@ object MItems {
val DANGER_STRIPE_BLOCK: Item by registry.register(MNames.DANGER_STRIPE_BLOCK) { BlockItem(MBlocks.DANGER_STRIPE_BLOCK, DEFAULT_PROPERTIES) }
val METAL_BEAM: Item by registry.register(MNames.METAL_BEAM) { BlockItem(MBlocks.METAL_BEAM, DEFAULT_PROPERTIES) }
val ENGINE: Item by registry.register(MNames.ENGINE) { BlockItem(MBlocks.ENGINE, DEFAULT_PROPERTIES) }
val HOLO_SIGN: Item by registry.register(MNames.HOLO_SIGN) { BlockItem(MBlocks.HOLO_SIGN, DEFAULT_PROPERTIES) }
val TRITANIUM_DOOR = registry.allColored(MNames.TRITANIUM_DOOR) { color, _ -> DoubleHighBlockItem(MBlocks.TRITANIUM_DOOR[color]!!, DEFAULT_PROPERTIES) }
val TRITANIUM_TRAPDOOR = registry.allColored(MNames.TRITANIUM_TRAPDOOR) { color, _ -> BlockItem(MBlocks.TRITANIUM_TRAPDOOR[color]!!, DEFAULT_PROPERTIES) }

View File

@ -33,6 +33,7 @@ object MMenus {
val PLATE_PRESS: MenuType<*> by registry.register(MNames.PLATE_PRESS) { MenuType(::PlatePressMenu) }
val MATTER_RECYCLER: MenuType<*> by registry.register(MNames.MATTER_RECYCLER) { MenuType(::MatterRecyclerMenu) }
val ENERGY_SERVO: MenuType<*> by registry.register(MNames.ENERGY_SERVO) { MenuType(::EnergyServoMenu) }
val HOLO_SIGN: MenuType<*> by registry.register(MNames.HOLO_SIGN) { MenuType(::HoloSignMenu) }
val STORAGE_BUS: MenuType<*> by registry.register(MNames.STORAGE_BUS) { MenuType(::StorageBusMenu) }
val STORAGE_EXPORTER: MenuType<*> by registry.register(MNames.STORAGE_EXPORTER) { MenuType(::StorageExporterMenu) }

View File

@ -10,6 +10,7 @@ object MNames {
const val DANGER_STRIPE_BLOCK = "danger_stripe_block"
const val METAL_BEAM = "metal_beam"
const val ENGINE = "engine"
const val HOLO_SIGN = "holo_sign"
// blocks
const val ANDROID_STATION = "android_station"