Skip to content

Commit

Permalink
compass now finds suitable location, now we can test if that location…
Browse files Browse the repository at this point in the history
… is suitable
  • Loading branch information
PeopleFromMars committed Dec 1, 2024
1 parent 83f667a commit dcbfb4a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
package net.martianz.beyondtheclouds.item.custom;

import net.martianz.beyondtheclouds.BeyondTheClouds;
import net.martianz.beyondtheclouds.component.DataComponentz;
import net.martianz.beyondtheclouds.item.Itemz;
import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos;
import net.minecraft.core.component.DataComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.util.RandomSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.CompassItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.Heightmap;

import java.util.List;
Expand All @@ -31,21 +28,21 @@ public InteractionResult use(Level level, Player player, InteractionHand interac
if(!level.isClientSide){
ItemStack thisStack = player.getItemInHand(interactionHand);
if(thisStack.is(Itemz.GATE_COMPASS.get())){
BlockPos origin = player.blockPosition();
BlockPos origin = new BlockPos(player.blockPosition().getX(), 0, player.blockPosition().getZ());
BlockPos highestWithin = origin;
for (int i = 0; i < 30; i++) {
RandomSource rnd = level.getRandom();
BlockPos randomPos = new BlockPos(rnd.nextInt(origin.getX()-500, origin.getX()+500), 320,rnd.nextInt(origin.getZ()-500, origin.getZ()+500));
BlockPos validHighest = new BlockPos(randomPos.getX(), level.getHeight(Heightmap.Types.MOTION_BLOCKING, randomPos.getX(), randomPos.getY()), randomPos.getZ());
BlockState randomState = level.getBlockState(validHighest);
if(validHighest.getY() > highestWithin.getY()){
highestWithin = randomPos;;;

for (BlockPos choice : BlockPos.betweenClosed(new BlockPos(origin.getX()-1000, 0, origin.getZ()-1000), new BlockPos(origin.getX()+1000, 0, origin.getZ()+1000))) {
int choiceY = level.getHeight(Heightmap.Types.WORLD_SURFACE, choice.getX(), choice.getZ());
if(choiceY >= highestWithin.getY()){
highestWithin = new BlockPos(choice.getX(), choiceY, choice.getZ());
}
}

if(highestWithin==origin){
System.out.println("roll again");
player.displayClientMessage(Component.translatable("clientmsg."+BeyondTheClouds.MODID +".entry_point_locating.fail").withStyle(ChatFormatting.RED), true);
}else{
thisStack.set(DataComponentz.COORDINATE_COMPONENT, highestWithin);
player.displayClientMessage(Component.translatable("clientmsg."+BeyondTheClouds.MODID +".entry_point_locating.success").withStyle(ChatFormatting.GREEN), true);
}
}
}
Expand All @@ -56,7 +53,9 @@ public InteractionResult use(Level level, Player player, InteractionHand interac
public void appendHoverText(ItemStack stack, TooltipContext context, List<Component> tooltipComponents, TooltipFlag tooltipFlag) {
if(stack.get(DataComponentz.COORDINATE_COMPONENT) != null){
BlockPos pos=stack.get(DataComponentz.COORDINATE_COMPONENT);
tooltipComponents.add(Component.translatable("tooltip.gate_compass.target").append( ": x:" + pos.getX() +", y:" + pos.getY()+ ", z:" +pos.getZ()).withStyle(ChatFormatting.GRAY));
tooltipComponents.add(Component.translatable("tooltip."+BeyondTheClouds.MODID+".gate_compass.target").append( ": x:" + pos.getX() +", y:" + pos.getY()+ ", z:" +pos.getZ()).withStyle(ChatFormatting.GREEN));
}else{
tooltipComponents.add(Component.translatable("tooltip."+BeyondTheClouds.MODID+".gate_compass.info").withStyle(ChatFormatting.GOLD));
}
super.appendHoverText(stack, context, tooltipComponents, tooltipFlag);
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/assets/beyondtheclouds/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"creativetab.beyondtheclouds.cloudrealm_tab": "Beyond The Clouds: Cloud Realm",
"tooltip.gate_compass.target": "Gate Location",
"tooltip.beyondtheclouds.gate_compass.target": "Entry Point Location",
"tooltip.beyondtheclouds.gate_compass.info": "Use Item to Locate Nearest Entry Point",
"clientmsg.beyondtheclouds.entry_point_locating.success": "Locating Entry Point Successful",
"clientmsg.beyondtheclouds.entry_point_locating.fail": "Locating Entry Point Failed",
"item.beyondtheclouds.gate_compass": "Gate Compass"
}

0 comments on commit dcbfb4a

Please sign in to comment.