port to 1.14.4

This commit is contained in:
Bixilon 2021-03-09 19:03:27 +01:00
parent 36ad4d5193
commit 599dd83566
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
5 changed files with 48 additions and 20 deletions

View File

@ -15,7 +15,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<kotlin.code.style>official</kotlin.code.style>
<kotlin.compiler.jvmTarget>1.8</kotlin.compiler.jvmTarget>
<minecraft.version>1.15.2</minecraft.version>
<minecraft.version>21w08a</minecraft.version>
</properties>
<repositories>

View File

@ -4,15 +4,11 @@ import com.mojang.authlib.GameProfile
import de.bixilon.pixlyzer.util.ReflectionUtil.getClass
import de.bixilon.pixlyzer.util.ReflectionUtil.getField
import de.bixilon.pixlyzer.util.ReflectionUtil.setFinalField
import net.minecraft.client.multiplayer.ClientLevel
import net.minecraft.client.player.RemotePlayer
import net.minecraft.world.entity.Entity
import net.minecraft.world.entity.EntityType
import net.minecraft.world.entity.fishing.FishingHook
import net.minecraft.world.entity.global.LightningBolt
import net.minecraft.world.level.Level
import net.minecraft.world.level.border.WorldBorder
import net.minecraft.world.level.dimension.NormalDimension
import net.minecraft.world.scores.Scoreboard
import org.objenesis.Objenesis
import org.objenesis.ObjenesisStd
@ -30,26 +26,33 @@ object EntitySpawner {
return entity
}
return when (entityType) {
EntityType.PLAYER -> RemotePlayer(CLIENT_LEVEL, GameProfile(UUID.randomUUID(), "dummy"))
EntityType.LIGHTNING_BOLT -> OBJENSIS.newInstance(LightningBolt::class.java)
EntityType.FISHING_BOBBER -> OBJENSIS.newInstance(FishingHook::class.java)
EntityType.PLAYER -> RemotePlayer::class.java.getConstructor(levelClass, GameProfile::class.java).newInstance(CLIENT_LEVEL, GameProfile(UUID.randomUUID(), "dummy"))
EntityType.LIGHTNING_BOLT -> OBJENSIS.newInstance(LIGHTNING_BOLT_CLASS) as Entity
EntityType.FISHING_BOBBER -> OBJENSIS.newInstance(FISHING_HOOK_CLASS) as Entity
else -> TODO("Entity type: $entityType")
}
}
private val LIGHTNING_BOLT_CLASS = getClass("net.minecraft.world.entity.global.LightningBolt", "net.minecraft.world.entity.LightningBolt")!!
private val FISHING_HOOK_CLASS = getClass("net.minecraft.world.entity.fishing.FishingHook", "net.minecraft.world.entity.projectile.FishingHook")!!
private val levelClass = getClass("net.minecraft.client.multiplayer.ClientLevel", "net.minecraft.client.multiplayer.MultiPlayerLevel")
private val FACTORY_FIELD = getField(EntityType::class.java, "factory")!!
var OBJENSIS: Objenesis = ObjenesisStd()
val CLIENT_LEVEL = OBJENSIS.newInstance(ClientLevel::class.java)
val CLIENT_LEVEL = OBJENSIS.newInstance(levelClass) as Level
init {
setFinalField(getField(Level::class.java, "random")!!, CLIENT_LEVEL, Random())
setFinalField(getField(Level::class.java, "worldBorder")!!, CLIENT_LEVEL, WorldBorder())
setFinalField(getField(Level::class.java, "levelData")!!, CLIENT_LEVEL, OBJENSIS.newInstance(getClass("net.minecraft.world.level.storage.PrimaryLevelData", "net.minecraft.world.level.storage.LevelData")))
setFinalField(getField(ClientLevel::class.java, "scoreboard")!!, CLIENT_LEVEL, Scoreboard())
setFinalField(getField(Level::class.java, "dimension")!!, CLIENT_LEVEL, OBJENSIS.newInstance(NormalDimension::class.java))
setFinalField(getField(levelClass, "scoreboard")!!, CLIENT_LEVEL, Scoreboard())
getClass("net.minecraft.world.level.dimension.NormalDimension")?.let {
setFinalField(getField(Level::class.java, "dimension")!!, CLIENT_LEVEL, OBJENSIS.newInstance(it))
}
}
}

View File

@ -12,7 +12,6 @@ import net.minecraft.core.IdMapper
import net.minecraft.core.Registry
import net.minecraft.world.level.block.Block
import net.minecraft.world.level.block.Blocks
import net.minecraft.world.level.block.state.AbstractStateHolder
import net.minecraft.world.level.block.state.BlockState
import net.minecraft.world.level.block.state.StateHolder
import net.minecraft.world.phys.shapes.VoxelShape
@ -44,11 +43,15 @@ object BlockGenerator : Generator(
if (block.friction != 0.6f) {
blockData.addProperty("friction", block.friction)
}
if (block.speedFactor != 1.0f) {
blockData.addProperty("speed_factor", block.speedFactor)
BLOCK_SPEED_FACTOR_FIELD?.getFloat(block)?.let {
if (it != 1.0f) {
blockData.addProperty("speed_factor", it)
}
}
if (block.jumpFactor != 1.0f) {
blockData.addProperty("jump_factor", block.jumpFactor)
BLOCK_JUMP_FACTOR_FIELD?.getFloat(block)?.let {
if (it != 1.0f) {
blockData.addProperty("jump_factor", it)
}
}
blockData.addProperty("default_state", Block.getId(block.defaultBlockState()))
if (block.hasDynamicShape()) {
@ -334,7 +337,7 @@ object BlockGenerator : Generator(
private val BLOCK_STATE_BASE_CLASS = getClass("net.minecraft.world.level.block.state.BlockBehaviour\$BlockStateBase", "net.minecraft.world.level.block.state.BlockState")!!
private val BLOCK_DESTROY_SPEED_FIELD = getField(BLOCK_STATE_BASE_CLASS, "destroySpeed") ?: getField(Block::class.java, "destroySpeed")!!
private val BLOCK_STATE_OWNER_FIELD = getField(StateHolder::class.java, "owner") ?: getField(AbstractStateHolder::class.java, "owner")!!
private val BLOCK_STATE_OWNER_FIELD = getField(StateHolder::class.java, "owner") ?: getField(getClass("net.minecraft.world.level.block.state.AbstractStateHolder"), "owner")!!
private val BLOCK_STATE_CACHE_FIELD = BLOCK_STATE_BASE_CLASS.getDeclaredField("cache")
private val REQUIRES_CORRECT_TOOL_FOR_DROP_FIELDS = getField(BlockState::class.java, "requiresCorrectToolForDrops")
@ -360,6 +363,10 @@ object BlockGenerator : Generator(
private val IS_COLLISION_SHAPE_FULL_BLOCK = BLOCK_STATE_CACHE_CLASS.getDeclaredField("isCollisionShapeFullBlock")
private val BLOCK_SPEED_FACTOR_FIELD = getField(Block::class.java, "speedFactor")
private val BLOCK_JUMP_FACTOR_FIELD = getField(Block::class.java, "jumpFactor")
init {
BLOCK_DESTROY_SPEED_FIELD.isAccessible = true
BLOCK_STATE_CACHE_FIELD.isAccessible = true

View File

@ -5,6 +5,7 @@ import de.bixilon.pixlyzer.EntitySpawner
import de.bixilon.pixlyzer.PixLyzer
import de.bixilon.pixlyzer.generator.Generator
import de.bixilon.pixlyzer.util.ReflectionUtil.getClass
import de.bixilon.pixlyzer.util.ReflectionUtil.getField
import net.minecraft.client.player.AbstractClientPlayer
import net.minecraft.client.player.RemotePlayer
import net.minecraft.core.Registry
@ -168,6 +169,12 @@ object EntityGenerator : Generator(
private fun getAttributes(): Map<String, Attribute> {
val attributeRegistryField = getField(Registry::class.java, "ATTRIBUTE")
val attributeNameField = try {
Attribute::class.java.getMethod("getName")
} catch (exception: NoSuchMethodException) {
null
}
val ret: MutableMap<String, Attribute> = mutableMapOf()
for (field in ATTRIBUTE_CLASS.declaredFields) {
if (field.type != Attribute::class.java) {
@ -177,7 +184,14 @@ object EntityGenerator : Generator(
continue
}
val attribute = field.get(null) as Attribute
ret[attribute.name] = attribute
attributeNameField?.let {
ret[it.invoke(attribute) as String] = attribute
} ?: let {
val registry = attributeRegistryField!!.get(null) as Registry<*>
val method = attributeRegistryField.type.getMethod("getKey", Object::class.java)
ret[method.invoke(registry, attribute).toString()] = attribute
}
}
return ret
}

View File

@ -3,7 +3,10 @@ package de.bixilon.pixlyzer.generator.generators
import com.google.gson.JsonArray
import com.google.gson.JsonObject
import de.bixilon.pixlyzer.generator.Generator
import de.bixilon.pixlyzer.util.ReflectionUtil.getField
import net.minecraft.core.Registry
import net.minecraft.sounds.SoundEvent
import net.minecraft.world.entity.npc.VillagerProfession
object VillagerProfessionGenerator : Generator(
"villager_professions"
@ -38,12 +41,13 @@ object VillagerProfessionGenerator : Generator(
}
}
villagerProfession.workSound?.let {
(WORK_SOUND_PROFESSION?.get(villagerProfession) as SoundEvent?)?.let {
villagerProfessionData.addProperty("work_sound", Registry.SOUND_EVENT.getId(it))
}
data.add(resourceIdentifier.toString(), villagerProfessionData)
}
}
val WORK_SOUND_PROFESSION = getField(VillagerProfession::class.java, "workSound")
}