1
0
mirror of https://github.com/chylex/Hardcore-Ender-Expansion-2.git synced 2025-02-28 00:46:00 +01:00

Add Experience Table

This commit is contained in:
chylex 2020-02-27 13:17:47 +01:00
parent cd2a480ab8
commit 9c82e4db2a
21 changed files with 244 additions and 2 deletions

Binary file not shown.

View File

@ -0,0 +1,153 @@
package chylex.hee.game.block.entity
import chylex.hee.game.block.entity.base.TileEntityBaseTable
import chylex.hee.game.block.entity.base.TileEntityBaseTableWithSupportingItem
import chylex.hee.game.item.ItemExperienceBottleCustom
import chylex.hee.game.mechanics.dust.DustType
import chylex.hee.game.mechanics.energy.IEnergyQuantity.Units
import chylex.hee.game.mechanics.table.interfaces.ITableContext
import chylex.hee.game.mechanics.table.interfaces.ITableInputTransformer.Companion.CONSUME_ONE
import chylex.hee.game.mechanics.table.interfaces.ITableInputTransformer.Companion.CONSUME_STACK
import chylex.hee.game.mechanics.table.interfaces.ITableProcess
import chylex.hee.game.mechanics.table.process.ProcessManyPedestals.State.Work
import chylex.hee.game.mechanics.table.process.ProcessOnePedestal
import chylex.hee.game.mechanics.table.process.serializer.MultiProcessSerializer
import chylex.hee.game.mechanics.table.process.serializer.MultiProcessSerializer.Companion.Mapping
import chylex.hee.init.ModItems
import chylex.hee.init.ModTileEntities
import chylex.hee.system.migration.vanilla.ItemBlock
import chylex.hee.system.migration.vanilla.Items
import chylex.hee.system.util.TagCompound
import chylex.hee.system.util.ceilToInt
import chylex.hee.system.util.color.IntColor.Companion.RGB
import chylex.hee.system.util.floorToInt
import chylex.hee.system.util.nextFloat
import chylex.hee.system.util.over
import chylex.hee.system.util.setStack
import chylex.hee.system.util.size
import net.minecraft.enchantment.EnchantmentHelper
import net.minecraft.inventory.Inventory
import net.minecraft.item.ItemStack
import net.minecraft.item.crafting.IRecipeType
import net.minecraft.tileentity.TileEntityType
import net.minecraft.util.math.BlockPos
import kotlin.math.pow
class TileEntityExperienceTable(type: TileEntityType<TileEntityExperienceTable>) : TileEntityBaseTableWithSupportingItem(type){
@Suppress("unused")
constructor() : this(ModTileEntities.EXPERIENCE_TABLE)
override val tableIndicatorColor = RGB(167, 187, 45)
override val tableDustType = DustType.STARDUST
override val processTickRate = 13
override val processSerializer = MultiProcessSerializer(
*SUPPORTING_ITEM_MAPPINGS, Mapping("", ::Process)
)
private val smeltingInventory = Inventory(1)
override fun isSupportingItem(stack: ItemStack): Boolean{
return stack.item === Items.GLASS_BOTTLE
}
override fun getProcessFor(pedestalPos: BlockPos, stack: ItemStack): ITableProcess?{
val rand = wrld.rand
val item = stack.item
if (item === Items.EXPERIENCE_BOTTLE){
return Process(this, pedestalPos, experience = (0 until stack.size).sumBy { 3 + rand.nextInt(5) + rand.nextInt(5) }, updates = 1, usesBottle = false)
}
else if (item === ModItems.EXPERIENCE_BOTTLE){
return Process(this, pedestalPos, experience = stack.size * ModItems.EXPERIENCE_BOTTLE.getExperienceAmountPerItem(stack), updates = 0, usesBottle = false)
}
else if (item === Items.ENCHANTED_BOOK){
val enchantments = EnchantmentHelper.getEnchantments(stack)
val experience = enchantments.entries.sumBy { (ench, level) -> (1F + (level.toFloat() / ench.maxLevel)).pow(1.5F + (level.coerceAtMost(5) * 0.5F)).floorToInt() }
val updates = 1 + enchantments.values.sum()
return Process(this, pedestalPos, experience, updates)
}
else if (item is ItemBlock){
val block = item.block
for(attempt in 1..50){
val experience = block.getExpDrop(block.defaultState, world, pedestalPos, 0, 0)
if (experience > 0){
return Process(this, pedestalPos, (experience * 1.75F).floorToInt().coerceAtLeast(1), updates = 9)
}
}
}
smeltingInventory.setStack(0, stack)
val recipe = wrld.recipeManager.getRecipe(IRecipeType.SMELTING, smeltingInventory, wrld).orElse(null)
smeltingInventory.setStack(0, ItemStack.EMPTY)
if (recipe != null){
return Process(this, pedestalPos, (recipe.experience * rand.nextFloat(1.75F, 3.25F)).ceilToInt(), updates = 5)
}
return null
}
private class Process : ProcessOnePedestal{
constructor(table: TileEntityBaseTable, pos: BlockPos) : super(table, pos)
constructor(table: TileEntityBaseTable, nbt: TagCompound) : super(table, nbt)
constructor(table: TileEntityBaseTable, pos: BlockPos, experience: Int, updates: Int, usesBottle: Boolean = true) : this(table, pos){
this.experience = experience
this.updatesLeft = updates
this.usesBottle = usesBottle
}
override val energyPerTick =
Units(1)
override val dustPerTick =
1 over 6
override val whenFinished
get() = if (usesBottle)
CONSUME_ONE
else
CONSUME_STACK
private var experience = 0
private var updatesLeft = 0
private var usesBottle = false
override fun isInputStillValid(oldInput: ItemStack, newInput: ItemStack): Boolean{
return oldInput.item === newInput.item
}
override fun onWorkTick(context: ITableContext, input: ItemStack): State{
if (updatesLeft == 0){
if (usesBottle && context.requestUseSupportingItem(Items.GLASS_BOTTLE, (experience + ItemExperienceBottleCustom.MAX_EXPERIENCE - 1) / ItemExperienceBottleCustom.MAX_EXPERIENCE) == null){
return Work.Blocked
}
return Output(ModItems.EXPERIENCE_BOTTLE.createBottles(experience).toTypedArray())
}
if (!context.requestUseResources()){
return Work.Blocked
}
--updatesLeft
return Work.Success
}
override fun serializeNBT() = super.serializeNBT().apply {
putShort("Experience", experience.toShort())
putShort("UpdatesLeft", updatesLeft.toShort())
putBoolean("UsesBottle", usesBottle)
}
override fun deserializeNBT(nbt: TagCompound) = with(nbt){
super.deserializeNBT(nbt)
experience = getShort("Experience").toInt()
updatesLeft = getShort("UpdatesLeft").toInt()
usesBottle = getBoolean("UsesBottle")
}
}
}

View File

@ -28,9 +28,10 @@ import net.minecraft.world.World
import kotlin.math.min
class ItemExperienceBottleCustom(builder: Properties) : ItemExpBottle(builder){
private companion object{
companion object{
private const val EXPERIENCE_TAG = "Experience"
private const val MAX_EXPERIENCE = 25
const val MAX_EXPERIENCE = 25
}
private fun setExperienceAmount(stack: ItemStack, amount: Int){

View File

@ -60,6 +60,7 @@ import chylex.hee.game.block.BlockWhitebarkLeaves
import chylex.hee.game.block.BlockWhitebarkLog
import chylex.hee.game.block.BlockWhitebarkSapling
import chylex.hee.game.block.entity.TileEntityAccumulationTable
import chylex.hee.game.block.entity.TileEntityExperienceTable
import chylex.hee.game.block.fluid.FluidEnderGoo
import chylex.hee.game.block.fluid.FluidEnderGooPurified
import chylex.hee.game.block.info.BlockBuilders.buildAncientCobweb
@ -341,6 +342,9 @@ object ModBlocks{
@JvmField val ACCUMULATION_TABLE_TIER_1 = BlockTableTile(buildTable, "accumulation_table", TileEntityAccumulationTable::class.java, tier = 1, firstTier = 1) named "accumulation_table_tier_1"
@JvmField val ACCUMULATION_TABLE_TIER_2 = BlockTableTile(buildTable, "accumulation_table", TileEntityAccumulationTable::class.java, tier = 2, firstTier = 1) named "accumulation_table_tier_2"
@JvmField val ACCUMULATION_TABLE_TIER_3 = BlockTableTile(buildTable, "accumulation_table", TileEntityAccumulationTable::class.java, tier = 3, firstTier = 1) named "accumulation_table_tier_3"
@JvmField val EXPERIENCE_TABLE_TIER_1 = BlockTableTile(buildTable, "experience_table", TileEntityExperienceTable::class.java, tier = 1, firstTier = 1) named "experience_table_tier_1"
@JvmField val EXPERIENCE_TABLE_TIER_2 = BlockTableTile(buildTable, "experience_table", TileEntityExperienceTable::class.java, tier = 2, firstTier = 1) named "experience_table_tier_2"
@JvmField val EXPERIENCE_TABLE_TIER_3 = BlockTableTile(buildTable, "experience_table", TileEntityExperienceTable::class.java, tier = 3, firstTier = 1) named "experience_table_tier_3"
// Blocks: Utilities
@ -513,6 +517,9 @@ object ModBlocks{
register(ACCUMULATION_TABLE_TIER_1 with basicItemBlock)
register(ACCUMULATION_TABLE_TIER_2 with basicItemBlock)
register(ACCUMULATION_TABLE_TIER_3 with basicItemBlock)
register(EXPERIENCE_TABLE_TIER_1 with basicItemBlock)
register(EXPERIENCE_TABLE_TIER_2 with basicItemBlock)
register(EXPERIENCE_TABLE_TIER_3 with basicItemBlock)
register(ETERNAL_FIRE)
register(SCAFFOLDING with basicItemBlock)

View File

@ -6,6 +6,7 @@ import chylex.hee.game.block.entity.TileEntityDarkChest
import chylex.hee.game.block.entity.TileEntityEndPortalAcceptor
import chylex.hee.game.block.entity.TileEntityEnergyCluster
import chylex.hee.game.block.entity.TileEntityExperienceGate
import chylex.hee.game.block.entity.TileEntityExperienceTable
import chylex.hee.game.block.entity.TileEntityIgneousPlate
import chylex.hee.game.block.entity.TileEntityInfusedTNT
import chylex.hee.game.block.entity.TileEntityJarODust
@ -34,6 +35,7 @@ object ModTileEntities{
val END_PORTAL_ACCEPTOR = build<TileEntityEndPortalAcceptor>(ModBlocks.END_PORTAL_ACCEPTOR) named "end_portal_acceptor"
val ENERGY_CLUSTER = build<TileEntityEnergyCluster>(ModBlocks.ENERGY_CLUSTER) named "energy_cluster"
val EXPERIENCE_GATE = build<TileEntityExperienceGate>(ModBlocks.EXPERIENCE_GATE_CONTROLLER) named "experience_gate"
val EXPERIENCE_TABLE = build<TileEntityExperienceTable>(ModBlocks.EXPERIENCE_TABLE_TIER_1, ModBlocks.EXPERIENCE_TABLE_TIER_2, ModBlocks.EXPERIENCE_TABLE_TIER_3) named "experience_table"
val IGNEOUS_PLATE = build<TileEntityIgneousPlate>(ModBlocks.IGNEOUS_PLATE) named "igneous_plate"
val INFUSED_TNT = build<TileEntityInfusedTNT>(ModBlocks.INFUSED_TNT) named "infused_tnt"
val JAR_O_DUST = build<TileEntityJarODust>(ModBlocks.JAR_O_DUST) named "jar_o_dust"
@ -54,6 +56,7 @@ object ModTileEntities{
register(END_PORTAL_ACCEPTOR)
register(ENERGY_CLUSTER)
register(EXPERIENCE_GATE)
register(EXPERIENCE_TABLE)
register(IGNEOUS_PLATE)
register(INFUSED_TNT)
register(JAR_O_DUST)

View File

@ -5,6 +5,7 @@ import chylex.hee.game.block.entity.TileEntityDarkChest;
import chylex.hee.game.block.entity.TileEntityEndPortalAcceptor;
import chylex.hee.game.block.entity.TileEntityEnergyCluster;
import chylex.hee.game.block.entity.TileEntityExperienceGate;
import chylex.hee.game.block.entity.TileEntityExperienceTable;
import chylex.hee.game.block.entity.TileEntityIgneousPlate;
import chylex.hee.game.block.entity.TileEntityInfusedTNT;
import chylex.hee.game.block.entity.TileEntityJarODust;
@ -29,6 +30,7 @@ public final class TileEntityConstructors{
add(TileEntityEndPortalAcceptor.class, TileEntityEndPortalAcceptor::new);
add(TileEntityEnergyCluster.class, TileEntityEnergyCluster::new);
add(TileEntityExperienceGate.class, TileEntityExperienceGate::new);
add(TileEntityExperienceTable.class, TileEntityExperienceTable::new);
add(TileEntityIgneousPlate.class, TileEntityIgneousPlate::new);
add(TileEntityInfusedTNT.class, TileEntityInfusedTNT::new);
add(TileEntityJarODust.class, TileEntityJarODust::new);

View File

@ -0,0 +1,5 @@
{
"variants": {
"": { "model": "hee:block/experience_table_tier_1" }
}
}

View File

@ -0,0 +1,5 @@
{
"variants": {
"": { "model": "hee:block/experience_table_tier_2" }
}
}

View File

@ -0,0 +1,5 @@
{
"variants": {
"": { "model": "hee:block/experience_table_tier_3" }
}
}

View File

@ -125,6 +125,7 @@
"block.hee.table_pedestal": "Table Pedestal",
"block.hee.table_base": "Table Base",
"block.hee.accumulation_table": "Accumulation Table",
"block.hee.experience_table": "Experience Table",
"block.hee.eternal_fire": "Eternal Fire",
"block.hee.scaffolding": "Scaffolding",

View File

@ -0,0 +1,7 @@
{
"parent": "hee:block/table_tier_1",
"textures": {
"overlay_top": "hee:block/experience_table_top",
"overlay_side": "hee:block/experience_table_side"
}
}

View File

@ -0,0 +1,7 @@
{
"parent": "hee:block/table_tier_2",
"textures": {
"overlay_top": "hee:block/experience_table_top",
"overlay_side": "hee:block/experience_table_side"
}
}

View File

@ -0,0 +1,7 @@
{
"parent": "hee:block/table_tier_3",
"textures": {
"overlay_top": "hee:block/experience_table_top",
"overlay_side": "hee:block/experience_table_side"
}
}

View File

@ -0,0 +1,3 @@
{
"parent": "hee:block/experience_table_tier_1"
}

View File

@ -0,0 +1,3 @@
{
"parent": "hee:block/experience_table_tier_2"
}

View File

@ -0,0 +1,3 @@
{
"parent": "hee:block/experience_table_tier_3"
}

Binary file not shown.

After

(image error) Size: 209 B

Binary file not shown.

After

(image error) Size: 232 B

View File

@ -0,0 +1,10 @@
{
"type": "minecraft:block",
"pools": [
{
"rolls": 1,
"name": "pool#auto=block",
"entries": []
}
]
}

View File

@ -0,0 +1,10 @@
{
"type": "minecraft:block",
"pools": [
{
"rolls": 1,
"name": "pool#auto=block",
"entries": []
}
]
}

View File

@ -0,0 +1,10 @@
{
"type": "minecraft:block",
"pools": [
{
"rolls": 1,
"name": "pool#auto=block",
"entries": []
}
]
}