Skip to content

Commit

Permalink
Modifier behavior tweaks
Browse files Browse the repository at this point in the history
Enderporting now triggers on harvest
Exchaging now no longer requires the tool to be effective to exchange
  • Loading branch information
KnightMiner committed Apr 24, 2022
1 parent bcdd6dc commit 0267d22
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package slimeknights.tconstruct.library.modifiers.hooks;

import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.block.state.BlockState;
import slimeknights.tconstruct.library.tools.nbt.IToolStackView;

/**
Expand All @@ -15,7 +15,7 @@ public interface IHarvestModifier {
* Called after a block is successfully harvested
* @param tool Tool used in harvesting
* @param level Tool level
* @param context Item use context, cooresponds to the original targeted position
* @param context Item use context, corresponds to the original targeted position
* @param world Server world instance
* @param state State before it was harvested
* @param pos Position that was harvested, may be different from the context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public Boolean removeBlock(IToolStackView tool, int level, ToolHarvestContext co
BlockState state = context.getState();
Level world = context.getWorld();
BlockPos pos = context.getPos();
if ((!context.isEffective() && state.getDestroySpeed(world, pos) > 0) || offhand.isEmpty() || !(offhand.getItem() instanceof BlockItem blockItem)) {
if (offhand.isEmpty() || !(offhand.getItem() instanceof BlockItem blockItem)) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.common.MinecraftForge;
import org.jetbrains.annotations.Nullable;
import slimeknights.tconstruct.common.Sounds;
import slimeknights.tconstruct.library.events.teleport.EnderportingTeleportEvent;
import slimeknights.tconstruct.library.modifiers.hooks.IHarvestModifier;
import slimeknights.tconstruct.library.modifiers.impl.NoLevelsModifier;
import slimeknights.tconstruct.library.tools.context.ToolAttackContext;
import slimeknights.tconstruct.library.tools.context.ToolHarvestContext;
Expand All @@ -21,7 +25,7 @@

import java.util.Set;

public class EnderportingModifier extends NoLevelsModifier {
public class EnderportingModifier extends NoLevelsModifier implements IHarvestModifier {
private static final Set<RelativeArgument> PACKET_FLAGS = ImmutableSet.of(RelativeArgument.X, RelativeArgument.Y, RelativeArgument.Z);

@Override
Expand Down Expand Up @@ -101,4 +105,21 @@ public void finishBreakingBlocks(IToolStackView tool, int level, ToolHarvestCont
}
}
}

@Override
public void afterHarvest(IToolStackView tool, int level, UseOnContext context, ServerLevel world, BlockState state, BlockPos pos) {
// only teleport to the center block
if (context.getClickedPos().equals(pos)) {
LivingEntity living = context.getPlayer();
if (living != null && tryTeleport(living, pos.getX() + 0.5f, pos.getY(), pos.getZ() + 0.5f)) {
ToolDamageUtil.damageAnimated(tool, 2, living);
}
}
}

@Nullable
@Override
public <T> T getModule(Class<T> type) {
return tryModuleMatch(type, IHarvestModifier.class, this);
}
}

0 comments on commit 0267d22

Please sign in to comment.