Skip to content

Commit

Permalink
InteractionResult.sideSuccess!
Browse files Browse the repository at this point in the history
  • Loading branch information
MehVahdJukaar committed Jan 15, 2024
1 parent 0ccde65 commit 495f9fb
Show file tree
Hide file tree
Showing 31 changed files with 121 additions and 118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public InteractionResult use(@NotNull BlockState state, Level worldIn, @NotNull
} else
worldIn.setBlockAndUpdate(pos, Blocks.ENCHANTING_TABLE.defaultBlockState());

return InteractionResult.SUCCESS;
return InteractionResult.sidedSuccess(worldIn.isClientSide);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public boolean useShapeForLightOcclusion(@NotNull BlockState state) {
public InteractionResult use(@NotNull BlockState state, Level worldIn, @NotNull BlockPos pos, @NotNull Player player, @NotNull InteractionHand handIn, @NotNull BlockHitResult hit) {
if(!worldIn.isClientSide && worldIn.getBlockEntity(pos) == null) {
worldIn.removeBlock(pos, false);
return InteractionResult.SUCCESS;
return InteractionResult.CONSUME;
} else
return InteractionResult.PASS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,12 @@ public InteractionResult use(@NotNull BlockState state, Level world, @NotNull Bl
if(player instanceof ServerPlayer sp)
TinyPotatoModule.patPotatoTrigger.trigger(sp);

if(!world.isClientSide) {
if(world instanceof ServerLevel serverLevel) {
AABB box = SHAPE.bounds();
((ServerLevel) world).sendParticles(ParticleTypes.HEART, pos.getX() + box.minX + Math.random() * (box.maxX - box.minX), pos.getY() + box.maxY, pos.getZ() + box.minZ + Math.random() * (box.maxZ - box.minZ), 1, 0, 0, 0, 0);
serverLevel.sendParticles(ParticleTypes.HEART, pos.getX() + box.minX + Math.random() * (box.maxX - box.minX), pos.getY() + box.maxY, pos.getZ() + box.minZ + Math.random() * (box.maxZ - box.minZ), 1, 0, 0, 0, 0);
}
}
return InteractionResult.SUCCESS;
return InteractionResult.sidedSuccess(world.isClientSide);
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public InteractionResult use(BlockState state, Level worldIn, BlockPos pos, Play
} while(!candidates.isEmpty());

if(fixedAny)
return InteractionResult.SUCCESS;
return InteractionResult.sidedSuccess(worldIn.isClientSide);
}

return super.use(state, worldIn, pos, player, handIn, hit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,15 @@ public class CopperPipeBlock extends BasePipeBlock implements SimpleWaterloggedB
DOWN_SHAPE, UP_SHAPE, NORTH_SHAPE, SOUTH_SHAPE, WEST_SHAPE, EAST_SHAPE
};

private static final VoxelShape[] shapeCache = new VoxelShape[64];
private static final VoxelShape[] SHAPE_CACHE = new VoxelShape[64];

public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;

public CopperPipeBlock(@Nullable ZetaModule module) {
super("pipe", SoundType.COPPER, module);
}

// Convert to encased
@Override
public InteractionResult use(BlockState state, Level worldIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult hit) {
ItemStack stack = player.getItemInHand(handIn);
Expand All @@ -84,7 +85,7 @@ public InteractionResult use(BlockState state, Level worldIn, BlockPos pos, Play
stack.shrink(1);
}
}
return InteractionResult.SUCCESS;
return InteractionResult.sidedSuccess(worldIn.isClientSide);
}

return super.use(state, worldIn, pos, player, handIn, hit);
Expand Down Expand Up @@ -136,7 +137,7 @@ public VoxelShape getShape(@NotNull BlockState state, @NotNull BlockGetter world
index += (1 << dir.ordinal());
}

VoxelShape cached = shapeCache[index];
VoxelShape cached = SHAPE_CACHE[index];
if(cached == null) {
VoxelShape currShape = CENTER_SHAPE;

Expand All @@ -146,7 +147,7 @@ public VoxelShape getShape(@NotNull BlockState state, @NotNull BlockGetter world
currShape = Shapes.or(currShape, SIDE_BOXES[dir.ordinal()]);
}

shapeCache[index] = currShape;
SHAPE_CACHE[index] = currShape;
cached = currShape;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public void onArmorStandInteract(ZPlayerInteract.EntityInteractSpecific event) {
player.playSound(SoundEvents.ARMOR_EQUIP_LEATHER);

event.setCanceled(true);
event.setCancellationResult(InteractionResult.SUCCESS);
event.setCancellationResult(InteractionResult.sidedSuccess(player.level().isClientSide));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.violetmoon.quark.content.automation.block;

import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.Containers;
import net.minecraft.world.InteractionHand;
Expand Down Expand Up @@ -28,6 +29,7 @@
import net.minecraft.world.phys.shapes.*;
import net.minecraftforge.common.util.ForgeSoundType;

import net.minecraftforge.network.NetworkHooks;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -133,9 +135,9 @@ public InteractionResult use(@NotNull BlockState state, Level world, @NotNull Bl
else {
MenuProvider container = this.getMenuProvider(state, world, pos);
if(container != null)
player.openMenu(container);
NetworkHooks.openScreen((ServerPlayer) player, container);

return InteractionResult.SUCCESS;
return InteractionResult.CONSUME;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ public InteractionResult use(@NotNull BlockState state, @NotNull Level worldIn,
stack.shrink(1);

worldIn.playSound(null, pos, soundType.getPlaceSound(), SoundSource.BLOCKS, 0.5F, 1F);
return InteractionResult.SUCCESS;
return InteractionResult.sidedSuccess(worldIn.isClientSide);
}
} else if(stack.getCapability(ForgeCapabilities.FLUID_HANDLER_ITEM).isPresent()) { //TODO: Forge extension
return FluidUtil.interactWithFluidHandler(player, hand, worldIn, getBottomPos(worldIn, pos), Direction.UP) ? InteractionResult.SUCCESS : InteractionResult.PASS;
return FluidUtil.interactWithFluidHandler(player, hand, worldIn, getBottomPos(worldIn, pos), Direction.UP) ? InteractionResult.sidedSuccess(worldIn.isClientSide) : InteractionResult.PASS;
} else if(stack.getItem() == Items.GLASS_BOTTLE) {
BlockPos bottomPos = getBottomPos(worldIn, pos);
BlockState stateAt = worldIn.getBlockState(bottomPos);
Expand All @@ -147,7 +147,7 @@ public InteractionResult use(@NotNull BlockState state, @NotNull Level worldIn,
else if(!player.getInventory().add(bottleStack))
player.drop(bottleStack, false);

return InteractionResult.SUCCESS;
return InteractionResult.sidedSuccess(worldIn.isClientSide);
}

return InteractionResult.PASS;
Expand All @@ -159,7 +159,7 @@ else if(!player.getInventory().add(bottleStack))
}

worldIn.playSound(null, pos, soundType.getBreakSound(), SoundSource.BLOCKS, 0.5F, 1F);
return InteractionResult.SUCCESS;
return InteractionResult.sidedSuccess(worldIn.isClientSide);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public InteractionResult use(BlockState state, @NotNull Level worldIn, @NotNull
worldIn.setBlockAndUpdate(pos, state.setValue(SAT_IN, true));
}

return InteractionResult.SUCCESS;
return InteractionResult.sidedSuccess(worldIn.isClientSide);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public InteractionResult useOn(UseOnContext context) {
stack.shrink(1);
}

return InteractionResult.SUCCESS;
return InteractionResult.sidedSuccess(world.isClientSide);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void onRightClick(ZRightClickBlock event) {
if(!player.getAbilities().instabuild)
MiscUtil.damageStack(player, event.getHand(), stack, 1);

event.setCancellationResult(InteractionResult.SUCCESS);
event.setCancellationResult(InteractionResult.sidedSuccess(world.isClientSide));
event.setCanceled(true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public void onClickEntity(ZPlayerInteract.EntityInteractSpecific event) {
if(!horse.hasChest() && held.getItem() != Items.CHEST) {
if(held.is(Tags.Items.CHESTS_WOODEN)) {
event.setCanceled(true);
event.setCancellationResult(InteractionResult.SUCCESS);
event.setCancellationResult(InteractionResult.sidedSuccess(player.level().isClientSide));

if(!target.level().isClientSide) {
ItemStack copy = held.copy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ public InteractionResult useOn(UseOnContext context) {
} else {
level.setBlock(pos, state, 0);
}

return InteractionResult.SUCCESS;
return InteractionResult.sidedSuccess(level.isClientSide);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void onEntityInteractSpecific(ZPlayerInteract.EntityInteractSpecific even

if(player.isCrouching()) {
event.setCanceled(true);
event.setCancellationResult(InteractionResult.SUCCESS);
event.setCancellationResult(InteractionResult.sidedSuccess(player.level().isClientSide));

swapSlot(player, armorStand, EquipmentSlot.HEAD);
swapSlot(player, armorStand, EquipmentSlot.CHEST);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,38 +295,39 @@ public InteractionResult mobInteract(Player player, @NotNull InteractionHand han
if(itemstack.getItem() == Items.BONE && !isTame())
return InteractionResult.PASS;

Level level = level();
if(this.isTame()) {
if(timeUntilPotatoEmerges <= 0 && itemstack.is(TinyPotatoModule.tiny_potato.asItem())) {
timeUntilPotatoEmerges = 600;

playSound(QuarkSounds.ENTITY_FOXHOUND_EAT, 1f, 1f);
if(!player.getAbilities().instabuild)
itemstack.shrink(1);
return InteractionResult.SUCCESS;
return InteractionResult.sidedSuccess(level.isClientSide);
}
} else {
if(!itemstack.isEmpty()) {
if(itemstack.getItem() == Items.COAL && (level().getDifficulty() == Difficulty.PEACEFUL || player.getAbilities().invulnerable || player.getEffect(MobEffects.FIRE_RESISTANCE) != null) && !level().isClientSide) {
if(itemstack.getItem() == Items.COAL && (level.getDifficulty() == Difficulty.PEACEFUL || player.getAbilities().invulnerable || player.getEffect(MobEffects.FIRE_RESISTANCE) != null) && !level.isClientSide) {
if(random.nextDouble() < FoxhoundModule.tameChance) {
this.tame(player);
this.navigation.stop();
this.setTarget(null);
this.setOrderedToSit(true);
this.setHealth(20.0F);
this.level().broadcastEntityEvent(this, (byte) 7);
level.broadcastEntityEvent(this, (byte) 7);
} else {
this.level().broadcastEntityEvent(this, (byte) 6);
level.broadcastEntityEvent(this, (byte) 6);
}

if(!player.getAbilities().instabuild)
itemstack.shrink(1);
return InteractionResult.SUCCESS;
return InteractionResult.sidedSuccess(level.isClientSide);
}
}
}

InteractionResult res = super.mobInteract(player, hand);
if(res == InteractionResult.SUCCESS && !level().isClientSide)
if(res.consumesAction() && !level.isClientSide)
setWoke();

return res;
Expand Down
33 changes: 16 additions & 17 deletions src/main/java/org/violetmoon/quark/content/mobs/entity/Shiba.java
Original file line number Diff line number Diff line change
Expand Up @@ -255,22 +255,22 @@ public void readAdditionalSaveData(@NotNull CompoundTag compound) {
public InteractionResult mobInteract(Player player, @NotNull InteractionHand hand) {
ItemStack itemstack = player.getItemInHand(hand);
Item item = itemstack.getItem();
Level level = this.level();
if(player.isDiscrete() && player.getMainHandItem().isEmpty()) {
if(hand == InteractionHand.MAIN_HAND && WantLoveGoal.canPet(this)) {
if(player.level() instanceof ServerLevel serverLevel) {
if(level instanceof ServerLevel serverLevel) {
Vec3 pos = position();
serverLevel.sendParticles(ParticleTypes.HEART, pos.x, pos.y + 0.5, pos.z, 1, 0, 0, 0, 0.1);
playSound(QuarkSounds.ENTITY_SHIBA_WHINE, 0.6F, 0.5F + (float) Math.random() * 0.5F);
} else
player.swing(InteractionHand.MAIN_HAND);
}

WantLoveGoal.setPetTime(this);
return InteractionResult.sidedSuccess(level.isClientSide);
}

return InteractionResult.SUCCESS;
} else if(this.level().isClientSide) {
}
else if(level.isClientSide) {
boolean flag = this.isOwnedBy(player) || this.isTame() || item == Items.BONE && !this.isTame();
return flag ? InteractionResult.CONSUME : InteractionResult.PASS;
return flag ? InteractionResult.SUCCESS : InteractionResult.PASS;
} else {
if(this.isTame()) {
ItemStack mouthItem = getMouthItem();
Expand All @@ -285,7 +285,7 @@ public InteractionResult mobInteract(Player player, @NotNull InteractionHand han
playSound(QuarkSounds.ENTITY_SHIBA_WHINE, 0.6F, 0.5F + (float) Math.random() * 0.5F);
}
setMouthItem(ItemStack.EMPTY);
return InteractionResult.SUCCESS;
return InteractionResult.CONSUME;
}

if(this.isFood(itemstack) && this.getHealth() < this.getMaxHealth()) {
Expand All @@ -294,7 +294,7 @@ public InteractionResult mobInteract(Player player, @NotNull InteractionHand han
}

this.heal((float) item.getFoodProperties().getNutrition());
return InteractionResult.SUCCESS;
return InteractionResult.CONSUME;
}

if(!(item instanceof DyeItem)) {
Expand All @@ -304,7 +304,7 @@ public InteractionResult mobInteract(Player player, @NotNull InteractionHand han
itemstack.setCount(itemstack.getCount() - 1);

setMouthItem(copy);
return InteractionResult.SUCCESS;
return InteractionResult.CONSUME;
}

InteractionResult actionresulttype = super.mobInteract(player, hand);
Expand All @@ -313,7 +313,7 @@ public InteractionResult mobInteract(Player player, @NotNull InteractionHand han
this.jumping = false;
this.navigation.stop();
this.setTarget(null);
return InteractionResult.SUCCESS;
return InteractionResult.CONSUME;
}

return actionresulttype;
Expand All @@ -326,7 +326,7 @@ public InteractionResult mobInteract(Player player, @NotNull InteractionHand han
itemstack.shrink(1);
}

return InteractionResult.SUCCESS;
return InteractionResult.CONSUME;
}
} else if(item == Items.BONE) {
if(!player.getAbilities().instabuild) {
Expand All @@ -340,16 +340,15 @@ public InteractionResult mobInteract(Player player, @NotNull InteractionHand han
this.navigation.stop();
this.setTarget(null);
this.setOrderedToSit(true);
this.level().broadcastEntityEvent(this, (byte) 7);
level.broadcastEntityEvent(this, (byte) 7);
} else {
this.level().broadcastEntityEvent(this, (byte) 6);
level.broadcastEntityEvent(this, (byte) 6);
}

return InteractionResult.SUCCESS;
return InteractionResult.CONSUME;
}

return super.mobInteract(player, hand);
}
return super.mobInteract(player, hand);
}

@Override
Expand Down
Loading

0 comments on commit 495f9fb

Please sign in to comment.