Skip to content

Commit

Permalink
added scissors
Browse files Browse the repository at this point in the history
  • Loading branch information
Trinsdar committed Dec 9, 2023
1 parent d13d257 commit 8a081f1
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package muramasa.antimatter.behaviour;

import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;

public interface IInteractEntity<T> extends IBehaviour<T> {
@Override
default String getId() {
return "interact_entity";
}

InteractionResult interactLivingEntity(T instance, ItemStack stack, Player player, LivingEntity interactionTarget, InteractionHand usedHand);
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class AntimatterDefaultTools {
public static final AntimatterToolType WIRE_CUTTER = AntimatterAPI.register(AntimatterToolType.class, new AntimatterToolType(Ref.ID, "wire_cutter", 1, 3, 2, 0.0F, -1.5F, false)).setUseSound(SoundEvents.SHEEP_SHEAR).addEffectiveMaterials(WOOL, SPONGE, WEB, CLOTH_DECORATION).setRepairable(false).addBlacklistedEnchantments(Enchantments.BLOCK_EFFICIENCY);
public static final AntimatterToolType BRANCH_CUTTER = AntimatterAPI.register(AntimatterToolType.class, new AntimatterToolType(Ref.ID, "branch_cutter", 1, 3, 2, 0.0F, -1.5F, false)).addTags("grafter").addEffectiveMaterials(LEAVES).setHasContainer(false).setDurabilityMultiplier(0.25f);
public static final AntimatterToolType KNIFE = AntimatterAPI.register(AntimatterToolType.class, new AntimatterToolType(Ref.ID, "knife", 1, 2, 1, 2.1F, -2.0F, false)).setToolClass(MaterialSword.class).addEffectiveBlocks(Blocks.COBWEB).setRepairable(false).setTag(new ResourceLocation(Ref.ID, "knives")).setOriginalTag(true);
public static final AntimatterToolType SCISSORS = AntimatterAPI.register(AntimatterToolType.class, new AntimatterToolType(Ref.ID, "scissors", 1, 2, 2, 1.0f, -1.5f, false));
public static final AntimatterToolType PLUNGER = AntimatterAPI.register(AntimatterToolType.class, new AntimatterToolType(Ref.ID, "plunger", 5, 5, 10, 0.0F, -2.9F, false)).setUseSound(SoundEvents.BUCKET_EMPTY).setHasSecondary(false).setRepairable(false);
public static final AntimatterArmorType HELMET = new AntimatterArmorType(Ref.ID, "helmet", 40, 0, 0.0F, 0.0F, EquipmentSlot.HEAD);
public static final AntimatterArmorType CHESTPLATE = new AntimatterArmorType(Ref.ID, "chestplate", 40, 0, 0.0F, 0.0F, EquipmentSlot.CHEST);
Expand All @@ -52,6 +53,7 @@ public static void init(Side side){
WRENCH.addBehaviour(BehaviourWrenchSwitching.INSTANCE);
WRENCH_ALT.addBehaviour(BehaviourWrenchSwitching.INSTANCE);
KNIFE.addBehaviour(BehaviourPumpkinCarving.INSTANCE);
SCISSORS.addBehaviour(BehaviourShearing.INSTANCE);
if (side == Side.CLIENT) {
clientInit();
}
Expand Down
11 changes: 11 additions & 0 deletions common/src/main/java/muramasa/antimatter/tool/IAntimatterTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,17 @@ default void refillTool(ItemStack stack, Player player){
}
}

default InteractionResult genericInteractLivingEntity(ItemStack stack, Player player, LivingEntity interactionTarget, InteractionHand usedHand){
InteractionResult result = InteractionResult.PASS;
for (Map.Entry<String, IBehaviour<IAntimatterTool>> e : getAntimatterToolType().getBehaviours().entrySet()) {
IBehaviour<?> b = e.getValue();
if (!(b instanceof IInteractEntity interactEntity)) continue;
InteractionResult r = interactEntity.interactLivingEntity(this, stack, player, interactionTarget, usedHand);
if (result != InteractionResult.SUCCESS) result = r;
}
return result;
}

@SuppressWarnings({"unchecked", "rawtypes"})
default InteractionResult onGenericItemUse(UseOnContext ctx) {
InteractionResult result = InteractionResult.PASS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,11 @@ public InteractionResult useOn(UseOnContext ctx) {
return onGenericItemUse(ctx);
}

@Override
public InteractionResult interactLivingEntity(ItemStack stack, Player player, LivingEntity interactionTarget, InteractionHand usedHand) {
return genericInteractLivingEntity(stack, player, interactionTarget, usedHand);
}

@Override
public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand usedHand) {
InteractionResultHolder<ItemStack> result = onGenericRightclick(level, player, usedHand);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package muramasa.antimatter.tool.behaviour;

import muramasa.antimatter.behaviour.IInteractEntity;
import muramasa.antimatter.behaviour.IItemUse;
import muramasa.antimatter.tool.IAntimatterTool;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.animal.Sheep;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.gameevent.GameEvent;

public class BehaviourShearing implements IInteractEntity<IAntimatterTool> {
public static final BehaviourShearing INSTANCE = new BehaviourShearing();
@Override
public String getId() {
return "shearing";
}

@Override
public InteractionResult interactLivingEntity(IAntimatterTool instance, ItemStack stack, Player player, LivingEntity interactionTarget, InteractionHand usedHand) {
if (!player.getLevel().isClientSide && interactionTarget instanceof Sheep sheep && sheep.readyForShearing()){
sheep.shear(SoundSource.PLAYERS);
sheep.gameEvent(GameEvent.SHEAR, player);
stack.hurtAndBreak(1, player, (playerx) -> {
playerx.broadcastBreakEvent(usedHand);
});
return InteractionResult.SUCCESS;
}
return InteractionResult.PASS;
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8a081f1

Please sign in to comment.