Skip to content

Commit

Permalink
Merge remote-tracking branch 'Kogepan229/fix-manapool-npe' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Dream-Master committed Aug 18, 2024
2 parents 0872239 + 7528dde commit a24da4d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 190 deletions.
29 changes: 0 additions & 29 deletions src/main/java/vazkii/botania/api/mana/IKeyLocked.java

This file was deleted.

19 changes: 0 additions & 19 deletions src/main/java/vazkii/botania/common/block/mana/BlockPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@

public class BlockPool extends BlockModContainer implements IWandHUD, IWandable, ILexiconable, ICraftAchievement {

boolean lastFragile = false;

public static IIcon manaIcon;

public BlockPool() {
Expand Down Expand Up @@ -89,23 +87,6 @@ public int damageDropped(int meta) {
return meta;
}

@Override
public void breakBlock(World par1World, int par2, int par3, int par4, Block par5, int par6) {
TilePool pool = (TilePool) par1World.getTileEntity(par2, par3, par4);
lastFragile = pool.fragile;
super.breakBlock(par1World, par2, par3, par4, par5, par6);
}

@Override
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) {
ArrayList<ItemStack> drops = new ArrayList();

if(!lastFragile)
drops.add(new ItemStack(this, 1, metadata));

return drops;
}

@Override
public void getSubBlocks(Item par1, CreativeTabs par2, List par3) {
par3.add(new ItemStack(par1, 1, 0));
Expand Down
72 changes: 15 additions & 57 deletions src/main/java/vazkii/botania/common/block/tile/mana/TilePool.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import vazkii.botania.api.internal.VanillaPacketDispatcher;
import vazkii.botania.api.item.IDyablePool;
import vazkii.botania.api.item.IManaDissolvable;
import vazkii.botania.api.mana.IKeyLocked;
import vazkii.botania.api.mana.IManaItem;
import vazkii.botania.api.mana.IManaPool;
import vazkii.botania.api.mana.IThrottledPacket;
Expand All @@ -57,7 +56,7 @@
import vazkii.botania.common.item.ModItems;
import vazkii.botania.common.lib.LibMisc;

public class TilePool extends TileMod implements IManaPool, IDyablePool, IKeyLocked, ISparkAttachable, IThrottledPacket {
public class TilePool extends TileMod implements IManaPool, IDyablePool, ISparkAttachable, IThrottledPacket {

public static final int MAX_MANA = 1000000;
public static final int MAX_MANA_DILLUTED = 10000;
Expand All @@ -67,11 +66,6 @@ public class TilePool extends TileMod implements IManaPool, IDyablePool, IKeyLoc
private static final String TAG_OUTPUTTING = "outputting";
private static final String TAG_COLOR = "color";
private static final String TAG_MANA_CAP = "manaCap";
private static final String TAG_CAN_ACCEPT = "canAccept";
private static final String TAG_CAN_SPARE = "canSpare";
private static final String TAG_FRAGILE = "fragile";
private static final String TAG_INPUT_KEY = "inputKey";
private static final String TAG_OUTPUT_KEY = "outputKey";

boolean outputting = false;
public boolean alchemy = false;
Expand All @@ -84,15 +78,9 @@ public class TilePool extends TileMod implements IManaPool, IDyablePool, IKeyLoc

public int manaCap = -1;
int soundTicks = 0;
boolean canAccept = true;
boolean canSpare = true;
public boolean fragile = false;
public boolean isDoingTransfer = false;
public int ticksDoingTransfer = 0;

String inputKey = "";
String outputKey = "";

int ticks = 0;
boolean sendPacket = false;

Expand Down Expand Up @@ -231,25 +219,21 @@ public void updateEntity() {
int transfRate = 1000 * (bellowCount + 1);

if(outputting) {
if(canSpare) {
if(getCurrentMana() > 0 && mana.getMana(stack) < mana.getMaxMana(stack))
didSomething = true;

int manaVal = Math.min(transfRate, Math.min(getCurrentMana(), mana.getMaxMana(stack) - mana.getMana(stack)));
if(!worldObj.isRemote)
mana.addMana(stack, manaVal);
recieveMana(-manaVal);
}
if(getCurrentMana() > 0 && mana.getMana(stack) < mana.getMaxMana(stack))
didSomething = true;

int manaVal = Math.min(transfRate, Math.min(getCurrentMana(), mana.getMaxMana(stack) - mana.getMana(stack)));
if(!worldObj.isRemote)
mana.addMana(stack, manaVal);
recieveMana(-manaVal);
} else {
if(canAccept) {
if(mana.getMana(stack) > 0 && !isFull())
didSomething = true;

int manaVal = Math.min(transfRate, Math.min(manaCap - getCurrentMana(), mana.getMana(stack)));
if(!worldObj.isRemote)
mana.addMana(stack, -manaVal);
recieveMana(manaVal);
}
if(mana.getMana(stack) > 0 && !isFull())
didSomething = true;

int manaVal = Math.min(transfRate, Math.min(manaCap - getCurrentMana(), mana.getMana(stack)));
if(!worldObj.isRemote)
mana.addMana(stack, -manaVal);
recieveMana(manaVal);
}

if(didSomething) {
Expand Down Expand Up @@ -282,12 +266,6 @@ public void writeCustomNBT(NBTTagCompound cmp) {
cmp.setInteger(TAG_COLOR, color);

cmp.setInteger(TAG_MANA_CAP, manaCap);
cmp.setBoolean(TAG_CAN_ACCEPT, canAccept);
cmp.setBoolean(TAG_CAN_SPARE, canSpare);
cmp.setBoolean(TAG_FRAGILE, fragile);

cmp.setString(TAG_INPUT_KEY, inputKey);
cmp.setString(TAG_OUTPUT_KEY, outputKey);
}

@Override
Expand All @@ -298,16 +276,6 @@ public void readCustomNBT(NBTTagCompound cmp) {

if(cmp.hasKey(TAG_MANA_CAP))
manaCap = cmp.getInteger(TAG_MANA_CAP);
if(cmp.hasKey(TAG_CAN_ACCEPT))
canAccept = cmp.getBoolean(TAG_CAN_ACCEPT);
if(cmp.hasKey(TAG_CAN_SPARE))
canSpare = cmp.getBoolean(TAG_CAN_SPARE);
fragile = cmp.getBoolean(TAG_FRAGILE);

if(cmp.hasKey(TAG_INPUT_KEY))
inputKey = cmp.getString(TAG_INPUT_KEY);
if(cmp.hasKey(TAG_OUTPUT_KEY))
inputKey = cmp.getString(TAG_OUTPUT_KEY);

if(cmp.hasKey(TAG_KNOWN_MANA))
knownMana = cmp.getInteger(TAG_KNOWN_MANA);
Expand Down Expand Up @@ -379,16 +347,6 @@ public int getCurrentMana() {
return worldObj != null && getBlockMetadata() == 1 ? MAX_MANA : mana;
}

@Override
public String getInputKey() {
return inputKey;
}

@Override
public String getOutputKey() {
return outputKey;
}

@Override
public boolean canAttachSpark(ItemStack stack) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import vazkii.botania.api.internal.IManaBurst;
import vazkii.botania.api.internal.VanillaPacketDispatcher;
import vazkii.botania.api.mana.BurstProperties;
import vazkii.botania.api.mana.IKeyLocked;
import vazkii.botania.api.mana.ILens;
import vazkii.botania.api.mana.ILensControl;
import vazkii.botania.api.mana.ILensEffect;
Expand All @@ -61,7 +60,7 @@
import vazkii.botania.common.entity.EntityManaBurst.PositionProperties;
import vazkii.botania.common.lib.LibBlockNames;

public class TileSpreader extends TileSimpleInventory implements IManaCollector, IWandBindable, IKeyLocked, IThrottledPacket, IManaSpreader, IRedirectable {
public class TileSpreader extends TileSimpleInventory implements IManaCollector, IWandBindable, IThrottledPacket, IManaSpreader, IRedirectable {

private static final int MAX_MANA = 1000;
private static final int ULTRA_MAX_MANA = 6400;
Expand All @@ -87,32 +86,6 @@ public class TileSpreader extends TileSimpleInventory implements IManaCollector,
private static final String TAG_FORCE_CLIENT_BINDING_Y = "forceClientBindingY";
private static final String TAG_FORCE_CLIENT_BINDING_Z = "forceClientBindingZ";

// Map Maker Tags

private static final String TAG_INPUT_KEY = "inputKey";
private static final String TAG_OUTPUT_KEY = "outputKey";

private static final String TAG_MAPMAKER_OVERRIDE = "mapmakerOverrideEnabled";
private static final String TAG_FORCED_COLOR = "mmForcedColor";
private static final String TAG_FORCED_MANA_PAYLOAD = "mmForcedManaPayload";
private static final String TAG_FORCED_TICKS_BEFORE_MANA_LOSS = "mmForcedTicksBeforeManaLoss";
private static final String TAG_FORCED_MANA_LOSS_PER_TICK = "mmForcedManaLossPerTick";
private static final String TAG_FORCED_GRAVITY = "mmForcedGravity";
private static final String TAG_FORCED_VELOCITY_MULTIPLIER = "mmForcedVelocityMultiplier";

boolean mapmakerOverride = false;
int mmForcedColor = 0x20FF20;
int mmForcedManaPayload = 160;
int mmForcedTicksBeforeManaLoss = 60;
float mmForcedManaLossPerTick = 4F;
float mmForcedGravity = 0F;
float mmForcedVelocityMultiplier = 1F;

String inputKey = "";
String outputKey = "";

// End Map Maker Tags

public static boolean staticRedstone = false;
public static boolean staticDreamwood = false;
public static boolean staticUltra = false;
Expand Down Expand Up @@ -181,9 +154,6 @@ public void updateEntity() {
if(tileAt instanceof IManaPool) {
IManaPool pool = (IManaPool) tileAt;
if(wasInNetwork && (pool != receiver || isRedstone())) {
if(pool instanceof IKeyLocked && !((IKeyLocked) pool).getOutputKey().equals(getInputKey()))
continue;

int manaInPool = pool.getCurrentMana();
if(manaInPool > 0 && !isFull()) {
int manaMissing = getMaxMana() - mana;
Expand Down Expand Up @@ -228,9 +198,6 @@ public void updateEntity() {
if(isredstone)
shouldShoot = redstone && !redstoneLastTick;

if(shouldShoot && receiver != null && receiver instanceof IKeyLocked)
shouldShoot = ((IKeyLocked) receiver).getInputKey().equals(getOutputKey());

ItemStack lens = getStackInSlot(0);
ILensControl control = getLensController(lens);
if(control != null) {
Expand Down Expand Up @@ -275,21 +242,10 @@ public void writeCustomNBT(NBTTagCompound cmp) {
cmp.setDouble(TAG_LAST_PINGBACK_Y, lastPingbackY);
cmp.setDouble(TAG_LAST_PINGBACK_Z, lastPingbackZ);

cmp.setString(TAG_INPUT_KEY, inputKey);
cmp.setString(TAG_OUTPUT_KEY, outputKey);

cmp.setInteger(TAG_FORCE_CLIENT_BINDING_X, receiver == null ? 0 : ((TileEntity) receiver).xCoord);
cmp.setInteger(TAG_FORCE_CLIENT_BINDING_Y, receiver == null ? -1 : ((TileEntity) receiver).yCoord);
cmp.setInteger(TAG_FORCE_CLIENT_BINDING_Z, receiver == null ? 0 : ((TileEntity) receiver).zCoord);

cmp.setBoolean(TAG_MAPMAKER_OVERRIDE, mapmakerOverride);
cmp.setInteger(TAG_FORCED_COLOR, mmForcedColor);
cmp.setInteger(TAG_FORCED_MANA_PAYLOAD, mmForcedManaPayload);
cmp.setInteger(TAG_FORCED_TICKS_BEFORE_MANA_LOSS, mmForcedTicksBeforeManaLoss);
cmp.setFloat(TAG_FORCED_MANA_LOSS_PER_TICK, mmForcedManaLossPerTick);
cmp.setFloat(TAG_FORCED_GRAVITY, mmForcedGravity);
cmp.setFloat(TAG_FORCED_VELOCITY_MULTIPLIER, mmForcedVelocityMultiplier);

requestsClientUpdate = false;
}

Expand All @@ -310,19 +266,6 @@ public void readCustomNBT(NBTTagCompound cmp) {
rotationY = cmp.getFloat(TAG_ROTATION_Y);
requestsClientUpdate = cmp.getBoolean(TAG_REQUEST_UPDATE);

if(cmp.hasKey(TAG_INPUT_KEY))
inputKey = cmp.getString(TAG_INPUT_KEY);
if(cmp.hasKey(TAG_OUTPUT_KEY))
inputKey = cmp.getString(TAG_OUTPUT_KEY);

mapmakerOverride = cmp.getBoolean(TAG_MAPMAKER_OVERRIDE);
mmForcedColor = cmp.getInteger(TAG_FORCED_COLOR);
mmForcedManaPayload = cmp.getInteger(TAG_FORCED_MANA_PAYLOAD);
mmForcedTicksBeforeManaLoss = cmp.getInteger(TAG_FORCED_TICKS_BEFORE_MANA_LOSS);
mmForcedManaLossPerTick = cmp.getFloat(TAG_FORCED_MANA_LOSS_PER_TICK);
mmForcedGravity = cmp.getFloat(TAG_FORCED_GRAVITY);
mmForcedVelocityMultiplier = cmp.getFloat(TAG_FORCED_VELOCITY_MULTIPLIER);

if(cmp.hasKey(TAG_KNOWN_MANA))
knownMana = cmp.getInteger(TAG_KNOWN_MANA);
if(cmp.hasKey(TAG_PADDING_COLOR))
Expand Down Expand Up @@ -482,23 +425,13 @@ public EntityManaBurst getBurst(boolean fake) {

burst.setSourceLens(lens);
if(getCurrentMana() >= props.maxMana || fake) {
if(mapmakerOverride) {
burst.setColor(mmForcedColor);
burst.setMana(mmForcedManaPayload);
burst.setStartingMana(mmForcedManaPayload);
burst.setMinManaLoss(mmForcedTicksBeforeManaLoss);
burst.setManaLossPerTick(mmForcedManaLossPerTick);
burst.setGravity(mmForcedGravity);
burst.setMotion(burst.motionX * mmForcedVelocityMultiplier, burst.motionY * mmForcedVelocityMultiplier, burst.motionZ * mmForcedVelocityMultiplier);
} else {
burst.setColor(props.color);
burst.setMana(props.maxMana);
burst.setStartingMana(props.maxMana);
burst.setMinManaLoss(props.ticksBeforeManaLoss);
burst.setManaLossPerTick(props.manaLossPerTick);
burst.setGravity(props.gravity);
burst.setMotion(burst.motionX * props.motionModifier, burst.motionY * props.motionModifier, burst.motionZ * props.motionModifier);
}
burst.setColor(props.color);
burst.setMana(props.maxMana);
burst.setStartingMana(props.maxMana);
burst.setMinManaLoss(props.ticksBeforeManaLoss);
burst.setManaLossPerTick(props.manaLossPerTick);
burst.setGravity(props.gravity);
burst.setMotion(burst.motionX * props.motionModifier, burst.motionY * props.motionModifier, burst.motionZ * props.motionModifier);

return burst;
}
Expand Down Expand Up @@ -637,16 +570,6 @@ public int getMaxMana() {
return isULTRA_SPREADER() ? ULTRA_MAX_MANA : MAX_MANA;
}

@Override
public String getInputKey() {
return inputKey;
}

@Override
public String getOutputKey() {
return outputKey;
}

@Override
public boolean canSelect(EntityPlayer player, ItemStack wand, int x, int y, int z, int side) {
return true;
Expand Down

0 comments on commit a24da4d

Please sign in to comment.