Skip to content

Commit

Permalink
No more errors
Browse files Browse the repository at this point in the history
  • Loading branch information
AlurienFlame committed Jun 11, 2023
1 parent 9e8d16b commit 67c2c25
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 128 deletions.
33 changes: 17 additions & 16 deletions src/main/java/net/balancedrecall/BalancedRecall.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,22 @@

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.recipe.RecipeSerializer;
import net.minecraft.item.ItemGroups;
import net.minecraft.stat.StatFormatter;
import net.minecraft.stat.Stats;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;

public class BalancedRecall implements ModInitializer {
public static final String MODID = "balancedrecall";

// Items
public static final Item MAGIC_MIRROR = new MagicMirror(new FabricItemSettings().group(ItemGroup.TOOLS).maxDamage(256));
public static final Item DIMENSIONAL_MIRROR = new DimensionalMirror(new FabricItemSettings().group(ItemGroup.TOOLS).maxDamage(512));
public static final Item SLEEPING_MAT = new SleepingMat(new FabricItemSettings().group(ItemGroup.TOOLS).maxDamage(128));

// Recipe
public static final RecipeSerializer<MirrorRepairingRecipe> MIRROR_REPAIRING_SERIALIZER = new MirrorRepairingRecipe.Serializer();
public static final Item MAGIC_MIRROR = new MagicMirror(new FabricItemSettings().maxDamage(256));
public static final Item DIMENSIONAL_MIRROR = new DimensionalMirror(new FabricItemSettings().maxDamage(512));
public static final Item SLEEPING_MAT = new SleepingMat(new FabricItemSettings().maxDamage(128));

// Stats
public static final Identifier RECALLS = new Identifier(MODID, "recalls");
Expand All @@ -28,16 +26,19 @@ public class BalancedRecall implements ModInitializer {
@Override
public void onInitialize() {
// Items
Registry.register(Registry.ITEM, new Identifier(MODID, "magic_mirror"), MAGIC_MIRROR);
Registry.register(Registry.ITEM, new Identifier(MODID, "dimensional_mirror"), DIMENSIONAL_MIRROR);
Registry.register(Registry.ITEM, new Identifier(MODID, "sleeping_mat"), SLEEPING_MAT);
Registry.register(Registries.ITEM, new Identifier(MODID, "magic_mirror"), MAGIC_MIRROR);
Registry.register(Registries.ITEM, new Identifier(MODID, "dimensional_mirror"), DIMENSIONAL_MIRROR);
Registry.register(Registries.ITEM, new Identifier(MODID, "sleeping_mat"), SLEEPING_MAT);

// Recipe
Registry.register(Registry.RECIPE_SERIALIZER, new Identifier(MODID, "mirror_repairing"), MIRROR_REPAIRING_SERIALIZER);
ItemGroupEvents.modifyEntriesEvent(ItemGroups.TOOLS).register(content -> {
content.add(MAGIC_MIRROR);
content.add(DIMENSIONAL_MIRROR);
content.add(SLEEPING_MAT);
});

// Stats
Registry.register(Registry.CUSTOM_STAT, "recalls", RECALLS);
Registry.register(Registry.CUSTOM_STAT, "mat_sleeps", MAT_SLEEPS);
Registry.register(Registries.CUSTOM_STAT, "recalls", RECALLS);
Registry.register(Registries.CUSTOM_STAT, "mat_sleeps", MAT_SLEEPS);

Stats.CUSTOM.getOrCreateStat(RECALLS, StatFormatter.DEFAULT);
Stats.CUSTOM.getOrCreateStat(MAT_SLEEPS, StatFormatter.DEFAULT);
Expand Down
22 changes: 18 additions & 4 deletions src/main/java/net/balancedrecall/MagicMirror.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@

import net.minecraft.block.BedBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.RespawnAnchorBlock;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUsage;
import net.minecraft.item.Items;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory;
Expand Down Expand Up @@ -75,19 +77,26 @@ public ItemStack finishUsing(ItemStack stack, World world, LivingEntity user) {

// Find respawn position
// PlayerEntity.findRespawnPosition exhausts respawn anchor charges, which is undesirable, so instead we replicate its functionality directly
Block respawnBlock = targetWorld.getBlockState(spawnpoint).getBlock();
BlockState respawnBlockState = targetWorld.getBlockState(spawnpoint);
Block respawnBlock = respawnBlockState.getBlock();
Optional<Vec3d> respawnPosition = Optional.empty();

if (respawnBlock instanceof RespawnAnchorBlock) {
respawnPosition = RespawnAnchorBlock.findRespawnPosition(EntityType.PLAYER, targetWorld, spawnpoint);

} else if (respawnBlock instanceof BedBlock) {
respawnPosition = BedBlock.findWakeUpPosition(EntityType.PLAYER, targetWorld, spawnpoint, serverPlayer.getSpawnAngle());
respawnPosition = BedBlock.findWakeUpPosition(
EntityType.PLAYER,
targetWorld,
spawnpoint,
respawnBlockState.get(BedBlock.FACING),
serverPlayer.getSpawnAngle()
);

} else if (serverPlayer.isSpawnForced()){
// Spawnpoint set by /spawnpoint command or equivalent
boolean footBlockClear = respawnBlock.canMobSpawnInside();
boolean headBlockClear = targetWorld.getBlockState(spawnpoint.up()).getBlock().canMobSpawnInside();
boolean footBlockClear = respawnBlock.canMobSpawnInside(respawnBlockState);
boolean headBlockClear = targetWorld.getBlockState(spawnpoint.up()).getBlock().canMobSpawnInside(respawnBlockState);
if (footBlockClear && headBlockClear) {
respawnPosition = Optional.of(new Vec3d((double)spawnpoint.getX() + 0.5D, (double)spawnpoint.getY() + 0.1D, (double)spawnpoint.getZ() + 0.5D));
}
Expand Down Expand Up @@ -148,4 +157,9 @@ private void teleportToWorldSpawn(PlayerEntity player, ServerPlayerEntity server
serverPlayer.teleport(overworld, worldSpawn.getX(), worldSpawn.getY(), worldSpawn.getZ(), serverPlayer.getSpawnAngle(), 0.5F);
overworld.playSound(null, worldSpawn, SoundEvents.ITEM_CHORUS_FRUIT_TELEPORT, SoundCategory.PLAYERS, 0.4f, 1f);
}

@Override
public boolean canRepair(ItemStack stack, ItemStack ingredient) {
return ingredient.isOf(Items.ENDER_PEARL) || super.canRepair(stack, ingredient);
}
}
83 changes: 0 additions & 83 deletions src/main/java/net/balancedrecall/MirrorRepairingRecipe.java

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/java/net/balancedrecall/SleepingMat.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand han
((MatSleepingPlayer) user).sleepOnMat(user.getBlockPos());

// Skip the night
if (!((ServerPlayerEntity) user).getWorld().isSleepingEnabled()) {
if (!((ServerPlayerEntity) user).getServerWorld().isSleepingEnabled()) {
user.sendMessage(NOT_POSSIBLE, false);
}
((ServerWorld) world).updateSleepingPlayers();
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit 67c2c25

Please sign in to comment.