Precondition the rest of the new API

This commit is contained in:
Nicholas Ignoffo 2017-08-20 16:12:50 -07:00
parent c00affa4aa
commit 36ce215b6b
2 changed files with 24 additions and 0 deletions

View file

@ -2,6 +2,7 @@ package WayofTime.bloodmagic.api_impl;
import WayofTime.bloodmagic.api.altar.EnumAltarComponent;
import WayofTime.bloodmagic.apiv2.IBloodMagicAPI;
import com.google.common.base.Preconditions;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
@ -43,11 +44,17 @@ public class BloodMagicAPI implements IBloodMagicAPI {
@Override
public void setSacrificialValue(@Nonnull ResourceLocation entityId, @Nonnegative int value) {
Preconditions.checkNotNull(entityId, "entityId cannot be null.");
Preconditions.checkArgument(value >= 0, "value cannot be negative.");
sacrificialValues.put(entityId, value);
}
@Override
public void registerAltarComponent(@Nonnull IBlockState state, @Nonnull String componentType) {
Preconditions.checkNotNull(state, "state cannot be null.");
Preconditions.checkNotNull(componentType, "componentType cannot be null.");
EnumAltarComponent component = EnumAltarComponent.NOTAIR;
for (EnumAltarComponent type : EnumAltarComponent.VALUES) {
if (type.name().equalsIgnoreCase(componentType)) {

View file

@ -1,6 +1,7 @@
package WayofTime.bloodmagic.api_impl;
import WayofTime.bloodmagic.apiv2.IBloodMagicBlacklist;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import net.minecraft.block.Block;
@ -28,48 +29,64 @@ public class BloodMagicBlacklist implements IBloodMagicBlacklist {
@Override
public void addTeleposer(@Nonnull IBlockState state) {
Preconditions.checkNotNull(state, "state cannot be null.");
if (!teleposer.contains(state))
teleposer.add(state);
}
@Override
public void addTeleposer(@Nonnull Block block) {
Preconditions.checkNotNull(block, "block cannot be null.");
for (IBlockState state : block.getBlockState().getValidStates())
addTeleposer(state);
}
@Override
public void addTeleposer(@Nonnull ResourceLocation entityId) {
Preconditions.checkNotNull(entityId, "entityId cannot be null.");
if (!teleposerEntities.contains(entityId))
teleposerEntities.add(entityId);
}
@Override
public void addTransposition(@Nonnull IBlockState state) {
Preconditions.checkNotNull(state, "state cannot be null.");
if (!transposition.contains(state))
transposition.add(state);
}
@Override
public void addTransposition(@Nonnull Block block) {
Preconditions.checkNotNull(block, "block cannot be null.");
for (IBlockState state : block.getBlockState().getValidStates())
addTransposition(state);
}
@Override
public void addGreenGrove(@Nonnull IBlockState state) {
Preconditions.checkNotNull(state, "state cannot be null.");
if (!greenGrove.contains(state))
greenGrove.add(state);
}
@Override
public void addGreenGrove(@Nonnull Block block) {
Preconditions.checkNotNull(block, "block cannot be null.");
for (IBlockState state : block.getBlockState().getValidStates())
addGreenGrove(state);
}
@Override
public void addWellOfSuffering(@Nonnull ResourceLocation entityId) {
Preconditions.checkNotNull(entityId, "entityId cannot be null.");
if (!sacrifice.contains(entityId))
sacrifice.add(entityId);
}