allow for entities to be visualized as well and visualize effect powder

This commit is contained in:
Ellpeck 2019-01-28 15:43:21 +01:00
parent 47d565a70c
commit 5fe865f299
11 changed files with 107 additions and 36 deletions

View file

@ -105,7 +105,7 @@ public class InternalHooks implements NaturesAuraAPI.IInternalHooks {
return false;
AxisAlignedBB bounds = new AxisAlignedBB(
entity.posX, entity.posY, entity.posZ,
entity.posX, entity.posY, entity.posZ).grow(entity.amount);
entity.posX, entity.posY, entity.posZ).grow(entity.getAmount());
return bounds.contains(new Vec3d(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5));
});
return !inhibitors.isEmpty();

View file

@ -6,7 +6,7 @@ import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public interface IVisualizableBlock {
public interface IVisualizable {
@SideOnly(Side.CLIENT)
AxisAlignedBB getVisualizationBounds(World world, BlockPos pos);

View file

@ -2,7 +2,7 @@ package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.api.render.IVisualizableBlock;
import de.ellpeck.naturesaura.api.render.IVisualizable;
import de.ellpeck.naturesaura.blocks.tiles.TileEntityAnimalGenerator;
import de.ellpeck.naturesaura.packet.PacketHandler;
import de.ellpeck.naturesaura.packet.PacketParticles;
@ -26,7 +26,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockAnimalGenerator extends BlockContainerImpl implements IVisualizableBlock {
public class BlockAnimalGenerator extends BlockContainerImpl implements IVisualizable {
public BlockAnimalGenerator() {
super(Material.ROCK, "animal_generator", TileEntityAnimalGenerator.class, "animal_generator");
this.setSoundType(SoundType.STONE);

View file

@ -1,6 +1,6 @@
package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.api.render.IVisualizableBlock;
import de.ellpeck.naturesaura.api.render.IVisualizable;
import de.ellpeck.naturesaura.blocks.tiles.TileEntityHopperUpgrade;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
@ -10,7 +10,7 @@ import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockHopperUpgrade extends BlockContainerImpl implements IVisualizableBlock {
public class BlockHopperUpgrade extends BlockContainerImpl implements IVisualizable {
public BlockHopperUpgrade() {
super(Material.IRON, "hopper_upgrade", TileEntityHopperUpgrade.class, "hopper_upgrade");
this.setSoundType(SoundType.METAL);

View file

@ -2,7 +2,7 @@ package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.render.IVisualizableBlock;
import de.ellpeck.naturesaura.api.render.IVisualizable;
import de.ellpeck.naturesaura.blocks.tiles.TileEntityOakGenerator;
import net.minecraft.block.BlockSapling;
import net.minecraft.block.SoundType;
@ -18,7 +18,7 @@ import net.minecraftforge.fml.relauncher.SideOnly;
import java.util.Random;
public class BlockOakGenerator extends BlockContainerImpl implements IVisualizableBlock {
public class BlockOakGenerator extends BlockContainerImpl implements IVisualizable {
public BlockOakGenerator() {
super(Material.WOOD, "oak_generator", TileEntityOakGenerator.class, "oak_generator");

View file

@ -1,7 +1,7 @@
package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.api.render.IVisualizableBlock;
import de.ellpeck.naturesaura.api.render.IVisualizable;
import de.ellpeck.naturesaura.blocks.tiles.TileEntityPickupStopper;
import de.ellpeck.naturesaura.packet.PacketHandler;
import de.ellpeck.naturesaura.packet.PacketParticles;
@ -19,7 +19,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockPickupStopper extends BlockContainerImpl implements IVisualizableBlock {
public class BlockPickupStopper extends BlockContainerImpl implements IVisualizable {
public BlockPickupStopper() {
super(Material.ROCK, "pickup_stopper", TileEntityPickupStopper.class, "pickup_stopper");
this.setSoundType(SoundType.STONE);

View file

@ -2,7 +2,7 @@ package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import de.ellpeck.naturesaura.api.render.IVisualizableBlock;
import de.ellpeck.naturesaura.api.render.IVisualizable;
import de.ellpeck.naturesaura.blocks.tiles.TileEntitySpawnLamp;
import de.ellpeck.naturesaura.packet.PacketHandler;
import de.ellpeck.naturesaura.packet.PacketParticles;
@ -26,7 +26,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockSpawnLamp extends BlockContainerImpl implements IVisualizableBlock {
public class BlockSpawnLamp extends BlockContainerImpl implements IVisualizable {
private static final AxisAlignedBB AABB = new AxisAlignedBB(4 / 16F, 0F, 4 / 16F, 12 / 16F, 13 / 16F, 12 / 16F);

View file

@ -1,6 +1,7 @@
package de.ellpeck.naturesaura.entities;
import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.api.render.IVisualizable;
import de.ellpeck.naturesaura.items.ItemEffectPowder;
import de.ellpeck.naturesaura.items.ModItems;
import net.minecraft.entity.Entity;
@ -12,13 +13,17 @@ import net.minecraft.network.datasync.EntityDataManager;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EntityDamageSource;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class EntityEffectInhibitor extends Entity {
public class EntityEffectInhibitor extends Entity implements IVisualizable {
private static final DataParameter<String> INHIBITED_EFFECT = EntityDataManager.createKey(EntityEffectInhibitor.class, DataSerializers.STRING);
private static final DataParameter<Integer> COLOR = EntityDataManager.createKey(EntityEffectInhibitor.class, DataSerializers.VARINT);
public int amount;
private static final DataParameter<Integer> AMOUNT = EntityDataManager.createKey(EntityEffectInhibitor.class, DataSerializers.VARINT);
public EntityEffectInhibitor(World worldIn) {
super(worldIn);
@ -29,20 +34,21 @@ public class EntityEffectInhibitor extends Entity {
this.setSize(0.25F, 0.25F);
this.dataManager.register(INHIBITED_EFFECT, null);
this.dataManager.register(COLOR, 0);
this.dataManager.register(AMOUNT, 0);
}
@Override
protected void readEntityFromNBT(NBTTagCompound compound) {
this.setInhibitedEffect(new ResourceLocation(compound.getString("effect")));
this.setColor(compound.getInteger("color"));
this.amount = compound.hasKey("amount") ? compound.getInteger("amount") : 24;
this.setAmount(compound.hasKey("amount") ? compound.getInteger("amount") : 24);
}
@Override
protected void writeEntityToNBT(NBTTagCompound compound) {
compound.setString("effect", this.getInhibitedEffect().toString());
compound.setInteger("color", this.getColor());
compound.setInteger("amount", this.amount);
compound.setInteger("amount", this.getAmount());
}
@Override
@ -70,7 +76,7 @@ public class EntityEffectInhibitor extends Entity {
public boolean attackEntityFrom(DamageSource source, float amount) {
if (source instanceof EntityDamageSource && !this.world.isRemote) {
this.setDead();
this.entityDropItem(ItemEffectPowder.setEffect(new ItemStack(ModItems.EFFECT_POWDER, this.amount), this.getInhibitedEffect()), 0F);
this.entityDropItem(ItemEffectPowder.setEffect(new ItemStack(ModItems.EFFECT_POWDER, this.getAmount()), this.getInhibitedEffect()), 0F);
return true;
} else
return super.attackEntityFrom(source, amount);
@ -91,4 +97,26 @@ public class EntityEffectInhibitor extends Entity {
public int getColor() {
return this.dataManager.get(COLOR);
}
public void setAmount(int amount) {
this.dataManager.set(AMOUNT, amount);
}
public int getAmount() {
return this.dataManager.get(AMOUNT);
}
@Override
@SideOnly(Side.CLIENT)
public AxisAlignedBB getVisualizationBounds(World world, BlockPos pos) {
return new AxisAlignedBB(
this.posX, this.posY, this.posZ,
this.posX, this.posY, this.posZ).grow(this.getAmount());
}
@Override
@SideOnly(Side.CLIENT)
public int getVisualizationColor(World world, BlockPos pos) {
return this.getColor();
}
}

View file

@ -8,7 +8,7 @@ import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import de.ellpeck.naturesaura.api.aura.container.IAuraContainer;
import de.ellpeck.naturesaura.api.aura.type.IAuraType;
import de.ellpeck.naturesaura.api.render.IVisualizableBlock;
import de.ellpeck.naturesaura.api.render.IVisualizable;
import de.ellpeck.naturesaura.blocks.tiles.TileEntityNatureAltar;
import de.ellpeck.naturesaura.blocks.tiles.TileEntityRFConverter;
import de.ellpeck.naturesaura.compat.Compat;
@ -23,6 +23,7 @@ import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
@ -30,6 +31,7 @@ import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
import net.minecraftforge.client.event.RenderWorldLastEvent;
@ -97,12 +99,19 @@ public class ClientEvents {
public void onClientTick(ClientTickEvent event) {
if (event.phase == Phase.END) {
Minecraft mc = Minecraft.getMinecraft();
mc.profiler.func_194340_a(() -> NaturesAura.MOD_ID + ":updateParticles");
if (!mc.isGamePaused())
ParticleHandler.updateParticles();
if (mc.world == null)
ParticleHandler.clearParticles();
mc.profiler.endSection();
if (mc.world == null) {
ParticleHandler.clearParticles();
if (!ItemRangeVisualizer.VISUALIZED_BLOCKS.isEmpty())
ItemRangeVisualizer.VISUALIZED_BLOCKS.clear();
if (!ItemRangeVisualizer.VISUALIZED_ENTITIES.isEmpty())
ItemRangeVisualizer.VISUALIZED_ENTITIES.clear();
}
}
}
@ -157,21 +166,19 @@ public class ClientEvents {
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBegin(GL11.GL_QUADS);
for (BlockPos pos : ItemRangeVisualizer.VISUALIZED_POSITIONS) {
for (BlockPos pos : ItemRangeVisualizer.VISUALIZED_BLOCKS) {
if (!mc.world.isBlockLoaded(pos))
continue;
IBlockState state = mc.world.getBlockState(pos);
Block block = state.getBlock();
if (!(block instanceof IVisualizableBlock))
if (!(block instanceof IVisualizable))
continue;
IVisualizableBlock visualize = (IVisualizableBlock) block;
AxisAlignedBB box = visualize.getVisualizationBounds(mc.world, pos);
if (box == null)
this.renderVisualize((IVisualizable) block, mc.world, pos);
}
for (Entity entity : ItemRangeVisualizer.VISUALIZED_ENTITIES) {
if (entity.isDead || !(entity instanceof IVisualizable))
continue;
box = box.grow(0.05F);
int color = visualize.getVisualizationColor(mc.world, pos);
GlStateManager.color(((color >> 16) & 255) / 255F, ((color >> 8) & 255) / 255F, (color & 255) / 255F, 0.5F);
Helper.renderWeirdBox(box.minX, box.minY, box.minZ, box.maxX - box.minX, box.maxY - box.minY, box.maxZ - box.minZ);
this.renderVisualize((IVisualizable) entity, mc.world, entity.getPosition());
}
GL11.glEnd();
GL11.glPopAttrib();
@ -184,6 +191,16 @@ public class ClientEvents {
mc.profiler.endSection();
}
private void renderVisualize(IVisualizable visualize, World world, BlockPos pos) {
AxisAlignedBB box = visualize.getVisualizationBounds(world, pos);
if (box == null)
return;
box = box.grow(0.05F);
int color = visualize.getVisualizationColor(world, pos);
GlStateManager.color(((color >> 16) & 255) / 255F, ((color >> 8) & 255) / 255F, (color & 255) / 255F, 0.5F);
Helper.renderWeirdBox(box.minX, box.minY, box.minZ, box.maxX - box.minX, box.maxY - box.minY, box.maxZ - box.minZ);
}
@SubscribeEvent
public void onOverlayRender(RenderGameOverlayEvent.Post event) {
Minecraft mc = Minecraft.getMinecraft();

View file

@ -29,7 +29,7 @@ public class ItemEffectPowder extends ItemImpl implements IColorProvidingItem {
EntityEffectInhibitor entity = new EntityEffectInhibitor(worldIn);
entity.setInhibitedEffect(effect);
entity.setColor(NaturesAuraAPI.EFFECT_POWDERS.get(effect));
entity.amount = stack.getCount();
entity.setAmount(stack.getCount());
entity.setPosition(pos.getX() + hitX, pos.getY() + hitY + 1, pos.getZ() + hitZ);
worldIn.spawnEntity(entity);
stack.setCount(0);

View file

@ -1,38 +1,64 @@
package de.ellpeck.naturesaura.items;
import de.ellpeck.naturesaura.api.render.IVisualizableBlock;
import de.ellpeck.naturesaura.api.render.IVisualizable;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import java.util.HashSet;
import java.util.Set;
public class ItemRangeVisualizer extends ItemImpl {
public static final Set<BlockPos> VISUALIZED_POSITIONS = new HashSet<>();
public static final Set<BlockPos> VISUALIZED_BLOCKS = new HashSet<>();
public static final Set<Entity> VISUALIZED_ENTITIES = new HashSet<>();
public ItemRangeVisualizer() {
super("range_visualizer");
MinecraftForge.EVENT_BUS.register(this);
}
@Override
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
IBlockState state = worldIn.getBlockState(pos);
Block block = state.getBlock();
if (block instanceof IVisualizableBlock) {
if (block instanceof IVisualizable) {
if (worldIn.isRemote)
if (VISUALIZED_POSITIONS.contains(pos))
VISUALIZED_POSITIONS.remove(pos);
if (VISUALIZED_BLOCKS.contains(pos))
VISUALIZED_BLOCKS.remove(pos);
else
VISUALIZED_POSITIONS.add(pos);
VISUALIZED_BLOCKS.add(pos);
return EnumActionResult.SUCCESS;
}
return EnumActionResult.PASS;
}
@SubscribeEvent
public void onInteract(PlayerInteractEvent.EntityInteractSpecific event) {
ItemStack stack = event.getItemStack();
if (stack.isEmpty() || stack.getItem() != this)
return;
Entity entity = event.getTarget();
if (entity instanceof IVisualizable) {
if (entity.world.isRemote) {
if (VISUALIZED_ENTITIES.contains(entity))
VISUALIZED_ENTITIES.remove(entity);
else
VISUALIZED_ENTITIES.add(entity);
}
event.getEntityPlayer().swingArm(event.getHand());
event.setCancellationResult(EnumActionResult.SUCCESS);
event.setCanceled(true);
}
}
}