Skip to content

Commit

Permalink
Last WIP before starting port to 1.20.4
Browse files Browse the repository at this point in the history
  • Loading branch information
robotgryphon committed Dec 12, 2023
1 parent b674108 commit bb2d5fa
Show file tree
Hide file tree
Showing 11 changed files with 409 additions and 62 deletions.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,31 @@ private static void doRegistration() {
Registries.UPGRADES.register(bus);
Registries.COMMAND_ARGUMENT_TYPES.register(bus);
Registries.LOOT_FUNCS.register(bus);
// Registries.VILLAGERS.register(bus);
Registries.VILLAGERS.register(bus);
// Villagers.TRADES.register(bus);
Registries.POINTS_OF_INTEREST.register(bus);

// CompactMachines.loadedAddons = ServiceLoader.load(ICompactMachinesAddon.class)
// .stream()
// .filter(p -> Arrays.stream(p.type().getAnnotationsByType(CompactMachinesAddon.class))
// .anyMatch(cma -> cma.major() == 2))
// .map(allowedThisMajor -> {
// allowedThisMajor.get();
// })
// .collect(Collectors.toSet());

CompactMachines.loadedAddons = AnnotationScanner.scanModList(CompactMachinesAddon.class)
.map(ModFileScanData.AnnotationData::memberName)
.map(cmAddonClass -> {
try {
final var cl = Class.forName(cmAddonClass);
final var cla = cl.asSubclass(ICompactMachinesAddon.class);
return cla.getDeclaredConstructor().newInstance();
} catch (Exception e) {
return null;
}
})
.filter(Objects::nonNull)
.map(ModFileScanData.AnnotationData::memberName)
.map(cmAddonClass -> {
try {
final var cl = Class.forName(cmAddonClass);
final var cla = cl.asSubclass(ICompactMachinesAddon.class);
return cla.getDeclaredConstructor().newInstance();
} catch (Exception e) {
return null;
}
})
.filter(Objects::nonNull)
.collect(Collectors.toSet());

CompactMachines.loadedAddons.forEach(addon -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ public static void sendIMC() {
.size(1)
.icon(CURIO_TEXTURE)
.build());


}

private static boolean isPsd(ItemStack stack) {
Expand All @@ -34,7 +32,7 @@ public static void addTextures(final TextureStitchEvent.Pre stitch) {
stitch.addSprite(CURIO_TEXTURE);
}

public static boolean hasPsdCurio(@Nonnull LivingEntity ent) {
public static boolean hasPsdCurio(@Nonnull LivingEntity ent) {
return CuriosApi.getCuriosHelper()
.findFirstCurio(ent, CuriosCompat::isPsd)
.isPresent();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.compactmods.machines.forge.machine.block;

import dev.compactmods.machines.LoggingUtil;
import dev.compactmods.machines.api.shrinking.PSDTags;
import dev.compactmods.machines.forge.machine.Machines;
import dev.compactmods.machines.forge.machine.entity.BoundCompactMachineBlockEntity;
import dev.compactmods.machines.forge.machine.item.BoundCompactMachineItem;
Expand All @@ -9,6 +10,10 @@
import dev.compactmods.machines.room.BasicRoomInfo;
import net.minecraft.core.BlockPos;
import net.minecraft.core.NonNullList;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.CreativeModeTab;
Expand All @@ -18,6 +23,8 @@
import net.minecraft.world.level.block.EntityBlock;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class BoundCompactMachineBlock extends CompactMachineBlock implements EntityBlock {
Expand Down Expand Up @@ -78,4 +85,24 @@ public void onRemove(BlockState oldState, Level level, BlockPos pos, BlockState
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
return new BoundCompactMachineBlockEntity(pos, state);
}

@NotNull
@Override
@SuppressWarnings("deprecation")
public InteractionResult use(@NotNull BlockState state, Level level, @NotNull BlockPos pos, Player player, @NotNull InteractionHand hand, @NotNull BlockHitResult hitResult) {
MinecraftServer server = level.getServer();
ItemStack mainItem = player.getMainHandItem();
if (mainItem.is(PSDTags.ITEM) && player instanceof ServerPlayer sp) {
return MachineBlockUtil.tryRoomTeleport(level, pos, sp, server);
}

// All other items, open preview screen
if(!level.isClientSide) {
level.getBlockEntity(pos, Machines.MACHINE_ENTITY.get()).ifPresent(machine -> {
MachineBlockUtil.roomPreviewScreen(pos, (ServerPlayer) player, server, machine);
});
}

return InteractionResult.sidedSuccess(level.isClientSide);
}
}
Loading

0 comments on commit bb2d5fa

Please sign in to comment.