Skip to content

Commit

Permalink
Merge pull request #247 from fixrtm/kaiz-patch-1.2
Browse files Browse the repository at this point in the history
port Kaiz patch 1.2
  • Loading branch information
anatawa12 authored Jul 9, 2021
2 parents df57e68 + caa1fab commit 8c978c9
Show file tree
Hide file tree
Showing 24 changed files with 699 additions and 15 deletions.
1 change: 1 addition & 0 deletions .patching-mods/ngtlib.patching-mod/modified-classes.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
jp.ngt.ngtlib.NGTCore
jp.ngt.ngtlib.block.TileEntityPlaceable
jp.ngt.ngtlib.command.CommandPermit
jp.ngt.ngtlib.io.NGTFileLoader
jp.ngt.ngtlib.io.NGTLog
Expand Down
9 changes: 9 additions & 0 deletions .patching-mods/rtm.patching-mod/modified-classes.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
jp.ngt.rtm.CreativeTabRTM
jp.ngt.rtm.RTMItem
jp.ngt.rtm.RTMRecipe
jp.ngt.rtm.block.BlockMachineBase
jp.ngt.rtm.block.tileentity.RenderMachine
jp.ngt.rtm.block.tileentity.TileEntityCrossingGate
jp.ngt.rtm.block.tileentity.TileEntityMachineBase
jp.ngt.rtm.block.tileentity.TileEntityMechanism
jp.ngt.rtm.block.tileentity.TileEntityOrnament
jp.ngt.rtm.block.tileentity.TileEntityPoint
jp.ngt.rtm.block.tileentity.TileEntityTrainWorkBench
jp.ngt.rtm.command.CommandRTM
jp.ngt.rtm.electric.TileEntityConnectorBase
jp.ngt.rtm.electric.TileEntityElectricalWiring
Expand Down Expand Up @@ -42,6 +47,10 @@ jp.ngt.rtm.modelpack.state.ResourceState
jp.ngt.rtm.rail.BlockLargeRailBase
jp.ngt.rtm.rail.BlockMarker
jp.ngt.rtm.rail.RenderMarkerBlock
jp.ngt.rtm.rail.RenderTurntable
jp.ngt.rtm.rail.TileEntityMarker
jp.ngt.rtm.rail.TileEntityTurnTableCore
jp.ngt.rtm.rail.util.MarkerState
jp.ngt.rtm.rail.util.RailMaker
jp.ngt.rtm.rail.util.SwitchType
jp.ngt.rtm.render.ModelObject
Expand Down
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ dependencies {
shade("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.1.0")
shade("io.sigpipe:jbsdiff:1.0")
shade("com.anatawa12.sai:sai:0.0.2")
shade("org.jetbrains:annotations:21.0.1")

compileOnly(files(file("run/fixrtm-cache/script-compiled-class")))
// compileOnly(files(projectDir.resolve("mods/rtm.deobf.jar"),
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/anatawa12/fixRtm/FixRtm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.anatawa12.fixRtm.asm.config.MainConfig
import com.anatawa12.fixRtm.asm.config.MainConfig.changeTestTrainTextureEnabled
import com.anatawa12.fixRtm.crash.RTMAllModelPackInfoCrashCallable
import com.anatawa12.fixRtm.crash.RTMSmallModelPackInfoCrashCallable
import com.anatawa12.fixRtm.gui.GuiHandler
import com.anatawa12.fixRtm.io.FIXFileLoader
import com.anatawa12.fixRtm.network.NetworkHandler
import com.anatawa12.fixRtm.rtm.modelpack.modelset.dummies.*
Expand Down Expand Up @@ -37,7 +38,7 @@ import net.minecraftforge.fml.common.event.FMLPreInitializationEvent
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import net.minecraftforge.fml.common.gameevent.PlayerEvent
import net.minecraftforge.fml.common.gameevent.TickEvent
import net.minecraftforge.fml.common.network.NetworkCheckHandler
import net.minecraftforge.fml.common.network.NetworkRegistry
import net.minecraftforge.fml.relauncher.Side
import paulscode.sound.SoundSystemConfig
import java.awt.Color
Expand Down Expand Up @@ -106,6 +107,7 @@ object FixRtm {
modMetadata = e.modMetadata
NetworkHandler.init()
PermissionManager.registerBuiltinPermissions()
NetworkRegistry.INSTANCE.registerGuiHandler(this, GuiHandler())

if (e.side == Side.CLIENT) {
SoundSystemConfig.setNumberNormalChannels(1024)
Expand Down
47 changes: 47 additions & 0 deletions src/main/java/com/anatawa12/fixRtm/KeyboardUtil.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.anatawa12.fixRtm

import org.lwjgl.input.Keyboard

object KeyboardUtil {
fun isIntegerKey(par: Int): Boolean {
return when (par) {
Keyboard.KEY_1,
Keyboard.KEY_2,
Keyboard.KEY_3,
Keyboard.KEY_4,
Keyboard.KEY_5,
Keyboard.KEY_6,
Keyboard.KEY_7,
Keyboard.KEY_8,
Keyboard.KEY_9,
Keyboard.KEY_0,

Keyboard.KEY_NUMPAD1,
Keyboard.KEY_NUMPAD2,
Keyboard.KEY_NUMPAD3,
Keyboard.KEY_NUMPAD4,
Keyboard.KEY_NUMPAD5,
Keyboard.KEY_NUMPAD6,
Keyboard.KEY_NUMPAD7,
Keyboard.KEY_NUMPAD8,
Keyboard.KEY_NUMPAD9,
Keyboard.KEY_NUMPAD0,

Keyboard.KEY_UP,
Keyboard.KEY_PRIOR,
Keyboard.KEY_LEFT,
Keyboard.KEY_RIGHT,

Keyboard.KEY_MINUS,
Keyboard.KEY_SUBTRACT,
Keyboard.KEY_BACK,
Keyboard.KEY_DELETE,
-> true
else -> false
}
}

fun isDecimalNumberKey(par: Int): Boolean {
return isIntegerKey(par) || par == Keyboard.KEY_PERIOD || par == Keyboard.KEY_DECIMAL
}
}
16 changes: 16 additions & 0 deletions src/main/java/com/anatawa12/fixRtm/Utils.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
package com.anatawa12.fixRtm

import com.anatawa12.fixRtm.gui.GuiId
import com.anatawa12.fixRtm.utils.ArrayPool
import com.anatawa12.fixRtm.utils.closeScope
import com.anatawa12.fixRtm.utils.sortedWalk
import com.google.common.collect.Iterators
import jp.ngt.rtm.RTMItem
import jp.ngt.rtm.block.tileentity.TileEntityMachineBase
import jp.ngt.rtm.item.ItemInstalledObject
import jp.ngt.rtm.modelpack.cfg.ResourceConfig
import net.minecraft.crash.CrashReportCategory
import net.minecraft.entity.Entity
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.entity.player.EntityPlayerMP
import net.minecraft.item.ItemStack
import net.minecraft.util.math.RayTraceResult
import net.minecraft.world.World
import net.minecraftforge.fml.common.Loader
import net.minecraftforge.fml.common.network.handshake.NetworkDispatcher
import java.io.*
Expand Down Expand Up @@ -226,3 +232,13 @@ fun joinLinesForJsonReading(lines: List<String>): String = buildString {
shouldAddNewLine = true
}
}

fun ItemStack.isItemOf(machine: TileEntityMachineBase): Boolean {
if (this.item !== RTMItem.installedObject) return false
val type = ItemInstalledObject.IstlObjType.getType(this.itemDamage)
return type.type == machine.subType
}

fun EntityPlayer.openGui(fixGuiId: GuiId, world: World, x: Int, y: Int, z: Int) {
openGui(FixRtm, fixGuiId.ordinal, world, x, y, z)
}
72 changes: 72 additions & 0 deletions src/main/java/com/anatawa12/fixRtm/gui/GuiChangeOffset.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.anatawa12.fixRtm.gui

import com.anatawa12.fixRtm.KeyboardUtil
import jp.ngt.ngtlib.block.TileEntityPlaceable
import jp.ngt.ngtlib.gui.GuiScreenCustom
import jp.ngt.ngtlib.gui.GuiTextFieldCustom
import jp.ngt.ngtlib.network.PacketNBT
import net.minecraft.client.gui.GuiButton
import net.minecraft.client.resources.I18n
import org.lwjgl.input.Keyboard

class GuiChangeOffset(private var tileEntity: TileEntityPlaceable) : GuiScreenCustom() {
private lateinit var fieldOffsetX: GuiTextFieldCustom
private lateinit var fieldOffsetY: GuiTextFieldCustom
private lateinit var fieldOffsetZ: GuiTextFieldCustom
private lateinit var fieldRotationYaw: GuiTextFieldCustom

override fun initGui() {
super.initGui()
buttonList.clear()
buttonList.add(GuiButton(0, width / 2 - 105, height - 28, 100, 20, I18n.format("gui.done")))
buttonList.add(GuiButton(1, width / 2 + 5, height - 28, 100, 20, I18n.format("gui.cancel")))
fieldOffsetX = setTextField(width - 70, 20, 60, 20, tileEntity.offsetX.toString())
fieldOffsetY = setTextField(width - 70, 50, 60, 20, tileEntity.offsetY.toString())
fieldOffsetZ = setTextField(width - 70, 80, 60, 20, tileEntity.offsetZ.toString())
fieldRotationYaw = setTextField(width - 70, 110, 60, 20, tileEntity.rotation.toString())
}

override fun drawScreen(par1: Int, par2: Int, par3: Float) {
drawDefaultBackground()
super.drawScreen(par1, par2, par3)
drawCenteredString(this.fontRenderer, "Offset X", width - 70, 10, 0xFFFFFF)
drawCenteredString(this.fontRenderer, "Offset Y", width - 70, 40, 0xFFFFFF)
drawCenteredString(this.fontRenderer, "Offset Z", width - 70, 70, 0xFFFFFF)
drawCenteredString(this.fontRenderer, "Rotation Yaw", width - 70, 100, 0xFFFFFF)
}

override fun actionPerformed(button: GuiButton) {
if (button.id == 0) {
mc.displayGuiScreen(null)
sendPacket()
} else if (button.id == 1) {
mc.displayGuiScreen(null)
}
super.actionPerformed(button)
}

override fun keyTyped(par1: Char, par2: Int) {
if (par2 == Keyboard.KEY_ESCAPE || par2 == mc.gameSettings.keyBindInventory.keyCode) {
mc.player.closeScreen()
}
if (currentTextField != null) {
if (KeyboardUtil.isDecimalNumberKey(par2)) {
currentTextField.textboxKeyTyped(par1, par2)
}
}
}

private fun updateValues() {
val offsetX: Float = fieldOffsetX.text.toFloatOrNull() ?: tileEntity.offsetX
val offsetY: Float = fieldOffsetY.text.toFloatOrNull() ?: tileEntity.offsetY
val offsetZ: Float = fieldOffsetZ.text.toFloatOrNull() ?: tileEntity.offsetZ
val rotation: Float = fieldRotationYaw.text.toFloatOrNull() ?: tileEntity.rotation
tileEntity.setOffset(offsetX, offsetY, offsetZ, false)
tileEntity.setRotation(rotation, false)
}

private fun sendPacket() {
updateValues()
PacketNBT.sendToServer(tileEntity)
}
}
23 changes: 23 additions & 0 deletions src/main/java/com/anatawa12/fixRtm/gui/GuiHandler.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.anatawa12.fixRtm.gui

import com.anatawa12.fixRtm.gui.GuiId.ChangeOffset
import com.anatawa12.fixRtm.gui.GuiId.values
import jp.ngt.ngtlib.block.TileEntityPlaceable
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.util.math.BlockPos
import net.minecraft.world.World
import net.minecraftforge.fml.common.network.IGuiHandler

class GuiHandler : IGuiHandler {
override fun getServerGuiElement(ID: Int, player: EntityPlayer?, world: World?, x: Int, y: Int, z: Int): Any? {
return when (values()[ID]) {
ChangeOffset -> null
}
}

override fun getClientGuiElement(ID: Int, player: EntityPlayer?, world: World?, x: Int, y: Int, z: Int): Any? {
return when (values()[ID]) {
ChangeOffset -> GuiChangeOffset(world!!.getTileEntity(BlockPos(x, y, z)) as TileEntityPlaceable)
}
}
}
5 changes: 5 additions & 0 deletions src/main/java/com/anatawa12/fixRtm/gui/GuiId.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.anatawa12.fixRtm.gui

enum class GuiId {
ChangeOffset,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
--- a/jp/ngt/ngtlib/block/TileEntityPlaceable.java
+++ b/jp/ngt/ngtlib/block/TileEntityPlaceable.java
@@ -4,10 +4,11 @@
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;

public abstract class TileEntityPlaceable extends TileEntityCustom {
private float rotation;
+ private float offsetX, offsetY, offsetZ;

public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt);
this.setRotation(nbt.getFloat("Yaw"), false);
}
@@ -33,6 +34,28 @@

public void setRotation(EntityPlayer player, float rotationInterval, boolean synch) {
int i = NGTMath.floor(NGTMath.normalizeAngle((double)(-player.rotationYaw) + 180.0D + (double)rotationInterval / 2.0D) / (double)rotationInterval);
this.setRotation((float)i * rotationInterval, synch);
}
+
+ public float getOffsetX() {
+ return offsetX;
+ }
+
+ public float getOffsetY() {
+ return offsetY;
+ }
+
+ public float getOffsetZ() {
+ return offsetZ;
+ }
+
+ public void setOffset(float offsetX, float offsetY, float offsetZ, boolean sync) {
+ this.offsetX = offsetX;
+ this.offsetY = offsetY;
+ this.offsetZ = offsetZ;
+ if (sync) {
+ this.getUpdatePacket();
+ this.markDirty();
+ }
+ }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
--- a/jp/ngt/rtm/block/BlockMachineBase.java
+++ b/jp/ngt/rtm/block/BlockMachineBase.java
@@ -22,10 +22,26 @@
this.clickMachine(holder.getWorld(), holder.getBlockPos().getX(), holder.getBlockPos().getY(), holder.getBlockPos().getZ(), holder.getPlayer());
return true;
}

protected boolean clickMachine(World world, int x, int y, int z, EntityPlayer player) {
+ if (world.isRemote) {
+ if (jp.ngt.ngtlib.util.NGTUtil.isEquippedItem(player, jp.ngt.rtm.RTMItem.installedObject)) {
+ net.minecraft.item.ItemStack itemStack = player.inventory.getCurrentItem();
+ TileEntityMachineBase machine = (TileEntityMachineBase) world.getTileEntity(new BlockPos(x, y, z));
+ assert machine != null;
+ if (com.anatawa12.fixRtm.UtilsKt.isItemOf(itemStack, machine)) {
+ com.anatawa12.fixRtm.UtilsKt.openGui(player, com.anatawa12.fixRtm.gui.GuiId.ChangeOffset, player.world, x, y, z);
+ return true;
+ }
+ }
+
+ if (player.isSneaking()) {
+ player.openGui(RTMCore.instance, RTMCore.guiIdSelectTileEntityModel, player.world, x, y, z);
+ return true;
+ }
+ }
if (player.isSneaking()) {
if (world.isRemote) {
player.openGui(RTMCore.instance, RTMCore.guiIdSelectTileEntityModel, player.getEntityWorld(), x, y, z);
}

@@ -33,12 +49,15 @@
} else {
return false;
}
}

+ @Deprecated
public int getLightValue(IBlockState state, IBlockAccess world, BlockPos pos) {
- TileEntityMachineBase tileentitymachinebase = (TileEntityMachineBase)world.getTileEntity(pos);
+ net.minecraft.tileentity.TileEntity tile = world.getTileEntity(pos);
+ if (!(tile instanceof TileEntityMachineBase)) return super.getLightValue(state);
+ TileEntityMachineBase tileentitymachinebase = (TileEntityMachineBase)tile;
if (tileentitymachinebase == null) {
return 0;
} else {
MachineConfig machineconfig = (MachineConfig)((ModelSetMachine)tileentitymachinebase.getResourceState().getResourceSet()).getConfig();
return tileentitymachinebase.isGettingPower ? machineconfig.brightness[1] : machineconfig.brightness[0];
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--- a/jp/ngt/rtm/block/tileentity/RenderMachine.java
+++ b/jp/ngt/rtm/block/tileentity/RenderMachine.java
@@ -15,10 +15,11 @@
private void renderMachine(TileEntityMachineBase par1, double par2, double par4, double par6, float par8) {
GL11.glPushMatrix();
GL11.glEnable(32826);
GL11.glTranslatef((float)par2 + 0.5F, (float)par4, (float)par6 + 0.5F);
GL11.glTranslatef(0.0F, 0.5F, 0.0F);
+ GL11.glTranslatef(par1.getOffsetX(), par1.getOffsetY(), par1.getOffsetZ());
ModelSetMachine modelsetmachine = (ModelSetMachine)par1.getResourceState().getResourceSet();
MachineConfig machineconfig = (MachineConfig)modelsetmachine.getConfig();
if (machineconfig.rotateByMetadata) {
switch(par1.getBlockMetadata()) {
case 0:
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--- a/jp/ngt/rtm/block/tileentity/TileEntityCrossingGate.java
+++ b/jp/ngt/rtm/block/tileentity/TileEntityCrossingGate.java
@@ -66,13 +66,14 @@

@SideOnly(Side.CLIENT)
public AxisAlignedBB getRenderBoundingBox() {
float[] afloat = ((MachineConfig)((ModelSetMachine)this.getResourceState().getResourceSet()).getConfig()).renderAABB;
BlockPos blockpos = this.getPos();
- AxisAlignedBB axisalignedbb = new AxisAlignedBB((double)((float)blockpos.getX() + afloat[0]), (double)((float)blockpos.getY() + afloat[1]), (double)((float)blockpos.getZ() + afloat[2]), (double)((float)blockpos.getX() + afloat[3]), (double)((float)blockpos.getY() + afloat[4]), (double)((float)blockpos.getZ() + afloat[5]));
+ AxisAlignedBB axisalignedbb = new AxisAlignedBB((double)((float)blockpos.getX() + afloat[0]), (double)((float)blockpos.getY() + afloat[1]), (double)((float)blockpos.getZ() + afloat[2]), (double)((float)blockpos.getX() + afloat[3]), (double)((float)blockpos.getY() + afloat[4]), (double)((float)blockpos.getZ() + afloat[5]))
+ .offset(getOffsetX(), getOffsetY(), getOffsetZ());
return axisalignedbb;
}

- protected ResourceType getSubType() {
+ public ResourceType getSubType() {
return RTMResource.MACHINE_GATE;
}
}
Loading

0 comments on commit 8c978c9

Please sign in to comment.