Skip to content

Commit

Permalink
Merge branch '1.19.4' of github.com:LordDeatHunter/FabricWaystones in…
Browse files Browse the repository at this point in the history
…to 1.19.2
  • Loading branch information
LordDeatHunter committed May 13, 2024
2 parents a9c19a9 + 8564619 commit b8b2dcb
Show file tree
Hide file tree
Showing 57 changed files with 1,135 additions and 471 deletions.
9 changes: 7 additions & 2 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ body:
label: Mod Version
description: "Please select the used version of 'Fabric Waystones'."
options:
- "v3.1.1 or newer"
- "v3.1.0"
- "v3.0.8"
- "v3.0.7 or newer"
- "v3.0.6"
- "v3.0.5"
Expand Down Expand Up @@ -90,7 +93,9 @@ body:
label: Minecraft Version
description: "Please select the used version of 'Minecraft'."
options:
- "1.19.3 or newer"
- "1.20 or newer"
- "1.19.4"
- "1.19.3"
- "1.19.2"
- "1.19.1"
- "1.19"
Expand All @@ -109,7 +114,7 @@ body:
label: Java Version
description: "Please select the used version of 'Java'."
options:
- "Java 18"
- "Java 18+"
- "Java 17"
- "Java 16"
- "Other"
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.0-SNAPSHOT'
id 'fabric-loom' version '1.6-SNAPSHOT'
id 'maven-publish'
}

Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ org.gradle.jvmargs=-Xmx2G
# check these on https://fabricmc.net/versions.html
minecraft_version=1.19.2
yarn_mappings=1.19.2+build.28
loader_version=0.14.17
loader_version=0.15.11
# Mod Properties
mod_version=3.0.8
mod_version=3.3.2
maven_group=wraith.waystones
archives_base_name=wraith-waystones
# Dependencies
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
fabric_version=0.75.1+1.19.2
fabric_version=0.77.0+1.19.2
# Optional Dependencies
# Journeymap & api
journeymap_api_version=1.19.1-1.9-fabric-SNAPSHOT
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
4 changes: 2 additions & 2 deletions src/main/java/wraith/fwaystones/access/PlayerAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public interface PlayerAccess {

ArrayList<String> getHashesSorted();
int getDiscoveredCount();
ArrayList<String> fabricWaystones$getHashesSorted();
int fabricWaystones$getDiscoveredCount();

}
54 changes: 27 additions & 27 deletions src/main/java/wraith/fwaystones/access/PlayerEntityMixinAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,53 +11,53 @@

public interface PlayerEntityMixinAccess extends PlayerAccess {

void discoverWaystone(WaystoneBlockEntity waystone);
void fabricWaystones$discoverWaystone(WaystoneBlockEntity waystone);

void discoverWaystone(String hash);
void fabricWaystones$discoverWaystone(String hash);

void discoverWaystone(String hash, boolean sync);
void fabricWaystones$discoverWaystone(String hash, boolean sync);

boolean hasDiscoveredWaystone(WaystoneBlockEntity waystone);
boolean fabricWaystones$hasDiscoveredWaystone(WaystoneBlockEntity waystone);

void forgetWaystone(WaystoneBlockEntity waystone);
void fabricWaystones$forgetWaystone(WaystoneBlockEntity waystone);

void forgetWaystone(String hash);
void fabricWaystones$forgetWaystone(String hash);

void forgetWaystone(String hash, boolean sync);
void fabricWaystones$forgetWaystone(String hash, boolean sync);

void syncData();
void fabricWaystones$syncData();

Set<String> getDiscoveredWaystones();
Set<String> fabricWaystones$getDiscoveredWaystones();

ArrayList<String> getWaystonesSorted();
ArrayList<String> fabricWaystones$getWaystonesSorted();

void learnWaystones(PlayerEntity player);
void fabricWaystones$learnWaystones(PlayerEntity player);

void fromTagW(NbtCompound tag);
void fabricWaystones$fromTagW(NbtCompound tag);

NbtCompound toTagW(NbtCompound tag);
NbtCompound fabricWaystones$toTagW(NbtCompound tag);

boolean shouldViewGlobalWaystones();
boolean fabricWaystones$shouldViewGlobalWaystones();

boolean shouldViewDiscoveredWaystones();
boolean fabricWaystones$shouldViewDiscoveredWaystones();

void toggleViewGlobalWaystones();
void fabricWaystones$toggleViewGlobalWaystones();

void toggleViewDiscoveredWaystones();
void fabricWaystones$toggleViewDiscoveredWaystones();

boolean hasDiscoveredWaystone(String hash);
boolean fabricWaystones$hasDiscoveredWaystone(String hash);

void discoverWaystones(HashSet<String> toLearn);
void fabricWaystones$discoverWaystones(HashSet<String> toLearn);

void forgetWaystones(HashSet<String> toForget);
void fabricWaystones$forgetWaystones(HashSet<String> toForget);

int getTeleportCooldown();
int fabricWaystones$getTeleportCooldown();

void setTeleportCooldown(int cooldown);
void fabricWaystones$setTeleportCooldown(int cooldown);

void forgetAllWaystones();
boolean autofocusWaystoneFields();
void toggleAutofocusWaystoneFields();
SearchType getSearchType();
void setSearchType(SearchType searchType);
void fabricWaystones$forgetAllWaystones();
boolean fabricWaystones$autofocusWaystoneFields();
void fabricWaystones$toggleAutofocusWaystoneFields();
SearchType fabricWaystones$getSearchType();
void fabricWaystones$setSearchType(SearchType searchType);
}
101 changes: 53 additions & 48 deletions src/main/java/wraith/fwaystones/block/WaystoneBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import net.minecraft.text.TextColor;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.ItemScatterer;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.hit.BlockHitResult;
Expand All @@ -48,6 +49,8 @@
import wraith.fwaystones.registry.BlockEntityRegistry;
import wraith.fwaystones.util.Utils;

import java.util.Set;

@SuppressWarnings("deprecation")
public class WaystoneBlock extends BlockWithEntity implements Waterloggable {

Expand All @@ -57,7 +60,6 @@ public class WaystoneBlock extends BlockWithEntity implements Waterloggable {
public static final EnumProperty<DoubleBlockHalf> HALF = Properties.DOUBLE_BLOCK_HALF;
public static final BooleanProperty MOSSY = BooleanProperty.of("mossy");
public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED;

protected static final VoxelShape VOXEL_SHAPE_TOP;
protected static final VoxelShape VOXEL_SHAPE_BOTTOM;

Expand Down Expand Up @@ -257,8 +259,6 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEnt
return ActionResult.PASS;
}

var discovered = ((PlayerEntityMixinAccess) player).getDiscoveredWaystones();

WaystoneBlockEntity blockEntity = (WaystoneBlockEntity) world.getBlockEntity(openPos);
if (blockEntity == null) {
return ActionResult.FAIL;
Expand All @@ -269,57 +269,62 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEnt
ItemScatterer.spawn(world, openPos.up(2), blockEntity.getInventory());
blockEntity.setInventory(DefaultedList.ofSize(0, ItemStack.EMPTY));
}
} else {
if (!FabricWaystones.CONFIG.discover_waystone_on_map_use() && FabricLoader.getInstance().isModLoaded("pinlib") && PinlibPlugin.tryUseOnMarkableBlock(player.getStackInHand(hand), world, openPos))
return ActionResult.SUCCESS;

FabricWaystones.WAYSTONE_STORAGE.tryAddWaystone(blockEntity);
if (!discovered.contains(blockEntity.getHash())) {
if (!blockEntity.isGlobal()) {
var discoverItemId = Utils.getDiscoverItem();
if (!player.isCreative()) {
var discoverItem = Registry.ITEM.get(discoverItemId);
var discoverAmount = FabricWaystones.CONFIG.take_amount_from_discover_item();
if (!Utils.containsItem(player.getInventory(), discoverItem, discoverAmount)) {
player.sendMessage(Text.translatable(
"fwaystones.missing_discover_item",
discoverAmount,
Text.translatable(discoverItem.getTranslationKey()).styled(style ->
style.withColor(TextColor.parse(Text.translatable("fwaystones.missing_discover_item.arg_color").getString()))
)
), false);
return ActionResult.FAIL;
} else if (discoverItem != Items.AIR) {
Utils.removeItem(player.getInventory(), discoverItem, discoverAmount);
player.sendMessage(Text.translatable(
"fwaystones.discover_item_paid",
discoverAmount,
Text.translatable(discoverItem.getTranslationKey()).styled(style ->
style.withColor(TextColor.parse(Text.translatable("fwaystones.discover_item_paid.arg_color").getString()))
)
), false);
}
return ActionResult.success(false);
}

if (!FabricWaystones.CONFIG.discover_waystone_on_map_use() && FabricLoader.getInstance().isModLoaded("pinlib") && PinlibPlugin.tryUseOnMarkableBlock(player.getStackInHand(hand), world, openPos))
return ActionResult.SUCCESS;

FabricWaystones.WAYSTONE_STORAGE.tryAddWaystone(blockEntity);
PlayerEntityMixinAccess playerAccess = (PlayerEntityMixinAccess) player;
Set<String> discovered = playerAccess.fabricWaystones$getDiscoveredWaystones();
if (!discovered.contains(blockEntity.getHash())) {
if (!blockEntity.isGlobal()) {
var discoverItemId = Utils.getDiscoverItem();
if (!player.isCreative()) {
var discoverItem = Registry.ITEM.get(discoverItemId);
var discoverAmount = FabricWaystones.CONFIG.take_amount_from_discover_item();
if (!Utils.containsItem(player.getInventory(), discoverItem, discoverAmount)) {
player.sendMessage(Text.translatable(
"fwaystones.missing_discover_item",
discoverAmount,
Text.translatable(discoverItem.getTranslationKey()).styled(style ->
style.withColor(TextColor.parse(Text.translatable("fwaystones.missing_discover_item.arg_color").getString()))
)
), false);
return ActionResult.FAIL;
} else if (discoverItem != Items.AIR) {
Utils.removeItem(player.getInventory(), discoverItem, discoverAmount);
player.sendMessage(Text.translatable(
"fwaystones.discover_item_paid",
discoverAmount,
Text.translatable(discoverItem.getTranslationKey()).styled(style ->
style.withColor(TextColor.parse(Text.translatable("fwaystones.discover_item_paid.arg_color").getString()))
)
), false);
}
player.sendMessage(Text.translatable(
"fwaystones.discover_waystone",
Text.literal(blockEntity.getWaystoneName()).styled(style ->
style.withColor(TextColor.parse(Text.translatable("fwaystones.discover_waystone.arg_color").getString()))
)
), false);
}
((PlayerEntityMixinAccess) player).discoverWaystone(blockEntity);
}
if (blockEntity.getOwner() == null) {
blockEntity.setOwner(player);
} else {
blockEntity.updateActiveState();
player.sendMessage(Text.translatable(
"fwaystones.discover_waystone",
Text.literal(blockEntity.getWaystoneName()).styled(style ->
style.withColor(TextColor.parse(Text.translatable("fwaystones.discover_waystone.arg_color").getString()))
)
), false);
}
playerAccess.fabricWaystones$discoverWaystone(blockEntity);
}
if (blockEntity.getOwner() == null) {
blockEntity.setOwner(player);
} else {
blockEntity.updateActiveState();
}

var screenHandlerFactory = state.createScreenHandlerFactory(world, pos);
NamedScreenHandlerFactory screenHandlerFactory = state.createScreenHandlerFactory(world, pos);

if (screenHandlerFactory != null)
player.openHandledScreen(screenHandlerFactory);
if (screenHandlerFactory != null) {
player.openHandledScreen(screenHandlerFactory);
}

blockEntity.markDirty();
return ActionResult.success(false);
}
Expand Down
30 changes: 18 additions & 12 deletions src/main/java/wraith/fwaystones/block/WaystoneBlockEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import net.fabricmc.fabric.api.dimension.v1.FabricDimensions;
import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerFactory;
import net.fabricmc.fabric.api.util.NbtType;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.LootableContainerBlockEntity;
import net.minecraft.entity.player.PlayerEntity;
Expand All @@ -11,6 +10,7 @@
import net.minecraft.inventory.SidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.particle.ParticleEffect;
import net.minecraft.particle.ParticleTypes;
Expand Down Expand Up @@ -64,6 +64,15 @@ public static void ticker(World world, BlockPos blockPos, BlockState blockState,
waystone.tick();
}

public static String createHashString(String dimensionName, BlockPos pos) {
return Utils.getSHA256(
"<POS X:" + pos.getX() +
", Y:" + pos.getY() +
", Z:" + pos.getZ() +
", WORLD: \">" + dimensionName + "\">"
);
}

public void updateActiveState() {
if (world != null && !world.isClient && world.getBlockState(pos).get(WaystoneBlock.ACTIVE) == (owner == null)) {
world.setBlockState(pos, world.getBlockState(pos).with(WaystoneBlock.ACTIVE, this.ownerName != null));
Expand All @@ -72,7 +81,7 @@ public void updateActiveState() {
}

public void createHash(World world, BlockPos pos) {
this.hash = Utils.getSHA256("<POS X:" + pos.getX() + ", Y:" + pos.getY() + ", Z:" + pos.getZ() + ", WORLD: \">" + world + "\">");
this.hash = createHashString(Utils.getDimensionName(world), pos);
markDirty();
}

Expand Down Expand Up @@ -138,7 +147,7 @@ public void readNbt(NbtCompound nbt) {
if (nbt.contains("waystone_owner_name")) {
this.ownerName = nbt.getString("waystone_owner_name");
}
this.color = nbt.contains("color", NbtType.INT) ? nbt.getInt("color") : null;
this.color = nbt.contains("color", NbtElement.INT_TYPE) ? nbt.getInt("color") : null;
this.inventory = DefaultedList.ofSize(nbt.getInt("inventory_size"), ItemStack.EMPTY);
Inventories.readNbt(nbt, inventory);
}
Expand Down Expand Up @@ -380,7 +389,7 @@ public boolean teleportPlayer(PlayerEntity player, boolean takeCost, TeleportSou
if (playerEntity.getStackInHand(hand).getItem() instanceof AbyssWatcherItem) {
player.sendToolBreakStatus(hand);
playerEntity.getStackInHand(hand).decrement(1);
player.world.playSound(null, pos, SoundEvents.BLOCK_GLASS_BREAK, SoundCategory.PLAYERS, 1F, 1F);
player.getWorld().playSound(null, pos, SoundEvents.BLOCK_GLASS_BREAK, SoundCategory.PLAYERS, 1F, 1F);
break;
}
}
Expand All @@ -390,7 +399,7 @@ public boolean teleportPlayer(PlayerEntity player, boolean takeCost, TeleportSou

private boolean doTeleport(ServerPlayerEntity player, ServerWorld world, TeleportTarget target, TeleportSources source, boolean takeCost) {
var playerAccess = (PlayerEntityMixinAccess) player;
var cooldown = playerAccess.getTeleportCooldown();
var cooldown = playerAccess.fabricWaystones$getTeleportCooldown();
if (source != TeleportSources.VOID_TOTEM && cooldown > 0) {
var cooldownSeconds = Utils.df.format(cooldown / 20F);
player.sendMessage(Text.translatable(
Expand All @@ -402,14 +411,11 @@ private boolean doTeleport(ServerPlayerEntity player, ServerWorld world, Telepor
), false);
return false;
}
if (source == TeleportSources.LOCAL_VOID && !FabricWaystones.CONFIG.free_local_void_teleport()) {
return false;
}
if (source != TeleportSources.VOID_TOTEM && !Utils.canTeleport(player, hash, takeCost)) {
if (!Utils.canTeleport(player, hash, source, takeCost)) {
return false;
}
var cooldowns = FabricWaystones.CONFIG.teleportation_cooldown;
playerAccess.setTeleportCooldown(switch (source) {
playerAccess.fabricWaystones$setTeleportCooldown(switch (source) {
case WAYSTONE -> cooldowns.cooldown_ticks_from_waystone();
case ABYSS_WATCHER -> cooldowns.cooldown_ticks_from_abyss_watcher();
case LOCAL_VOID -> cooldowns.cooldown_ticks_from_local_void();
Expand All @@ -418,12 +424,12 @@ private boolean doTeleport(ServerPlayerEntity player, ServerWorld world, Telepor
});
var oldPos = player.getBlockPos();
world.getChunkManager().addTicket(ChunkTicketType.POST_TELEPORT, new ChunkPos(new BlockPos(target.position)), 1, player.getId());
player.world.playSound(null, oldPos, SoundEvents.ENTITY_ENDERMAN_TELEPORT, SoundCategory.BLOCKS, 1F, 1F);
player.getWorld().playSound(null, oldPos, SoundEvents.ENTITY_ENDERMAN_TELEPORT, SoundCategory.BLOCKS, 1F, 1F);
player.detach();
FabricDimensions.teleport(player, world, target);
BlockPos playerPos = player.getBlockPos();

if (!oldPos.isWithinDistance(playerPos, 6) || !player.world.getRegistryKey().equals(world.getRegistryKey())) {
if (!oldPos.isWithinDistance(playerPos, 6) || !player.getWorld().getRegistryKey().equals(world.getRegistryKey())) {
world.playSound(null, playerPos, SoundEvents.ENTITY_ENDERMAN_TELEPORT, SoundCategory.BLOCKS, 1F, 1F);
}
return true;
Expand Down
Loading

0 comments on commit b8b2dcb

Please sign in to comment.