mirror of
				https://github.com/SquidDev-CC/CC-Tweaked
				synced 2025-10-30 21:23:00 +00:00 
			
		
		
		
	Handle tile entity changes
This commit is contained in:
		| @@ -46,7 +46,7 @@ public abstract class BlockGeneric extends Block implements | |||||||
|     public final void dropBlockAsItemWithChance( World world, BlockPos pos, IBlockState state, float chance, int fortune ) |     public final void dropBlockAsItemWithChance( World world, BlockPos pos, IBlockState state, float chance, int fortune ) | ||||||
|     { |     { | ||||||
|     } |     } | ||||||
|          |  | ||||||
|     @Override |     @Override | ||||||
|     public final List<ItemStack> getDrops( IBlockAccess world, BlockPos pos, IBlockState state, int fortune ) |     public final List<ItemStack> getDrops( IBlockAccess world, BlockPos pos, IBlockState state, int fortune ) | ||||||
|     { |     { | ||||||
| @@ -107,7 +107,7 @@ public abstract class BlockGeneric extends Block implements | |||||||
|     { |     { | ||||||
|         Block.spawnAsEntity( world, pos, stack ); |         Block.spawnAsEntity( world, pos, stack ); | ||||||
|     } |     } | ||||||
|      |  | ||||||
|     @Override |     @Override | ||||||
|     public final void breakBlock( World world, BlockPos pos, IBlockState newState ) |     public final void breakBlock( World world, BlockPos pos, IBlockState newState ) | ||||||
|     { |     { | ||||||
| @@ -162,6 +162,17 @@ public abstract class BlockGeneric extends Block implements | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public final void onNeighborChange( IBlockAccess world, BlockPos pos, BlockPos neighbour ) | ||||||
|  |     { | ||||||
|  |         TileEntity tile = world.getTileEntity( pos ); | ||||||
|  |         if( tile instanceof TileGeneric ) | ||||||
|  |         { | ||||||
|  |             TileGeneric generic = (TileGeneric)tile; | ||||||
|  |             generic.onNeighbourTileEntityChange( neighbour ); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public final boolean isSideSolid( IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing side ) |     public final boolean isSideSolid( IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing side ) | ||||||
|     { |     { | ||||||
|   | |||||||
| @@ -95,6 +95,10 @@ public abstract class TileGeneric extends TileEntity | |||||||
|     { |     { | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     public void onNeighbourTileEntityChange( BlockPos neighbour ) | ||||||
|  |     { | ||||||
|  |     } | ||||||
|  |  | ||||||
|     public boolean isSolidOnSide( int side ) |     public boolean isSolidOnSide( int side ) | ||||||
|     { |     { | ||||||
|         return true; |         return true; | ||||||
|   | |||||||
| @@ -196,6 +196,12 @@ public abstract class TileComputerBase extends TileGeneric | |||||||
|         updateInput(); |         updateInput(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public void onNeighbourTileEntityChange( BlockPos neighbour ) | ||||||
|  |     { | ||||||
|  |         updateInput( neighbour ); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public void update() |     public void update() | ||||||
|     { |     { | ||||||
| @@ -307,6 +313,21 @@ public abstract class TileComputerBase extends TileGeneric | |||||||
|         return localSide; |         return localSide; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     private void updateSideInput( ServerComputer computer, EnumFacing dir, BlockPos offset ) | ||||||
|  |     { | ||||||
|  |         EnumFacing offsetSide = dir.getOpposite(); | ||||||
|  |         int localDir = remapLocalSide( DirectionUtil.toLocal( this, dir ) ); | ||||||
|  |         if( !isRedstoneBlockedOnSide( localDir ) ) | ||||||
|  |         { | ||||||
|  |             computer.setRedstoneInput( localDir, RedstoneUtil.getRedstoneOutput( worldObj, offset, offsetSide ) ); | ||||||
|  |             computer.setBundledRedstoneInput( localDir, RedstoneUtil.getBundledRedstoneOutput( worldObj, offset, offsetSide ) ); | ||||||
|  |         } | ||||||
|  |         if( !isPeripheralBlockedOnSide( localDir ) ) | ||||||
|  |         { | ||||||
|  |             computer.setPeripheral( localDir, PeripheralUtil.getPeripheral( worldObj, offset, offsetSide ) ); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|     public void updateInput() |     public void updateInput() | ||||||
|     { |     { | ||||||
|         if( worldObj == null || worldObj.isRemote ) |         if( worldObj == null || worldObj.isRemote ) | ||||||
| @@ -315,6 +336,24 @@ public abstract class TileComputerBase extends TileGeneric | |||||||
|         } |         } | ||||||
|  |  | ||||||
|         // Update redstone and peripherals |         // Update redstone and peripherals | ||||||
|  |         ServerComputer computer = getServerComputer(); | ||||||
|  |         if( computer != null ) | ||||||
|  |         { | ||||||
|  |             BlockPos pos = computer.getPosition(); | ||||||
|  |             for( EnumFacing dir : EnumFacing.VALUES ) | ||||||
|  |             { | ||||||
|  |                 updateSideInput( computer, dir, pos.offset( dir ) ); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public void updateInput( BlockPos neighbour ) | ||||||
|  |     { | ||||||
|  |         if( worldObj == null || worldObj.isRemote ) | ||||||
|  |         { | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  |  | ||||||
|         ServerComputer computer = getServerComputer(); |         ServerComputer computer = getServerComputer(); | ||||||
|         if( computer != null ) |         if( computer != null ) | ||||||
|         { |         { | ||||||
| @@ -322,16 +361,10 @@ public abstract class TileComputerBase extends TileGeneric | |||||||
|             for( EnumFacing dir : EnumFacing.VALUES ) |             for( EnumFacing dir : EnumFacing.VALUES ) | ||||||
|             { |             { | ||||||
|                 BlockPos offset = pos.offset( dir ); |                 BlockPos offset = pos.offset( dir ); | ||||||
|                 EnumFacing offsetSide = dir.getOpposite(); |                 if ( offset.equals( neighbour ) ) | ||||||
|                 int localDir = remapLocalSide( DirectionUtil.toLocal( this, dir ) ); |  | ||||||
|                 if( !isRedstoneBlockedOnSide( localDir ) ) |  | ||||||
|                 { |                 { | ||||||
|                     computer.setRedstoneInput( localDir, RedstoneUtil.getRedstoneOutput( worldObj, offset, offsetSide ) ); |                     updateSideInput( computer, dir, offset ); | ||||||
|                     computer.setBundledRedstoneInput( localDir, RedstoneUtil.getBundledRedstoneOutput( worldObj, offset, offsetSide ) ); |                     break; | ||||||
|                 } |  | ||||||
|                 if( !isPeripheralBlockedOnSide( localDir ) ) |  | ||||||
|                 { |  | ||||||
|                     computer.setPeripheral( localDir, PeripheralUtil.getPeripheral( worldObj, offset, offsetSide ) ); |  | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Bartek Bok
					Bartek Bok