Skip to content

Commit

Permalink
Lumos changes - closes #74
Browse files Browse the repository at this point in the history
  • Loading branch information
yorkeJohn committed Jan 8, 2022
1 parent fbe4b73 commit 13bfced
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 75 deletions.
12 changes: 1 addition & 11 deletions src/main/java/taintedmagic/common/blocks/BlockLumos.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public BlockLumos () {
setTickRandomly(false);
setLightLevel(1.0F);
setBlockTextureName("thaumcraft:blank");
setBlockBounds(0.3F, 0.3F, 0.3F, 0.7F, 0.7F, 0.7F);
}

@Override
Expand All @@ -52,17 +53,6 @@ void spawnBreakParticles (final World world, final double x, final double y, fin
ParticleEngine.instance.addEffect(world, fx);
}

@Override
public void setBlockBoundsBasedOnState (final IBlockAccess world, final int x, final int y, final int z) {
final int meta = world.getBlockMetadata(x, y, z);
if (meta == 0) {
setBlockBounds(0.3F, 0.3F, 0.3F, 0.7F, 0.7F, 0.7F);
}
else {
setBlockBounds(0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F);
}
}

@Override
public AxisAlignedBB getCollisionBoundingBoxFromPool (final World world, final int x, final int y, final int z) {
return null;
Expand Down
51 changes: 3 additions & 48 deletions src/main/java/taintedmagic/common/blocks/tile/TileLumos.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,67 +17,22 @@

public class TileLumos extends TileEntity {

public TileLumos () {
}

@Override
public boolean canUpdate () {
return true;
}

@Override
public void updateEntity () {
final Block block = worldObj.getBlock(xCoord, yCoord, zCoord);
final int meta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);

if (block instanceof BlockLumos) {
final EntityPlayer player = worldObj.getClosestPlayer(xCoord, yCoord, zCoord, 4);

if (meta == 0 && worldObj.rand.nextInt(15) == 0 && worldObj.isRemote) {
if (this.getBlockType() instanceof BlockLumos) {
if (worldObj.rand.nextInt(15) == 0 && worldObj.isRemote) {
spawnParticles();
}
if ( (meta == 1 || meta == 2) && player == null) {
worldObj.setBlockToAir(xCoord, yCoord, zCoord);
}
else if (meta == 1 && player != null) {
if (player.getHeldItem() == null
|| player.getHeldItem() != null && ! (player.getHeldItem().getItem() instanceof ItemWandCasting)) {
worldObj.setBlockToAir(xCoord, yCoord, zCoord);
}
else if (player.getHeldItem() != null && player.getHeldItem().getItem() instanceof ItemWandCasting) {
final ItemStack stack = player.getHeldItem();
final ItemWandCasting wand = (ItemWandCasting) stack.getItem();

if (wand.getFocus(stack) == null
|| wand.getFocus(stack) != null && wand.getFocus(stack) != ItemRegistry.ItemFocusLumos) {
worldObj.setBlockToAir(xCoord, yCoord, zCoord);
}
}
}
if (meta == 2 && player != null) {
final IInventory baub = BaublesApi.getBaubles(player);
if (baub.getStackInSlot(1) == null && baub.getStackInSlot(2) == null) {
worldObj.setBlockToAir(xCoord, yCoord, zCoord);
}
else if (baub.getStackInSlot(1) != null && baub.getStackInSlot(2) == null
&& ! (baub.getStackInSlot(1).getItem() instanceof ItemLumosRing)) {
worldObj.setBlockToAir(xCoord, yCoord, zCoord);
}
else if (baub.getStackInSlot(1) == null && baub.getStackInSlot(2) != null
&& ! (baub.getStackInSlot(2).getItem() instanceof ItemLumosRing)) {
worldObj.setBlockToAir(xCoord, yCoord, zCoord);
}
else if (baub.getStackInSlot(1) != null && baub.getStackInSlot(2) != null
&& ! (baub.getStackInSlot(1).getItem() instanceof ItemLumosRing)
&& ! (baub.getStackInSlot(2).getItem() instanceof ItemLumosRing)) {
worldObj.setBlockToAir(xCoord, yCoord, zCoord);
}
}
}
}

@SideOnly (Side.CLIENT)
void spawnParticles () {
private void spawnParticles () {
final FXSparkle fx = new FXSparkle(worldObj, xCoord + 0.5D + worldObj.rand.nextGaussian() * 0.1D,
yCoord + 0.5D + worldObj.rand.nextGaussian() * 0.1D, zCoord + 0.5D + worldObj.rand.nextGaussian() * 0.1D, 1.75F,
6, 3 + worldObj.rand.nextInt(2));
Expand Down
47 changes: 31 additions & 16 deletions src/main/java/taintedmagic/common/handler/TMEventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import taintedmagic.common.items.equipment.ItemLumosRing;
import taintedmagic.common.items.tools.ItemHollowDagger;
import taintedmagic.common.items.wand.foci.ItemFocusMageMace;
import taintedmagic.common.registry.BlockRegistry;
import taintedmagic.common.registry.ItemRegistry;
import thaumcraft.api.ThaumcraftApiHelper;
import thaumcraft.api.wands.ItemFocusBasic;
Expand All @@ -46,7 +45,7 @@ public void playerTick (final LivingEvent.LivingUpdateEvent event) {
final EntityPlayer player = (EntityPlayer) event.entity;

repairItems(player);
createLumos(player);
applyNightVision(player);
modifyAttackDamage(player);
}
}
Expand All @@ -65,30 +64,46 @@ public void repairItems (final EntityPlayer player) {
}
}

private boolean hasNightVision = false;

/**
* Create Lumos lightsource blocks when the player is holding a wand or staff
* Apply Night Vision effect when the player is holding a wand or staff
* with the Lumos focus equipped or when the Lumos ring is equipped.
*/
public void createLumos (final EntityPlayer player) {
final int x = (int) Math.floor(player.posX);
final int y = (int) Math.floor(player.posY) + 1;
final int z = (int) Math.floor(player.posZ);
public void applyNightVision (final EntityPlayer player) {
if (player.worldObj.isRemote)
return;

boolean lumos = false;

if (player.getHeldItem() != null && player.getHeldItem().getItem() instanceof ItemWandCasting) {
final IInventory baub = BaublesApi.getBaubles(player);
if ( (baub.getStackInSlot(1) != null && baub.getStackInSlot(1).getItem() instanceof ItemLumosRing)
|| (baub.getStackInSlot(2) != null && baub.getStackInSlot(2).getItem() instanceof ItemLumosRing)) {
lumos = true;
}
else if (player.getHeldItem() != null && player.getHeldItem().getItem() instanceof ItemWandCasting) {
final ItemStack held = player.getHeldItem();
final ItemWandCasting wand = (ItemWandCasting) held.getItem();

if (wand.getFocus(held) != null && wand.getFocus(held) == ItemRegistry.ItemFocusLumos && !player.worldObj.isRemote
&& player.worldObj.isAirBlock(x, y, z)) {
player.worldObj.setBlock(x, y, z, BlockRegistry.BlockLumos, 1, 3);
if (wand.getFocus(held) != null && wand.getFocus(held) == ItemRegistry.ItemFocusLumos) {
lumos = true;
}
}

final IInventory baub = BaublesApi.getBaubles(player);
if (baub.getStackInSlot(1) != null && baub.getStackInSlot(1).getItem() instanceof ItemLumosRing
|| baub.getStackInSlot(2) != null && baub.getStackInSlot(2).getItem() instanceof ItemLumosRing
&& !player.worldObj.isRemote && player.worldObj.isAirBlock(x, y, z)) {
player.worldObj.setBlock(x, y, z, BlockRegistry.BlockLumos, 2, 3);
if (lumos) {
if (!hasNightVision) {
if (!player.isPotionActive(Potion.nightVision.id)) {
player.addPotionEffect(new PotionEffect(Potion.nightVision.id, 260, -1));
hasNightVision = true;
}
}
else if (player.ticksExisted % 20 == 0) {
player.addPotionEffect(new PotionEffect(Potion.nightVision.id, 260, -1));
}
}
else if (hasNightVision) {
player.removePotionEffect(Potion.nightVision.id);
hasNightVision = false;
}
}

Expand Down

0 comments on commit 13bfced

Please sign in to comment.