Allow sparks to have different color networks like corporea. For now, show by coloring the upgrade icon, and displaying the corporea star if there is no upgrade

This commit is contained in:
Vincent Lee committed 2019-10-07 19:40:34 -05:00
1 parent be6d7f610e
commit d798e44e8c
10 files changed
+136 -105

No files matched your search

@@ -10,6 +10,8 @@
*/
package vazkii.botania.api.mana.spark;
import net.minecraft.item.DyeColor;
import java.util.Collection;
/**
@@ -53,4 +55,9 @@ public interface ISparkEntity {
*/
public boolean areIncomingTransfersDone();
/**
* Gets the network that this spark is on, or the color it's displaying. Sparks may only connect to others
* of the same network.
*/
public DyeColor getNetwork();
}
@@ -12,15 +12,21 @@ package vazkii.botania.api.mana.spark;
import com.google.common.base.Predicates;
import net.minecraft.entity.Entity;
import net.minecraft.item.DyeColor;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.world.World;
import java.util.List;
import java.util.stream.Stream;
public final class SparkHelper {
public static final int SPARK_SCAN_RANGE = 12;
public static Stream<ISparkEntity> getSparksAround(World world, double x, double y, double z, DyeColor color) {
return getSparksAround(world, x, y, z).stream().filter(s -> s.getNetwork() == color);
}
public static List<ISparkEntity> getSparksAround(World world, double x, double y, double z) {
return SparkHelper.getEntitiesAround(ISparkEntity.class, world, x, y, z);
}
@@ -35,20 +35,6 @@ public class RenderCorporeaSpark extends RenderSparkBase<EntityCorporeaSpark> {
return entity.isMaster() ? MiscellaneousIcons.INSTANCE.corporeaWorldIconMaster : MiscellaneousIcons.INSTANCE.corporeaWorldIcon;
}
@Override
public void colorSpinningIcon(EntityCorporeaSpark entity, float a) {
int hex = entity.getNetwork().colorValue;
int r = (hex & 0xFF0000) >> 16;
int g = (hex & 0xFF00) >> 8;
int b = hex & 0xFF;
GlStateManager.color4f(r / 255F, g / 255F, b / 255F, a);
}
@Override
public TextureAtlasSprite getSpinningIcon(EntityCorporeaSpark entity) {
return MiscellaneousIcons.INSTANCE.corporeaIconStar;
}
@Override
public void renderCallback(EntityCorporeaSpark entity, float pticks) {
int time = entity.getItemDisplayTicks();
@@ -24,7 +24,9 @@ public class RenderSpark extends RenderSparkBase<EntitySpark> {
@Override
public TextureAtlasSprite getSpinningIcon(EntitySpark entity) {
int upgrade = entity.getUpgrade().ordinal() - 1;
return upgrade >= 0 && upgrade < MiscellaneousIcons.INSTANCE.sparkUpgradeIcons.length ? MiscellaneousIcons.INSTANCE.sparkUpgradeIcons[upgrade] : null;
return upgrade >= 0 && upgrade < MiscellaneousIcons.INSTANCE.sparkUpgradeIcons.length
? MiscellaneousIcons.INSTANCE.sparkUpgradeIcons[upgrade]
: super.getSpinningIcon(entity);
}
}
@@ -24,11 +24,12 @@ import org.lwjgl.opengl.GL11;
import vazkii.botania.client.core.handler.ClientTickHandler;
import vazkii.botania.client.core.handler.MiscellaneousIcons;
import vazkii.botania.client.core.proxy.ClientProxy;
import vazkii.botania.common.entity.EntitySparkBase;
import javax.annotation.Nonnull;
import java.util.Random;
public abstract class RenderSparkBase<T extends Entity> extends EntityRenderer<T> {
public abstract class RenderSparkBase<T extends EntitySparkBase> extends EntityRenderer<T> {
public RenderSparkBase(EntityRendererManager manager) {
super(manager);
@@ -64,12 +65,11 @@ public abstract class RenderSparkBase<T extends Entity> extends EntityRenderer<T
renderIcon(tessellator, iicon);
TextureAtlasSprite spinningIcon = getSpinningIcon(tEntity);
if(spinningIcon != null) {
GlStateManager.translatef(-0.02F + (float) Math.sin(time / 20) * 0.2F, 0.24F + (float) Math.cos(time / 20) * 0.2F, 0.005F);
GlStateManager.scalef(0.2F, 0.2F, 0.2F);
colorSpinningIcon(tEntity, a);
renderIcon(tessellator, spinningIcon);
}
GlStateManager.translatef(-0.02F + (float) Math.sin(time / 20) * 0.2F, 0.24F + (float) Math.cos(time / 20) * 0.2F, 0.005F);
GlStateManager.scalef(0.2F, 0.2F, 0.2F);
colorSpinningIcon(tEntity, a);
renderIcon(tessellator, spinningIcon);
GlStateManager.popMatrix();
GlStateManager.color4f(1F, 1F, 1F, 1F);
renderCallback(tEntity, par9);
@@ -83,17 +83,23 @@ public abstract class RenderSparkBase<T extends Entity> extends EntityRenderer<T
return MiscellaneousIcons.INSTANCE.sparkWorldIcon;
}
protected void colorSpinningIcon(T entity, float a) {}
private void colorSpinningIcon(T entity, float a) {
int hex = entity.getNetwork().colorValue;
int r = (hex & 0xFF0000) >> 16;
int g = (hex & 0xFF00) >> 8;
int b = hex & 0xFF;
GlStateManager.color4f(r / 255F, g / 255F, b / 255F, a);
}
protected TextureAtlasSprite getSpinningIcon(T entity) {
return null;
return MiscellaneousIcons.INSTANCE.corporeaIconStar;
}
protected void renderCallback(T entity, float pticks) {}
@Nonnull
@Override
protected ResourceLocation getEntityTexture(@Nonnull Entity entity) {
protected ResourceLocation getEntityTexture(@Nonnull EntitySparkBase entity) {
return AtlasTexture.LOCATION_BLOCKS_TEXTURE;
}
@@ -112,7 +118,6 @@ public abstract class RenderSparkBase<T extends Entity> extends EntityRenderer<T
tess.getBuffer().pos(f4 - f5, f4 - f6, 0.0D).tex(f1, f2).lightmap(240, 240).normal(0.0F, 1.0F, 0.0F).endVertex();
tess.getBuffer().pos(0.0F - f5, f4 - f6, 0.0D).tex(f, f2).lightmap(240, 240).normal(0.0F, 1.0F, 0.0F).endVertex();
tess.draw();
}
}
@@ -208,14 +208,9 @@ public class TileEnchanter extends TileMod implements ISparkAttachable, ITickabl
} else {
ISparkEntity spark = getAttachedSpark();
if(spark != null) {
List<ISparkEntity> sparkEntities = SparkHelper.getSparksAround(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
for(ISparkEntity otherSpark : sparkEntities) {
if(spark == otherSpark)
continue;
if(otherSpark.getAttachedTile() != null && otherSpark.getAttachedTile() instanceof IManaPool)
otherSpark.registerTransfer(spark);
}
SparkHelper.getSparksAround(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, spark.getNetwork())
.filter(otherSpark -> spark != otherSpark && otherSpark.getAttachedTile() instanceof IManaPool)
.forEach(os -> os.registerTransfer(spark));
}
if(stageTicks % 5 == 0)
sync();
@@ -93,14 +93,9 @@ public class TileTerraPlate extends TileMod implements ISparkAttachable, ITickab
removeMana = false;
ISparkEntity spark = getAttachedSpark();
if(spark != null) {
List<ISparkEntity> sparkEntities = SparkHelper.getSparksAround(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
for(ISparkEntity otherSpark : sparkEntities) {
if(spark == otherSpark)
continue;
if(otherSpark.getAttachedTile() != null && otherSpark.getAttachedTile() instanceof IManaPool)
otherSpark.registerTransfer(spark);
}
SparkHelper.getSparksAround(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, spark.getNetwork())
.filter(otherSpark -> spark != otherSpark && otherSpark.getAttachedTile() instanceof IManaPool)
.forEach(os -> os.registerTransfer(spark));
}
if(mana > 0) {
VanillaPacketDispatcher.dispatchTEToNearbyPlayers(world, pos);
@@ -126,7 +121,7 @@ public class TileTerraPlate extends TileMod implements ISparkAttachable, ITickab
recieveMana(-1000);
}
List<ItemEntity> getItems() {
private List<ItemEntity> getItems() {
return world.getEntitiesWithinAABB(ItemEntity.class, new AxisAlignedBB(pos, pos.add(1, 1, 1)));
}
@@ -41,18 +41,15 @@ import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
public class EntityCorporeaSpark extends Entity implements ICorporeaSpark {
public class EntityCorporeaSpark extends EntitySparkBase implements ICorporeaSpark {
@ObjectHolder(LibMisc.MOD_ID + ":corporea_spark")
public static EntityType<EntityCorporeaSpark> TYPE;
private static final int SCAN_RANGE = 8;
private static final String TAG_MASTER = "master";
private static final String TAG_NETWORK = "network";
private static final String TAG_INVIS = "invis";
private static final DataParameter<Boolean> MASTER = EntityDataManager.createKey(EntityCorporeaSpark.class, DataSerializers.BOOLEAN);
private static final DataParameter<Integer> NETWORK = EntityDataManager.createKey(EntityCorporeaSpark.class, DataSerializers.VARINT);
private static final DataParameter<Integer> ITEM_DISPLAY_TICKS = EntityDataManager.createKey(EntityCorporeaSpark.class, DataSerializers.VARINT);
private static final DataParameter<ItemStack> DISPLAY_STACK = EntityDataManager.createKey(EntityCorporeaSpark.class, DataSerializers.ITEMSTACK);
@@ -71,8 +68,8 @@ public class EntityCorporeaSpark extends Entity implements ICorporeaSpark {
@Override
protected void registerData() {
super.registerData();
dataManager.register(MASTER, false);
dataManager.register(NETWORK, 0);
dataManager.register(ITEM_DISPLAY_TICKS, 0);
dataManager.register(DISPLAY_STACK, ItemStack.EMPTY);
}
@@ -83,11 +80,6 @@ public class EntityCorporeaSpark extends Entity implements ICorporeaSpark {
return isMaster() ? new ItemStack(ModItems.corporeaSparkMaster) : new ItemStack(ModItems.corporeaSpark);
}
@Override
public boolean canBeCollidedWith() {
return true;
}
@Override
public void tick() {
super.tick();
@@ -241,15 +233,6 @@ public class EntityCorporeaSpark extends Entity implements ICorporeaSpark {
return dataManager.get(MASTER);
}
public void setNetwork(DyeColor network) {
dataManager.set(NETWORK, network.getId());
}
@Override
public DyeColor getNetwork() {
return DyeColor.byId(dataManager.get(NETWORK));
}
public int getItemDisplayTicks() {
return dataManager.get(ITEM_DISPLAY_TICKS);
}
@@ -315,16 +298,14 @@ public class EntityCorporeaSpark extends Entity implements ICorporeaSpark {
@Override
protected void readAdditional(@Nonnull CompoundNBT cmp) {
super.readAdditional(cmp);
setMaster(cmp.getBoolean(TAG_MASTER));
setNetwork(DyeColor.byId(cmp.getInt(TAG_NETWORK)));
setInvisible(cmp.getInt(TAG_INVIS) == 1);
}
@Override
protected void writeAdditional(@Nonnull CompoundNBT cmp) {
super.writeAdditional(cmp);
cmp.putBoolean(TAG_MASTER, isMaster());
cmp.putInt(TAG_NETWORK, getNetwork().getId());
cmp.putInt(TAG_INVIS, isInvisible() ? 1 : 0);
}
}
@@ -14,6 +14,7 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.item.DyeColor;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.network.IPacket;
@@ -38,6 +39,7 @@ import vazkii.botania.api.mana.spark.SparkHelper;
import vazkii.botania.api.mana.spark.SparkUpgradeType;
import vazkii.botania.common.item.ItemSparkUpgrade;
import vazkii.botania.common.item.ModItems;
import vazkii.botania.common.item.material.ItemDye;
import vazkii.botania.common.lib.LibMisc;
import vazkii.botania.common.network.PacketBotaniaEffect;
import vazkii.botania.common.network.PacketHandler;
@@ -51,14 +53,15 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.WeakHashMap;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.Nonnull;
public class EntitySpark extends Entity implements ISparkEntity {
public class EntitySpark extends EntitySparkBase implements ISparkEntity {
@ObjectHolder(LibMisc.MOD_ID + ":spark")
public static EntityType<EntitySpark> TYPE;
private static final int TRANSFER_RATE = 1000;
private static final String TAG_UPGRADE = "upgrade";
private static final String TAG_INVIS = "invis";
private static final DataParameter<Integer> UPGRADE = EntityDataManager.createKey(EntitySpark.class, DataSerializers.VARINT);
private final Set<ISparkEntity> transfers = Collections.newSetFromMap(new WeakHashMap<>());
@@ -75,6 +78,7 @@ public class EntitySpark extends Entity implements ISparkEntity {
@Override
protected void registerData() {
super.registerData();
dataManager.register(UPGRADE, 0);
}
@@ -98,10 +102,6 @@ public class EntitySpark extends Entity implements ISparkEntity {
}
SparkUpgradeType upgrade = getUpgrade();
List<ISparkEntity> allSparks = null;
if(upgrade == SparkUpgradeType.DOMINANT || upgrade == SparkUpgradeType.RECESSIVE)
allSparks = SparkHelper.getSparksAround(world, posX, posY + (getHeight() / 2.0), posZ);
Collection<ISparkEntity> transfers = getTransfers();
switch(upgrade) {
@@ -160,29 +160,27 @@ public class EntitySpark extends Entity implements ISparkEntity {
break;
}
case DOMINANT : {
List<ISparkEntity> validSparks = new ArrayList<>();
for(ISparkEntity spark : allSparks) {
if(spark == this)
continue;
SparkUpgradeType upgrade_ = spark.getUpgrade();
if(upgrade_ == SparkUpgradeType.NONE && spark.getAttachedTile() instanceof IManaPool)
validSparks.add(spark);
}
List<ISparkEntity> validSparks = SparkHelper.getSparksAround(world, posX, posY + (getHeight() / 2), posZ, getNetwork())
.filter(s -> {
SparkUpgradeType otherUpgrade = s.getUpgrade();
return s != this && otherUpgrade == SparkUpgradeType.NONE && s.getAttachedTile() instanceof IManaPool;
})
.collect(Collectors.toList());
if(validSparks.size() > 0)
validSparks.get(world.rand.nextInt(validSparks.size())).registerTransfer(this);
break;
}
case RECESSIVE : {
for(ISparkEntity spark : allSparks) {
if(spark == this)
continue;
SparkUpgradeType upgrade_ = spark.getUpgrade();
if(upgrade_ != SparkUpgradeType.DOMINANT && upgrade_ != SparkUpgradeType.RECESSIVE && upgrade_ != SparkUpgradeType.ISOLATED)
transfers.add(spark);
}
SparkHelper.getSparksAround(world, posX, posY + (getHeight() / 2), posZ, getNetwork())
.filter(s -> {
SparkUpgradeType otherUpgrade = s.getUpgrade();
return s != this
&& otherUpgrade != SparkUpgradeType.DOMINANT
&& otherUpgrade != SparkUpgradeType.RECESSIVE
&& otherUpgrade != SparkUpgradeType.ISOLATED;
})
.forEach(transfers::add);
break;
}
case NONE:
@@ -239,18 +237,13 @@ public class EntitySpark extends Entity implements ISparkEntity {
remove();
}
@Override
public boolean canBeCollidedWith() {
return true;
}
@Override
public boolean processInitialInteract(PlayerEntity player, Hand hand) {
ItemStack stack = player.getHeldItem(hand);
if(!removed && !stack.isEmpty()) {
if(isAlive() && !stack.isEmpty()) {
if(world.isRemote) {
boolean valid = stack.getItem() == ModItems.twigWand || stack.getItem() instanceof ItemSparkUpgrade
|| stack.getItem() == ModItems.phantomInk;
|| stack.getItem() == ModItems.phantomInk || stack.getItem() instanceof ItemDye;
if(valid)
player.swingArm(hand);
return valid;
@@ -268,8 +261,8 @@ public class EntitySpark extends Entity implements ISparkEntity {
} else dropAndKill();
return true;
} else {
for(ISparkEntity spark : SparkHelper.getSparksAround(world, posX, posY + (getHeight() / 2.0), posZ))
particleBeam(player, this, (Entity) spark);
SparkHelper.getSparksAround(world, posX, posY + (getHeight() / 2), posZ, getNetwork())
.forEach(s -> particleBeam(player, this, (Entity) s));
return true;
}
} else if(stack.getItem() instanceof ItemSparkUpgrade && upgrade == SparkUpgradeType.NONE) {
@@ -279,6 +272,13 @@ public class EntitySpark extends Entity implements ISparkEntity {
} else if (stack.getItem() == ModItems.phantomInk) {
setInvisible(true);
return true;
} else if (stack.getItem() instanceof ItemDye) {
DyeColor color = ((ItemDye) stack.getItem()).color;
if(color != getNetwork()) {
setNetwork(color);
stack.shrink(1);
return true;
}
}
}
@@ -293,14 +293,14 @@ public class EntitySpark extends Entity implements ISparkEntity {
@Override
protected void readAdditional(@Nonnull CompoundNBT cmp) {
super.readAdditional(cmp);
setUpgrade(SparkUpgradeType.values()[cmp.getInt(TAG_UPGRADE)]);
setInvisible(cmp.getInt(TAG_INVIS) == 1);
}
@Override
protected void writeAdditional(@Nonnull CompoundNBT cmp) {
super.writeAdditional(cmp);
cmp.putInt(TAG_UPGRADE, getUpgrade().ordinal());
cmp.putInt(TAG_INVIS, isInvisible() ? 1 : 0);
}
@Override
@@ -309,7 +309,7 @@ public class EntitySpark extends Entity implements ISparkEntity {
int y = MathHelper.floor(posY) - 1;
int z = MathHelper.floor(posZ);
TileEntity tile = world.getTileEntity(new BlockPos(x, y, z));
if(tile != null && tile instanceof ISparkAttachable)
if(tile instanceof ISparkAttachable)
return (ISparkAttachable) tile;
return null;
@@ -323,10 +323,14 @@ public class EntitySpark extends Entity implements ISparkEntity {
SparkUpgradeType supgr = spark.getUpgrade();
ISparkAttachable atile = spark.getAttachedTile();
if(!(spark != this
&& !spark.areIncomingTransfersDone()
&& atile != null && !atile.isFull()
&& (upgr == SparkUpgradeType.NONE && supgr == SparkUpgradeType.DOMINANT || upgr == SparkUpgradeType.RECESSIVE && (supgr == SparkUpgradeType.NONE || supgr == SparkUpgradeType.DISPERSIVE) || !(atile instanceof IManaPool))))
if(spark == this
|| spark.areIncomingTransfersDone()
|| getNetwork() != spark.getNetwork()
|| atile == null
|| atile.isFull()
|| !(upgr == SparkUpgradeType.NONE && supgr == SparkUpgradeType.DOMINANT
|| upgr == SparkUpgradeType.RECESSIVE && (supgr == SparkUpgradeType.NONE || supgr == SparkUpgradeType.DISPERSIVE)
|| !(atile instanceof IManaPool)))
iter.remove();
}
}
@@ -0,0 +1,50 @@
package vazkii.botania.common.entity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.item.DyeColor;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.network.datasync.DataParameter;
import net.minecraft.network.datasync.DataSerializers;
import net.minecraft.network.datasync.EntityDataManager;
import net.minecraft.world.World;
public abstract class EntitySparkBase extends Entity {
private static final String TAG_INVIS = "invis";
private static final String TAG_NETWORK = "network";
private static final DataParameter<Integer> NETWORK = EntityDataManager.createKey(EntitySparkBase.class, DataSerializers.VARINT);
public EntitySparkBase(EntityType<?> type, World world) {
super(type, world);
}
@Override
protected void registerData() {
dataManager.register(NETWORK, 0);
}
public DyeColor getNetwork() {
return DyeColor.byId(dataManager.get(NETWORK));
}
public void setNetwork(DyeColor color) {
dataManager.set(NETWORK, color.getId());
}
@Override
public boolean canBeCollidedWith() {
return true;
}
@Override
protected void readAdditional(CompoundNBT compound) {
setInvisible(compound.getBoolean(TAG_INVIS));
setNetwork(DyeColor.byId(compound.getInt(TAG_NETWORK)));
}
@Override
protected void writeAdditional(CompoundNBT compound) {
compound.putBoolean(TAG_INVIS, isInvisible());
compound.putInt(TAG_NETWORK, getNetwork().getId());
}
}