mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-18 19:29:31 +00:00
Implement the new luminizers
This commit is contained in:
1 parent
3c6f38bdf2
commit
b4e42c861a
5 files changed
+128
-70
No files matched your search
@@ -96,14 +96,7 @@ public class BlockAnimatedTorch extends BlockMod implements IWandable, IManaTrig
|
||||
if(tile.rotating)
|
||||
return 0;
|
||||
|
||||
EnumFacing[] SIDES = new EnumFacing[] {
|
||||
EnumFacing.NORTH,
|
||||
EnumFacing.EAST,
|
||||
EnumFacing.SOUTH,
|
||||
EnumFacing.WEST
|
||||
};
|
||||
|
||||
if(SIDES[tile.side] == side)
|
||||
if(TileAnimatedTorch.SIDES[tile.side] == side)
|
||||
return 15;
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -108,7 +108,7 @@ public class BlockLightLauncher extends BlockMod implements ILexiconable {
|
||||
TileEntity tile = world.getTileEntity(pos.offset(dir));
|
||||
if(tile instanceof TileLightRelay) {
|
||||
TileLightRelay relay = (TileLightRelay) tile;
|
||||
if(relay.getBinding() != null)
|
||||
if(relay.getNextDestination() != null)
|
||||
relays.add(relay);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,11 +10,13 @@
|
||||
*/
|
||||
package vazkii.botania.common.block;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.BlockStateContainer;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
@@ -34,6 +36,7 @@ import vazkii.botania.api.state.BotaniaStateProps;
|
||||
import vazkii.botania.api.state.enums.LuminizerVariant;
|
||||
import vazkii.botania.api.wand.IWandable;
|
||||
import vazkii.botania.client.core.handler.ModelHandler;
|
||||
import vazkii.botania.common.Botania;
|
||||
import vazkii.botania.common.block.tile.TileLightRelay;
|
||||
import vazkii.botania.common.item.block.ItemBlockWithMetadataAndName;
|
||||
import vazkii.botania.common.lexicon.LexiconData;
|
||||
@@ -124,6 +127,16 @@ public class BlockLightRelay extends BlockMod implements IWandable, ILexiconable
|
||||
public int tickRate(World world) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn) {
|
||||
if(!worldIn.isRemote) {
|
||||
if(state.getValue(BotaniaStateProps.POWERED) && !worldIn.isBlockPowered(pos))
|
||||
worldIn.setBlockState(pos, state.withProperty(BotaniaStateProps.POWERED, false));
|
||||
else if(!state.getValue(BotaniaStateProps.POWERED) && worldIn.isBlockPowered(pos))
|
||||
worldIn.setBlockState(pos, state.withProperty(BotaniaStateProps.POWERED, true));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) {
|
||||
@@ -132,7 +145,7 @@ public class BlockLightRelay extends BlockMod implements IWandable, ILexiconable
|
||||
|
||||
@Override
|
||||
public boolean canProvidePower(IBlockState state) {
|
||||
return true;
|
||||
return state.getValue(BotaniaStateProps.LUMINIZER_VARIANT) == LuminizerVariant.DETECTOR;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,6 +17,7 @@ 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.EnumFacing;
|
||||
import net.minecraft.util.EnumParticleTypes;
|
||||
import net.minecraft.util.text.translation.I18n;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
@@ -24,7 +25,7 @@ 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";
|
||||
@@ -32,99 +33,106 @@ public class TileAnimatedTorch extends TileMod {
|
||||
public static final String TAG_TORCH_MODE = "torchMode";
|
||||
public static final String TAG_NEXT_RANDOM_ROTATION = "nextRandomRotation";
|
||||
|
||||
public static final EnumFacing[] SIDES = new EnumFacing[] {
|
||||
EnumFacing.NORTH,
|
||||
EnumFacing.EAST,
|
||||
EnumFacing.SOUTH,
|
||||
EnumFacing.WEST
|
||||
};
|
||||
|
||||
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]);
|
||||
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);
|
||||
@@ -134,7 +142,7 @@ public class TileAnimatedTorch extends TileMod {
|
||||
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);
|
||||
@@ -143,23 +151,23 @@ public class TileAnimatedTorch extends TileMod {
|
||||
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,7 +10,14 @@
|
||||
*/
|
||||
package vazkii.botania.common.block.tile;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.item.EntityEnderPearl;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
@@ -35,11 +42,6 @@ import vazkii.botania.common.achievement.ModAchievements;
|
||||
import vazkii.botania.common.block.ModBlocks;
|
||||
import vazkii.botania.common.core.helper.Vector3;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TileLightRelay extends TileMod implements IWandBindable {
|
||||
|
||||
private static final int MAX_DIST = 20;
|
||||
@@ -52,10 +54,11 @@ public class TileLightRelay extends TileMod implements IWandBindable {
|
||||
int ticksElapsed = 0;
|
||||
|
||||
public void mountEntity(Entity e) {
|
||||
if(e.isRiding() || worldObj.isRemote || bindPos.getY() == -1 || !isValidBinding())
|
||||
BlockPos nextDest = getNextDestination();
|
||||
if(e.isRiding() || worldObj.isRemote || nextDest != null || !isValidBinding())
|
||||
return;
|
||||
|
||||
EntityPlayerMover mover = new EntityPlayerMover(worldObj, pos, bindPos);
|
||||
EntityPlayerMover mover = new EntityPlayerMover(worldObj, pos, nextDest);
|
||||
worldObj.spawnEntityInWorld(mover);
|
||||
e.startRiding(mover);
|
||||
if(!(e instanceof EntityItem)) {
|
||||
@@ -69,28 +72,30 @@ public class TileLightRelay extends TileMod implements IWandBindable {
|
||||
public void update() {
|
||||
ticksElapsed++;
|
||||
|
||||
if(bindPos.getY() > -1 && isValidBinding()) {
|
||||
BlockPos nextDest = getNextDestination();
|
||||
if(nextDest != null && nextDest.getY() > -1 && isValidBinding()) {
|
||||
if(worldObj.isRemote) {
|
||||
Vector3 vec = getMovementVector();
|
||||
if(vec != null) {
|
||||
double dist = 0.1;
|
||||
int size = (int) (vec.mag() / dist);
|
||||
int count = 10;
|
||||
int start = ticksElapsed % size;
|
||||
|
||||
double dist = 0.1;
|
||||
int size = (int) (vec.mag() / dist);
|
||||
int count = 10;
|
||||
int start = ticksElapsed % size;
|
||||
Vector3 vecMag = vec.normalize().multiply(dist);
|
||||
Vector3 vecTip = vecMag.multiply(start).add(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
|
||||
|
||||
Vector3 vecMag = vec.normalize().multiply(dist);
|
||||
Vector3 vecTip = vecMag.multiply(start).add(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
|
||||
|
||||
double radPer = Math.PI / 16.0;
|
||||
float mul = 0.5F;
|
||||
float mulPer = 0.4F;
|
||||
float maxMul = 2;
|
||||
for(int i = start; i < start + count; i++) {
|
||||
mul = Math.min(maxMul, mul + mulPer);
|
||||
double rad = radPer * (i + ticksElapsed * 0.4);
|
||||
Vector3 vecRot = vecMag.crossProduct(Vector3.ONE).multiply(mul).rotate(rad, vecMag).add(vecTip);
|
||||
Botania.proxy.wispFX(vecRot.x, vecRot.y, vecRot.z, 0.4F, 0.4F, 1F, 0.1F, (float) -vecMag.x, (float) -vecMag.y, (float) -vecMag.z, 1F);
|
||||
vecTip = vecTip.add(vecMag);
|
||||
double radPer = Math.PI / 16.0;
|
||||
float mul = 0.5F;
|
||||
float mulPer = 0.4F;
|
||||
float maxMul = 2;
|
||||
for(int i = start; i < start + count; i++) {
|
||||
mul = Math.min(maxMul, mul + mulPer);
|
||||
double rad = radPer * (i + ticksElapsed * 0.4);
|
||||
Vector3 vecRot = vecMag.crossProduct(Vector3.ONE).multiply(mul).rotate(rad, vecMag).add(vecTip);
|
||||
Botania.proxy.wispFX(vecRot.x, vecRot.y, vecRot.z, 0.4F, 0.4F, 1F, 0.1F, (float) -vecMag.x, (float) -vecMag.y, (float) -vecMag.z, 1F);
|
||||
vecTip = vecTip.add(vecMag);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
BlockPos endpoint = getEndpoint();
|
||||
@@ -112,7 +117,11 @@ public class TileLightRelay extends TileMod implements IWandBindable {
|
||||
}
|
||||
|
||||
private boolean isValidBinding() {
|
||||
Block block = worldObj.getBlockState(bindPos).getBlock();
|
||||
BlockPos nextDest = getNextDestination();
|
||||
if(nextDest == null)
|
||||
return false;
|
||||
|
||||
Block block = worldObj.getBlockState(nextDest).getBlock();
|
||||
return block == ModBlocks.lightRelay;
|
||||
}
|
||||
|
||||
@@ -128,7 +137,7 @@ public class TileLightRelay extends TileMod implements IWandBindable {
|
||||
return null; // Circular path
|
||||
pointsPassed.add(relay);
|
||||
|
||||
BlockPos coords = relay.getBinding();
|
||||
BlockPos coords = relay.getNextDestination();
|
||||
if(coords == null)
|
||||
return lastCoords;
|
||||
|
||||
@@ -144,12 +153,47 @@ public class TileLightRelay extends TileMod implements IWandBindable {
|
||||
}
|
||||
|
||||
public Vector3 getMovementVector() {
|
||||
return new Vector3(bindPos.getX() - pos.getX(), bindPos.getY() - pos.getY(), bindPos.getZ() - pos.getZ());
|
||||
BlockPos dest = getNextDestination();
|
||||
if(dest == null)
|
||||
return null;
|
||||
|
||||
return new Vector3(dest.getX() - pos.getX(), dest.getY() - pos.getY(), dest.getZ() - pos.getZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockPos getBinding() {
|
||||
return bindPos.getY() == -1 ? null : bindPos;
|
||||
return bindPos;
|
||||
}
|
||||
|
||||
public BlockPos getNextDestination() {
|
||||
IBlockState state = worldObj.getBlockState(pos);
|
||||
if(state.getValue(BotaniaStateProps.LUMINIZER_VARIANT) == LuminizerVariant.TOGGLE && state.getValue(BotaniaStateProps.POWERED))
|
||||
return null;
|
||||
else if(state.getValue(BotaniaStateProps.LUMINIZER_VARIANT) == LuminizerVariant.FORK) {
|
||||
BlockPos torchPos = null;
|
||||
for(int i = -2; i < 3; i++) {
|
||||
BlockPos testPos = pos.add(0, i, 0);
|
||||
|
||||
IBlockState testState = worldObj.getBlockState(testPos);
|
||||
if(testState.getBlock() == ModBlocks.animatedTorch) {
|
||||
torchPos = testPos;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(torchPos != null) {
|
||||
TileAnimatedTorch torch = (TileAnimatedTorch) worldObj.getTileEntity(torchPos);
|
||||
EnumFacing side = TileAnimatedTorch.SIDES[torch.side].getOpposite();
|
||||
for(int i = 1; i < MAX_DIST; i++) {
|
||||
BlockPos testPos = pos.offset(side, i);
|
||||
IBlockState testState = worldObj.getBlockState(testPos);
|
||||
if(testState.getBlock() == ModBlocks.lightRelay)
|
||||
return testPos;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return getBinding();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -232,7 +276,7 @@ public class TileLightRelay extends TileMod implements IWandBindable {
|
||||
}
|
||||
|
||||
TileLightRelay relay = (TileLightRelay) tile;
|
||||
BlockPos bind = relay.getBinding();
|
||||
BlockPos bind = relay.getNextDestination();
|
||||
if(bind != null && relay.isValidBinding()) {
|
||||
setExit(bind);
|
||||
return;
|
||||
|
||||
Reference in new issue
Block a user