Skip to content

Commit

Permalink
Rendering fixes
Browse files Browse the repository at this point in the history
Redid the *RiftFX classes based on the old 1.6.4 code, but overriding ParticleSimpleAnimated.
  • Loading branch information
Runemoro committed Dec 20, 2017
1 parent 3d50cd8 commit 0599a6d
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 140 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
language: java
notifications:
email: false
if: tag IS blank

before_install: chmod +x gradlew
install: "./gradlew setupCIWorkspace"
script: "./gradlew build"
Expand All @@ -13,6 +15,7 @@ cache:
- "$HOME/.gradle/caches/"
- "$HOME/.gradle/wrapper/"
sudo: false

deploy:
skip_cleanup: true
provider: releases
Expand Down
88 changes: 0 additions & 88 deletions src/main/java/com/zixiken/dimdoors/client/ClosingRiftFX.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class CloudRenderBlank extends IRenderHandler
{
public class CloudRenderBlank extends IRenderHandler {
@Override
@SideOnly(Side.CLIENT)
public void render(float partialTicks, WorldClient world, Minecraft mc) {

}
public void render(float partialTicks, WorldClient world, Minecraft mc) {}
}
4 changes: 2 additions & 2 deletions src/main/java/com/zixiken/dimdoors/client/DDProxyClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)
@SideOnly(Side.CLIENT) // 8 4
public class DDProxyClient extends DDProxyCommon {

@Override
public void onPreInitialization(FMLPreInitializationEvent event) {
super.onPreInitialization(event);
//ModelManager.addCustomStateMappers();
// ModelManager.addCustomStateMappers(); // TODO: fix this
ModelManager.registerModelVariants();
registerRenderers();
}
Expand Down
15 changes: 0 additions & 15 deletions src/main/java/com/zixiken/dimdoors/client/GoggleRiftFX.java

This file was deleted.

59 changes: 59 additions & 0 deletions src/main/java/com/zixiken/dimdoors/client/ParticleRiftEffect.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.zixiken.dimdoors.client;

import com.zixiken.dimdoors.shared.util.WorldUtils;
import com.zixiken.dimdoors.shared.world.DimDoorDimensions;
import net.minecraft.client.particle.ParticleFirework;
import net.minecraft.client.particle.ParticleSimpleAnimated;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.entity.Entity;
import net.minecraft.world.World;

// This has exactly the same appearence as the 1.6.4 mod.
public class ParticleRiftEffect extends ParticleSimpleAnimated { // TODO: colors, density

private float colorMultiplier;

public ParticleRiftEffect(World world, double x, double y, double z, double motionX, double motionY, double motionZ, float nonPocketColorMultiplier, float pocketColorMultiplier, float scale, int size, int spread) {
super(world, x, y, z, 160, 8, 0);
this.motionX = motionX;
this.motionY = motionY;
this.motionZ = motionZ;

particleScale *= scale;
particleMaxAge = size - spread / 2 + rand.nextInt(spread);
colorMultiplier = DimDoorDimensions.isPocketDimension(WorldUtils.getDim(world)) ? pocketColorMultiplier : nonPocketColorMultiplier;
}

@Override
public void renderParticle(BufferBuilder buffer, Entity entityIn, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ) {
if (particleAge < particleMaxAge / 3 || (particleAge + particleMaxAge) / 3 % 2 == 0) {
float oldRed = particleRed;
float oldGreen = particleGreen;
float oldBlue = particleBlue;
float oldAlpha = particleAlpha;
setRBGColorF(colorMultiplier * particleRed, colorMultiplier * particleGreen, colorMultiplier * particleBlue);
setAlphaF(0.7f);
super.renderParticle(buffer, entityIn, partialTicks, rotationX, rotationZ, rotationYZ, rotationXY, rotationXZ);
setRBGColorF(oldRed, oldGreen, oldBlue);
setAlphaF(oldAlpha);
}
}

public static class Rift extends ParticleRiftEffect {
public Rift(World world, double x, double y, double z, double motionX, double motionY, double motionZ) {
super(world, x, y, z, motionX, motionY, motionZ, 0.0f, 0.7f, 0.55f, 38, 16);
}
}

public static class ClosingRiftEffect extends ParticleRiftEffect {
public ClosingRiftEffect(World world, double x, double y, double z, double motionX, double motionY, double motionZ) {
super(world, x, y, z, motionX, motionY, motionZ, 0.8f, 0.4f, 0.55f, 38, 16);
}
}

public static class GogglesRiftEffect extends ParticleRiftEffect {
public GogglesRiftEffect(World world, double x, double y, double z, double motionX, double motionY, double motionZ) {
super(world, x, y, z, motionX, motionY, motionZ, 0.0f, 0.7f, 0.55f, 38, 16);
}
}
}
42 changes: 21 additions & 21 deletions src/main/java/com/zixiken/dimdoors/shared/blocks/BlockRift.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package com.zixiken.dimdoors.shared.blocks;

import com.zixiken.dimdoors.DimDoors;
import com.zixiken.dimdoors.client.ClosingRiftFX;
import com.zixiken.dimdoors.client.GoggleRiftFX;
import com.zixiken.dimdoors.client.ParticleRiftEffect;
import com.zixiken.dimdoors.shared.items.ModItems;
import com.zixiken.dimdoors.shared.tileentities.TileEntityFloatingRift;

import java.util.*;
import net.minecraft.block.Block;
import net.minecraft.block.BlockDoor;
import net.minecraft.block.BlockLiquid;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.EnumPushReaction;
import net.minecraft.block.material.Material;
Expand Down Expand Up @@ -134,24 +131,27 @@ public EnumPushReaction getMobilityFlag(IBlockState state) {
@Override
@SideOnly(Side.CLIENT)
public void randomDisplayTick(IBlockState stateIn, World worldIn, BlockPos pos, Random rand) {
//ArrayList<BlockPos> targets = findReachableBlocks(worldIn, pos, 2, false);
//TODO: implement the parts specified in the method comment?
int x = pos.getX(), y = pos.getY(), z = pos.getZ();

TileEntityFloatingRift tile = (TileEntityFloatingRift) worldIn.getTileEntity(pos);
//renders an extra little blob on top of the actual rift location so its easier to find.
// Eventually will only renderDoorRift if the player has the goggles.
//FMLClientHandler.instance().getClient().effectRenderer.addEffect(new GoggleRiftFX(
/* worldIn,
x + .5, y + .5, z + .5,
rand.nextGaussian() * 0.01D,
rand.nextGaussian() * 0.01D,
rand.nextGaussian() * 0.01D));*/

if (tile.shouldClose) { //renders an opposite color effect if it is being closed by the rift remover
FMLClientHandler.instance().getClient().effectRenderer.addEffect(new ClosingRiftFX(
//ArrayList<BlockPos> targets = findReachableBlocks(worldIn, pos, 2, false); // TODO
TileEntityFloatingRift rift = (TileEntityFloatingRift) worldIn.getTileEntity(pos);

if (true) {
FMLClientHandler.instance().getClient().effectRenderer.addEffect(new ParticleRiftEffect.Rift( // TODO: this effect was unfinished in the 1.6.4 mod too
worldIn,
pos.getX() + .5, pos.getY() + .5, pos.getZ() + .5,
rand.nextGaussian() * 0.01D, rand.nextGaussian() * 0.01D, rand.nextGaussian() * 0.01D));
}

if (false) {
FMLClientHandler.instance().getClient().effectRenderer.addEffect(new ParticleRiftEffect.GogglesRiftEffect( // TODO: this effect was unfinished in the 1.6.4 mod too
worldIn,
pos.getX() + .5, pos.getY() + .5, pos.getZ() + .5,
rand.nextGaussian() * 0.01D, rand.nextGaussian() * 0.01D, rand.nextGaussian() * 0.01D));
}

if (rift.shouldClose) { // Renders an opposite color effect if it is being closed by the rift remover
FMLClientHandler.instance().getClient().effectRenderer.addEffect(new ParticleRiftEffect.ClosingRiftEffect(
worldIn,
x + .5, y + .5, z + .5,
pos.getX() + .5, pos.getY() + .5, pos.getZ() + .5,
rand.nextGaussian() * 0.01D, rand.nextGaussian() * 0.01D, rand.nextGaussian() * 0.01D));
}
}
Expand Down
40 changes: 40 additions & 0 deletions src/main/java/com/zixiken/dimdoors/shared/util/MCPReflection.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.zixiken.dimdoors.shared.util;

import net.minecraft.entity.Entity;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

public class MCPReflection {
public static Field getMCPField(Class<?> class0, String deobfuscatedName, String obfuscatedName) throws NoSuchFieldException {
Field field;
try {
field = class0.getDeclaredField(obfuscatedName);
} catch (NoSuchFieldException e) { // Running on deobfuscated Minecraft
field = class0.getDeclaredField(deobfuscatedName);
}
field.setAccessible(true);

try {
Field modifiers = Field.class.getDeclaredField("modifiers");
modifiers.setAccessible(true);
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}

return field;
}

public static Method getMCPMethod(Class<?> class0, String deobfuscatedName, String obfuscatedName, Class<?> args) throws NoSuchMethodException {
Method method;
try {
method = Entity.class.getDeclaredMethod(obfuscatedName, args);
} catch (NoSuchMethodException e) { // Running on deobfuscated Minecraft
method = Entity.class.getDeclaredMethod(deobfuscatedName, args);
}
method.setAccessible(true);
return method;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.network.play.server.*;
import net.minecraft.potion.PotionEffect;
Expand Down Expand Up @@ -76,13 +77,7 @@ public static Entity teleport(Entity entity, int newDimension, double x, double
if (entity instanceof EntityPlayerMP) {
EntityPlayerMP player = (EntityPlayerMP) entity;
try {
Field invulnerableDimensionChange;
try {
invulnerableDimensionChange = EntityPlayerMP.class.getDeclaredField("field_184851_cj"); // If this breaks, check that Minecraft didn't rename the field
} catch (NoSuchFieldException e) { // Running on deobfuscated Minecraft
invulnerableDimensionChange = EntityPlayerMP.class.getDeclaredField("invulnerableDimensionChange");
}
invulnerableDimensionChange.setAccessible(true);
Field invulnerableDimensionChange = MCPReflection.getMCPField(EntityPlayerMP.class, "invulnerableDimensionChange", "field_184851_cj");
invulnerableDimensionChange.setBoolean(player, true); // Prevent Minecraft from cancelling the position change being too big if the player is not in creative
} catch (NoSuchFieldException|IllegalAccessException e) {
throw new RuntimeException(e);
Expand Down Expand Up @@ -142,8 +137,7 @@ public static Entity teleport(Entity entity, int newDimension, double x, double

if (newEntity != null) {
try {
Method copyDataFromOld = Entity.class.getDeclaredMethod("copyDataFromOld", Entity.class);
copyDataFromOld.setAccessible(true);
Method copyDataFromOld = MCPReflection.getMCPMethod(Entity.class,"copyDataFromOld", "func_180432_n", Entity.class);
copyDataFromOld.invoke(newEntity, entity);
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
throw new RuntimeException(e);
Expand Down

0 comments on commit 0599a6d

Please sign in to comment.