-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
141 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
common/src/main/java/com/hammy275/immersivemc/mixin/AbstractCauldronBlockAccessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.hammy275.immersivemc.mixin; | ||
|
||
import net.minecraft.core.cauldron.CauldronInteraction; | ||
import net.minecraft.world.item.Item; | ||
import net.minecraft.world.level.block.AbstractCauldronBlock; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Accessor; | ||
|
||
import java.util.Map; | ||
|
||
@Mixin(AbstractCauldronBlock.class) | ||
public interface AbstractCauldronBlockAccessor { | ||
|
||
@Accessor("interactions") | ||
public Map<Item, CauldronInteraction> getInteractions(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
common/src/main/java/com/hammy275/immersivemc/server/tracker/vrhand/CauldronTracker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package com.hammy275.immersivemc.server.tracker.vrhand; | ||
|
||
import com.hammy275.immersivemc.common.config.ServerPlayerConfig; | ||
import com.hammy275.immersivemc.mixin.AbstractCauldronBlockAccessor; | ||
import com.hammy275.immersivemc.server.data.LastTickData; | ||
import net.blf02.vrapi.api.data.IVRData; | ||
import net.blf02.vrapi.api.data.IVRPlayer; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.cauldron.CauldronInteraction; | ||
import net.minecraft.world.InteractionHand; | ||
import net.minecraft.world.InteractionResult; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.item.*; | ||
import net.minecraft.world.item.alchemy.Potion; | ||
import net.minecraft.world.item.alchemy.PotionUtils; | ||
import net.minecraft.world.item.alchemy.Potions; | ||
import net.minecraft.world.level.block.AbstractCauldronBlock; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.level.material.Fluids; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
|
||
public class CauldronTracker extends AbstractVRHandTracker { | ||
|
||
private Map<UUID, Integer> cooldown = new HashMap<>(); | ||
|
||
@Override | ||
public void preTick(Player player) { | ||
super.preTick(player); | ||
int newCooldown = cooldown.getOrDefault(player.getUUID(), 0) - 1; | ||
if (newCooldown <= 0) { | ||
cooldown.remove(player.getUUID()); | ||
} else { | ||
cooldown.put(player.getUUID(), newCooldown); | ||
} | ||
} | ||
|
||
@Override | ||
protected boolean shouldRunForHand(Player player, InteractionHand hand, ItemStack stackInHand, IVRPlayer currentVRData, LastTickData lastVRData) { | ||
if (cooldown.getOrDefault(player.getUUID(), 0) > 0) return false; | ||
IVRData data = currentVRData.getController(hand.ordinal()); | ||
// If block at hand pos is cauldron or block at hand pos is air and block below is cauldron. | ||
return player.level.getBlockState(new BlockPos(data.position())).getBlock() instanceof AbstractCauldronBlock || | ||
(player.level.getBlockState(new BlockPos(data.position()).below()).getBlock() instanceof AbstractCauldronBlock | ||
&& player.level.getBlockState(new BlockPos(data.position())).isAir()); | ||
} | ||
|
||
@Override | ||
protected void runForHand(Player player, InteractionHand hand, ItemStack stackInHand, IVRPlayer currentVRData, LastTickData lastVRData) { | ||
IVRData data = currentVRData.getController(hand.ordinal()); | ||
BlockState handState = player.level.getBlockState(new BlockPos(data.position())); | ||
|
||
BlockPos cauldronPos = handState.getBlock() instanceof AbstractCauldronBlock ? new BlockPos(data.position()) : | ||
new BlockPos(data.position()).below(); | ||
BlockState cauldron = player.level.getBlockState(cauldronPos); | ||
AbstractCauldronBlock cauldronBlock = (AbstractCauldronBlock) cauldron.getBlock(); | ||
boolean inCauldronBlock = handState.getBlock() instanceof AbstractCauldronBlock; | ||
ItemStack handStack = player.getItemInHand(hand); | ||
Item handItem = handStack.getItem(); | ||
Potion heldPotion = PotionUtils.getPotion(handStack); | ||
CauldronInteraction interaction = ((AbstractCauldronBlockAccessor) cauldronBlock).getInteractions().get(handItem); | ||
|
||
if (interaction == null) return; | ||
|
||
// If holding an empty bucket or glass bottle, see if we can fill it. | ||
if (inCauldronBlock && (handItem instanceof BottleItem || (handItem instanceof BucketItem bucketItem && bucketItem.arch$getFluid().isSame(Fluids.EMPTY)))) { | ||
// Pointing up in any way | ||
if (Math.abs(data.getRoll()) < 90) { | ||
possiblySetCooldown(player, interaction.interact(cauldron, player.level, cauldronPos, player, hand, handStack)); | ||
} | ||
} else if ((handItem instanceof PotionItem && heldPotion == Potions.WATER) || | ||
(handItem instanceof BucketItem bucketItem && !bucketItem.arch$getFluid().isSame(Fluids.EMPTY)) || | ||
handItem instanceof SolidBucketItem) { | ||
// 20-degrees in either direction from straight down | ||
if (Math.abs(data.getRoll()) > 160) { | ||
possiblySetCooldown(player, interaction.interact(cauldron, player.level, cauldronPos, player, hand, handStack)); | ||
} | ||
} else if (inCauldronBlock) { | ||
possiblySetCooldown(player, interaction.interact(cauldron, player.level, cauldronPos, player, hand, handStack)); | ||
} | ||
|
||
|
||
} | ||
|
||
@Override | ||
public boolean isEnabledInConfig(ServerPlayerConfig config) { | ||
return config.useCauldronImmersion; | ||
} | ||
|
||
private void possiblySetCooldown(Player player, InteractionResult res) { | ||
if (res.consumesAction()) { | ||
cooldown.put(player.getUUID(), 5); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters