Skip to content

Commit

Permalink
Merge pull request #683 from fixrtm/fix-picking-machine
Browse files Browse the repository at this point in the history
Fix picking blocks
  • Loading branch information
anatawa12 committed Jul 2, 2023
2 parents 7f941bf + 85a8e78 commit 90cff1b
Show file tree
Hide file tree
Showing 19 changed files with 229 additions and 45 deletions.
9 changes: 9 additions & 0 deletions .patching-mods/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,23 @@ mods:
- jp.ngt.rtm.RTMItem
- jp.ngt.rtm.RTMRecipe
- jp.ngt.rtm.RTMSound
- jp.ngt.rtm.block.BlockCrossingGate
- jp.ngt.rtm.block.BlockDecoration
- jp.ngt.rtm.block.BlockFlag
- jp.ngt.rtm.block.BlockFluorescent
- jp.ngt.rtm.block.BlockLight
- jp.ngt.rtm.block.BlockLinePole
- jp.ngt.rtm.block.BlockMachineBase
- jp.ngt.rtm.block.BlockMechanism
- jp.ngt.rtm.block.BlockPipe
- jp.ngt.rtm.block.BlockPlant
- jp.ngt.rtm.block.BlockPoint
- jp.ngt.rtm.block.BlockRailroadSign
- jp.ngt.rtm.block.BlockScaffold
- jp.ngt.rtm.block.BlockScaffoldStairs
- jp.ngt.rtm.block.BlockSignBoard
- jp.ngt.rtm.block.BlockStation
- jp.ngt.rtm.block.BlockTurnstile
- jp.ngt.rtm.block.tileentity.RenderMachine
- jp.ngt.rtm.block.tileentity.RenderOrnament
- jp.ngt.rtm.block.tileentity.RenderRailroadSign
Expand All @@ -76,6 +84,7 @@ mods:
- jp.ngt.rtm.electric.BlockElectricalWiring
- jp.ngt.rtm.electric.BlockInsulator
- jp.ngt.rtm.electric.BlockSignal
- jp.ngt.rtm.electric.BlockSpeaker
- jp.ngt.rtm.electric.BlockTicketVendor
- jp.ngt.rtm.electric.RenderElectricalWiring
- jp.ngt.rtm.electric.RenderSignal
Expand Down
16 changes: 16 additions & 0 deletions CHANGELOG-SNAPSHOTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ The changelog for 2.0.23 and earlier is generated by [anatawa12's fork of `auto-
- This also reverts `#633` because it's broken for long train
- Slow trains will get too slow `#681`
- Entering world should be prevented while model construction phase `#682`
- Picking block for many blocks broken `#683`
- This also reverts `#667` because it's not efficient implementation
- Picking following blocks, which are categorized to machine, would pick as fluorescent is now fixed
- Boom barrier for Crossing (CROSSING)
- Ticket Gate (TURNSTILE)
- Point Lever (POINT)
- Light (LIGHT, not a FLUORESCENT)
- Speaker (SPEAKER)
- Picking for the following blocks, is now implemented
- Station core block
- Decoration block
- Flags
- Mechanism blocks such as gears
- Picking of the following blocks doesn't pick block model is now fixed
- Ticket vendor
- Rail-road sign

### Security

Expand Down
23 changes: 15 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,27 @@ Thanks to prepare-changelog.sh, we have some macros.
- syncVehicleState(Door, data) does not work as the setter of getVehicleState(Door) `#660`
- Previously, to sync door direction between trains, door bit can be swapped.
- Now, improvements in bits swapping condition is improved.
- Picking any machine block would pick as fluorescent `#667`
- Picking following blocks, which are categorized to machine, would pick as fluorescent is now fixed
- Boom barrier for Crossing (CROSSING)
- Ticket Gate (TURNSTILE)
- Point Lever (POINT)
- Ticket Vendor (TICKET_VENDOR)
- Light (LIGHT, not a FLUORESCENT)
- Speaker (SPEAKER)
- Unnecessary ABI breaking changes `#676`
- we don't need to remove original signature of `RenderElectricalWiring.renderAllWire`
- Directory based ModelPacks not working `#677`
- Getting onto bogie of moving train may drive train opposite direction `#680`
- Slow trains will get too slow `#681`
- Entering world should be prevented while model construction phase `#682`
- Picking block for many blocks broken `#683`
- Picking following blocks, which are categorized to machine, would pick as fluorescent is now fixed
- Boom barrier for Crossing (CROSSING)
- Ticket Gate (TURNSTILE)
- Point Lever (POINT)
- Light (LIGHT, not a FLUORESCENT)
- Speaker (SPEAKER)
- Picking for the following blocks, is now implemented
- Station core block
- Decoration block
- Flags
- Mechanism blocks such as gears
- Picking of the following blocks doesn't pick block model is now fixed
- Ticket vendor
- Rail-road sign

### Security

Expand Down
22 changes: 22 additions & 0 deletions src/main/java/com/anatawa12/fixRtm/rtm/block/BlockDecoration.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/// Copyright (c) 2023 anatawa12 and other contributors
/// This file is part of fixRTM, released under GNU LGPL v3 with few exceptions
/// See LICENSE at https://github.com/fixrtm/fixRTM for more details

package com.anatawa12.fixRtm.rtm.block

import jp.ngt.rtm.RTMItem
import jp.ngt.rtm.block.tileentity.TileEntityDecoration
import jp.ngt.rtm.item.ItemDecoration
import net.minecraft.item.ItemStack
import net.minecraft.util.math.BlockPos
import net.minecraft.world.World

fun getPickBlock(world: World, pos: BlockPos): ItemStack {
val tileEntity = world.getTileEntity(pos)
if (tileEntity is TileEntityDecoration) {
val itemStack = ItemStack(RTMItem.decoration_block)
ItemDecoration.setModel(itemStack, tileEntity.modelName)
return itemStack
}
return ItemStack.EMPTY
}
33 changes: 0 additions & 33 deletions src/main/java/com/anatawa12/fixRtm/rtm/block/BlockMachineBase.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ object BlockOrnamentMain {
@JvmStatic
fun getPickBlock(world: World, pos: BlockPos, type: ItemInstalledObject.IstlObjType): ItemStack {
val tileEntity = world.getTileEntity(pos)
if (tileEntity is TileEntityPlaceable && tileEntity is IResourceSelector<*>) {
if (tileEntity is IResourceSelector<*>) {
val itemStack = ItemStack(RTMItem.installedObject)
itemStack.itemDamage = type.id.toInt()
(RTMItem.installedObject as ItemInstalledObject).setModelState(itemStack, tileEntity.resourceState)

if (GuiScreen.isCtrlKeyDown()) {
if (GuiScreen.isCtrlKeyDown() && tileEntity is TileEntityPlaceable) {
ItemWithModelEx.copyOffsetToItemStack(tileEntity, itemStack)
}
return itemStack
Expand Down
14 changes: 14 additions & 0 deletions src/main/rtm-patches/jp/ngt/rtm/block/BlockCrossingGate.java.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--- a/jp/ngt/rtm/block/BlockCrossingGate.java
+++ b/jp/ngt/rtm/block/BlockCrossingGate.java
@@ -46,6 +46,11 @@

private void checkPower(World world, int x, int y, int z) {
TileEntityCrossingGate tileentitycrossinggate = (TileEntityCrossingGate)BlockUtil.getTileEntity(world, x, y, z);
tileentitycrossinggate.isGettingPower = world.getRedstonePowerFromNeighbors(new BlockPos(x, y, z)) > 0;
}
+
+ @Override
+ public ItemStack getPickBlock(IBlockState state, net.minecraft.util.math.RayTraceResult target, World world, BlockPos pos, net.minecraft.entity.player.EntityPlayer player) {
+ return com.anatawa12.fixRtm.rtm.block.BlockOrnamentMain.getPickBlock(world, pos, ItemInstalledObject.IstlObjType.CROSSING);
+ }
}
13 changes: 13 additions & 0 deletions src/main/rtm-patches/jp/ngt/rtm/block/BlockDecoration.java.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--- a/jp/ngt/rtm/block/BlockDecoration.java
+++ b/jp/ngt/rtm/block/BlockDecoration.java
@@ -12,6 +12,10 @@
}

public TileEntity createNewTileEntity(World world, int meta) {
return new TileEntityDecoration();
}
+
+ public net.minecraft.item.ItemStack getPickBlock(net.minecraft.block.state.IBlockState state, net.minecraft.util.math.RayTraceResult target, World world, net.minecraft.util.math.BlockPos pos, net.minecraft.entity.player.EntityPlayer player) {
+ return com.anatawa12.fixRtm.rtm.block.BlockDecorationKt.getPickBlock(world, pos);
+ }
}
14 changes: 14 additions & 0 deletions src/main/rtm-patches/jp/ngt/rtm/block/BlockFlag.java.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--- a/jp/ngt/rtm/block/BlockFlag.java
+++ b/jp/ngt/rtm/block/BlockFlag.java
@@ -31,6 +31,11 @@
entityplayer.openGui(RTMCore.instance, RTMCore.guiIdSelectTileEntityTexture, holder.getWorld(), i, j, k);
}

return true;
}
+
+ @Override
+ public net.minecraft.item.ItemStack getPickBlock(net.minecraft.block.state.IBlockState state, net.minecraft.util.math.RayTraceResult target, World world, net.minecraft.util.math.BlockPos pos, EntityPlayer player) {
+ return com.anatawa12.fixRtm.rtm.block.BlockOrnamentMain.getPickBlock(world, pos, jp.ngt.rtm.item.ItemInstalledObject.IstlObjType.FLAG);
+ }
}
14 changes: 14 additions & 0 deletions src/main/rtm-patches/jp/ngt/rtm/block/BlockLight.java.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--- a/jp/ngt/rtm/block/BlockLight.java
+++ b/jp/ngt/rtm/block/BlockLight.java
@@ -30,6 +30,11 @@
return super.removedByPlayer(holder, willHarvest);
} else {
return PermissionManager.INSTANCE.hasPermission(holder.getPlayer(), "editOrnament") ? super.removedByPlayer(holder, willHarvest) : false;
}
}
+
+ @Override
+ public ItemStack getPickBlock(net.minecraft.block.state.IBlockState state, net.minecraft.util.math.RayTraceResult target, World world, net.minecraft.util.math.BlockPos pos, net.minecraft.entity.player.EntityPlayer player) {
+ return com.anatawa12.fixRtm.rtm.block.BlockOrnamentMain.getPickBlock(world, pos, ItemInstalledObject.IstlObjType.LIGHT);
+ }
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@
+
+ @Override
+ public net.minecraft.item.ItemStack getPickBlock(net.minecraft.block.state.IBlockState state, net.minecraft.util.math.RayTraceResult target, World world, net.minecraft.util.math.BlockPos pos, net.minecraft.entity.player.EntityPlayer player) {
+ return com.anatawa12.fixRtm.rtm.block.BlockMachineBase.getPickBlock(world, pos);
+ return com.anatawa12.fixRtm.rtm.block.BlockOrnamentMain.getPickBlock(world, pos, jp.ngt.rtm.item.ItemInstalledObject.IstlObjType.FLUORESCENT);
+ }
}
14 changes: 14 additions & 0 deletions src/main/rtm-patches/jp/ngt/rtm/block/BlockMechanism.java.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--- a/jp/ngt/rtm/block/BlockMechanism.java
+++ b/jp/ngt/rtm/block/BlockMechanism.java
@@ -29,6 +29,11 @@
return true;
} else {
return false;
}
}
+
+ @Override
+ public net.minecraft.item.ItemStack getPickBlock(net.minecraft.block.state.IBlockState state, net.minecraft.util.math.RayTraceResult target, World world, net.minecraft.util.math.BlockPos pos, net.minecraft.entity.player.EntityPlayer player) {
+ return com.anatawa12.fixRtm.rtm.block.BlockOrnamentMain.getPickBlock(world, pos, jp.ngt.rtm.item.ItemInstalledObject.IstlObjType.MECHANISM);
+ }
}
14 changes: 14 additions & 0 deletions src/main/rtm-patches/jp/ngt/rtm/block/BlockPoint.java.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--- a/jp/ngt/rtm/block/BlockPoint.java
+++ b/jp/ngt/rtm/block/BlockPoint.java
@@ -65,6 +65,11 @@
}

public boolean canProvidePower(IBlockState state) {
return true;
}
+
+ @Override
+ public net.minecraft.item.ItemStack getPickBlock(IBlockState state, net.minecraft.util.math.RayTraceResult target, World world, BlockPos pos, EntityPlayer player) {
+ return com.anatawa12.fixRtm.rtm.block.BlockOrnamentMain.getPickBlock(world, pos, jp.ngt.rtm.item.ItemInstalledObject.IstlObjType.POINT);
+ }
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--- a/jp/ngt/rtm/block/BlockRailroadSign.java
+++ b/jp/ngt/rtm/block/BlockRailroadSign.java
@@ -38,10 +38,14 @@
@@ -38,15 +38,20 @@
int i = holder.getBlockPos().getX();
int j = holder.getBlockPos().getY();
int k = holder.getBlockPos().getZ();
Expand All @@ -15,3 +15,11 @@

return true;
}

- protected ItemStack getItem(int damage) {
- return new ItemStack(RTMItem.installedObject, 1, ItemInstalledObject.IstlObjType.RAILLOAD_SIGN.id);
+ @Override
+ public ItemStack getPickBlock(IBlockState state, net.minecraft.util.math.RayTraceResult target, World world, BlockPos pos, EntityPlayer player) {
+ return com.anatawa12.fixRtm.rtm.block.BlockOrnamentMain.getPickBlock(world, pos, ItemInstalledObject.IstlObjType.RAILLOAD_SIGN);
}
}
14 changes: 14 additions & 0 deletions src/main/rtm-patches/jp/ngt/rtm/block/BlockStation.java.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--- a/jp/ngt/rtm/block/BlockStation.java
+++ b/jp/ngt/rtm/block/BlockStation.java
@@ -56,6 +56,11 @@
int j = pos.getY();
int k = pos.getZ();
}

}
+
+ @Override
+ protected net.minecraft.item.ItemStack getItem(int damage) {
+ return new net.minecraft.item.ItemStack(this);
+ }
}
14 changes: 14 additions & 0 deletions src/main/rtm-patches/jp/ngt/rtm/block/BlockTurnstile.java.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--- a/jp/ngt/rtm/block/BlockTurnstile.java
+++ b/jp/ngt/rtm/block/BlockTurnstile.java
@@ -113,6 +113,11 @@
}

public PathNodeType getAiPathNodeType(IBlockState state, IBlockAccess world, BlockPos pos) {
return canThrough(world, pos) ? PathNodeType.OPEN : PathNodeType.BLOCKED;
}
+
+ @Override
+ public ItemStack getPickBlock(IBlockState state, net.minecraft.util.math.RayTraceResult target, World world, BlockPos pos, EntityPlayer player) {
+ return com.anatawa12.fixRtm.rtm.block.BlockOrnamentMain.getPickBlock(world, pos, ItemInstalledObject.IstlObjType.TURNSTILE);
+ }
}
14 changes: 14 additions & 0 deletions src/main/rtm-patches/jp/ngt/rtm/electric/BlockSpeaker.java.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--- a/jp/ngt/rtm/electric/BlockSpeaker.java
+++ b/jp/ngt/rtm/electric/BlockSpeaker.java
@@ -45,6 +45,11 @@
}

public boolean canConnect(World world, int x, int y, int z) {
return true;
}
+
+ @Override
+ public ItemStack getPickBlock(net.minecraft.block.state.IBlockState state, net.minecraft.util.math.RayTraceResult target, World world, BlockPos pos, EntityPlayer player) {
+ return com.anatawa12.fixRtm.rtm.block.BlockOrnamentMain.getPickBlock(world, pos, ItemInstalledObject.IstlObjType.SPEAKER);
+ }
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,13 @@

public void dropBlockAsItemWithChance(World world, BlockPos pos, IBlockState state, float chance, int fortune) {
if (!world.isRemote) {
@@ -49,8 +51,8 @@
}

}

public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player) {
- return new ItemStack(RTMItem.installedObject, 1, ItemInstalledObject.IstlObjType.TICKET_VENDOR.id);
+ return com.anatawa12.fixRtm.rtm.block.BlockOrnamentMain.getPickBlock(world, pos, ItemInstalledObject.IstlObjType.TICKET_VENDOR);
}
}
20 changes: 20 additions & 0 deletions src/main/rtm-patches/jp/ngt/rtm/rail/BlockMarker.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,23 @@
BlockUtil.setBlock(world, i, j, k, RTMRail.TURNTABLE_CORE, 0, 3);
TileEntityTurnTableCore tileentityturntablecore = (TileEntityTurnTableCore)BlockUtil.getTileEntity(world, i, j, k);
tileentityturntablecore.setRailPositions(new RailPosition[]{start, end});
@@ -379,10 +401,19 @@

return null;
}
}

+ @Override
+ protected ItemStack getItem(int damage) {
+ if (com.anatawa12.fixRtm.asm.config.MainConfig.mergeMarker) {
+ return new ItemStack(this, 1, 8);
+ } else {
+ return new ItemStack(this, 1, damage & 4);
+ }
+ }
+
public static enum MarkerType {
STANDARD(16711680),
SWITCH(255);

public final int color;

0 comments on commit 90cff1b

Please sign in to comment.