From 104ed78b0d30762098d799b6c1e3994fa43a454c Mon Sep 17 00:00:00 2001
From: NeunEinser <daniel30797@gmail.com>
Date: Fri, 18 Oct 2019 01:53:36 +0200
Subject: Replaced block entity with state in comparator

---
 .../block/AbstractRedstoneGateBlock.java      | 69 ++++--------------
 src/net/minecraft/block/ComparatorBlock.java  | 57 ++++-----------
 src/net/minecraft/block/RepeaterBlock.java    | 72 +++++++++++++++----
 3 files changed, 82 insertions(+), 116 deletions(-)

diff --git a/src/net/minecraft/block/AbstractRedstoneGateBlock.java b/src/net/minecraft/block/AbstractRedstoneGateBlock.java
index 3f7aaa1..70ab0f7 100644
--- a/src/net/minecraft/block/AbstractRedstoneGateBlock.java
+++ b/src/net/minecraft/block/AbstractRedstoneGateBlock.java
@@ -3,27 +3,22 @@
 // 
 
 package net.minecraft.block;
-
-import net.minecraft.state.property.Properties;
-import net.minecraft.item.ItemStack;
-import net.minecraft.entity.LivingEntity;
-import net.minecraft.item.ItemPlacementContext;
+	
 import net.minecraft.block.entity.BlockEntity;
-import net.minecraft.util.math.Direction;
-import net.minecraft.util.TaskPriority;
-import java.util.Random;
-import net.minecraft.world.World;
-import net.minecraft.world.ViewableWorld;
 import net.minecraft.entity.EntityContext;
+import net.minecraft.entity.LivingEntity;
+import net.minecraft.item.ItemPlacementContext;
+import net.minecraft.item.ItemStack;
 import net.minecraft.util.math.BlockPos;
-import net.minecraft.world.BlockView;
-import net.minecraft.state.property.BooleanProperty;
+import net.minecraft.util.math.Direction;
 import net.minecraft.util.shape.VoxelShape;
-
+import net.minecraft.world.BlockView;
+import net.minecraft.world.ViewableWorld;
+import net.minecraft.world.World;
+	
 public abstract class AbstractRedstoneGateBlock extends HorizontalFacingBlock
 {
 	protected static final VoxelShape SHAPE;
-	public static final BooleanProperty POWERED;
 	
 	protected AbstractRedstoneGateBlock(final Settings settings) {
 		super(settings);
@@ -39,23 +34,6 @@ public abstract class AbstractRedstoneGateBlock extends HorizontalFacingBlock
 		return Block.isSolidMediumSquare(world, pos.down());
 	}
 	
-	@Override
-	public void onScheduledTick(final BlockState state, final World world, final BlockPos pos, final Random random) {
-		if (!this.isLocked(world, pos, state)) {
-			final boolean powered = state.get(AbstractRedstoneGateBlock.POWERED);
-			final boolean shouldBePowered = this.hasPower(world, pos, state);
-			if (powered && !shouldBePowered) {
-				world.setBlockState(pos, state.with(AbstractRedstoneGateBlock.POWERED, false), 2);
-			}
-			else if (!powered) {
-				world.setBlockState(pos, state.with(AbstractRedstoneGateBlock.POWERED, true), 2);
-				if (!shouldBePowered) {
-					world.getBlockTickScheduler().schedule(pos, this, this.getUpdateDelayInternal(state), TaskPriority.HIGH);
-				}
-			}
-		}
-	}
-	
 	@Override
 	public int getStrongRedstonePower(final BlockState state, final BlockView view, final BlockPos pos, final Direction facing) {
 		return state.getWeakRedstonePower(view, pos, facing);
@@ -63,9 +41,6 @@ public abstract class AbstractRedstoneGateBlock extends HorizontalFacingBlock
 	
 	@Override
 	public int getWeakRedstonePower(final BlockState state, final BlockView view, final BlockPos pos, final Direction facing) {
-		if (!state.get(AbstractRedstoneGateBlock.POWERED)) {
-			return 0;
-		}
 		if (state.get(AbstractRedstoneGateBlock.FACING) == facing) {
 			return this.getOutputLevel(view, pos, state);
 		}
@@ -87,24 +62,9 @@ public abstract class AbstractRedstoneGateBlock extends HorizontalFacingBlock
 		}
 	}
 	
-	protected void updatePowered(final World world, final BlockPos pos, final BlockState state) {
-		if (!this.isLocked(world, pos, state)) {
-			final boolean powered = state.get(AbstractRedstoneGateBlock.POWERED);
-			final boolean shouldBePowered = this.hasPower(world, pos, state);
-			if (powered != shouldBePowered && !world.getBlockTickScheduler().isTicking(pos, this)) {
-				TaskPriority priority = TaskPriority.HIGH;
-				if (this.isTargetNotAligned(world, pos, state)) {
-					priority = TaskPriority.EXTREMELY_HIGH;
-				}
-				else if (powered) {
-					priority = TaskPriority.VERY_HIGH;
-				}
-				world.getBlockTickScheduler().schedule(pos, this, this.getUpdateDelayInternal(state), priority);
-			}
-		}
-	}
-		
-		public boolean isLocked(final ViewableWorld world, final BlockPos pos, final BlockState state) {
+	protected abstract void updatePowered(final World world, final BlockPos pos, final BlockState state);
+	
+	public boolean isLocked(final ViewableWorld world, final BlockPos pos, final BlockState state) {
 		return false;
 	}
 	
@@ -192,9 +152,7 @@ public abstract class AbstractRedstoneGateBlock extends HorizontalFacingBlock
 		return state.emitsRedstonePower();
 	}
 	
-	protected int getOutputLevel(final BlockView view, final BlockPos pos, final BlockState state) {
-		return 15;
-	}
+	protected abstract int getOutputLevel(final BlockView view, final BlockPos pos, final BlockState state);
 	
 	public static boolean isRedstoneGate(final BlockState state) {
 		return state.getBlock() instanceof AbstractRedstoneGateBlock;
@@ -220,6 +178,5 @@ public abstract class AbstractRedstoneGateBlock extends HorizontalFacingBlock
 	
 	static {
 		SHAPE = Block.createCuboidShape(0.0, 0.0, 0.0, 16.0, 2.0, 16.0);
-		POWERED = Properties.POWERED;
 	}
 }
diff --git a/src/net/minecraft/block/ComparatorBlock.java b/src/net/minecraft/block/ComparatorBlock.java
index 8f56300..d9529b6 100644
--- a/src/net/minecraft/block/ComparatorBlock.java
+++ b/src/net/minecraft/block/ComparatorBlock.java
@@ -5,9 +5,7 @@
  *  javax.annotation.Nullable
  */
 package net.minecraft.block;
-
-import net.minecraft.block.entity.BlockEntity;
-import net.minecraft.block.entity.ComparatorBlockEntity;
+    
 import net.minecraft.block.enums.ComparatorMode;
 import net.minecraft.entity.decoration.ItemFrameEntity;
 import net.minecraft.entity.player.PlayerEntity;
@@ -15,6 +13,7 @@ import net.minecraft.sound.SoundCategory;
 import net.minecraft.sound.SoundEvents;
 import net.minecraft.state.StateFactory;
 import net.minecraft.state.property.EnumProperty;
+import net.minecraft.state.property.IntProperty;
 import net.minecraft.state.property.Properties;
 import net.minecraft.util.Hand;
 import net.minecraft.util.TaskPriority;
@@ -29,12 +28,13 @@ import javax.annotation.Nullable;
 import java.util.List;
 import java.util.Random;
 
-public class ComparatorBlock extends AbstractRedstoneGateBlock implements BlockEntityProvider {
+public class ComparatorBlock extends AbstractRedstoneGateBlock {
     public static final EnumProperty<ComparatorMode> MODE = Properties.COMPARATOR_MODE;
+    public static final IntProperty POWER = Properties.POWER;
 
     public ComparatorBlock(final Settings settings) {
         super(settings);
-        this.setDefaultState(this.stateFactory.getDefaultState().with(FACING, Direction.NORTH).with(POWERED, false).with(MODE, ComparatorMode.COMPARE));
+        this.setDefaultState(this.stateFactory.getDefaultState().with(FACING, Direction.NORTH).with(POWER, 0).with(MODE, ComparatorMode.COMPARE));
     }
 
     @Override
@@ -44,11 +44,7 @@ public class ComparatorBlock extends AbstractRedstoneGateBlock implements BlockE
 
     @Override
     protected int getOutputLevel(final BlockView view, final BlockPos pos, final BlockState state) {
-        final BlockEntity blockEntity = view.getBlockEntity(pos);
-        if (blockEntity instanceof ComparatorBlockEntity) {
-            return ((ComparatorBlockEntity)blockEntity).getOutputSignal();
-        }
-        return 0;
+        return state.get(POWER);
     }
 
     private int calculateOutputSignal(final World world, final BlockPos pos, final BlockState state) {
@@ -125,10 +122,9 @@ public class ComparatorBlock extends AbstractRedstoneGateBlock implements BlockE
     protected void updatePowered(final World world, final BlockPos pos, final BlockState state) {
         if (!world.getBlockTickScheduler().isTicking(pos, this)) {
             final int calculatedOutputSignal = this.calculateOutputSignal(world, pos, state);
-            final BlockEntity blockEntity = world.getBlockEntity(pos);
-            final int currentOutputSignal = blockEntity instanceof ComparatorBlockEntity ? ((ComparatorBlockEntity) blockEntity).getOutputSignal() : 0;
+            final int currentOutputSignal = state.get(POWER);
             
-            if (calculatedOutputSignal != currentOutputSignal || state.get(POWERED) != this.hasPower(world, pos, state)) {
+            if (calculatedOutputSignal != currentOutputSignal) {
                 final TaskPriority priority = this.isTargetNotAligned(world, pos, state) ? TaskPriority.HIGH : TaskPriority.NORMAL;
                 world.getBlockTickScheduler().schedule(pos, this, 2, priority);
             }
@@ -137,26 +133,10 @@ public class ComparatorBlock extends AbstractRedstoneGateBlock implements BlockE
 
     private void update(final World world, final BlockPos pos, final BlockState state) {
         final int calculatedOutputSignal = this.calculateOutputSignal(world, pos, state);
-        final BlockEntity blockEntity = world.getBlockEntity(pos);
-        int previousOutputSignal = 0;
-        
-        if (blockEntity instanceof ComparatorBlockEntity) {
-            final ComparatorBlockEntity comparatorBE = (ComparatorBlockEntity)blockEntity;
-            previousOutputSignal = comparatorBE.getOutputSignal();
-            comparatorBE.setOutputSignal(calculatedOutputSignal);
-        }
+        final int previousOutputSignal = state.get(POWER);
         
         if (previousOutputSignal != calculatedOutputSignal || state.get(MODE) == ComparatorMode.COMPARE) {
-            final boolean shouldBePowered = this.hasPower(world, pos, state);
-            final boolean powered = state.get(POWERED);
-            
-            if (powered && !shouldBePowered) {
-                world.setBlockState(pos, state.with(POWERED, false), 2);
-                
-            } else if (!powered && shouldBePowered) {
-                world.setBlockState(pos, state.with(POWERED, true), 2);
-            }
-            
+            world.setBlockState(pos, state.with(POWER, calculatedOutputSignal));
             this.updateTarget(world, pos, state);
         }
     }
@@ -166,21 +146,8 @@ public class ComparatorBlock extends AbstractRedstoneGateBlock implements BlockE
         this.update(world, pos, state);
     }
 
-    @Override
-    public boolean onBlockAction(final BlockState state, final World world, final BlockPos pos, final int type, final int data) {
-        super.onBlockAction(state, world, pos, type, data);
-        final BlockEntity blockEntity = world.getBlockEntity(pos);
-        return blockEntity != null && blockEntity.onBlockAction(type, data);
-    }
-
-    @Override
-    public BlockEntity createBlockEntity(final BlockView view) {
-        return new ComparatorBlockEntity();
-    }
-
     @Override
     protected void appendProperties(final StateFactory.Builder<Block, BlockState> builder) {
-        builder.add(FACING, MODE, POWERED);
+        builder.add(FACING, MODE, POWER);
     }
 }
-
diff --git a/src/net/minecraft/block/RepeaterBlock.java b/src/net/minecraft/block/RepeaterBlock.java
index ed1933c..7ce0634 100644
--- a/src/net/minecraft/block/RepeaterBlock.java
+++ b/src/net/minecraft/block/RepeaterBlock.java
@@ -3,28 +3,30 @@
 // 
 
 package net.minecraft.block;
-
-import net.minecraft.state.property.Properties;
-import net.minecraft.state.StateFactory;
-import net.minecraft.particle.DustParticleEffect;
-
-import java.util.Random;
-
-import net.minecraft.world.IWorld;
-import net.minecraft.world.ViewableWorld;
+	
+import net.minecraft.entity.player.PlayerEntity;
 import net.minecraft.item.ItemPlacementContext;
-import net.minecraft.util.hit.BlockHitResult;
+import net.minecraft.particle.DustParticleEffect;
+import net.minecraft.state.StateFactory;
+import net.minecraft.state.property.BooleanProperty;
+import net.minecraft.state.property.IntProperty;
+import net.minecraft.state.property.Properties;
 import net.minecraft.util.Hand;
-import net.minecraft.entity.player.PlayerEntity;
+import net.minecraft.util.TaskPriority;
+import net.minecraft.util.hit.BlockHitResult;
 import net.minecraft.util.math.BlockPos;
-import net.minecraft.world.World;
 import net.minecraft.util.math.Direction;
-import net.minecraft.state.property.IntProperty;
-import net.minecraft.state.property.BooleanProperty;
-
+import net.minecraft.world.BlockView;
+import net.minecraft.world.IWorld;
+import net.minecraft.world.ViewableWorld;
+import net.minecraft.world.World;
+	
+import java.util.Random;
+	
 public class RepeaterBlock extends AbstractRedstoneGateBlock {
 	public static final BooleanProperty LOCKED = Properties.LOCKED;
 	public static final IntProperty DELAY = Properties.DELAY;
+	public static final BooleanProperty POWERED = Properties.POWERED;
 	
 	protected RepeaterBlock(final Settings settings) {
 		super(settings);
@@ -69,6 +71,46 @@ public class RepeaterBlock extends AbstractRedstoneGateBlock {
 		return isRedstoneGate(state);
 	}
 	
+	@Override
+	public void onScheduledTick(final BlockState state, final World world, final BlockPos pos, final Random random) {
+		if (!this.isLocked(world, pos, state)) {
+			final boolean powered = state.get(RepeaterBlock.POWERED);
+			final boolean shouldBePowered = this.hasPower(world, pos, state);
+			if (powered && !shouldBePowered) {
+				world.setBlockState(pos, state.with(RepeaterBlock.POWERED, false), 2);
+			}
+			else if (!powered) {
+				world.setBlockState(pos, state.with(RepeaterBlock.POWERED, true), 2);
+				if (!shouldBePowered) {
+					world.getBlockTickScheduler().schedule(pos, this, this.getUpdateDelayInternal(state), TaskPriority.HIGH);
+				}
+			}
+		}
+	}
+	
+	@Override
+	protected void updatePowered(final World world, final BlockPos pos, final BlockState state) {
+		if (!this.isLocked(world, pos, state)) {
+			final boolean powered = state.get(RepeaterBlock.POWERED);
+			final boolean shouldBePowered = this.hasPower(world, pos, state);
+			if (powered != shouldBePowered && !world.getBlockTickScheduler().isTicking(pos, this)) {
+				TaskPriority priority = TaskPriority.HIGH;
+				if (this.isTargetNotAligned(world, pos, state)) {
+					priority = TaskPriority.EXTREMELY_HIGH;
+				}
+				else if (powered) {
+					priority = TaskPriority.VERY_HIGH;
+				}
+				world.getBlockTickScheduler().schedule(pos, this, this.getUpdateDelayInternal(state), priority);
+			}
+		}
+	}
+	
+	@Override
+	protected int getOutputLevel(final BlockView view, final BlockPos pos, final BlockState state) {
+		return state.get(RepeaterBlock.POWERED) ? 15 : 0;
+	}
+	
 	@Override
 	public void randomDisplayTick(final BlockState state, final World world, final BlockPos pos, final Random rnd) {
 		if (state.get(RepeaterBlock.POWERED)) {
-- 
2.22.0.windows.1