Skip to content

Commit

Permalink
suggested changes + evil style changes
Browse files Browse the repository at this point in the history
absolutely diabolical
  • Loading branch information
imreallybadatnames committed May 10, 2024
1 parent c978e43 commit d15297e
Show file tree
Hide file tree
Showing 35 changed files with 53 additions and 161 deletions.
2 changes: 0 additions & 2 deletions src/main/java/de/dafuqs/revelationary/ClientAdvancements.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

@Environment(EnvType.CLIENT)
public class ClientAdvancements {

protected static boolean receivedFirstAdvancementPacket = false;
public static List<ClientAdvancementPacketCallback> callbacks = new ArrayList<>();

Expand Down Expand Up @@ -77,5 +76,4 @@ public static boolean hasDone(Identifier identifier) {
public static void playerLogout() {
receivedFirstAdvancementPacket = false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public static void processRemovedAdvancements(@NotNull Set<Identifier> removedAd
// rerender chunks to show newly swapped blocks
static void rebuildAllChunks() {
WorldRenderer renderer = MinecraftClient.getInstance().worldRenderer;
((WorldRendererAccessor) renderer).rebuildAllChunks();
((WorldRendererAccessor) renderer).revelationary$rebuildAllChunks();
}

// BLOCKS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.util.Map;

public class RevelationDataLoader extends JsonDataLoader implements IdentifiableResourceReloadListener {

public static final RevelationDataLoader INSTANCE = new RevelationDataLoader();

private RevelationDataLoader() {
Expand All @@ -28,5 +27,4 @@ protected void apply(Map<Identifier, JsonElement> prepared, ResourceManager mana
public Identifier getFabricId() {
return new Identifier(Revelationary.MOD_ID, "revelations");
}

}
48 changes: 3 additions & 45 deletions src/main/java/de/dafuqs/revelationary/RevelationRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import de.dafuqs.revelationary.api.advancements.AdvancementHelper;
import de.dafuqs.revelationary.api.revelations.RevelationAware;
import de.dafuqs.revelationary.config.RevelationaryConfig;
import de.dafuqs.revelationary.networking.RevelationaryPackets;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import net.minecraft.block.*;
Expand All @@ -25,7 +24,6 @@
import java.util.*;

public class RevelationRegistry {

private static Object2ObjectOpenHashMap<Identifier, ObjectArrayList<BlockState>> advToBlockStates = new Object2ObjectOpenHashMap<>();
private static Object2ObjectOpenHashMap<BlockState, Identifier> blockStateToAdv = new Object2ObjectOpenHashMap<>();
private static Object2ObjectOpenHashMap<BlockState, BlockState> blockStateCloaks = new Object2ObjectOpenHashMap<>();
Expand Down Expand Up @@ -69,15 +67,6 @@ public static MutableText getTranslationString(Block block) {
// Get the localized name of the block and scatter it using §k to make it unreadable
return Text.literal("§k" + Language.getInstance().get(block.getTranslationKey()));
}

public static void clear() {
advToBlockStates.clear();
advToItems.clear();
blockStateCloaks.clear();
itemCloaks.clear();
cloakedBlockNameTranslations.clear();
cloakedItemNameTranslations.clear();
}

public static void trim() {
advToBlockStates.trim();
Expand Down Expand Up @@ -209,37 +198,6 @@ public static void registerFromJson(JsonObject jsonObject) {
}

// BLOCKS
private static void registerBlockState(Identifier advancementIdentifier, BlockState sourceBlockState, BlockState targetBlockState) {
if(sourceBlockState.isAir()) {
Revelationary.logError("Trying to register invalid block cloak. Advancement: " + advancementIdentifier
+ " Source Block: " + Registries.BLOCK.getId(sourceBlockState.getBlock())
+ " Target Block: " + Registries.BLOCK.getId(targetBlockState.getBlock()));
return;
}

ObjectArrayList<BlockState> list;
if (advToBlockStates.containsKey(advancementIdentifier)) {
list = advToBlockStates.get(advancementIdentifier);
list.add(sourceBlockState);
} else {
list = new ObjectArrayList<>();
list.add(sourceBlockState);
advToBlockStates.put(advancementIdentifier, list);
}

Item sourceBlockItem = sourceBlockState.getBlock().asItem();
if (sourceBlockItem != Items.AIR) {
Item targetBlockItem = targetBlockState.getBlock().asItem();
if (targetBlockItem != Items.AIR) {
registerItem(advancementIdentifier, sourceBlockItem, targetBlockItem);
}
}

blockStateCloaks.put(sourceBlockState, targetBlockState);
blockCloaks.putIfAbsent(sourceBlockState.getBlock(), targetBlockState.getBlock());
blockStateToAdv.put(sourceBlockState, advancementIdentifier);
}

private static void registerBlockStatesForIdentifier(Identifier advancementIdentifier, ObjectArrayList<BlockState> sourceBlockStates, ObjectArrayList<BlockState> targetBlockStates) {
if (sourceBlockStates.size() != targetBlockStates.size()) throw new IllegalArgumentException("Unequal sizes of sourceBlockStates and targetBlockStates arrays");
int sz = sourceBlockStates.size();
Expand Down Expand Up @@ -414,7 +372,7 @@ public static List<Item> getItemEntries(Identifier advancement) {
return advToItems.getOrDefault(advancement, ObjectArrayList.of());
}

public static void fromPacket(RevelationaryPackets.RevelationSync syncPacket) {
public static void fromPacket(RevelationaryNetworking.RevelationSync syncPacket) {
advToBlockStates = syncPacket.advToBlockStates();
blockStateToAdv = syncPacket.blockStateToAdv();
blockStateCloaks = syncPacket.blockStateCloaks();
Expand All @@ -429,8 +387,8 @@ public static void fromPacket(RevelationaryPackets.RevelationSync syncPacket) {
RevelationRegistry.deepTrim();
}

public static RevelationaryPackets.RevelationSync intoPacket() {
return new RevelationaryPackets.RevelationSync(advToBlockStates,
public static RevelationaryNetworking.RevelationSync intoPacket() {
return new RevelationaryNetworking.RevelationSync(advToBlockStates,
blockStateToAdv,
blockStateCloaks,
blockCloaks,
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/de/dafuqs/revelationary/Revelationary.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
package de.dafuqs.revelationary;

import de.dafuqs.revelationary.api.advancements.*;
import de.dafuqs.revelationary.networking.RevelationaryPackets;
import net.fabricmc.api.*;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.fabricmc.fabric.api.event.lifecycle.v1.*;
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
import net.fabricmc.fabric.api.resource.*;
import net.fabricmc.loader.api.*;
import net.minecraft.resource.*;
import org.slf4j.*;

public class Revelationary implements ModInitializer {

public static final String MOD_ID = "revelationary";
private static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);

Expand All @@ -27,12 +24,15 @@ public static void logWarning(String message) {
public static void logError(String message) {
LOGGER.error("[Revelationary] {}", message);
}
public static void logException(Throwable t) {
LOGGER.error("[Revelationary] ", t);
}

@Override
public void onInitialize() {
logInfo("Starting Common Startup");

PayloadTypeRegistry.playS2C().register(RevelationaryPackets.RevelationSync.ID, RevelationaryPackets.RevelationSync.CODEC);
RevelationaryNetworking.register();

AdvancementCriteria.register();
CommandRegistrationCallback.EVENT.register(Commands::register);
Expand All @@ -48,5 +48,4 @@ public void onInitialize() {

logInfo("Common startup completed!");
}

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package de.dafuqs.revelationary;

import de.dafuqs.revelationary.networking.RevelationaryS2CPacketReceivers;
import net.fabricmc.api.ClientModInitializer;

public class RevelationaryClient implements ClientModInitializer {

@Override
public void onInitializeClient() {
RevelationaryS2CPacketReceivers.register();
}

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package de.dafuqs.revelationary.networking;
package de.dafuqs.revelationary;

import com.mojang.brigadier.exceptions.CommandSyntaxException;
import de.dafuqs.revelationary.Revelationary;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.command.argument.BlockArgumentParser;
Expand All @@ -12,16 +17,37 @@
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.network.packet.CustomPayload;
import net.minecraft.registry.Registries;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.text.TextCodecs;
import net.minecraft.util.Identifier;

import java.util.Map;

public class RevelationaryPackets {

public static final Identifier REVELATION_SYNC = new Identifier(Revelationary.MOD_ID, "revelation_sync");
public class RevelationaryNetworking {
public static void register() {
PayloadTypeRegistry.playS2C().register(RevelationSync.ID, RevelationSync.CODEC);
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) registerPacketReceivers();
}

@Environment(EnvType.CLIENT)
public static void registerPacketReceivers() {
ClientPlayNetworking.registerGlobalReceiver(RevelationaryNetworking.RevelationSync.ID, (payload, context) -> {
try {
RevelationRegistry.fromPacket(payload);
} catch (Exception e) {
Revelationary.logError("Error fetching results from sync packet");
Revelationary.logException(e);
}
ClientRevelationHolder.cloakAll();
});
}

@Environment(EnvType.SERVER)
public static void sendRevelations(ServerPlayerEntity player) {
ServerPlayNetworking.send(player, RevelationRegistry.intoPacket());
}

public record RevelationSync(Object2ObjectOpenHashMap<Identifier, ObjectArrayList<BlockState>> advToBlockStates,
Object2ObjectOpenHashMap<BlockState, Identifier> blockStateToAdv,
Expand All @@ -33,7 +59,7 @@ public record RevelationSync(Object2ObjectOpenHashMap<Identifier, ObjectArrayLis
Object2ObjectOpenHashMap<Block, MutableText> cloakedBlockNameTranslations,
Object2ObjectOpenHashMap<Item, MutableText> cloakedItemNameTranslations) implements CustomPayload {
public static final PacketCodec<RegistryByteBuf, RevelationSync> CODEC = CustomPayload.codecOf(RevelationSync::write, RevelationSync::read);
public static final CustomPayload.Id<RevelationSync> ID = new Id<>(REVELATION_SYNC);
public static final CustomPayload.Id<RevelationSync> ID = new Id<>(new Identifier(Revelationary.MOD_ID, "revelation_sync"));

private static void writeText(RegistryByteBuf buf, Text text) {
TextCodecs.REGISTRY_PACKET_CODEC.encode(buf, text);
Expand Down Expand Up @@ -66,7 +92,7 @@ public static RevelationSync read(RegistryByteBuf buf) {
blockCloaks.putIfAbsent(sourceState.getBlock(), targetState.getBlock());
} catch (CommandSyntaxException e) {
Revelationary.logError(e.getMessage());
};
}
}
advToBlockStates.put(advancementIdentifier, advancementStates);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import java.util.*;

public class AdvancementCountCriterion extends AbstractCriterion<AdvancementCountCriterion.Conditions> {

public void trigger(ServerPlayerEntity player) {
this.trigger(player, (conditions) -> conditions.matches(player));
}
Expand Down Expand Up @@ -55,5 +54,4 @@ public boolean matches(ServerPlayerEntity serverPlayerEntity) {
return this.range == null ? allMatched : this.range.test(matchingAdvancements);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.util.Optional;

public class AdvancementGottenCriterion extends AbstractCriterion<AdvancementGottenCriterion.Conditions> {

public void trigger(ServerPlayerEntity player, AdvancementEntry advancement) {
this.trigger(player, (conditions) -> conditions.matches(advancement));
}
Expand All @@ -35,5 +34,4 @@ public Identifier getAdvancementIdentifier() {
return advancementIdentifier;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import java.util.Optional;

public class HadRevelationCriterion extends AbstractCriterion<HadRevelationCriterion.Conditions> {

public void trigger(ServerPlayerEntity player, Block block) {
this.trigger(player, (conditions) -> conditions.matches(block));
}
Expand Down Expand Up @@ -42,5 +41,4 @@ public boolean matches(Object object) {
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import net.minecraft.advancement.criterion.Criteria;

public class AdvancementCriteria {

/**
* Triggered every time a player gets a new advancement
*/
Expand All @@ -24,5 +23,4 @@ public static void register() {
HAD_REVELATION = Criteria.register("revelationary:had_revelation", new HadRevelationCriterion());
ADVANCEMENT_GOTTEN = Criteria.register("revelationary:advancement_gotten", new AdvancementGottenCriterion());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import net.minecraft.util.Identifier;

public class AdvancementHelper {

/**
* Checks if any player has the advancement. Can be used both server- and clientside
* Special cases:
Expand Down Expand Up @@ -57,5 +56,4 @@ public static boolean hasAdvancement(PlayerEntity playerEntity, Identifier advan
public static boolean hasAdvancementClient(Identifier advancementIdentifier) {
return ClientAdvancements.hasDone(advancementIdentifier);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

@Environment(EnvType.CLIENT)
public interface ClientAdvancementPacketCallback {

/**
* Gets called every time advancements get synched from server- to client side
*
Expand All @@ -32,5 +31,4 @@ public interface ClientAdvancementPacketCallback {
static void registerCallback(ClientAdvancementPacketCallback callback) {
ClientAdvancements.callbacks.add(callback);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.util.Map;

public abstract class CloakedBlock extends Block implements RevelationAware {

final Block cloakedBlock;

public CloakedBlock(Settings settings, Block cloakedBlock) {
Expand All @@ -29,5 +28,4 @@ public Map<BlockState, BlockState> getBlockStateCloaks() {
public Pair<Item, Item> getItemCloak() {
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.util.Map;

public class CloakedBlockItem extends BlockItem implements RevelationAware {

Identifier cloakAdvancementIdentifier;
BlockItem cloakItem;

Expand All @@ -36,5 +35,4 @@ public Map<BlockState, BlockState> getBlockStateCloaks() {
public Pair<Item, Item> getItemCloak() {
return new Pair<>(this, cloakItem);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.util.Map;

public class CloakedItem extends Item implements RevelationAware {

Identifier cloakAdvancementIdentifier;
Item cloakItem;

Expand All @@ -35,5 +34,4 @@ public Map<BlockState, BlockState> getBlockStateCloaks() {
public Pair<Item, Item> getItemCloak() {
return new Pair<>(this, cloakItem);
}

}
Loading

0 comments on commit d15297e

Please sign in to comment.