Added fancy Laser Relay visuals

This commit is contained in:
Ellpeck 2016-12-27 17:40:27 +01:00
parent 95ee1c0d24
commit ed5378a159
5 changed files with 181 additions and 13 deletions

View file

@ -14,13 +14,16 @@ import de.ellpeck.actuallyadditions.mod.data.PlayerData;
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
import de.ellpeck.actuallyadditions.mod.network.gui.INumberReactor;
import de.ellpeck.actuallyadditions.mod.network.gui.IStringReactor;
import de.ellpeck.actuallyadditions.mod.particle.ParticleLaserItem;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.client.particle.Particle;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
@ -38,7 +41,7 @@ import java.util.UUID;
public final class PacketHandler{
public static final List<IDataHandler> DATA_HANDLERS = new ArrayList<IDataHandler>();
public static final IDataHandler PARTICLE_HANDLER = new IDataHandler(){
public static final IDataHandler LASER_HANDLER = new IDataHandler(){
@Override
@SideOnly(Side.CLIENT)
public void handleData(NBTTagCompound compound){
@ -58,6 +61,27 @@ public final class PacketHandler{
}
}
};
public static final IDataHandler LASER_PARTICLE_HANDLER = new IDataHandler(){
@Override
@SideOnly(Side.CLIENT)
public void handleData(NBTTagCompound compound){
Minecraft mc = Minecraft.getMinecraft();
ItemStack stack = new ItemStack(compound);
double inX = compound.getDouble("InX")+0.5;
double inY = compound.getDouble("InY")+0.925;
double inZ = compound.getDouble("InZ")+0.5;
double outX = compound.getDouble("OutX")+0.5;
double outY = compound.getDouble("OutY")+0.525;
double outZ = compound.getDouble("OutZ")+0.5;
if(mc.player.getDistance(outX, outY, outZ) <= 16){
Particle fx = new ParticleLaserItem(mc.world, outX, outY, outZ, stack, 0.025, inX, inY, inZ);
mc.effectRenderer.addEffect(fx);
}
}
};
public static final IDataHandler GUI_BUTTON_TO_TILE_HANDLER = new IDataHandler(){
@Override
public void handleData(NBTTagCompound compound){
@ -128,12 +152,13 @@ public final class PacketHandler{
theNetwork.registerMessage(PacketServerToClient.Handler.class, PacketServerToClient.class, 0, Side.CLIENT);
theNetwork.registerMessage(PacketClientToServer.Handler.class, PacketClientToServer.class, 1, Side.SERVER);
DATA_HANDLERS.add(PARTICLE_HANDLER);
DATA_HANDLERS.add(LASER_HANDLER);
DATA_HANDLERS.add(TILE_ENTITY_HANDLER);
DATA_HANDLERS.add(GUI_BUTTON_TO_TILE_HANDLER);
DATA_HANDLERS.add(GUI_STRING_TO_TILE_HANDLER);
DATA_HANDLERS.add(GUI_NUMBER_TO_TILE_HANDLER);
DATA_HANDLERS.add(CHANGE_PLAYER_DATA_HANDLER);
DATA_HANDLERS.add(GUI_BUTTON_TO_CONTAINER_HANDLER);
DATA_HANDLERS.add(LASER_PARTICLE_HANDLER);
}
}

View file

@ -8,7 +8,7 @@
* © 2015-2016 Ellpeck
*/
package de.ellpeck.actuallyadditions.mod.misc;
package de.ellpeck.actuallyadditions.mod.particle;
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
import net.minecraft.client.particle.Particle;

View file

@ -0,0 +1,94 @@
/*
* This file ("ParticleLaserItem.java") is part of the Actually Additions mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://ellpeck.de/actaddlicense
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
* © 2015-2016 Ellpeck
*/
package de.ellpeck.actuallyadditions.mod.particle;
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.client.particle.Particle;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.VertexBuffer;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL14;
@SideOnly(Side.CLIENT)
public class ParticleLaserItem extends Particle{
private final double otherX;
private final double otherY;
private final double otherZ;
private final ItemStack stack;
private ParticleLaserItem(World world, double posX, double posY, double posZ, ItemStack stack, double motionY){
this(world, posX, posY, posZ, stack, motionY, 0, 0, 0);
}
public ParticleLaserItem(World world, double posX, double posY, double posZ, ItemStack stack, double motionY, double otherX, double otherY, double otherZ){
super(world, posX+(world.rand.nextDouble()-0.5)/12, posY, posZ+(world.rand.nextDouble()-0.5)/12);
this.stack = stack;
this.otherX = otherX;
this.otherY = otherY;
this.otherZ = otherZ;
this.motionX = 0;
this.motionY = motionY;
this.motionZ = 0;
this.particleMaxAge = 20;
this.canCollide = false;
}
@Override
public void setExpired(){
super.setExpired();
if(this.otherX != 0 || this.otherY != 0 || this.otherZ != 0){
Particle fx = new ParticleLaserItem(this.world, this.otherX, this.otherY, this.otherZ, this.stack, -0.025);
Minecraft.getMinecraft().effectRenderer.addEffect(fx);
}
}
@Override
public void renderParticle(VertexBuffer buffer, Entity entityIn, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ){
GlStateManager.pushMatrix();
RenderHelper.enableStandardItemLighting();
GlStateManager.translate(this.posX-TileEntityRendererDispatcher.staticPlayerX, this.posY-TileEntityRendererDispatcher.staticPlayerY, this.posZ-TileEntityRendererDispatcher.staticPlayerZ);
GlStateManager.scale(0.3F, 0.3F, 0.3F);
double boop = Minecraft.getSystemTime()/600D;
GlStateManager.rotate((float)((boop*40D)%360), 0, 1, 0);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_CONSTANT_COLOR, GlStateManager.SourceFactor.ONE.factor, GlStateManager.DestFactor.ZERO.factor);
float ageRatio = (float)this.particleAge/(float)this.particleMaxAge;
float color = this.motionY < 0 ? 1F-ageRatio : ageRatio;
GL14.glBlendColor(color, color, color, color);
AssetUtil.renderItemWithoutScrewingWithColors(this.stack);
RenderHelper.disableStandardItemLighting();
GlStateManager.popMatrix();
}
@Override
public int getFXLayer(){
return 3;
}
}

View file

@ -12,12 +12,16 @@ package de.ellpeck.actuallyadditions.mod.tile;
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
import de.ellpeck.actuallyadditions.api.laser.Network;
import de.ellpeck.actuallyadditions.mod.network.PacketHandler;
import de.ellpeck.actuallyadditions.mod.network.PacketServerToClient;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint;
import net.minecraftforge.items.IItemHandler;
import java.util.*;
@ -62,11 +66,12 @@ public class TileEntityItemViewer extends TileEntityBase{
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate){
SpecificItemHandlerInfo info = TileEntityItemViewer.this.getSwitchedIndexHandler(slot);
if(info != null && TileEntityItemViewer.this.isWhitelisted(info, stack, false)){
ItemStack inserted = info.handler.insertItem(info.switchedIndex, stack, simulate);
if(!ItemStack.areItemStacksEqual(inserted, stack)){
ItemStack remain = info.handler.insertItem(info.switchedIndex, stack, simulate);
if(!ItemStack.areItemStacksEqual(remain, stack) && !simulate){
TileEntityItemViewer.this.markDirty();
TileEntityItemViewer.this.doItemParticle(stack, info.relayInQuestion.getPos(), TileEntityItemViewer.this.connectedRelay.getPos());
}
return inserted;
return remain;
}
return stack;
}
@ -78,8 +83,9 @@ public class TileEntityItemViewer extends TileEntityBase{
SpecificItemHandlerInfo info = TileEntityItemViewer.this.getSwitchedIndexHandler(slot);
if(info != null && TileEntityItemViewer.this.isWhitelisted(info, stackIn, true)){
ItemStack extracted = info.handler.extractItem(info.switchedIndex, amount, simulate);
if(extracted != null){
if(StackUtil.isValid(extracted) && !simulate){
TileEntityItemViewer.this.markDirty();
TileEntityItemViewer.this.doItemParticle(extracted, TileEntityItemViewer.this.connectedRelay.getPos(), info.relayInQuestion.getPos());
}
return extracted;
}
@ -114,6 +120,23 @@ public class TileEntityItemViewer extends TileEntityBase{
return this.genericInfos;
}
private void doItemParticle(ItemStack stack, BlockPos input, BlockPos output){
if(!this.world.isRemote){
NBTTagCompound compound = new NBTTagCompound();
stack.writeToNBT(compound);
compound.setDouble("InX", input.getX());
compound.setDouble("InY", input.getY());
compound.setDouble("InZ", input.getZ());
compound.setDouble("OutX", output.getX());
compound.setDouble("OutY", output.getY());
compound.setDouble("OutZ", output.getZ());
PacketHandler.theNetwork.sendToAllAround(new PacketServerToClient(compound, PacketHandler.LASER_PARTICLE_HANDLER), new TargetPoint(this.world.provider.getDimension(), this.pos.getX(), this.pos.getY(), this.pos.getZ(), 16));
}
}
private void queryAndSaveData(){
if(this.connectedRelay != null){
Network network = ActuallyAdditionsAPI.connectionHandler.getNetworkFor(this.connectedRelay.getPos(), this.world);

View file

@ -10,21 +10,21 @@
package de.ellpeck.actuallyadditions.mod.util;
import de.ellpeck.actuallyadditions.mod.misc.ParticleBeam;
import de.ellpeck.actuallyadditions.mod.network.PacketHandler;
import de.ellpeck.actuallyadditions.mod.network.PacketServerToClient;
import de.ellpeck.actuallyadditions.mod.particle.ParticleBeam;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.particle.Particle;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.*;
import net.minecraft.client.renderer.GlStateManager.DestFactor;
import net.minecraft.client.renderer.GlStateManager.SourceFactor;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.VertexBuffer;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.item.ItemStack;
@ -32,6 +32,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraftforge.client.ForgeHooksClient;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@ -82,6 +83,31 @@ public final class AssetUtil{
}
}
@SideOnly(Side.CLIENT)
public static void renderItemWithoutScrewingWithColors(ItemStack stack){
if(StackUtil.isValid(stack)){
Minecraft mc = Minecraft.getMinecraft();
RenderItem renderer = mc.getRenderItem();
TextureManager manager = mc.getTextureManager();
IBakedModel model = renderer.getItemModelWithOverrides(stack, null, null);
manager.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
manager.getTexture(TextureMap.LOCATION_BLOCKS_TEXTURE).setBlurMipmap(false, false);
GlStateManager.enableRescaleNormal();
GlStateManager.enableBlend();
GlStateManager.pushMatrix();
model = ForgeHooksClient.handleCameraTransforms(model, TransformType.FIXED, false);
renderer.renderItem(stack, model);
GlStateManager.cullFace(GlStateManager.CullFace.BACK);
GlStateManager.popMatrix();
GlStateManager.disableRescaleNormal();
GlStateManager.disableBlend();
manager.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
manager.getTexture(TextureMap.LOCATION_BLOCKS_TEXTURE).restoreLastBlurMipmap();
}
}
@SideOnly(Side.CLIENT)
public static void renderStackToGui(ItemStack stack, int x, int y, float scale){
GlStateManager.pushMatrix();
@ -188,7 +214,7 @@ public final class AssetUtil{
data.setFloat("Size", size);
data.setInteger("MaxAge", maxAge);
data.setFloat("Alpha", alpha);
PacketHandler.theNetwork.sendToAllAround(new PacketServerToClient(data, PacketHandler.PARTICLE_HANDLER), new NetworkRegistry.TargetPoint(world.provider.getDimension(), startX, startY, startZ, 96));
PacketHandler.theNetwork.sendToAllAround(new PacketServerToClient(data, PacketHandler.LASER_HANDLER), new NetworkRegistry.TargetPoint(world.provider.getDimension(), startX, startY, startZ, 96));
}
}