Ritual portal delay / Bound Pickaxe fix/improvement (#1387)

* Teleportation now works similar to the Nether Portal:

if teleportation is attempted before the cooldown (10 ticks) is over, the cooldown gets reset.
This way teleportation loops are prevented.

You can now:
- Stand on a loop of permanently activated (well, constantly refreshing through a high-speed redstone clock) Teleposers, only getting teleposed once per stepping on it
- AFK in the Gate of the Fold without getting teleported constantly
- and other things, I guess.

* Bound Pickaxe AoE ability now destroys blocks properly.

closes #1001

* Streamlined bound tool harvest code.

Cleanup, duplicate code for bound tools moved as method to ItemBoundTool.sharedHarvest()

Tested aoe harvest with Stone, Dirt/Grass and Oak trees. Same result as before.

* silkTouch and fortuneLvl are now passed instead of recalculated on every block
This commit is contained in:
AEon - Tobias 2018-08-26 21:50:02 +02:00 committed by Nick Ignoffo
parent 72eb314da8
commit 753958ac9c
5 changed files with 40 additions and 64 deletions

View file

@ -10,7 +10,6 @@ import com.google.common.collect.HashMultiset;
import com.google.common.collect.Multimap;
import com.google.common.collect.Sets;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLeaves;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.ItemMeshDefinition;
@ -31,7 +30,6 @@ import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import java.util.List;
import java.util.Set;
import java.util.function.Consumer;
@ -57,8 +55,9 @@ public class ItemBoundAxe extends ItemBoundTool implements IMeshProvider {
if (world.isRemote)
return;
boolean silkTouch = EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, stack) > 0;
int fortuneLvl = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, stack);
boolean silkTouch = EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, stack) > 0;
int range = charge / 6; //Charge is a max of 30 - want 5 to be the max
HashMultiset<ItemStackWrapper> drops = HashMultiset.create();
@ -81,22 +80,7 @@ public class ItemBoundAxe extends ItemBoundTool implements IMeshProvider {
if (MinecraftForge.EVENT_BUS.post(event) || event.getResult() == Event.Result.DENY)
continue;
if (blockStack.getState().getBlockHardness(world, blockPos) != -1.0F) {
float strengthVsBlock = getDestroySpeed(stack, blockStack.getState());
if (strengthVsBlock > 1.1F || blockStack.getBlock() instanceof BlockLeaves && world.canMineBlockBody(player, blockPos)) {
if (silkTouch && blockStack.getBlock().canSilkHarvest(world, blockPos, world.getBlockState(blockPos), player))
drops.add(new ItemStackWrapper(blockStack));
else {
List<ItemStack> itemDrops = blockStack.getBlock().getDrops(world, blockPos, world.getBlockState(blockPos), fortuneLvl);
for (ItemStack stacks : itemDrops)
drops.add(ItemStackWrapper.getHolder(stacks));
}
world.setBlockToAir(blockPos);
}
}
sharedHarvest(stack, world, player, blockPos, blockStack, drops, silkTouch, fortuneLvl);
}
}
}

View file

@ -28,7 +28,6 @@ import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import java.util.List;
import java.util.Set;
import java.util.function.Consumer;
@ -69,8 +68,9 @@ public class ItemBoundPickaxe extends ItemBoundTool implements IMeshProvider {
if (world.isRemote)
return;
boolean silkTouch = EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, stack) > 0;
int fortuneLvl = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, stack);
boolean silkTouch = EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, stack) > 0;
int range = (charge / 6); //Charge is a max of 30 - want 5 to be the max
HashMultiset<ItemStackWrapper> drops = HashMultiset.create();
@ -93,21 +93,7 @@ public class ItemBoundPickaxe extends ItemBoundTool implements IMeshProvider {
if (MinecraftForge.EVENT_BUS.post(event) || event.getResult() == Event.Result.DENY)
continue;
if (blockStack.getBlock() != null && blockStack.getBlock().getBlockHardness(blockStack.getState(), world, blockPos) != -1) {
float strengthVsBlock = getDestroySpeed(stack, blockStack.getState());
if (strengthVsBlock > 1.1F && world.canMineBlockBody(player, blockPos)) {
if (silkTouch && blockStack.getBlock().canSilkHarvest(world, blockPos, world.getBlockState(blockPos), player))
drops.add(new ItemStackWrapper(blockStack));
else {
List<ItemStack> itemDrops = blockStack.getBlock().getDrops(world, blockPos, world.getBlockState(blockPos), fortuneLvl);
for (ItemStack stacks : itemDrops)
drops.add(ItemStackWrapper.getHolder(stacks));
}
world.setBlockToAir(blockPos);
}
}
sharedHarvest(stack, world, player, blockPos, blockStack, drops, silkTouch, fortuneLvl);
}
}
}

View file

@ -28,7 +28,6 @@ import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import java.util.List;
import java.util.Set;
import java.util.function.Consumer;
@ -53,15 +52,16 @@ public class ItemBoundShovel extends ItemBoundTool implements IMeshProvider {
protected void onBoundRelease(ItemStack stack, World world, EntityPlayer player, int charge) {
if (world.isRemote)
return;
boolean silkTouch = EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, stack) > 0;
int fortuneLvl = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, stack);
boolean silkTouch = EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, stack) > 0;
int range = charge / 6; //Charge is a max of 30 - want 5 to be the max
HashMultiset<ItemStackWrapper> drops = HashMultiset.create();
BlockPos playerPos = player.getPosition();
for (int i = -range; i <= range; i++) {
for (int j = 0; j <= 2 * range; j++) {
for (int k = -range; k <= range; k++) {
@ -79,21 +79,7 @@ public class ItemBoundShovel extends ItemBoundTool implements IMeshProvider {
if (MinecraftForge.EVENT_BUS.post(event) || event.getResult() == Event.Result.DENY)
continue;
if (blockStack.getBlock() != null && blockStack.getBlock().getBlockHardness(blockStack.getState(), world, blockPos) != -1) {
float strengthVsBlock = getDestroySpeed(stack, blockStack.getState());
if (strengthVsBlock > 1.1F && world.canMineBlockBody(player, blockPos)) {
if (silkTouch && blockStack.getBlock().canSilkHarvest(world, blockPos, world.getBlockState(blockPos), player))
drops.add(new ItemStackWrapper(blockStack));
else {
List<ItemStack> itemDrops = blockStack.getBlock().getDrops(world, blockPos, world.getBlockState(blockPos), fortuneLvl);
for (ItemStack stacks : itemDrops)
drops.add(ItemStackWrapper.getHolder(stacks));
}
world.setBlockToAir(blockPos);
}
}
sharedHarvest(stack, world, player, blockPos, blockStack, drops, silkTouch, fortuneLvl);
}
}
}

View file

@ -1,20 +1,19 @@
package WayofTime.bloodmagic.item;
import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.core.RegistrarBloodMagicItems;
import WayofTime.bloodmagic.core.data.Binding;
import WayofTime.bloodmagic.core.data.SoulTicket;
import WayofTime.bloodmagic.util.ItemStackWrapper;
import WayofTime.bloodmagic.event.BoundToolEvent;
import WayofTime.bloodmagic.iface.IActivatable;
import WayofTime.bloodmagic.iface.IBindable;
import WayofTime.bloodmagic.util.helper.NetworkHelper;
import WayofTime.bloodmagic.core.RegistrarBloodMagicItems;
import WayofTime.bloodmagic.util.BlockStack;
import WayofTime.bloodmagic.util.ItemStackWrapper;
import WayofTime.bloodmagic.util.Utils;
import WayofTime.bloodmagic.util.helper.NetworkHelper;
import WayofTime.bloodmagic.util.helper.TextHelper;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Multimap;
import com.google.common.collect.Multiset;
import com.google.common.collect.*;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.util.ITooltipFlag;
@ -251,4 +250,22 @@ public class ItemBoundTool extends ItemTool implements IBindable, IActivatable {
world.spawnEntity(new EntityItem(world, posToDrop.getX(), posToDrop.getY(), posToDrop.getZ(), stack.toStack(count)));
}
}
protected void sharedHarvest(ItemStack stack, World world, EntityPlayer player, BlockPos blockPos, BlockStack blockStack, HashMultiset drops, boolean silkTouch, int fortuneLvl){
if (blockStack.getBlock() != null && blockStack.getState().getBlockHardness(world, blockPos) != -1.0F) {
float strengthVsBlock = getDestroySpeed(stack, blockStack.getState());
if (strengthVsBlock > 1.1F && world.canMineBlockBody(player, blockPos)) {
if (silkTouch && blockStack.getBlock().canSilkHarvest(world, blockPos, world.getBlockState(blockPos), player))
drops.add(new ItemStackWrapper(blockStack));
else {
List<ItemStack> itemDrops = blockStack.getBlock().getDrops(world, blockPos, world.getBlockState(blockPos), fortuneLvl);
for (ItemStack stacks : itemDrops)
drops.add(ItemStackWrapper.getHolder(stacks));
}
blockStack.getBlock().removedByPlayer(world.getBlockState(blockPos), world, blockPos,player, false);
}
}
}
}

View file

@ -49,6 +49,7 @@ public class Teleports {
if (entity != null) {
BlockPos targetTeleposer = new BlockPos(x,y,z);
if (entity.timeUntilPortal <= 0) {
entity.timeUntilPortal = 10;
if (entity instanceof EntityPlayer) {
SoulNetwork network = NetworkHelper.getSoulNetwork(networkOwner);
@ -65,7 +66,6 @@ public class Teleports {
player.setPositionAndUpdate(x + 0.5, y + 0.5, z + 0.5);
player.getEntityWorld().updateEntityWithOptionalForce(player, false);
player.connection.sendPacket(new SPacketUpdateHealth(player.getHealth(), player.getFoodStats().getFoodLevel(), player.getFoodStats().getSaturationLevel()));
player.timeUntilPortal = 150;
player.getEntityWorld().playSound(x, y, z, SoundEvents.ENTITY_ENDERMEN_TELEPORT, SoundCategory.AMBIENT, 1.0F, 1.0F, false);
if (teleposer)
@ -83,13 +83,14 @@ public class Teleports {
network.syphon(ticket(world, entity, getTeleportCost() / 10));
entity.setPosition(x + 0.5, y + 0.5, z + 0.5);
entity.timeUntilPortal = 150;
world.resetUpdateEntityTick();
entity.getEntityWorld().playSound(x, y, z, SoundEvents.ENTITY_ENDERMEN_TELEPORT, SoundCategory.AMBIENT, 1.0F, 1.0F, false);
if (teleposer)
MinecraftForge.EVENT_BUS.post(new TeleposeEvent.Ent.Post(entity, entity.getEntityWorld(), entity.getPosition(), entity.getEntityWorld(), targetTeleposer));
}
}else{
entity.timeUntilPortal = 10;
}
}
}
@ -120,6 +121,7 @@ public class Teleports {
public void teleport() {
if (entity != null) {
if (entity.timeUntilPortal <= 0) {
entity.timeUntilPortal = 10;
MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
WorldServer oldWorldServer = server.getWorld(entity.dimension);
WorldServer newWorldServer = server.getWorld(newWorldID);
@ -206,7 +208,6 @@ public class Teleports {
teleportedEntity.forceSpawn = true;
newWorldServer.spawnEntity(teleportedEntity);
teleportedEntity.setWorld(newWorldServer);
teleportedEntity.timeUntilPortal = teleportedEntity instanceof EntityPlayer ? 150 : 20;
}
oldWorldServer.resetUpdateEntityTick();
@ -214,8 +215,10 @@ public class Teleports {
if (teleposer)
MinecraftForge.EVENT_BUS.post(new TeleposeEvent.Ent.Post(entity, entity.getEntityWorld(), entity.getPosition(), newWorldServer, targetTeleposer));
}
entity.timeUntilPortal = entity instanceof EntityLiving ? 150 : 20;
newWorldServer.playSound(x, y, z, SoundEvents.ENTITY_ENDERMEN_TELEPORT, SoundCategory.AMBIENT, 1.0F, 1.0F, false);
}else{
entity.timeUntilPortal = 10;
ForgeChunkManager.releaseTicket(chunkTicket);
}
}