Animated Torch.

This commit is contained in:
Vasco Lavos committed 2016-09-28 20:32:15 +01:00
1 parent c6f9ecb5f9
commit d46db2943c
13 files changed
+431 -13

No files matched your search

@@ -0,0 +1,25 @@
/**
* This class was created by <Vazkii>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*
* File Created @ [28/09/2016, 20:01:14 (GMT)]
*/
package vazkii.botania.api.item;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
/**
* Have a block implement this class to make it do something when an adjacent
* Hovering Hourglass turns.
*/
public interface IHourglassTrigger {
public void onTriggeredByHourglass(World world, BlockPos pos, TileEntity hourglass);
}
@@ -1,4 +1,4 @@
@API(owner = "Botania", apiVersion = "81", provides = "BotaniaAPI")
@API(owner = "Botania", apiVersion = "82", provides = "BotaniaAPI")
package vazkii.botania.api;
import net.minecraftforge.fml.common.API;
@@ -10,6 +10,14 @@
*/
package vazkii.botania.client.core.proxy;
import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.time.LocalDateTime;
import java.time.Month;
import java.util.Map;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.model.ModelBiped;
@@ -46,6 +54,7 @@ import vazkii.botania.api.wiki.IWikiProvider;
import vazkii.botania.api.wiki.WikiHooks;
import vazkii.botania.client.challenge.ModChallenges;
import vazkii.botania.client.core.handler.BaubleRenderHandler;
import vazkii.botania.client.core.handler.BlockHighlightRenderHandler;
import vazkii.botania.client.core.handler.BossBarHandler;
import vazkii.botania.client.core.handler.BotaniaPlayerController;
import vazkii.botania.client.core.handler.BoundTileRenderer;
@@ -61,7 +70,6 @@ import vazkii.botania.client.core.handler.ModelHandler;
import vazkii.botania.client.core.handler.MultiblockRenderHandler;
import vazkii.botania.client.core.handler.PersistentVariableHelper;
import vazkii.botania.client.core.handler.RenderLexicon;
import vazkii.botania.client.core.handler.BlockHighlightRenderHandler;
import vazkii.botania.client.core.handler.TooltipAdditionDisplayHandler;
import vazkii.botania.client.core.handler.TooltipHandler;
import vazkii.botania.client.core.helper.ShaderHelper;
@@ -83,6 +91,7 @@ import vazkii.botania.client.render.entity.RenderSnowballStack;
import vazkii.botania.client.render.entity.RenderSpark;
import vazkii.botania.client.render.tile.RenderTileAlfPortal;
import vazkii.botania.client.render.tile.RenderTileAltar;
import vazkii.botania.client.render.tile.RenderTileAnimatedTorch;
import vazkii.botania.client.render.tile.RenderTileAvatar;
import vazkii.botania.client.render.tile.RenderTileBellows;
import vazkii.botania.client.render.tile.RenderTileBrewery;
@@ -91,6 +100,7 @@ import vazkii.botania.client.render.tile.RenderTileCorporeaCrystalCube;
import vazkii.botania.client.render.tile.RenderTileCorporeaIndex;
import vazkii.botania.client.render.tile.RenderTileEnchanter;
import vazkii.botania.client.render.tile.RenderTileFloatingFlower;
import vazkii.botania.client.render.tile.RenderTileGaiaHead;
import vazkii.botania.client.render.tile.RenderTileHourglass;
import vazkii.botania.client.render.tile.RenderTileIncensePlate;
import vazkii.botania.client.render.tile.RenderTileLightRelay;
@@ -99,7 +109,6 @@ import vazkii.botania.client.render.tile.RenderTilePrism;
import vazkii.botania.client.render.tile.RenderTilePylon;
import vazkii.botania.client.render.tile.RenderTileRedString;
import vazkii.botania.client.render.tile.RenderTileRuneAltar;
import vazkii.botania.client.render.tile.RenderTileGaiaHead;
import vazkii.botania.client.render.tile.RenderTileSparkChanger;
import vazkii.botania.client.render.tile.RenderTileSpreader;
import vazkii.botania.client.render.tile.RenderTileStarfield;
@@ -111,6 +120,7 @@ import vazkii.botania.common.Botania;
import vazkii.botania.common.block.subtile.functional.BergamuteEventHandler;
import vazkii.botania.common.block.tile.TileAlfPortal;
import vazkii.botania.common.block.tile.TileAltar;
import vazkii.botania.common.block.tile.TileAnimatedTorch;
import vazkii.botania.common.block.tile.TileAvatar;
import vazkii.botania.common.block.tile.TileBrewery;
import vazkii.botania.common.block.tile.TileCocoon;
@@ -159,14 +169,6 @@ import vazkii.botania.common.item.equipment.bauble.ItemMonocle;
import vazkii.botania.common.lexicon.LexiconData;
import vazkii.botania.common.lib.LibObfuscation;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.time.LocalDateTime;
import java.time.Month;
import java.util.Map;
public class ClientProxy implements IProxy {
public static boolean jingleTheBells = false;
@@ -263,6 +265,7 @@ public class ClientProxy implements IProxy {
ClientRegistry.bindTileEntitySpecialRenderer(TileGaiaHead.class, new RenderTileGaiaHead());
ClientRegistry.bindTileEntitySpecialRenderer(TileTeruTeruBozu.class, new RenderTileTeruTeruBozu());
ClientRegistry.bindTileEntitySpecialRenderer(TileAvatar.class, new RenderTileAvatar());
ClientRegistry.bindTileEntitySpecialRenderer(TileAnimatedTorch.class, new RenderTileAnimatedTorch());
RenderingRegistry.registerEntityRenderingHandler(EntityPixie.class, RenderPixie::new);
RenderingRegistry.registerEntityRenderingHandler(EntityDoppleganger.class, RenderDoppleganger::new);
@@ -0,0 +1,54 @@
/**
* This class was created by <Vazkii>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*
* File Created @ [28/09/2016, 17:55:36 (GMT)]
*/
package vazkii.botania.client.render.tile;
import java.util.Random;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import vazkii.botania.client.core.handler.ClientTickHandler;
import vazkii.botania.common.block.tile.TileAnimatedTorch;
public class RenderTileAnimatedTorch extends TileEntitySpecialRenderer<TileAnimatedTorch> {
@Override
public void renderTileEntityAt(TileAnimatedTorch te, double x, double y, double z, float partialTicks, int destroyStage) {
Minecraft mc = Minecraft.getMinecraft();
GlStateManager.pushMatrix();
GlStateManager.translate(x, y, z);
boolean hasWorld = te != null && te.getWorld() != null;
int wtime = !hasWorld ? 0 : ClientTickHandler.ticksInGame;
if(wtime != 0)
wtime += new Random(te.getPos().hashCode()).nextInt(360);
float time = wtime == 0 ? 0 : wtime + partialTicks;
float xt = 0.5F + (float) Math.cos(time * 0.05F) * 0.025F;
float yt = 0.1F + (float) (Math.sin(time * 0.04F) + 1F) * 0.05F;
float zt = 0.5F + (float) Math.sin(time * 0.05F) * 0.025F;
GlStateManager.translate(xt, yt, zt);
GlStateManager.scale(2F, 2F, 2F);
GlStateManager.rotate(90F, 1F, 0F, 0F);
float rotation = (float) te.rotation;
if(te.rotating)
rotation += te.anglePerTick * partialTicks;
GlStateManager.rotate(rotation, 0F, 0F, 1F);
mc.getRenderItem().renderItem(new ItemStack(Blocks.REDSTONE_TORCH), ItemCameraTransforms.TransformType.GROUND);
GlStateManager.popMatrix();
}
}
@@ -0,0 +1,139 @@
/**
* This class was created by <Vazkii>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*
* File Created @ [28/09/2016, 16:14:04 (GMT)]
*/
package vazkii.botania.common.block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import vazkii.botania.api.internal.IManaBurst;
import vazkii.botania.api.item.IHourglassTrigger;
import vazkii.botania.api.mana.IManaTrigger;
import vazkii.botania.api.wand.IWandHUD;
import vazkii.botania.api.wand.IWandable;
import vazkii.botania.common.block.tile.TileAnimatedTorch;
import vazkii.botania.common.lib.LibBlockNames;
public class BlockAnimatedTorch extends BlockMod implements IWandable, IManaTrigger, IHourglassTrigger, IWandHUD {
private static final AxisAlignedBB AABB = new AxisAlignedBB(0, 0, 0, 1, 0.25, 1);
public BlockAnimatedTorch() {
super(Material.CIRCUITS, LibBlockNames.ANIMATED_TORCH);
setLightLevel(0.5F);
}
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
if(hand == EnumHand.MAIN_HAND && playerIn.isSneaking() && playerIn.getHeldItem(hand) == null) {
((TileAnimatedTorch) worldIn.getTileEntity(pos)).handRotate();
return true;
}
return false;
}
@Override
public void onBurstCollision(IManaBurst burst, World world, BlockPos pos) {
if(!burst.isFake())
((TileAnimatedTorch) world.getTileEntity(pos)).toggle();
}
@Override
public void onTriggeredByHourglass(World world, BlockPos pos, TileEntity hourglass) {
((TileAnimatedTorch) world.getTileEntity(pos)).toggle();
}
@Override
public boolean onUsedByWand(EntityPlayer player, ItemStack stack, World world, BlockPos pos, EnumFacing side) {
((TileAnimatedTorch) world.getTileEntity(pos)).onWanded();
return true;
}
@Override
@SideOnly(Side.CLIENT)
public void renderHUD(Minecraft mc, ScaledResolution res, World world, BlockPos pos) {
((TileAnimatedTorch) world.getTileEntity(pos)).renderHUD(mc, res);
}
@Override
public boolean canProvidePower(IBlockState state) {
return true;
}
@Override
public int getStrongPower(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {
return getWeakPower(blockState, blockAccess, pos, side);
}
@Override
public int getWeakPower(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {
TileAnimatedTorch tile = (TileAnimatedTorch) blockAccess.getTileEntity(pos);
if(tile.rotating)
return 0;
EnumFacing[] SIDES = new EnumFacing[] {
EnumFacing.NORTH,
EnumFacing.EAST,
EnumFacing.SOUTH,
EnumFacing.WEST
};
if(SIDES[tile.side] == side)
return 15;
return 0;
}
@Override
public EnumBlockRenderType getRenderType(IBlockState state) {
return EnumBlockRenderType.ENTITYBLOCK_ANIMATED;
}
@Override
public boolean isOpaqueCube(IBlockState state) {
return false;
}
@Override
public boolean isFullCube(IBlockState state) {
return false;
}
@Override
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess world, BlockPos pos) {
return AABB;
}
@Override
public TileEntity createTileEntity(World world, IBlockState state) {
return new TileAnimatedTorch();
}
@Override
public boolean hasTileEntity(IBlockState state) {
return true;
}
}
@@ -113,6 +113,7 @@ import vazkii.botania.common.block.subtile.generating.SubTileSpectrolus;
import vazkii.botania.common.block.subtile.generating.SubTileThermalily;
import vazkii.botania.common.block.tile.TileAlfPortal;
import vazkii.botania.common.block.tile.TileAltar;
import vazkii.botania.common.block.tile.TileAnimatedTorch;
import vazkii.botania.common.block.tile.TileAvatar;
import vazkii.botania.common.block.tile.TileBifrost;
import vazkii.botania.common.block.tile.TileBrewery;
@@ -252,6 +253,7 @@ public final class ModBlocks {
public static Block shimmerwoodPlanks;
public static Block avatar;
public static Block altGrass;
public static Block animatedTorch;
public static void init() {
flower = new BlockModFlower();
@@ -336,7 +338,8 @@ public final class ModBlocks {
shimmerwoodPlanks = new BlockShimmerwoodPlanks();
avatar = new BlockAvatar();
altGrass = new BlockAltGrass();
animatedTorch = new BlockAnimatedTorch();
ModFluffBlocks.init();
for(int i = 0; i < 16; i++)
@@ -430,6 +433,7 @@ public final class ModBlocks {
registerTile(TileCorporeaRetainer.class, LibBlockNames.CORPOREA_RETAINER);
registerTile(TileTeruTeruBozu.class, LibBlockNames.TERU_TERU_BOZU);
registerTile(TileAvatar.class, LibBlockNames.AVATAR);
registerTile(TileAnimatedTorch.class, LibBlockNames.ANIMATED_TORCH);
BotaniaAPI.registerSubTile(LibBlockNames.SUBTILE_PUREDAISY, SubTilePureDaisy.class);
BotaniaAPI.registerSubTile(LibBlockNames.SUBTILE_MANASTAR, SubTileManastar.class);
@@ -0,0 +1,167 @@
/**
* This class was created by <Vazkii>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*
* File Created @ [28/09/2016, 17:21:24 (GMT)]
*/
package vazkii.botania.common.block.tile;
import java.util.function.Function;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.text.translation.I18n;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import vazkii.botania.api.internal.VanillaPacketDispatcher;
public class TileAnimatedTorch extends TileMod {
public static final String TAG_SIDE = "side";
public static final String TAG_ROTATING = "rotating";
public static final String TAG_ROTATION_TICKS = "rotationTicks";
public static final String TAG_ANGLE_PER_TICK = "anglePerTick";
public static final String TAG_TORCH_MODE = "torchMode";
public static final String TAG_NEXT_RANDOM_ROTATION = "nextRandomRotation";
public int side;
public double rotation;
public boolean rotating;
public double lastTickRotation;
public int nextRandomRotation;
public int currentRandomRotation;
private int rotationTicks;
public double anglePerTick;
private TorchMode torchMode = TorchMode.TOGGLE;
@Override
public void onLoad() {
if(!worldObj.isRemote)
nextRandomRotation = worldObj.rand.nextInt(4);
}
public void handRotate() {
rotateTo((side + 1) % 4);
}
public void toggle() {
rotateTo(torchMode.modeSwitcher.rotate(this, side));
if(!worldObj.isRemote) {
nextRandomRotation = worldObj.rand.nextInt(4);
VanillaPacketDispatcher.dispatchTEToNearbyPlayers(this);
}
}
public void onWanded() {
int modeOrdinal = torchMode.ordinal();
TorchMode[] modes = TorchMode.class.getEnumConstants();
modeOrdinal++;
if(modeOrdinal >= modes.length)
modeOrdinal = 0;
torchMode = modes[modeOrdinal];
}
public void rotateTo(int side) {
if(rotating)
return;
currentRandomRotation = nextRandomRotation;
int finalRotation = side * 90;
double diff = (finalRotation - (rotation % 360)) % 360;
if(diff < 0)
diff = 360 + diff;
rotationTicks = 4;
anglePerTick = diff / rotationTicks;
this.side = side;
rotating = true;
worldObj.notifyNeighborsOfStateChange(getPos(), getBlockType());
}
@SideOnly(Side.CLIENT)
public void renderHUD(Minecraft mc, ScaledResolution res) {
int x = res.getScaledWidth() / 2 + 10;
int y = res.getScaledHeight() / 2 - 8;
mc.getRenderItem().renderItemAndEffectIntoGUI(new ItemStack(Blocks.REDSTONE_TORCH), x, y);
mc.fontRendererObj.drawStringWithShadow(I18n.translateToLocal("botania.animatedTorch." + torchMode.name().toLowerCase()), x + 18, y + 6, 0xFF4444);
}
@Override
public void update() {
if(rotating) {
lastTickRotation = rotation;
rotation = (rotation + anglePerTick) % 360;
rotationTicks--;
if(rotationTicks <= 0) {
rotating = false;
worldObj.notifyNeighborsOfStateChange(getPos(), getBlockType());
}
} else rotation = side * 90;
int amt = rotating ? 3 : Math.random() < 0.1 ? 1 : 0;
double x = getPos().getX() + 0.5 + Math.cos((rotation + 90) / 180.0 * Math.PI) * 0.35;
double y = getPos().getY() + 0.2;
double z = getPos().getZ() + 0.5 + Math.sin((rotation + 90) / 180.0 * Math.PI) * 0.35;
for(int i = 0; i < amt; i++)
worldObj.spawnParticle(EnumParticleTypes.REDSTONE, x, y, z, 0.0D, 0.0D, 0.0D, new int[0]);
}
@Override
public void writePacketNBT(NBTTagCompound cmp) {
cmp.setInteger(TAG_SIDE, side);
cmp.setBoolean(TAG_ROTATING, rotating);
cmp.setInteger(TAG_ROTATION_TICKS, rotationTicks);
cmp.setDouble(TAG_ANGLE_PER_TICK, anglePerTick);
cmp.setInteger(TAG_TORCH_MODE, torchMode.ordinal());
cmp.setInteger(TAG_NEXT_RANDOM_ROTATION, nextRandomRotation);
}
@Override
public void readPacketNBT(NBTTagCompound cmp) {
side = cmp.getInteger(TAG_SIDE);
rotating = cmp.getBoolean(TAG_ROTATING);
if(worldObj != null && !worldObj.isRemote)
rotationTicks = cmp.getInteger(TAG_ROTATION_TICKS);
anglePerTick = cmp.getDouble(TAG_ANGLE_PER_TICK);
nextRandomRotation = cmp.getInteger(TAG_NEXT_RANDOM_ROTATION);
int modeOrdinal = cmp.getInteger(TAG_TORCH_MODE);
TorchMode[] modes = TorchMode.class.getEnumConstants();
torchMode = modes[Math.max(0, Math.min(modes.length - 1, modeOrdinal))];
}
public static enum TorchMode {
TOGGLE((t, i) -> (i + 2) % 4),
ROTATE((t, i) -> (i + 1) % 4),
RANDOM((t, i) -> t.currentRandomRotation);
private TorchMode(RotationHandler modeSwitcher) {
this.modeSwitcher = modeSwitcher;
}
public final RotationHandler modeSwitcher;
private static interface RotationHandler {
int rotate(TileAnimatedTorch tile, int curr);
}
}
}
@@ -10,6 +10,7 @@
*/
package vazkii.botania.common.block.tile;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.GlStateManager;
@@ -19,10 +20,13 @@ import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.StringUtils;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import vazkii.botania.api.internal.VanillaPacketDispatcher;
import vazkii.botania.api.item.IHourglassTrigger;
import vazkii.botania.api.state.BotaniaStateProps;
public class TileHourglass extends TileSimpleInventory {
@@ -51,11 +55,18 @@ public class TileHourglass extends TileSimpleInventory {
time = 0;
flip = !flip;
flipTicks = 4;
if (!worldObj.isRemote) {
if(!worldObj.isRemote) {
worldObj.setBlockState(getPos(), worldObj.getBlockState(getPos()).withProperty(BotaniaStateProps.POWERED, true), 1 | 2);
VanillaPacketDispatcher.dispatchTEToNearbyPlayers(this);
worldObj.scheduleUpdate(pos, getBlockType(), getBlockType().tickRate(worldObj));
}
for(EnumFacing facing : EnumFacing.VALUES) {
BlockPos pos = getPos().offset(facing);
IBlockState state = worldObj.getBlockState(pos);
if(state.getBlock() instanceof IHourglassTrigger)
((IHourglassTrigger) state.getBlock()).onTriggeredByHourglass(worldObj, pos, this);
}
}
timeFraction = (float) time / (float) totalTime;
} else {
@@ -146,6 +146,7 @@ public final class BotaniaCreativeTab extends CreativeTabs {
addBlock(ModBlocks.pylon);
addBlock(ModBlocks.pistonRelay);
addBlock(ModBlocks.hourglass);
addBlock(ModBlocks.animatedTorch);
addBlock(ModBlocks.redStringContainer);
addBlock(ModBlocks.redStringDispenser);
@@ -103,6 +103,7 @@ public final class LibBlockNames {
public static final String SHIMMERWOOD_PLANKS = "shimmerwoodPlanks";
public static final String AVATAR = "avatar";
public static final String ALT_GRASS = "altGrass";
public static final String ANIMATED_TORCH = "animatedTorch";
public static final String SUBTILE_PUREDAISY = "puredaisy";
public static final String SUBTILE_MANASTAR = "manastar";
@@ -241,6 +241,11 @@ botania.wings7=Wings: Sylph
botania.wings8=Wings: Mega Ultra Chicken
botania.wings9=Wings: The One
# TORCH MODES
botania.animatedTorch.toggle=Toggle
botania.animatedTorch.rotate=Rotate
botania.animatedTorch.random=Random
# ARMOR SETS
botania.armorset.manasteel.name=Mana Affinity
botania.armorset.manasteel.desc=10%% less Mana cost on Mana Tools and Rods
@@ -1149,6 +1154,7 @@ tile.botania:altGrass2.name=Vivid Grass
tile.botania:altGrass3.name=Scorched Grass
tile.botania:altGrass4.name=Infused Grass
tile.botania:altGrass5.name=Mutated Grass
tile.botania:animatedTorch.name=Animated Torch
# FLOWER NAMES
tile.botania:flower..name=Botania Flower
@@ -0,0 +1,7 @@
{
"parent": "item/generated",
"textures": {
"layer0": "minecraft:blocks/redstone_torch_on",
"layer1": "botania:blocks/animated_torch_glimmer"
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB