This commit is contained in:
Hexugory 2024-05-22 18:25:06 -05:00
parent 9df4bcf87d
commit 3e06d33470
22 changed files with 304 additions and 299 deletions

View File

@ -33,7 +33,7 @@ repositories {
dependencies { dependencies {
// To change the versions see the gradle.properties file // To change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}" minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" mappings loom.officialMojangMappings()
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
// Fabric API. This is technically optional, but you probably want it anyway. // Fabric API. This is technically optional, but you probably want it anyway.

View File

@ -1,6 +1,6 @@
package net.touhoudiscord; package net.touhoudiscord;
import net.minecraft.util.math.BlockPos; import net.minecraft.core.BlockPos;
public interface BuyStationCapable { public interface BuyStationCapable {
default void hardcoreredeploy_openBuyStationScreen(BlockPos blockPos) { default void hardcoreredeploy_openBuyStationScreen(BlockPos blockPos) {

View File

@ -8,26 +8,26 @@ import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder; import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder;
import net.minecraft.block.Block; import net.minecraft.core.BlockPos;
import net.minecraft.block.BlockState; import net.minecraft.core.Direction;
import net.minecraft.block.HorizontalFacingBlock; import net.minecraft.core.Registry;
import net.minecraft.block.entity.BlockEntityType; import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.entity.effect.StatusEffect; import net.minecraft.nbt.CompoundTag;
import net.minecraft.entity.projectile.FireworkRocketEntity; import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.item.Item; import net.minecraft.resources.ResourceLocation;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sound.SoundEvent; import net.minecraft.sounds.SoundEvent;
import net.minecraft.util.Identifier; import net.minecraft.world.effect.MobEffect;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.entity.projectile.FireworkRocketEntity;
import net.minecraft.util.math.Direction; import net.minecraft.world.item.Item;
import net.minecraft.util.math.Vec3d; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.GameMode; import net.minecraft.world.level.GameType;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.Vec3;
import net.touhoudiscord.block.BuyStation; import net.touhoudiscord.block.BuyStation;
import net.touhoudiscord.block.BuyStationEntity; import net.touhoudiscord.block.BuyStationEntity;
import net.touhoudiscord.commands.RedeployPlayerCommand; import net.touhoudiscord.commands.RedeployPlayerCommand;
@ -47,24 +47,24 @@ public class HardcoreRedeploy implements ModInitializer {
public static final String MOD_ID = "hardcore_redeploy"; public static final String MOD_ID = "hardcore_redeploy";
public static final Logger LOGGER = LoggerFactory.getLogger("hardcore_redeploy"); public static final Logger LOGGER = LoggerFactory.getLogger("hardcore_redeploy");
public static final StatusEffect REDEPLOYING = new RedeployingStatusEffect(); public static final MobEffect REDEPLOYING = new RedeployingStatusEffect();
public static final Block BUY_STATION = Registry.register(Registries.BLOCK, new Identifier(HardcoreRedeploy.MOD_ID, "buy_station"), new BuyStation(FabricBlockSettings.create().nonOpaque().requiresTool().resistance(6).hardness(3))); public static final Block BUY_STATION = Registry.register(BuiltInRegistries.BLOCK, new ResourceLocation(HardcoreRedeploy.MOD_ID, "buy_station"), new BuyStation(FabricBlockSettings.of().noOcclusion().requiresCorrectToolForDrops().explosionResistance(6).destroyTime(3)));
public static final Item BUY_STATION_ITEM = Registry.register(Registries.ITEM, new Identifier(HardcoreRedeploy.MOD_ID, "buy_station"), new BuyStationItem(HardcoreRedeploy.BUY_STATION, new FabricItemSettings())); public static final Item BUY_STATION_ITEM = Registry.register(BuiltInRegistries.ITEM, new ResourceLocation(HardcoreRedeploy.MOD_ID, "buy_station"), new BuyStationItem(HardcoreRedeploy.BUY_STATION, new FabricItemSettings()));
public static final Identifier BUY_STATION_SOUND_ID = new Identifier(HardcoreRedeploy.MOD_ID, "buy_station"); public static final ResourceLocation BUY_STATION_SOUND_ID = new ResourceLocation(HardcoreRedeploy.MOD_ID, "buy_station");
public static SoundEvent BUY_STATION_SOUND_EVENT = SoundEvent.of(BUY_STATION_SOUND_ID); public static SoundEvent BUY_STATION_SOUND_EVENT = SoundEvent.createVariableRangeEvent(BUY_STATION_SOUND_ID);
public static BlockEntityType<BuyStationEntity> BUY_STATION_ENTITY; public static BlockEntityType<BuyStationEntity> BUY_STATION_ENTITY;
public static final Identifier SEND_REVIVES_UPDATE = new Identifier(HardcoreRedeploy.MOD_ID, "send_revives_update"); public static final ResourceLocation SEND_REVIVES_UPDATE = new ResourceLocation(HardcoreRedeploy.MOD_ID, "send_revives_update");
public static final Identifier REQUEST_REVIVE = new Identifier(HardcoreRedeploy.MOD_ID, "request_revive"); public static final ResourceLocation REQUEST_REVIVE = new ResourceLocation(HardcoreRedeploy.MOD_ID, "request_revive");
public static final Identifier SEND_REVIVE = new Identifier(HardcoreRedeploy.MOD_ID, "send_revive"); public static final ResourceLocation SEND_REVIVE = new ResourceLocation(HardcoreRedeploy.MOD_ID, "send_revive");
public static final Identifier SYNC_CONFIG = new Identifier(HardcoreRedeploy.MOD_ID, "sync_config"); public static final ResourceLocation SYNC_CONFIG = new ResourceLocation(HardcoreRedeploy.MOD_ID, "sync_config");
private static final ItemStack firework; private static final ItemStack firework;
static { static {
firework = new ItemStack(Registries.ITEM.get(new Identifier("minecraft", "firework_rocket"))); firework = new ItemStack(BuiltInRegistries.ITEM.get(new ResourceLocation("minecraft", "firework_rocket")));
NbtCompound nbt = new NbtCompound(); CompoundTag nbt = new CompoundTag();
nbt.putByte("Flight", (byte)3); nbt.putByte("Flight", (byte)3);
firework.setSubNbt("Fireworks", nbt); firework.addTagElement("Fireworks", nbt);
} }
@ -75,32 +75,32 @@ public class HardcoreRedeploy implements ModInitializer {
GeckoLib.initialize(); GeckoLib.initialize();
ServerPlayNetworking.registerGlobalReceiver(REQUEST_REVIVE, (server, player, handler, buf, responseSender) -> { ServerPlayNetworking.registerGlobalReceiver(REQUEST_REVIVE, (server, player, handler, buf, responseSender) -> {
UUID uuid = buf.readUuid(); UUID uuid = buf.readUUID();
BlockPos blockPos = buf.readBlockPos(); BlockPos blockPos = buf.readBlockPos();
server.execute(() -> { server.execute(() -> {
ServerPlayerEntity spectator = server.getPlayerManager().getPlayer(uuid); ServerPlayer spectator = server.getPlayerList().getPlayer(uuid);
if (spectator == null) return; if (spectator == null) return;
BlockState invokingBlock = player.getWorld().getBlockState(blockPos); BlockState invokingBlock = player.level().getBlockState(blockPos);
if (invokingBlock.getBlock() instanceof BuyStation && player.getPos().isInRange(blockPos.toCenterPos(), 5)) { if (invokingBlock.getBlock() instanceof BuyStation && player.position().closerThan(blockPos.getCenter(), 5)) {
int cost = config.baseCost + config.additiveCost * RedeployStateSaver.getPlayerState(spectator).timesRevived; int cost = config.baseCost + config.additiveCost * RedeployStateSaver.getPlayerState(spectator).timesRevived;
boolean isCreative = player.interactionManager.getGameMode() == GameMode.CREATIVE; boolean isCreative = player.gameMode.getGameModeForPlayer() == GameType.CREATIVE;
if (!isCreative && player.experienceLevel < cost) return; if (!isCreative && player.experienceLevel < cost) return;
Vec3d fireworkPos = blockPos.toCenterPos(); Vec3 fireworkPos = blockPos.getCenter();
BlockState blockState = player.getWorld().getBlockState(blockPos); BlockState blockState = player.level().getBlockState(blockPos);
Direction offset = blockState.get(HorizontalFacingBlock.FACING).rotateYClockwise(); Direction offset = blockState.getValue(HorizontalDirectionalBlock.FACING).getClockWise();
if (blockState.get(BUY_STATION_PART) == BuyStation.BuyStationPart.AUX) if (blockState.getValue(BUY_STATION_PART) == BuyStation.BuyStationPart.AUX)
offset = offset.getOpposite(); offset = offset.getOpposite();
FireworkRocketEntity fireworkRocketEntity = new FireworkRocketEntity(player.getWorld(), fireworkPos.x + offset.getOffsetX() / 2., fireworkPos.y, fireworkPos.z + offset.getOffsetZ() / 2., firework); FireworkRocketEntity fireworkRocketEntity = new FireworkRocketEntity(player.level(), fireworkPos.x + offset.getStepX() / 2., fireworkPos.y, fireworkPos.z + offset.getStepZ() / 2., firework);
player.getWorld().spawnEntity(fireworkRocketEntity); player.level().addFreshEntity(fireworkRocketEntity);
if (!isCreative) player.setExperienceLevel(player.experienceLevel - cost); if (!isCreative) player.setExperienceLevels(player.experienceLevel - cost);
((TimerAccess) server).hardcoreredeploy_redeployInTicks(spectator, player, 60L); ((TimerAccess) server).hardcoreredeploy_redeployInTicks(spectator, player, 60L);
PacketByteBuf buf1 = PacketByteBufs.create(); FriendlyByteBuf buf1 = PacketByteBufs.create();
ServerPlayNetworking.send(spectator, SEND_REVIVE, buf1); ServerPlayNetworking.send(spectator, SEND_REVIVE, buf1);
} }
}); });
@ -114,18 +114,18 @@ public class HardcoreRedeploy implements ModInitializer {
}); });
}); });
BUY_STATION_ENTITY = Registry.register(Registries.BLOCK_ENTITY_TYPE, BUY_STATION_ENTITY = Registry.register(BuiltInRegistries.BLOCK_ENTITY_TYPE,
new Identifier(HardcoreRedeploy.MOD_ID, "buy_station_entity"), new ResourceLocation(HardcoreRedeploy.MOD_ID, "buy_station_entity"),
FabricBlockEntityTypeBuilder.create(BuyStationEntity::new, FabricBlockEntityTypeBuilder.create(BuyStationEntity::new,
HardcoreRedeploy.BUY_STATION).build()); HardcoreRedeploy.BUY_STATION).build());
Registry.register(Registries.STATUS_EFFECT, new Identifier(HardcoreRedeploy.MOD_ID, "redeploying"), REDEPLOYING); Registry.register(BuiltInRegistries.MOB_EFFECT, new ResourceLocation(HardcoreRedeploy.MOD_ID, "redeploying"), REDEPLOYING);
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> RedeployPlayerCommand.register(dispatcher)); CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> RedeployPlayerCommand.register(dispatcher));
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> SetRevivesCommand.register(dispatcher)); CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> SetRevivesCommand.register(dispatcher));
Registry.register(Registries.SOUND_EVENT, BUY_STATION_SOUND_ID, BUY_STATION_SOUND_EVENT); Registry.register(BuiltInRegistries.SOUND_EVENT, BUY_STATION_SOUND_ID, BUY_STATION_SOUND_EVENT);
} }
public static void syncConfig(MinecraftServer server, ServerPlayerEntity receiver) { public static void syncConfig(MinecraftServer server, ServerPlayer receiver) {
PacketByteBuf buf = PacketByteBufs.create(); FriendlyByteBuf buf = PacketByteBufs.create();
buf.writeInt(HardcoreRedeployConfigHandler.config.baseCost); buf.writeInt(HardcoreRedeployConfigHandler.config.baseCost);
buf.writeInt(HardcoreRedeployConfigHandler.config.additiveCost); buf.writeInt(HardcoreRedeployConfigHandler.config.additiveCost);
server.execute(() -> { server.execute(() -> {
@ -133,10 +133,10 @@ public class HardcoreRedeploy implements ModInitializer {
}); });
} }
public static void syncRevives(MinecraftServer server, ServerPlayerEntity receiver, UUID uuid) { public static void syncRevives(MinecraftServer server, ServerPlayer receiver, UUID uuid) {
PlayerData playerData = RedeployStateSaver.getPlayerState(server, uuid); PlayerData playerData = RedeployStateSaver.getPlayerState(server, uuid);
PacketByteBuf buf = PacketByteBufs.create(); FriendlyByteBuf buf = PacketByteBufs.create();
buf.writeUuid(uuid); buf.writeUUID(uuid);
buf.writeInt(playerData.timesRevived); buf.writeInt(playerData.timesRevived);
server.execute(() -> { server.execute(() -> {
ServerPlayNetworking.send(receiver, SEND_REVIVES_UPDATE, buf); ServerPlayNetworking.send(receiver, SEND_REVIVES_UPDATE, buf);

View File

@ -4,7 +4,7 @@ import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.minecraft.client.render.block.entity.BlockEntityRendererFactories; import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
import net.touhoudiscord.HardcoreRedeployConfigHandler.HardcoreRedeployConfig; import net.touhoudiscord.HardcoreRedeployConfigHandler.HardcoreRedeployConfig;
import net.touhoudiscord.block.client.BuyStationRenderer; import net.touhoudiscord.block.client.BuyStationRenderer;
import net.touhoudiscord.screen.RedeployingScreen; import net.touhoudiscord.screen.RedeployingScreen;
@ -20,10 +20,10 @@ public class HardcoreRedeployClient implements ClientModInitializer {
@Override @Override
public void onInitializeClient() { public void onInitializeClient() {
BlockEntityRendererFactories.register(HardcoreRedeploy.BUY_STATION_ENTITY, BuyStationRenderer::new); BlockEntityRenderers.register(HardcoreRedeploy.BUY_STATION_ENTITY, BuyStationRenderer::new);
ClientPlayNetworking.registerGlobalReceiver(HardcoreRedeploy.SEND_REVIVES_UPDATE, (client, handler, buf, responseSender) -> { ClientPlayNetworking.registerGlobalReceiver(HardcoreRedeploy.SEND_REVIVES_UPDATE, (client, handler, buf, responseSender) -> {
UUID uuid = buf.readUuid(); UUID uuid = buf.readUUID();
int revives = buf.readInt(); int revives = buf.readInt();
client.execute(() -> { client.execute(() -> {
reviveMap.put(uuid, revives); reviveMap.put(uuid, revives);

View File

@ -1,20 +1,20 @@
package net.touhoudiscord; package net.touhoudiscord;
import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.GameMode; import net.minecraft.world.level.GameType;
public class RedeployPlayer { public class RedeployPlayer {
public static void redeploy(ServerPlayerEntity spectator, ServerPlayerEntity target) { public static void redeploy(ServerPlayer spectator, ServerPlayer target) {
if (!(spectator.interactionManager.getGameMode() == GameMode.SPECTATOR)) return; if (!(spectator.gameMode.getGameModeForPlayer() == GameType.SPECTATOR)) return;
if (!target.getServerWorld().getDimension().hasCeiling()) spectator.addStatusEffect(new StatusEffectInstance(HardcoreRedeploy.REDEPLOYING, 20*20, 0)); if (!target.serverLevel().dimensionType().hasCeiling()) spectator.addEffect(new MobEffectInstance(HardcoreRedeploy.REDEPLOYING, 20*20, 0));
spectator.teleport(target.getServerWorld(), target.getPos().x, target.getServerWorld().getDimension().hasCeiling() ? target.getPos().y : 320, target.getPos().z, 0, 30); spectator.teleportTo(target.serverLevel(), target.position().x, target.serverLevel().dimensionType().hasCeiling() ? target.position().y : 320, target.position().z, 0, 30);
spectator.changeGameMode(GameMode.SURVIVAL); spectator.setGameMode(GameType.SURVIVAL);
RedeployStateSaver.getPlayerState(spectator).timesRevived++; RedeployStateSaver.getPlayerState(spectator).timesRevived++;
spectator.server.getPlayerManager().getPlayerList().forEach(player -> { spectator.server.getPlayerList().getPlayers().forEach(player -> {
HardcoreRedeploy.syncRevives(player.server, player, spectator.getUuid()); HardcoreRedeploy.syncRevives(player.server, player, spectator.getUUID());
}); });
} }
} }

View File

@ -1,25 +1,24 @@
package net.touhoudiscord; package net.touhoudiscord;
import net.minecraft.entity.LivingEntity; import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.world.PersistentState; import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.PersistentStateManager; import net.minecraft.world.level.Level;
import net.minecraft.world.World; import net.minecraft.world.level.saveddata.SavedData;
import net.minecraft.world.level.storage.DimensionDataStorage;
import java.util.HashMap; import java.util.HashMap;
import java.util.UUID; import java.util.UUID;
public class RedeployStateSaver extends PersistentState { public class RedeployStateSaver extends SavedData {
public HashMap<UUID, PlayerData> players = new HashMap<>(); public HashMap<UUID, PlayerData> players = new HashMap<>();
@Override @Override
public NbtCompound writeNbt(NbtCompound nbt) { public CompoundTag save(CompoundTag nbt) {
NbtCompound playersNbt = new NbtCompound(); CompoundTag playersNbt = new CompoundTag();
players.forEach((uuid, playerData) -> { players.forEach((uuid, playerData) -> {
NbtCompound playerNbt = new NbtCompound(); CompoundTag playerNbt = new CompoundTag();
playerNbt.putInt("timesRevived", playerData.timesRevived); playerNbt.putInt("timesRevived", playerData.timesRevived);
@ -30,11 +29,11 @@ public class RedeployStateSaver extends PersistentState {
return nbt; return nbt;
} }
public static RedeployStateSaver createFromNbt(NbtCompound tag) { public static RedeployStateSaver createFromNbt(CompoundTag tag) {
RedeployStateSaver state = new RedeployStateSaver(); RedeployStateSaver state = new RedeployStateSaver();
NbtCompound playersNbt = tag.getCompound("players"); CompoundTag playersNbt = tag.getCompound("players");
playersNbt.getKeys().forEach(key -> { playersNbt.getAllKeys().forEach(key -> {
PlayerData playerData = new PlayerData(); PlayerData playerData = new PlayerData();
playerData.timesRevived = playersNbt.getCompound(key).getInt("timesRevived"); playerData.timesRevived = playersNbt.getCompound(key).getInt("timesRevived");
@ -47,19 +46,19 @@ public class RedeployStateSaver extends PersistentState {
} }
public static RedeployStateSaver getServerState(MinecraftServer server) { public static RedeployStateSaver getServerState(MinecraftServer server) {
PersistentStateManager persistentStateManager = server.getWorld(World.OVERWORLD).getPersistentStateManager(); DimensionDataStorage persistentStateManager = server.getLevel(Level.OVERWORLD).getDataStorage();
RedeployStateSaver state = persistentStateManager.getOrCreate(RedeployStateSaver::createFromNbt, RedeployStateSaver::new, HardcoreRedeploy.MOD_ID); RedeployStateSaver state = persistentStateManager.computeIfAbsent(RedeployStateSaver::createFromNbt, RedeployStateSaver::new, HardcoreRedeploy.MOD_ID);
state.markDirty(); state.setDirty();
return state; return state;
} }
public static PlayerData getPlayerState(LivingEntity player) { public static PlayerData getPlayerState(LivingEntity player) {
RedeployStateSaver serverState = getServerState(player.getWorld().getServer()); RedeployStateSaver serverState = getServerState(player.level().getServer());
PlayerData playerState = serverState.players.computeIfAbsent(player.getUuid(), uuid -> new PlayerData()); PlayerData playerState = serverState.players.computeIfAbsent(player.getUUID(), uuid -> new PlayerData());
return playerState; return playerState;
} }

View File

@ -1,7 +1,7 @@
package net.touhoudiscord; package net.touhoudiscord;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.level.ServerPlayer;
public interface TimerAccess { public interface TimerAccess {
void hardcoreredeploy_redeployInTicks(ServerPlayerEntity spectator, ServerPlayerEntity target, Long ticks); void hardcoreredeploy_redeployInTicks(ServerPlayer spectator, ServerPlayer target, Long ticks);
} }

View File

@ -1,87 +1,93 @@
package net.touhoudiscord.block; package net.touhoudiscord.block;
import net.minecraft.block.*; import net.minecraft.core.BlockPos;
import net.minecraft.block.entity.BlockEntity; import net.minecraft.core.Direction;
import net.minecraft.entity.LivingEntity; import net.minecraft.util.StringRepresentable;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.world.InteractionHand;
import net.minecraft.item.ItemPlacementContext; import net.minecraft.world.InteractionResult;
import net.minecraft.item.ItemStack; import net.minecraft.world.entity.LivingEntity;
import net.minecraft.state.StateManager; import net.minecraft.world.entity.player.Player;
import net.minecraft.state.property.EnumProperty; import net.minecraft.world.item.ItemStack;
import net.minecraft.util.ActionResult; import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.util.Hand; import net.minecraft.world.level.BlockGetter;
import net.minecraft.util.StringIdentifiable; import net.minecraft.world.level.Level;
import net.minecraft.util.hit.BlockHitResult; import net.minecraft.world.level.LevelReader;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.level.block.BaseEntityBlock;
import net.minecraft.util.math.Direction; import net.minecraft.world.level.block.Block;
import net.minecraft.util.shape.VoxelShape; import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.BlockView; import net.minecraft.world.level.block.HorizontalDirectionalBlock;
import net.minecraft.world.World; import net.minecraft.world.level.block.LevelEvent;
import net.minecraft.world.WorldEvents; import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.WorldView; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.EnumProperty;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.touhoudiscord.BuyStationCapable; import net.touhoudiscord.BuyStationCapable;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
public class BuyStation extends BlockWithEntity { public class BuyStation extends BaseEntityBlock {
public static final EnumProperty<BuyStationPart> BUY_STATION_PART = EnumProperty.of("part", BuyStationPart.class); public static final EnumProperty<BuyStationPart> BUY_STATION_PART = EnumProperty.create("part", BuyStationPart.class);
protected static final VoxelShape NORTH_SHAPE = Block.createCuboidShape(1.0, 0.0, 1.0, 16.0, 12.0, 15.0); protected static final VoxelShape NORTH_SHAPE = Block.box(1.0, 0.0, 1.0, 16.0, 12.0, 15.0);
protected static final VoxelShape SOUTH_SHAPE = Block.createCuboidShape(0.0, 0.0, 1.0, 15.0, 12.0, 15.0); protected static final VoxelShape SOUTH_SHAPE = Block.box(0.0, 0.0, 1.0, 15.0, 12.0, 15.0);
protected static final VoxelShape WEST_SHAPE = Block.createCuboidShape(1.0, 0.0, 0.0, 15.0, 12.0, 15.0); protected static final VoxelShape WEST_SHAPE = Block.box(1.0, 0.0, 0.0, 15.0, 12.0, 15.0);
protected static final VoxelShape EAST_SHAPE = Block.createCuboidShape(1.0, 0.0, 1.0, 15.0, 12.0, 16.0); protected static final VoxelShape EAST_SHAPE = Block.box(1.0, 0.0, 1.0, 15.0, 12.0, 16.0);
public BuyStation(Settings settings) { public BuyStation(Properties settings) {
super(settings); super(settings);
this.setDefaultState(this.getDefaultState() this.registerDefaultState(this.defaultBlockState()
.with(HorizontalFacingBlock.FACING, Direction.NORTH) .setValue(HorizontalDirectionalBlock.FACING, Direction.NORTH)
.with(BUY_STATION_PART, BuyStationPart.MAIN)); .setValue(BUY_STATION_PART, BuyStationPart.MAIN));
} }
@Nullable @Nullable
@Override @Override
public BlockState getPlacementState(ItemPlacementContext ctx) { public BlockState getStateForPlacement(BlockPlaceContext ctx) {
return this.getDefaultState().with(HorizontalFacingBlock.FACING, ctx.getHorizontalPlayerFacing()); return this.defaultBlockState().setValue(HorizontalDirectionalBlock.FACING, ctx.getHorizontalDirection());
} }
@Override @Override
public void onPlaced(World world, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack itemStack) { public void setPlacedBy(Level world, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack itemStack) {
super.onPlaced(world, pos, state, placer, itemStack); super.setPlacedBy(world, pos, state, placer, itemStack);
if (!world.isClient) { if (!world.isClientSide) {
BlockPos blockPos = pos.offset(state.get(HorizontalFacingBlock.FACING).rotateYClockwise()); BlockPos blockPos = pos.relative(state.getValue(HorizontalDirectionalBlock.FACING).getClockWise());
world.setBlockState(blockPos, state.with(BUY_STATION_PART, BuyStationPart.AUX), Block.NOTIFY_ALL); world.setBlock(blockPos, state.setValue(BUY_STATION_PART, BuyStationPart.AUX), Block.UPDATE_ALL);
world.updateNeighbors(pos, Blocks.AIR); world.blockUpdated(pos, Blocks.AIR);
state.updateNeighbors(world, pos, Block.NOTIFY_ALL); state.updateNeighbourShapes(world, pos, Block.UPDATE_ALL);
} }
} }
@Override @Override
public void onBreak(World world, BlockPos pos, BlockState state, PlayerEntity player) { public void playerWillDestroy(Level world, BlockPos pos, BlockState state, Player player) {
if (world.isClient()) { if (world.isClientSide()) {
super.onBreak(world, pos, state, player); super.playerWillDestroy(world, pos, state, player);
} }
BuyStationPart part = state.get(BUY_STATION_PART); BuyStationPart part = state.getValue(BUY_STATION_PART);
if (part == BuyStationPart.MAIN) { if (part == BuyStationPart.MAIN) {
BlockPos otherpos = pos.offset(state.get(HorizontalFacingBlock.FACING).rotateYClockwise()); BlockPos otherpos = pos.relative(state.getValue(HorizontalDirectionalBlock.FACING).getClockWise());
BlockState otherstate = world.getBlockState(otherpos); BlockState otherstate = world.getBlockState(otherpos);
if (otherstate.getBlock() == this) { if (otherstate.getBlock() == this) {
world.setBlockState(otherpos, Blocks.AIR.getDefaultState(), Block.NOTIFY_ALL); world.setBlock(otherpos, Blocks.AIR.defaultBlockState(), Block.UPDATE_ALL);
world.syncWorldEvent(player, WorldEvents.BLOCK_BROKEN, otherpos, Block.getRawIdFromState(otherstate)); world.levelEvent(player, LevelEvent.PARTICLES_DESTROY_BLOCK, otherpos, Block.getId(otherstate));
} }
} }
else if (part == BuyStationPart.AUX) { else if (part == BuyStationPart.AUX) {
BlockPos otherpos = pos.offset(state.get(HorizontalFacingBlock.FACING).rotateYCounterclockwise()); BlockPos otherpos = pos.relative(state.getValue(HorizontalDirectionalBlock.FACING).getCounterClockWise());
BlockState otherstate = world.getBlockState(otherpos); BlockState otherstate = world.getBlockState(otherpos);
if (otherstate.getBlock() == this) { if (otherstate.getBlock() == this) {
world.setBlockState(otherpos, Blocks.AIR.getDefaultState(), Block.NOTIFY_ALL); world.setBlock(otherpos, Blocks.AIR.defaultBlockState(), Block.UPDATE_ALL);
world.syncWorldEvent(player, WorldEvents.BLOCK_BROKEN, otherpos, Block.getRawIdFromState(otherstate)); world.levelEvent(player, LevelEvent.PARTICLES_DESTROY_BLOCK, otherpos, Block.getId(otherstate));
} }
} }
} }
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) {
Direction direction = state.get(HorizontalFacingBlock.FACING); Direction direction = state.getValue(HorizontalDirectionalBlock.FACING);
BuyStationPart part = state.get(BUY_STATION_PART); BuyStationPart part = state.getValue(BUY_STATION_PART);
if (part == BuyStationPart.AUX) direction = direction.getOpposite(); if (part == BuyStationPart.AUX) direction = direction.getOpposite();
return switch (direction) { return switch (direction) {
default -> NORTH_SHAPE; default -> NORTH_SHAPE;
@ -92,38 +98,38 @@ public class BuyStation extends BlockWithEntity {
} }
@Override @Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
Block block = world.getBlockState(pos).getBlock(); Block block = world.getBlockState(pos).getBlock();
if (block instanceof BuyStation) { if (block instanceof BuyStation) {
((BuyStationCapable) player).hardcoreredeploy_openBuyStationScreen(pos); ((BuyStationCapable) player).hardcoreredeploy_openBuyStationScreen(pos);
return ActionResult.success(world.isClient); return InteractionResult.sidedSuccess(world.isClientSide);
} else { } else {
return ActionResult.PASS; return InteractionResult.PASS;
} }
} }
@Override @Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) { protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(HorizontalFacingBlock.FACING, BUY_STATION_PART); builder.add(HorizontalDirectionalBlock.FACING, BUY_STATION_PART);
} }
@Nullable @Nullable
@Override @Override
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) { public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
return state.get(BUY_STATION_PART) == BuyStationPart.MAIN ? new BuyStationEntity(pos, state) : null; return state.getValue(BUY_STATION_PART) == BuyStationPart.MAIN ? new BuyStationEntity(pos, state) : null;
} }
@Override @Override
public BlockRenderType getRenderType(BlockState state) { public RenderShape getRenderShape(BlockState state) {
return state.get(BUY_STATION_PART) == BuyStationPart.MAIN ? BlockRenderType.MODEL : BlockRenderType.INVISIBLE; return state.getValue(BUY_STATION_PART) == BuyStationPart.MAIN ? RenderShape.MODEL : RenderShape.INVISIBLE;
} }
@Override @Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) {
return world.getBlockState(pos.offset(state.get(HorizontalFacingBlock.FACING).rotateYClockwise())).isReplaceable() && super.canPlaceAt(state, world, pos); return world.getBlockState(pos.relative(state.getValue(HorizontalDirectionalBlock.FACING).getClockWise())).canBeReplaced() && super.canSurvive(state, world, pos);
} }
public enum BuyStationPart implements StringIdentifiable { public enum BuyStationPart implements StringRepresentable {
MAIN("main"), MAIN("main"),
AUX("aux"); AUX("aux");
@ -137,7 +143,7 @@ public class BuyStation extends BlockWithEntity {
return this.name; return this.name;
} }
public String asString() { public String getSerializedName() {
return this.name; return this.name;
} }
} }

View File

@ -1,11 +1,11 @@
package net.touhoudiscord.block; package net.touhoudiscord.block;
import net.minecraft.block.BlockState; import net.minecraft.core.BlockPos;
import net.minecraft.block.entity.BlockEntity; import net.minecraft.sounds.SoundSource;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.world.entity.player.Player;
import net.minecraft.sound.SoundCategory; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.util.math.Vec3d; import net.minecraft.world.phys.Vec3;
import net.touhoudiscord.HardcoreRedeploy; import net.touhoudiscord.HardcoreRedeploy;
import software.bernie.geckolib.animatable.GeoBlockEntity; import software.bernie.geckolib.animatable.GeoBlockEntity;
import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache; import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache;
@ -29,8 +29,8 @@ public class BuyStationEntity extends BlockEntity implements GeoBlockEntity {
@Override @Override
public void registerControllers(AnimatableManager.ControllerRegistrar controllers) { public void registerControllers(AnimatableManager.ControllerRegistrar controllers) {
controllers.add(new AnimationController<>(this, "buystationcontroller", 0, state -> { controllers.add(new AnimationController<>(this, "buystationcontroller", 0, state -> {
Vec3d pos = state.getAnimatable().getPos().toCenterPos(); Vec3 pos = state.getAnimatable().getBlockPos().getCenter();
if (state.getAnimatable().getWorld().getClosestPlayer(pos.x, pos.y, pos.z, 5, false) instanceof PlayerEntity) { if (state.getAnimatable().getLevel().getNearestPlayer(pos.x, pos.y, pos.z, 5, false) instanceof Player) {
return state.setAndContinue(OPEN); return state.setAndContinue(OPEN);
} }
else { else {
@ -38,10 +38,10 @@ public class BuyStationEntity extends BlockEntity implements GeoBlockEntity {
} }
}) })
.setSoundKeyframeHandler(event -> { .setSoundKeyframeHandler(event -> {
PlayerEntity player = ClientUtils.getClientPlayer(); Player player = ClientUtils.getClientPlayer();
if (player != null) { if (player != null) {
player.getWorld().playSound(player, this.getPos(), HardcoreRedeploy.BUY_STATION_SOUND_EVENT, SoundCategory.BLOCKS, 1, 1); player.level().playSound(player, this.getBlockPos(), HardcoreRedeploy.BUY_STATION_SOUND_EVENT, SoundSource.BLOCKS, 1, 1);
} }
})); }));
} }

View File

@ -2,7 +2,7 @@ package net.touhoudiscord.block.client;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.minecraft.util.Identifier; import net.minecraft.resources.ResourceLocation;
import net.touhoudiscord.HardcoreRedeploy; import net.touhoudiscord.HardcoreRedeploy;
import net.touhoudiscord.block.BuyStationEntity; import net.touhoudiscord.block.BuyStationEntity;
import software.bernie.geckolib.model.GeoModel; import software.bernie.geckolib.model.GeoModel;
@ -10,17 +10,17 @@ import software.bernie.geckolib.model.GeoModel;
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public class BuyStationModel extends GeoModel<BuyStationEntity> { public class BuyStationModel extends GeoModel<BuyStationEntity> {
@Override @Override
public Identifier getModelResource(BuyStationEntity animatable) { public ResourceLocation getModelResource(BuyStationEntity animatable) {
return new Identifier(HardcoreRedeploy.MOD_ID, "geo/buy_station.geo.json"); return new ResourceLocation(HardcoreRedeploy.MOD_ID, "geo/buy_station.geo.json");
} }
@Override @Override
public Identifier getTextureResource(BuyStationEntity animatable) { public ResourceLocation getTextureResource(BuyStationEntity animatable) {
return new Identifier(HardcoreRedeploy.MOD_ID, "textures/block/buy_station.png"); return new ResourceLocation(HardcoreRedeploy.MOD_ID, "textures/block/buy_station.png");
} }
@Override @Override
public Identifier getAnimationResource(BuyStationEntity animatable) { public ResourceLocation getAnimationResource(BuyStationEntity animatable) {
return new Identifier(HardcoreRedeploy.MOD_ID, "animations/buy_station.animation.json"); return new ResourceLocation(HardcoreRedeploy.MOD_ID, "animations/buy_station.animation.json");
} }
} }

View File

@ -1,27 +1,27 @@
package net.touhoudiscord.block.client; package net.touhoudiscord.block.client;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.minecraft.block.HorizontalFacingBlock; import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.render.VertexConsumer; import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.core.Direction;
import net.minecraft.client.render.block.entity.BlockEntityRendererFactory; import net.minecraft.world.level.block.HorizontalDirectionalBlock;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.math.Direction;
import net.touhoudiscord.block.BuyStationEntity; import net.touhoudiscord.block.BuyStationEntity;
import software.bernie.geckolib.cache.object.BakedGeoModel; import software.bernie.geckolib.cache.object.BakedGeoModel;
import software.bernie.geckolib.renderer.GeoBlockRenderer; import software.bernie.geckolib.renderer.GeoBlockRenderer;
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public class BuyStationRenderer extends GeoBlockRenderer<BuyStationEntity> { public class BuyStationRenderer extends GeoBlockRenderer<BuyStationEntity> {
public BuyStationRenderer(BlockEntityRendererFactory.Context context) { public BuyStationRenderer(BlockEntityRendererProvider.Context context) {
super(new BuyStationModel()); super(new BuyStationModel());
} }
@Override @Override
public void preRender(MatrixStack poseStack, BuyStationEntity animatable, BakedGeoModel model, VertexConsumerProvider bufferSource, VertexConsumer buffer, boolean isReRender, float partialTick, int packedLight, int packedOverlay, float red, float green, float blue, float alpha) { public void preRender(PoseStack poseStack, BuyStationEntity animatable, BakedGeoModel model, MultiBufferSource bufferSource, VertexConsumer buffer, boolean isReRender, float partialTick, int packedLight, int packedOverlay, float red, float green, float blue, float alpha) {
Direction direction = animatable.getCachedState().get(HorizontalFacingBlock.FACING).rotateYClockwise(); Direction direction = animatable.getBlockState().getValue(HorizontalDirectionalBlock.FACING).getClockWise();
poseStack.translate(direction.getOffsetX()/2., 0, direction.getOffsetZ()/2.); poseStack.translate(direction.getStepX()/2., 0, direction.getStepZ()/2.);
super.preRender(poseStack, animatable, model, bufferSource, buffer, isReRender, partialTick, packedLight, packedOverlay, red, green, blue, alpha); super.preRender(poseStack, animatable, model, bufferSource, buffer, isReRender, partialTick, packedLight, packedOverlay, red, green, blue, alpha);
} }
} }

View File

@ -1,28 +1,28 @@
package net.touhoudiscord.commands; package net.touhoudiscord.commands;
import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.CommandDispatcher;
import net.minecraft.command.CommandSource; import net.minecraft.commands.CommandSourceStack;
import net.minecraft.command.argument.EntityArgumentType; import net.minecraft.commands.SharedSuggestionProvider;
import net.minecraft.server.PlayerManager; import net.minecraft.commands.arguments.EntityArgument;
import net.minecraft.server.command.ServerCommandSource; import net.minecraft.network.chat.Component;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.text.Text; import net.minecraft.server.players.PlayerList;
import net.minecraft.world.GameMode; import net.minecraft.world.level.GameType;
import net.touhoudiscord.RedeployPlayer; import net.touhoudiscord.RedeployPlayer;
import static net.minecraft.server.command.CommandManager.argument; import static net.minecraft.commands.Commands.argument;
import static net.minecraft.server.command.CommandManager.literal; import static net.minecraft.commands.Commands.literal;
public class RedeployPlayerCommand { public class RedeployPlayerCommand {
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) { public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
dispatcher.register(literal("redeployplayer") dispatcher.register(literal("redeployplayer")
.requires(source -> source.hasPermissionLevel(4)) .requires(source -> source.hasPermission(4))
.then(argument("player", EntityArgumentType.player()) .then(argument("player", EntityArgument.player())
.suggests((context, builder) -> { .suggests((context, builder) -> {
PlayerManager playerManager = (context.getSource()).getServer().getPlayerManager(); PlayerList playerManager = (context.getSource()).getServer().getPlayerList();
return CommandSource.suggestMatching(playerManager.getPlayerList().stream().filter( return SharedSuggestionProvider.suggest(playerManager.getPlayers().stream().filter(
(player) -> player.interactionManager.getGameMode() == GameMode.SPECTATOR (player) -> player.gameMode.getGameModeForPlayer() == GameType.SPECTATOR
).map( ).map(
(player) -> player.getGameProfile().getName() (player) -> player.getGameProfile().getName()
), builder); ), builder);
@ -30,9 +30,9 @@ public class RedeployPlayerCommand {
.executes(context -> { .executes(context -> {
if (context.getSource().getPlayer() == null) return 0; if (context.getSource().getPlayer() == null) return 0;
ServerPlayerEntity player = EntityArgumentType.getPlayer(context, "player"); ServerPlayer player = EntityArgument.getPlayer(context, "player");
RedeployPlayer.redeploy(player, context.getSource().getPlayer()); RedeployPlayer.redeploy(player, context.getSource().getPlayer());
context.getSource().sendFeedback(() -> Text.literal("Redeployed ").append(player.getName()), true); context.getSource().sendSuccess(() -> Component.literal("Redeployed ").append(player.getName()), true);
return 1; return 1;
}))); })));

View File

@ -2,33 +2,33 @@ package net.touhoudiscord.commands;
import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.arguments.IntegerArgumentType;
import net.minecraft.command.argument.EntityArgumentType; import net.minecraft.commands.CommandSourceStack;
import net.minecraft.server.command.ServerCommandSource; import net.minecraft.commands.arguments.EntityArgument;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.network.chat.Component;
import net.minecraft.text.Text; import net.minecraft.server.level.ServerPlayer;
import net.touhoudiscord.HardcoreRedeploy; import net.touhoudiscord.HardcoreRedeploy;
import net.touhoudiscord.RedeployStateSaver; import net.touhoudiscord.RedeployStateSaver;
import static net.minecraft.server.command.CommandManager.argument; import static net.minecraft.commands.Commands.argument;
import static net.minecraft.server.command.CommandManager.literal; import static net.minecraft.commands.Commands.literal;
public class SetRevivesCommand { public class SetRevivesCommand {
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) { public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
dispatcher.register(literal("setrevives") dispatcher.register(literal("setrevives")
.requires(source -> source.hasPermissionLevel(4)) .requires(source -> source.hasPermission(4))
.then(argument("player", EntityArgumentType.player()) .then(argument("player", EntityArgument.player())
.then(argument("revives", IntegerArgumentType.integer(0)) .then(argument("revives", IntegerArgumentType.integer(0))
.executes(context -> { .executes(context -> {
if (context.getSource().getPlayer() == null) return 0; if (context.getSource().getPlayer() == null) return 0;
ServerPlayerEntity player = EntityArgumentType.getPlayer(context, "player"); ServerPlayer player = EntityArgument.getPlayer(context, "player");
RedeployStateSaver.getPlayerState(player).timesRevived = IntegerArgumentType.getInteger(context, "revives"); RedeployStateSaver.getPlayerState(player).timesRevived = IntegerArgumentType.getInteger(context, "revives");
context.getSource().getServer().getPlayerManager().getPlayerList().forEach(player1 -> { context.getSource().getServer().getPlayerList().getPlayers().forEach(player1 -> {
HardcoreRedeploy.syncRevives(context.getSource().getServer(), player1, player.getUuid()); HardcoreRedeploy.syncRevives(context.getSource().getServer(), player1, player.getUUID());
}); });
context.getSource().sendFeedback(() -> Text.literal("Set revives for ").append(player.getName()), true); context.getSource().sendSuccess(() -> Component.literal("Set revives for ").append(player.getName()), true);
return 1; return 1;
})))); }))));

View File

@ -1,8 +1,8 @@
package net.touhoudiscord.item; package net.touhoudiscord.item;
import net.minecraft.block.Block; import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer;
import net.minecraft.client.render.item.BuiltinModelItemRenderer; import net.minecraft.world.item.BlockItem;
import net.minecraft.item.BlockItem; import net.minecraft.world.level.block.Block;
import net.touhoudiscord.item.client.BuyStationItemRenderer; import net.touhoudiscord.item.client.BuyStationItemRenderer;
import software.bernie.geckolib.animatable.GeoItem; import software.bernie.geckolib.animatable.GeoItem;
import software.bernie.geckolib.animatable.SingletonGeoAnimatable; import software.bernie.geckolib.animatable.SingletonGeoAnimatable;
@ -21,7 +21,7 @@ public class BuyStationItem extends BlockItem implements GeoItem {
private final AnimatableInstanceCache cache = new SingletonAnimatableInstanceCache(this); private final AnimatableInstanceCache cache = new SingletonAnimatableInstanceCache(this);
private final Supplier<Object> renderProvider = GeoItem.makeRenderer(this); private final Supplier<Object> renderProvider = GeoItem.makeRenderer(this);
public BuyStationItem(Block block, Settings settings) { public BuyStationItem(Block block, Properties settings) {
super(block, settings); super(block, settings);
SingletonGeoAnimatable.registerSyncedAnimatable(this); SingletonGeoAnimatable.registerSyncedAnimatable(this);
} }
@ -31,7 +31,7 @@ public class BuyStationItem extends BlockItem implements GeoItem {
consumer.accept(new RenderProvider() { consumer.accept(new RenderProvider() {
private final BuyStationItemRenderer renderer = new BuyStationItemRenderer(); private final BuyStationItemRenderer renderer = new BuyStationItemRenderer();
@Override @Override
public BuiltinModelItemRenderer getCustomRenderer() { public BlockEntityWithoutLevelRenderer getCustomRenderer() {
return this.renderer; return this.renderer;
} }
}); });

View File

@ -2,7 +2,7 @@ package net.touhoudiscord.item.client;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.minecraft.util.Identifier; import net.minecraft.resources.ResourceLocation;
import net.touhoudiscord.HardcoreRedeploy; import net.touhoudiscord.HardcoreRedeploy;
import net.touhoudiscord.item.BuyStationItem; import net.touhoudiscord.item.BuyStationItem;
import software.bernie.geckolib.model.GeoModel; import software.bernie.geckolib.model.GeoModel;
@ -10,17 +10,17 @@ import software.bernie.geckolib.model.GeoModel;
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public class BuyStationItemModel extends GeoModel<BuyStationItem> { public class BuyStationItemModel extends GeoModel<BuyStationItem> {
@Override @Override
public Identifier getModelResource(BuyStationItem animatable) { public ResourceLocation getModelResource(BuyStationItem animatable) {
return new Identifier(HardcoreRedeploy.MOD_ID, "geo/buy_station.geo.json"); return new ResourceLocation(HardcoreRedeploy.MOD_ID, "geo/buy_station.geo.json");
} }
@Override @Override
public Identifier getTextureResource(BuyStationItem animatable) { public ResourceLocation getTextureResource(BuyStationItem animatable) {
return new Identifier(HardcoreRedeploy.MOD_ID, "textures/block/buy_station.png"); return new ResourceLocation(HardcoreRedeploy.MOD_ID, "textures/block/buy_station.png");
} }
@Override @Override
public Identifier getAnimationResource(BuyStationItem animatable) { public ResourceLocation getAnimationResource(BuyStationItem animatable) {
return new Identifier(HardcoreRedeploy.MOD_ID, "animations/buy_station.animation.json"); return new ResourceLocation(HardcoreRedeploy.MOD_ID, "animations/buy_station.animation.json");
} }
} }

View File

@ -1,11 +1,11 @@
package net.touhoudiscord.mixin; package net.touhoudiscord.mixin;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.core.BlockPos;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.entity.player.Player;
import net.touhoudiscord.BuyStationCapable; import net.touhoudiscord.BuyStationCapable;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
@Mixin(PlayerEntity.class) @Mixin(Player.class)
public class BuyStationScreenMixin implements BuyStationCapable { public class BuyStationScreenMixin implements BuyStationCapable {
@Override @Override
public void hardcoreredeploy_openBuyStationScreen(BlockPos blockPos) { public void hardcoreredeploy_openBuyStationScreen(BlockPos blockPos) {

View File

@ -1,20 +1,20 @@
package net.touhoudiscord.mixin; package net.touhoudiscord.mixin;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.Minecraft;
import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.client.player.LocalPlayer;
import net.minecraft.util.math.BlockPos; import net.minecraft.core.BlockPos;
import net.touhoudiscord.BuyStationCapable; import net.touhoudiscord.BuyStationCapable;
import net.touhoudiscord.screen.BuyStationScreen; import net.touhoudiscord.screen.BuyStationScreen;
import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
@Mixin(ClientPlayerEntity.class) @Mixin(LocalPlayer.class)
public class ClientBuyStationScreenMixin implements BuyStationCapable { public class ClientBuyStationScreenMixin implements BuyStationCapable {
@Shadow @Final protected MinecraftClient client; @Shadow @Final protected Minecraft minecraft;
@Override @Override
public void hardcoreredeploy_openBuyStationScreen(BlockPos blockPos) { public void hardcoreredeploy_openBuyStationScreen(BlockPos blockPos) {
this.client.setScreen(new BuyStationScreen(blockPos)); this.minecraft.setScreen(new BuyStationScreen(blockPos));
} }
} }

View File

@ -1,8 +1,8 @@
package net.touhoudiscord.mixin; package net.touhoudiscord.mixin;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.server.PlayerManager; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.players.PlayerList;
import net.touhoudiscord.PlayerTimer; import net.touhoudiscord.PlayerTimer;
import net.touhoudiscord.RedeployPlayer; import net.touhoudiscord.RedeployPlayer;
import net.touhoudiscord.TimerAccess; import net.touhoudiscord.TimerAccess;
@ -18,24 +18,24 @@ import java.util.UUID;
@Mixin(MinecraftServer.class) @Mixin(MinecraftServer.class)
public abstract class RedeployTimerMixin implements TimerAccess { public abstract class RedeployTimerMixin implements TimerAccess {
@Shadow public abstract PlayerManager getPlayerManager(); @Shadow public abstract PlayerList getPlayerList();
@Unique @Unique
private final HashMap<UUID, PlayerTimer> playerTimers = new HashMap<>(); private final HashMap<UUID, PlayerTimer> playerTimers = new HashMap<>();
@Inject(method = "tick", at = @At("TAIL")) @Inject(method = "tickServer", at = @At("TAIL"))
private void onTick(CallbackInfo ci) { private void onTick(CallbackInfo ci) {
this.playerTimers.forEach((uuid, timer) -> { this.playerTimers.forEach((uuid, timer) -> {
if (--timer.ticks == 0L) { if (--timer.ticks == 0L) {
ServerPlayerEntity spectator = this.getPlayerManager().getPlayer(uuid); ServerPlayer spectator = this.getPlayerList().getPlayer(uuid);
ServerPlayerEntity target = this.getPlayerManager().getPlayer(timer.target); ServerPlayer target = this.getPlayerList().getPlayer(timer.target);
if (spectator != null && target != null) RedeployPlayer.redeploy(spectator, target); if (spectator != null && target != null) RedeployPlayer.redeploy(spectator, target);
} }
}); });
} }
@Override @Override
public void hardcoreredeploy_redeployInTicks(ServerPlayerEntity spectator, ServerPlayerEntity target, Long ticks) { public void hardcoreredeploy_redeployInTicks(ServerPlayer spectator, ServerPlayer target, Long ticks) {
this.playerTimers.put(spectator.getUuid(), new PlayerTimer(target.getUuid(), ticks)); this.playerTimers.put(spectator.getUUID(), new PlayerTimer(target.getUUID(), ticks));
} }
} }

View File

@ -1,9 +1,9 @@
package net.touhoudiscord.mixin; package net.touhoudiscord.mixin;
import net.minecraft.entity.LivingEntity; import net.minecraft.tags.DamageTypeTags;
import net.minecraft.entity.damage.DamageSource; import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.entity.effect.StatusEffect; import net.minecraft.world.effect.MobEffect;
import net.minecraft.registry.tag.DamageTypeTags; import net.minecraft.world.entity.LivingEntity;
import net.touhoudiscord.HardcoreRedeploy; import net.touhoudiscord.HardcoreRedeploy;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
@ -13,10 +13,10 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(LivingEntity.class) @Mixin(LivingEntity.class)
public abstract class RedeployingMixin { public abstract class RedeployingMixin {
@Shadow public abstract boolean hasStatusEffect(StatusEffect effect); @Shadow public abstract boolean hasEffect(MobEffect effect);
@Inject(at = @At("HEAD"), method = "damage", cancellable = true) @Inject(at = @At("HEAD"), method = "hurt", cancellable = true)
private void init(DamageSource source, float amount, CallbackInfoReturnable<Boolean> cir) { private void init(DamageSource source, float amount, CallbackInfoReturnable<Boolean> cir) {
if (source.isIn(DamageTypeTags.IS_FALL) && this.hasStatusEffect(HardcoreRedeploy.REDEPLOYING)) cir.setReturnValue(false); if (source.is(DamageTypeTags.IS_FALL) && this.hasEffect(HardcoreRedeploy.REDEPLOYING)) cir.setReturnValue(false);
} }
} }

View File

@ -4,17 +4,17 @@ import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.Element; import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.Selectable; import net.minecraft.client.gui.components.ContainerObjectSelectionList;
import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.components.events.GuiEventListener;
import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.gui.narration.NarratableEntry;
import net.minecraft.client.gui.widget.ElementListWidget; import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.PacketByteBuf; import net.minecraft.core.BlockPos;
import net.minecraft.text.Text; import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.util.math.BlockPos; import net.minecraft.network.chat.Component;
import net.minecraft.world.GameMode; import net.minecraft.world.level.GameType;
import net.touhoudiscord.HardcoreRedeploy; import net.touhoudiscord.HardcoreRedeploy;
import net.touhoudiscord.HardcoreRedeployClient; import net.touhoudiscord.HardcoreRedeployClient;
@ -30,46 +30,46 @@ public class BuyStationScreen extends Screen {
private PlayerListWidget playerList; private PlayerListWidget playerList;
public BuyStationScreen(BlockPos blockPos) { public BuyStationScreen(BlockPos blockPos) {
super(Text.literal("Buy Station")); super(Component.literal("Buy Station"));
this.blockPos = blockPos; this.blockPos = blockPos;
} }
@Override @Override
protected void init() { protected void init() {
super.init(); super.init();
playerList = new PlayerListWidget(client, width+38, height, height/2-58, height/2+84, 28); playerList = new PlayerListWidget(minecraft, width+38, height, height/2-58, height/2+84, 28);
client.player.networkHandler.getListedPlayerListEntries().forEach(entry -> { minecraft.player.connection.getListedOnlinePlayers().forEach(entry -> {
if (entry.getGameMode() == GameMode.SPECTATOR) playerList.addPlayerEntry(new PlayerListEntry(Text.literal(entry.getProfile().getName()), entry.getProfile().getId())); if (entry.getGameMode() == GameType.SPECTATOR) playerList.addPlayerEntry(new PlayerListEntry(Component.literal(entry.getProfile().getName()), entry.getProfile().getId()));
}); });
addDrawableChild(playerList); addRenderableWidget(playerList);
} }
@Override @Override
public void render(DrawContext context, int mouseX, int mouseY, float delta) { public void render(GuiGraphics context, int mouseX, int mouseY, float delta) {
renderBackground(context); renderBackground(context);
context.fill(width/2-93, height/2-84, width/2+93, height/2+84, 0x8F_000000); context.fill(width/2-93, height/2-84, width/2+93, height/2+84, 0x8F_000000);
context.fill(width/2-93, height/2-84, width/2+93, height/2-58, 0xA0_000000); context.fill(width/2-93, height/2-84, width/2+93, height/2-58, 0xA0_000000);
context.getMatrices().push(); context.pose().pushPose();
context.getMatrices().scale(1.5f, 1.5f, 1f); context.pose().scale(1.5f, 1.5f, 1f);
context.drawText(textRenderer, Text.literal("Buy Station"), Math.round((width/2-80)/1.5f), Math.round((height/2-75)/1.5f), 0xFF_73c0e7, false); context.drawString(font, Component.literal("Buy Station"), Math.round((width/2-80)/1.5f), Math.round((height/2-75)/1.5f), 0xFF_73c0e7, false);
context.getMatrices().pop(); context.pose().popPose();
Text money = Text.literal("$").append(Text.literal(String.valueOf(client.player.experienceLevel*100))); Component money = Component.literal("$").append(Component.literal(String.valueOf(minecraft.player.experienceLevel*100)));
context.drawText(textRenderer, money, width/2+80-textRenderer.getWidth(money), height/2-72, 0xFF_FFFFFF, false); context.drawString(font, money, width/2+80-font.width(money), height/2-72, 0xFF_FFFFFF, false);
playerList.render(context, mouseX, mouseY, delta); playerList.render(context, mouseX, mouseY, delta);
super.render(context, mouseX, mouseY, delta); super.render(context, mouseX, mouseY, delta);
} }
@Override @Override
public boolean shouldPause() { public boolean isPauseScreen() {
return false; return false;
} }
public class PlayerListWidget extends ElementListWidget<PlayerListEntry> { public class PlayerListWidget extends ContainerObjectSelectionList<PlayerListEntry> {
public PlayerListWidget(MinecraftClient minecraftClient, int i, int j, int k, int l, int m) { public PlayerListWidget(Minecraft minecraftClient, int i, int j, int k, int l, int m) {
super(minecraftClient, i, j, k, l, m); super(minecraftClient, i, j, k, l, m);
this.setRenderBackground(false); this.setRenderBackground(false);
this.setRenderHorizontalShadows(false); this.setRenderTopAndBottom(false);
} }
public void addPlayerEntry(PlayerListEntry entry) { public void addPlayerEntry(PlayerListEntry entry) {
@ -77,20 +77,20 @@ public class BuyStationScreen extends Screen {
} }
} }
public class PlayerListEntry extends ElementListWidget.Entry<PlayerListEntry> { public class PlayerListEntry extends ContainerObjectSelectionList.Entry<PlayerListEntry> {
private final ButtonWidget button; private final Button button;
private final Text name; private final Component name;
private final UUID uuid; private final UUID uuid;
public PlayerListEntry(Text name, UUID uuid) { public PlayerListEntry(Component name, UUID uuid) {
this.button = ButtonWidget.builder(name, button1 -> { this.button = Button.builder(name, button1 -> {
PacketByteBuf buf = PacketByteBufs.create(); FriendlyByteBuf buf = PacketByteBufs.create();
buf.writeUuid(uuid); buf.writeUUID(uuid);
buf.writeBlockPos(blockPos); buf.writeBlockPos(blockPos);
ClientPlayNetworking.send(HardcoreRedeploy.REQUEST_REVIVE, buf); ClientPlayNetworking.send(HardcoreRedeploy.REQUEST_REVIVE, buf);
client.setScreen(null); minecraft.setScreen(null);
}) })
.position(4,2) .pos(4,2)
.size(178, 18) .size(178, 18)
.build(); .build();
this.name = name; this.name = name;
@ -98,28 +98,28 @@ public class BuyStationScreen extends Screen {
} }
@Override @Override
public List<? extends Selectable> selectableChildren() { public List<? extends NarratableEntry> narratables() {
return List.of(button); return List.of(button);
} }
@Override @Override
public List<? extends Element> children() { public List<? extends GuiEventListener> children() {
return List.of(button); return List.of(button);
} }
@Override @Override
public void render(DrawContext context, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) { public void render(GuiGraphics context, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) {
button.setX(x); button.setX(x);
button.setY(y); button.setY(y);
boolean isHovered = mouseX >= x && mouseX <= x+178 && mouseY >= y && mouseY <= y+18; boolean isHovered = mouseX >= x && mouseX <= x+178 && mouseY >= y && mouseY <= y+18;
Integer revives = HardcoreRedeployClient.reviveMap.get(this.uuid); Integer revives = HardcoreRedeployClient.reviveMap.get(this.uuid);
int cost = serverConfig.baseCost+(revives == null ? 0 : revives)*serverConfig.additiveCost; int cost = serverConfig.baseCost+(revives == null ? 0 : revives)*serverConfig.additiveCost;
int backgroundColor = ((isHovered ? 0x30 : 0x20) << 24) + int backgroundColor = ((isHovered ? 0x30 : 0x20) << 24) +
((client.player.experienceLevel >= cost) ? 0x2397d1 : 0xa3a3a3); ((minecraft.player.experienceLevel >= cost) ? 0x2397d1 : 0xa3a3a3);
context.fill(x, y, x+178, y+18, backgroundColor); context.fill(x, y, x+178, y+18, backgroundColor);
context.drawText(textRenderer, button.getMessage(), x+4, y+5, 0xFF_73c0e7, false); context.drawString(font, button.getMessage(), x+4, y+5, 0xFF_73c0e7, false);
Text money = Text.literal("$").append(Text.literal(String.valueOf(cost*100))); Component money = Component.literal("$").append(Component.literal(String.valueOf(cost*100)));
context.drawText(textRenderer, money, x+178-4-textRenderer.getWidth(money), y+5, 0xFF_7efc20, false); context.drawString(font, money, x+178-4-font.width(money), y+5, 0xFF_7efc20, false);
} }
} }
} }

View File

@ -1,8 +1,8 @@
package net.touhoudiscord.screen; package net.touhoudiscord.screen;
import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screens.Screen;
import net.minecraft.text.Text; import net.minecraft.network.chat.Component;
public class RedeployingScreen extends Screen { public class RedeployingScreen extends Screen {
@ -10,20 +10,20 @@ public class RedeployingScreen extends Screen {
private float time; private float time;
public RedeployingScreen(float duration) { public RedeployingScreen(float duration) {
super(Text.empty()); super(Component.empty());
this.duration = duration; this.duration = duration;
} }
@Override @Override
public void render(DrawContext context, int mouseX, int mouseY, float delta) { public void render(GuiGraphics context, int mouseX, int mouseY, float delta) {
time += delta; time += delta;
context.fill(0, 0, width, height, Math.round((1-Math.abs((float)Math.sin(((time/(duration/2))-1)*(Math.PI/2))))*255)<<24); context.fill(0, 0, width, height, Math.round((1-Math.abs((float)Math.sin(((time/(duration/2))-1)*(Math.PI/2))))*255)<<24);
super.render(context, mouseX, mouseY, delta); super.render(context, mouseX, mouseY, delta);
if (time > duration) client.setScreen(null); if (time > duration) minecraft.setScreen(null);
} }
@Override @Override
public boolean shouldPause() { public boolean isPauseScreen() {
return false; return false;
} }

View File

@ -1,10 +1,10 @@
package net.touhoudiscord.status; package net.touhoudiscord.status;
import net.minecraft.entity.effect.StatusEffect; import net.minecraft.world.effect.MobEffect;
import net.minecraft.entity.effect.StatusEffectCategory; import net.minecraft.world.effect.MobEffectCategory;
public class RedeployingStatusEffect extends StatusEffect { public class RedeployingStatusEffect extends MobEffect {
public RedeployingStatusEffect() { public RedeployingStatusEffect() {
super(StatusEffectCategory.BENEFICIAL, 0xFFFFFF); super(MobEffectCategory.BENEFICIAL, 0xFFFFFF);
} }
} }