mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-19 11:49:37 +00:00
Merge pull request #2702 from quat1024/retainerComparator2
Corporea retainers use richer signal strength depending on request size (but better)
This commit is contained in:
5 files changed
+26
-9
No files matched your search
@@ -17,6 +17,7 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import vazkii.botania.api.BotaniaAPI;
|
||||
@@ -297,4 +298,13 @@ public final class CorporeaHelper {
|
||||
public static String stripControlCodes(String str) {
|
||||
return patternControlCode.matcher(str).replaceAll("");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the comparator strength for a corporea request that corporea crystal cubes and retainers use, following the usual "each step up requires double the items" formula.
|
||||
*/
|
||||
public static int signalStrengthForRequestSize(int requestSize) {
|
||||
if(requestSize <= 0) return 0;
|
||||
else if (requestSize >= 16384) return 15;
|
||||
else return Math.min(15, MathHelper.log2(requestSize) + 1);
|
||||
}
|
||||
}
|
||||
@@ -128,7 +128,7 @@ public class BlockCorporeaCrystalCube extends BlockCorporeaBase implements ILexi
|
||||
|
||||
@Override
|
||||
public int getComparatorInputOverride(IBlockState state, World world, BlockPos pos) {
|
||||
return ((TileCorporeaCrystalCube) world.getTileEntity(pos)).compValue;
|
||||
return ((TileCorporeaCrystalCube) world.getTileEntity(pos)).getComparatorValue();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
|
||||
@@ -75,7 +75,7 @@ public class BlockCorporeaRetainer extends BlockMod implements ILexiconable {
|
||||
|
||||
@Override
|
||||
public int getComparatorInputOverride(IBlockState state, World world, BlockPos pos) {
|
||||
return ((TileCorporeaRetainer) world.getTileEntity(pos)).hasPendingRequest() ? 15 : 0;
|
||||
return ((TileCorporeaRetainer) world.getTileEntity(pos)).getComparatorValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+6
-6
@@ -41,7 +41,7 @@ public class TileCorporeaCrystalCube extends TileCorporeaBase implements ICorpor
|
||||
ItemStack requestTarget = ItemStack.EMPTY;
|
||||
int itemCount = 0;
|
||||
int ticks = 0;
|
||||
public int compValue = 0;
|
||||
int compValue = 0;
|
||||
|
||||
private final IAnimationStateMachine asm;
|
||||
|
||||
@@ -111,8 +111,10 @@ public class TileCorporeaCrystalCube extends TileCorporeaBase implements ICorpor
|
||||
}
|
||||
|
||||
private void onUpdateCount() {
|
||||
compValue = getComparatorValue();
|
||||
world.updateComparatorOutputLevel(pos, world.getBlockState(pos).getBlock());
|
||||
int oldCompValue = compValue;
|
||||
compValue = CorporeaHelper.signalStrengthForRequestSize(itemCount);
|
||||
if(compValue != oldCompValue)
|
||||
world.updateComparatorOutputLevel(pos, world.getBlockState(pos).getBlock());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -134,9 +136,7 @@ public class TileCorporeaCrystalCube extends TileCorporeaBase implements ICorpor
|
||||
}
|
||||
|
||||
public int getComparatorValue() {
|
||||
if(itemCount == 0)
|
||||
return 0;
|
||||
return Math.min(15, (int) Math.floor(Math.log(itemCount) / LOG_2) + 1);
|
||||
return compValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -38,6 +38,7 @@ public class TileCorporeaRetainer extends TileMod {
|
||||
BlockPos requestPos = BlockPos.ORIGIN;
|
||||
Object request;
|
||||
int requestCount;
|
||||
int compValue;
|
||||
|
||||
public void setPendingRequest(BlockPos pos, Object request, int requestCount) {
|
||||
if(pendingRequest)
|
||||
@@ -47,9 +48,15 @@ public class TileCorporeaRetainer extends TileMod {
|
||||
this.request = request;
|
||||
this.requestCount = requestCount;
|
||||
pendingRequest = true;
|
||||
|
||||
compValue = CorporeaHelper.signalStrengthForRequestSize(requestCount);
|
||||
world.updateComparatorOutputLevel(getPos(), world.getBlockState(getPos()).getBlock());
|
||||
}
|
||||
|
||||
|
||||
public int getComparatorValue() {
|
||||
return compValue;
|
||||
}
|
||||
|
||||
public boolean hasPendingRequest() {
|
||||
return pendingRequest;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user