|
4 | 4 | import java.util.List; |
5 | 5 | import java.util.Random; |
6 | 6 |
|
| 7 | +import javax.annotation.Nonnull; |
7 | 8 | import javax.annotation.Nullable; |
8 | 9 |
|
9 | 10 | import com.mojang.datafixers.util.Pair; |
|
33 | 34 | import net.minecraft.util.SoundEvents; |
34 | 35 | import net.minecraft.util.math.BlockPos; |
35 | 36 | import net.minecraft.util.math.BlockRayTraceResult; |
| 37 | +import net.minecraft.util.math.MathHelper; |
36 | 38 | import net.minecraft.world.IBlockReader; |
37 | 39 | import net.minecraft.world.IWorld; |
38 | 40 | import net.minecraft.world.World; |
39 | 41 | import net.minecraftforge.api.distmarker.Dist; |
40 | 42 | import net.minecraftforge.api.distmarker.OnlyIn; |
41 | 43 | import net.minecraftforge.common.Tags; |
42 | 44 | import net.minecraftforge.fml.network.NetworkHooks; |
| 45 | +import net.minecraftforge.items.IItemHandler; |
43 | 46 |
|
44 | 47 | public class JumboFurnaceBlock extends Block |
45 | 48 | { |
@@ -303,6 +306,64 @@ else if (x == 2 && z == 1) |
303 | 306 | return null; |
304 | 307 | } |
305 | 308 | } |
| 309 | + |
| 310 | + @Override |
| 311 | + @Deprecated |
| 312 | + public boolean hasComparatorInputOverride(BlockState state) |
| 313 | + { |
| 314 | + return true; |
| 315 | + } |
| 316 | + |
| 317 | + @Override |
| 318 | + @Deprecated |
| 319 | + public int getComparatorInputOverride(BlockState state, World world, BlockPos pos) |
| 320 | + { |
| 321 | + BlockPos corePos = getCorePos(state, pos); |
| 322 | + TileEntity te = world.getTileEntity(corePos); |
| 323 | + if (!(te instanceof JumboFurnaceCoreTileEntity) || !state.hasProperty(Y)) |
| 324 | + { |
| 325 | + // if we are in an invalid state, return 0 |
| 326 | + return 0; |
| 327 | + } |
| 328 | + |
| 329 | + JumboFurnaceCoreTileEntity core = (JumboFurnaceCoreTileEntity)te; |
| 330 | + int y = state.get(Y); |
| 331 | + |
| 332 | + // top layer of blocks: comparator output is input inventory |
| 333 | + // middle layer of blocks: comparator output is fuel inventory |
| 334 | + // bottom layer of blocks: comparator output is output inventory |
| 335 | + |
| 336 | + switch(y) |
| 337 | + { |
| 338 | + case 0: return calcRedstoneFromItemHandler(core.output); |
| 339 | + case 1: return calcRedstoneFromItemHandler(core.fuel); |
| 340 | + case 2: return calcRedstoneFromItemHandler(core.input); |
| 341 | + default: return 0; |
| 342 | + } |
| 343 | + } |
| 344 | + |
| 345 | + // same math as Container.calcRedstone |
| 346 | + public static int calcRedstoneFromItemHandler(@Nonnull IItemHandler handler) |
| 347 | + { |
| 348 | + int nonEmptySlots = 0; |
| 349 | + float totalItemValue = 0.0F; |
| 350 | + int slots = handler.getSlots(); |
| 351 | + |
| 352 | + for (int slot = 0; slot < slots; ++slot) |
| 353 | + { |
| 354 | + ItemStack itemstack = handler.getStackInSlot(slot); |
| 355 | + if (!itemstack.isEmpty()) |
| 356 | + { |
| 357 | + totalItemValue += itemstack.getCount() / (float) Math.min(handler.getSlotLimit(slot), itemstack.getMaxStackSize()); |
| 358 | + ++nonEmptySlots; |
| 359 | + } |
| 360 | + } |
| 361 | + |
| 362 | + float averageItemValue = totalItemValue = totalItemValue / slots; |
| 363 | + return MathHelper.floor(averageItemValue * 14.0F) + (nonEmptySlots > 0 ? 1 : 0); |
| 364 | + } |
| 365 | + |
| 366 | + |
306 | 367 |
|
307 | 368 | /** |
308 | 369 | * Returns the blockstate with the given rotation from the passed blockstate. If |
|
0 commit comments