Skip to content

Commit

Permalink
revolutionary innovation
Browse files Browse the repository at this point in the history
you can now sit on chairs
  • Loading branch information
TropheusJ committed Jul 26, 2023
1 parent 2c59b4d commit d0508dc
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
16 changes: 16 additions & 0 deletions src/main/java/com/fusionflux/portalcubed/entity/ChairEntity.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
package com.fusionflux.portalcubed.entity;

import com.fusionflux.portalcubed.util.PortalCubedComponents;

import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.PathfinderMob;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;

public class ChairEntity extends CorePhysicsEntity {
public ChairEntity(EntityType<? extends PathfinderMob> type, Level world) {
super(type, world);
}

@Override
protected InteractionResult physicsEntityInteraction(Player player, InteractionHand hand) {
if (isVehicle() || level().isClientSide())
return InteractionResult.PASS;
CorePhysicsEntity heldEntity = PortalCubedComponents.HOLDER_COMPONENT.get(player).entityBeingHeld();
if (heldEntity == this)
return InteractionResult.PASS;

player.startRiding(this);
return InteractionResult.SUCCESS;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,15 @@ public boolean hurt(DamageSource source, float amount) {
@Override
@NotNull
protected InteractionResult mobInteract(Player player, InteractionHand hand) {
Level level = level();
if (level.isClientSide() || !player.isCreative() || !player.isShiftKeyDown())
return player.isShiftKeyDown() ? toggleLock(player, hand) : physicsEntityInteraction(player, hand);
}

protected InteractionResult physicsEntityInteraction(Player player, InteractionHand hand) {
return InteractionResult.PASS;
}

private InteractionResult toggleLock(Player player, InteractionHand hand) {
if (level().isClientSide() || !player.isCreative())
return InteractionResult.PASS;
ItemStack stack = player.getItemInHand(hand);
if (!stack.is(PortalCubedItems.HAMMER))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,8 @@ public void tick() {
}
}

@NotNull
@Override
protected InteractionResult mobInteract(Player player, InteractionHand hand) {
if (player.isShiftKeyDown())
return super.mobInteract(player, hand);

protected InteractionResult physicsEntityInteraction(Player player, InteractionHand hand) {
if (!level().isClientSide && player.getItemInHand(hand).is(PortalCubedItems.WRENCHES)) {
setAllowMute(!isAllowMute());
if (isAllowMute()) {
Expand Down

0 comments on commit d0508dc

Please sign in to comment.