Skip to content

Commit

Permalink
Fixed rarity and gui issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Dragonoidzero committed Feb 19, 2021
1 parent 4fa341b commit ea7c822
Show file tree
Hide file tree
Showing 21 changed files with 518 additions and 338 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx4G
loader_version=0.11.1

# Mod Properties
mod_version = ALPHA.2
mod_version = ALPHA.3
maven_group = azzy.ttlg
archives_base_name = TTLG
libgui_version = 3.3.3+1.16.5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import azzy.fabric.lookingglass.gui.*;
import azzy.fabric.lookingglass.particle.TTLGParticles;
import azzy.fabric.lookingglass.render.*;
import azzy.fabric.lookingglass.util.ClientNetworkingUtils;
import azzy.fabric.lookingglass.util.client.RenderCache;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.EnvType;
Expand Down Expand Up @@ -45,12 +46,9 @@ public void onInitializeClient() {
BlockRenderLayerMap.INSTANCE.putBlocks(RenderLayer.getCutoutMipped(), FISH_BREEDER_BLOCK, BLOCK_TESSERACT_BLOCK);
BlockRenderLayerMap.INSTANCE.putBlocks(RenderLayer.getTranslucent(), CREATIVE_ENERGY_SOURCE_BLOCK);

//I will update this some day k I promise
ScreenProviderRegistry.INSTANCE.registerFactory(new Identifier(MODID, "projector_gui"), (syncID, id, player, buf) -> new ProjectorScreen( new ProjectorGuiDescription(ScreenHandlerType.ANVIL, syncID, player.inventory, ScreenHandlerContext.create(player.world, buf.readBlockPos())), player));


TTLGParticles.init();
LookingGlassGUIs.initClient();
ClientNetworkingUtils.init();
RenderCache.init();

//ClientTickEvents.END_WORLD_TICK.register(clientWorld -> {
Expand Down
58 changes: 6 additions & 52 deletions src/main/java/azzy/fabric/lookingglass/LookingGlassCommon.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import azzy.fabric.lookingglass.blockentity.ProjectorEntity;
import azzy.fabric.lookingglass.feature.TTLGConfiguredFeatures;
import azzy.fabric.lookingglass.gui.LookingGlassGUIs;
import azzy.fabric.lookingglass.gui.ProjectorGuiDescription;
import azzy.fabric.lookingglass.item.TTLGItems;
import azzy.fabric.lookingglass.util.GeneralNetworking;
import azzy.fabric.lookingglass.util.datagen.Metadata;
import com.chocohead.mm.api.ClassTinkerers;
import net.fabricmc.api.ModInitializer;
Expand Down Expand Up @@ -38,7 +38,10 @@ public class LookingGlassCommon implements ModInitializer {

public static final BlockSoundGroup ELDENMETAL = new BlockSoundGroup(1.0F, 1.0F, SoundEvents.BLOCK_RESPAWN_ANCHOR_SET_SPAWN, SoundEvents.BLOCK_SHROOMLIGHT_PLACE, SoundEvents.BLOCK_RESPAWN_ANCHOR_CHARGE, SoundEvents.BLOCK_RESPAWN_ANCHOR_AMBIENT, SoundEvents.BLOCK_BEACON_DEACTIVATE);

public static final Rarity NULL_RARITY = ClassTinkerers.getEnum(Rarity.class, "NULL");
public static final Rarity FINIS_RARITY = ClassTinkerers.getEnum(Rarity.class, "FINIS");
public static final Rarity ELDENMETAL_RARITY = ClassTinkerers.getEnum(Rarity.class, "NULL");
public static final Rarity LUPREVAN_RARITY = ClassTinkerers.getEnum(Rarity.class, "DAWN");
public static final Rarity WORLDFORGE_RARITY = ClassTinkerers.getEnum(Rarity.class, "TERMINUS");

public static final Logger FFLog = LogManager.getLogger(MODID);
public static final SplittableRandom RANDOM = new SplittableRandom();
Expand All @@ -61,55 +64,6 @@ public void onInitialize() {
TTLGConfiguredFeatures.init();
TTLGConfiguredFeatures.Registrar.init();
LookingGlassGUIs.initCommon();

ServerSidePacketRegistry.INSTANCE.register(STRING_TO_SERVER_PACKET, ((packetContext, packetByteBuf) -> {

String url = packetByteBuf.readString(4096);
BlockPos pos = packetByteBuf.readBlockPos();
int index = packetByteBuf.readInt();
World world = packetContext.getPlayer().getEntityWorld();

packetContext.getTaskQueue().execute(() -> {
if(world.isChunkLoaded(pos) && world.getBlockState(pos).getBlock() == PROJECTORBLOCK){
ProjectorEntity projector = (ProjectorEntity) world.getBlockEntity(pos);
assert projector != null;
if(index == 0)
projector.sign = url;
else if(index == 2)
projector.color = url;
else
projector.setUrl(url);
projector.sync();
}
});
}));

ServerSidePacketRegistry.INSTANCE.register(DOUBLES_TO_SERVER_PACKET, ((packetContext, packetByteBuf) -> {

int index = packetByteBuf.readInt();
double value = packetByteBuf.readDouble();
BlockPos pos = packetByteBuf.readBlockPos();
World world = packetContext.getPlayer().getEntityWorld();

packetContext.getTaskQueue().execute(() -> {
if(world.isChunkLoaded(pos) && world.getBlockState(pos).getBlock() == PROJECTORBLOCK){
ProjectorEntity projector = (ProjectorEntity) world.getBlockEntity(pos);
assert projector != null;

switch(index){
case (1): projector.rotX = value; break;
case (2): projector.rotY = value; break;
case (3): projector.rotZ = value; break;
case (4): projector.disX = value; break;
case (5): projector.disY = value; break;
case (6): projector.disZ = value; break;
case (7): projector.scale = value; break;
}
projector.sync();
}
});
}));

ContainerProviderRegistry.INSTANCE.registerFactory(new Identifier(MODID, "projector_gui"), (syncID, id, player, buf) -> new ProjectorGuiDescription(ScreenHandlerType.ANVIL, syncID, player.inventory, ScreenHandlerContext.create(player.world, buf.readBlockPos())));
GeneralNetworking.init();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ public void run() {
mappingResolver.mapClassName("intermediary", "net.minecraft.class_1814"), // Rarity
"L" + mappingResolver.mapClassName("intermediary", "net.minecraft.class_124") + ";" // Formatting
);
enumAdder.addEnum("FINIS", () -> new Object[]{ Formatting.BLUE });
enumAdder.addEnum("NULL", () -> new Object[]{ Formatting.DARK_PURPLE });
enumAdder.addEnum("DAWN", () -> new Object[]{ Formatting.GOLD });
enumAdder.addEnum("TERMINUS", () -> new Object[]{ Formatting.UNDERLINE });
enumAdder.build();
}
}
44 changes: 24 additions & 20 deletions src/main/java/azzy/fabric/lookingglass/block/ProjectorBlock.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package azzy.fabric.lookingglass.block;

import azzy.fabric.lookingglass.blockentity.ProjectorEntity;
import azzy.fabric.lookingglass.util.GeneralNetworking;
import net.fabricmc.fabric.api.container.ContainerProviderRegistry;
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.block.Block;
import net.minecraft.block.BlockEntityProvider;
import net.minecraft.block.BlockState;
Expand All @@ -11,6 +14,7 @@
import net.minecraft.client.resource.language.I18n;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.Inventory;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.LiteralText;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
Expand All @@ -37,34 +41,34 @@ public ProjectorBlock(Settings settings) {
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
ProjectorEntity entity = (ProjectorEntity) world.getBlockEntity(pos);
if(entity != null) {
if(!player.isInSneakingPose())
player.openHandledScreen(state.createScreenHandlerFactory(world, pos));
if(!world.isClient) {
if(!player.isInSneakingPose()) {
ContainerProviderRegistry.INSTANCE.openContainer(new Identifier(MODID, "projector_gui"), player, (packetByteBuf -> packetByteBuf.writeBlockPos(pos)));
entity.sync();
}
}
if(player.isInSneakingPose()){
if(entity.displayState < 4)
entity.displayState++;
else
entity.displayState = 0;
if(world.isClient()) {
String label = "";
switch(entity.displayState){
case(0): label = I18n.translate("label.lookingglass.glass.image_switch", label); break;
case(1): label = I18n.translate("label.lookingglass.glass.item_switch", label); break;
case(2): label = I18n.translate("label.lookingglass.glass.sign_switch");; break;
case(3): label = I18n.translate("label.lookingglass.glass.mob_switch");; break;
case(4): label = I18n.translate("label.lookingglass.glass.player_switch"); break;
}
if(player.isInSneakingPose()) {
if(entity.displayState < 4)
entity.displayState++;
else
entity.displayState = 0;

MinecraftClient.getInstance().player.sendSystemMessage(new LiteralText(label), null);
ServerPlayNetworking.send((ServerPlayerEntity) player, GeneralNetworking.TRANSLATEABLE_PACKET, PacketByteBufs.create().writeString(getClientMessage(entity)));
}
entity.sync();
}
}
return ActionResult.SUCCESS;
}

public String getClientMessage(ProjectorEntity entity) {
switch(entity.displayState){
case(0): return "label.lookingglass.glass.image_switch";
case(1): return "label.lookingglass.glass.item_switch";
case(2): return "label.lookingglass.glass.sign_switch";
case(3): return "label.lookingglass.glass.mob_switch";
case(4): return "label.lookingglass.glass.player_switch";
default:return "";
}
}

@Override
public VoxelShape getCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return shape;
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/azzy/fabric/lookingglass/block/TTLGBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.block.*;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.util.Identifier;
Expand Down Expand Up @@ -118,7 +116,7 @@ private static FabricBlockSettings eldenMachine() {
//Misc
public static final Block NEBULOUS_HALITE = registerBlock("nebulous_halite", new NebulousHaliteBlock(FabricBlockSettings.of(Material.GLASS).sounds(BlockSoundGroup.GLASS).emissiveLighting((a, b, c) -> true).requiresTool().breakByTool(FabricToolTags.PICKAXES, 3).nonOpaque().luminance(9).postProcess((a, b, c) -> true).strength(25, 500)), new FabricItemSettings().fireproof().group(LOOKINGGLASS_BLOCKS));
public static final Block NEBULOUS_SALTS = TTLGBlocks.registerBlock("nebulous_salts", new NebulousSaltBlock(FabricBlockSettings.of(Material.GLASS).sounds(BlockSoundGroup.GLASS).emissiveLighting((a, b, c) -> true).requiresTool().breakByTool(FabricToolTags.PICKAXES, 3).nonOpaque().luminance(7).postProcess((a, b, c) -> true).strength(20, 500)), new FabricItemSettings().fireproof().group(LOOKINGGLASS_BLOCKS));
public static final Block ELDENMETAL_BLOCK = registerBlock("eldenmetal_block", new Block(FabricBlockSettings.copyOf(Blocks.OBSIDIAN).luminance(state -> 3).nonOpaque().sounds(LookingGlassCommon.ELDENMETAL)), basicMachineItem().fireproof().rarity(NULL_RARITY));
public static final Block ELDENMETAL_BLOCK = registerBlock("eldenmetal_block", new Block(FabricBlockSettings.copyOf(Blocks.OBSIDIAN).luminance(state -> 3).nonOpaque().sounds(LookingGlassCommon.ELDENMETAL)), basicMachineItem().fireproof().rarity(ELDENMETAL_RARITY));
public static final Block SALMON_EGGS = registerBlock("salmon_egg", new SalmonEggBlock(FabricBlockSettings.copyOf(Blocks.TURTLE_EGG).sounds(BlockSoundGroup.HONEY).ticksRandomly()), basicMachineItem());

// BLOCK ENTITIES
Expand Down
Loading

0 comments on commit ea7c822

Please sign in to comment.