Skip to content

Commit

Permalink
Added more abilities to builder sigil
Browse files Browse the repository at this point in the history
  • Loading branch information
TeamDman committed Nov 15, 2016
1 parent c386890 commit 7d5579f
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/teamdman/animus/AnimusConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public static Configuration getConfig() {

// General
public static boolean muteWither;
public static int builderRange;

public static void init(File file)
{
Expand Down Expand Up @@ -66,6 +67,7 @@ public static void syncConfig() {
config.addCustomCategoryComment(category,"General Preferences");
config.setCategoryRequiresMcRestart(category,false);
muteWither = config.get(category,"muteWither",true).getBoolean();
builderRange = config.get(category,"builderRange",64).getInt();
config.save();
}

Expand Down
122 changes: 120 additions & 2 deletions src/main/java/com/teamdman/animus/items/sigils/ItemSigilBuilder.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
package com.teamdman.animus.items.sigils;

import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.api.util.helper.NBTHelper;
import WayofTime.bloodmagic.api.util.helper.NetworkHelper;
import com.teamdman.animus.AnimusConfig;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

import java.lang.reflect.Field;
Expand All @@ -12,15 +27,118 @@
*/
public class ItemSigilBuilder extends com.teamdman.animus.items.sigils.ItemSigilToggleableBase {
public ItemSigilBuilder() {
super("builder",100);
super("builder", 100);
}

public ItemStack getStackToUse(EnumHand hand, EntityPlayer player) {
return hand == EnumHand.MAIN_HAND ? player.getHeldItemOffhand() : player.getHeldItemMainhand();
}

@Override
public void onSigilUpdate(ItemStack stack, World world, EntityPlayer player, int itemSlot, boolean isSelected) {
super.onSigilUpdate(stack, world, player, itemSlot, isSelected);
ItemSigilBuilder.removeDelay();
}
// NetworkHelper.getSoulNetwork(playerIn).syphonAndDamage(playerIn, getLpUsed());

@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand) {
if (!world.isRemote && !isUnusable(stack)) {
if (player.isSneaking()) {

NBTTagCompound comp = NBTHelper.checkNBT(stack).getTagCompound();
boolean activated = getActivated(stack);
if (activated) {
if (comp.getInteger("debounce") < 5) {
comp.setInteger("debounce", comp.getInteger("debounce") + 1);
} else {
comp.setBoolean(Constants.NBT.ACTIVATED, !activated);
comp.setInteger("debounce", 0);
}
} else {
comp.setBoolean(Constants.NBT.ACTIVATED, !activated);
}
} else {
ItemStack _stack = getStackToUse(hand,player);
if (_stack != null) {
BlockPos air = player.getPosition().offset(player.getHorizontalFacing(), 2).up();
if (world.isAirBlock(air)) {
ItemBlock _item = (ItemBlock) _stack.getItem();
if (_item != null) {
IBlockState _state = Block.getBlockFromItem(_item).getStateFromMeta(_item.getDamage(_stack));
world.setBlockState(air, _state);
NetworkHelper.getSoulNetwork(player).syphonAndDamage(player, getLpUsed());
_stack.stackSize--;
if (hand == EnumHand.MAIN_HAND && _stack.stackSize <= 0)
player.setItemStackToSlot(EntityEquipmentSlot.OFFHAND, null);
}
}
}
}
}

return new ActionResult(EnumActionResult.PASS, stack);
}

@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
BlockPos air = pos;
int dist = 0;
if (player.isSneaking()) {
for (int radius = 1; radius <= Math.sqrt(AnimusConfig.builderRange); radius++) {
for (int x = -radius; x <= radius; x++) {
for (int z = -radius; z <= radius; z++) {
switch(side.getAxis()) {
case X:
air=pos.add(0,x,z);
break;
case Y:
air=pos.add(x,0,z);
break;
case Z:
air=pos.add(x,z,0);
break;
}
if (world.isAirBlock(air)) {
ItemStack _stack = getStackToUse(hand,player);
if (_stack == null)
return EnumActionResult.SUCCESS;
ItemBlock _item = (ItemBlock) _stack.getItem();
if (_item == null)
return EnumActionResult.SUCCESS;
IBlockState _state = Block.getBlockFromItem(_item).getStateFromMeta(_item.getDamage(_stack));
world.setBlockState(air, _state);
_stack.stackSize--;
if (hand == EnumHand.MAIN_HAND && _stack.stackSize <= 0)
player.setItemStackToSlot(EntityEquipmentSlot.OFFHAND, null);
return EnumActionResult.SUCCESS;
}
}
}
}
} else {
do {
air = air.offset(side.getOpposite(), 1);
dist++;
if (dist > AnimusConfig.builderRange)
return EnumActionResult.SUCCESS;
} while (!world.isAirBlock(air) || air.getY() <= 0);

ItemStack _stack = getStackToUse(hand,player);
if (_stack == null)
return EnumActionResult.SUCCESS;
ItemBlock _item = (ItemBlock) _stack.getItem();
if (_item == null)
return EnumActionResult.SUCCESS;

IBlockState _state = Block.getBlockFromItem(_item).getStateFromMeta(_item.getDamage(_stack));
world.setBlockState(air, _state);
NetworkHelper.getSoulNetwork(player).syphonAndDamage(player, getLpUsed());
_stack.stackSize--;
if (hand == EnumHand.MAIN_HAND && _stack.stackSize <= 0)
player.setItemStackToSlot(EntityEquipmentSlot.OFFHAND, null);
}
return EnumActionResult.SUCCESS;
}

public static void removeDelay() {
try {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/assets/animus/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ guide.animus.sigils.chains.page0=Captures the soul of a mob when right clicked o
guide.animus.sigils.transposition.entry=Sigil of Transposition
guide.animus.sigils.transposition.page0=Right click marks a block in the world, right clicking elsewhere will move the block.
guide.animus.sigils.builder.entry=Sigil of the Fast Builder
guide.animus.sigils.builder.page0=When activated, the sigil will let the user place blocks incredibly fast.
guide.animus.sigils.builder.page0=When activated, the sigil will let the user place blocks incredibly fast. Right click on open air to place a block from your off-hand in front of you. Shift-right click on a block to expand it using blocks from your off-hand.

guide.animus.blocks.phantom.entry=Phantom Builder Block
guide.animus.blocks.phantom.page0=Right clicking this block will replace it with the held item in the world. Disappears after a short period of time.
Expand Down

0 comments on commit 7d5579f

Please sign in to comment.