Skip to content

Commit

Permalink
Add blueprint table screen
Browse files Browse the repository at this point in the history
  • Loading branch information
JustAPotota committed Sep 11, 2023
1 parent 7bee043 commit 024319d
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 16 deletions.
21 changes: 12 additions & 9 deletions src/main/java/io/github/teampropulsive/Propulsive.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@
import io.github.teampropulsive.block.Blocks;
import io.github.teampropulsive.celestial.Star;
import io.github.teampropulsive.celestial.Terrestrial;
import io.github.teampropulsive.screen.BlueprintTableScreenHandler;
import io.github.teampropulsive.types.AtmoCompositionGas;
import io.github.teampropulsive.types.Planet;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.biome.v1.BiomeModifications;
import net.fabricmc.fabric.api.biome.v1.BiomeSelectors;
import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerType;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.block.Block;
import net.minecraft.entity.damage.DamageType;
import net.minecraft.registry.Registerable;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.registry.tag.BlockTags;
import net.minecraft.registry.tag.TagKey;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Vec2f;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraft.world.gen.GenerationStep;
import net.minecraft.world.gen.feature.*;
import net.minecraft.world.gen.feature.PlacedFeature;

import java.util.ArrayList;

Expand All @@ -31,9 +31,12 @@

public class Propulsive implements ModInitializer {
public static ArrayList<Planet> TICKABLE_PLANETS = new ArrayList<>();
public static final RegistryKey<PlacedFeature> ALUMINUM_ORE_PLACED_KEY = RegistryKey.of(RegistryKeys.PLACED_FEATURE, new Identifier("propulsive","ore_aluminum"));
public static final RegistryKey<PlacedFeature> BAUXITE_CLUSTER_PLACED_KEY = RegistryKey.of(RegistryKeys.PLACED_FEATURE, new Identifier("propulsive","ore_bauxite_cluster"));
public static final RegistryKey<PlacedFeature> PURE_BAUXITE_CLUSTER_PLACED_KEY = RegistryKey.of(RegistryKeys.PLACED_FEATURE, new Identifier("propulsive","ore_pure_bauxite"));
public static final RegistryKey<PlacedFeature> ALUMINUM_ORE_PLACED_KEY = RegistryKey.of(RegistryKeys.PLACED_FEATURE, id("ore_aluminum"));
public static final RegistryKey<PlacedFeature> BAUXITE_CLUSTER_PLACED_KEY = RegistryKey.of(RegistryKeys.PLACED_FEATURE, id("ore_bauxite_cluster"));
public static final RegistryKey<PlacedFeature> PURE_BAUXITE_CLUSTER_PLACED_KEY = RegistryKey.of(RegistryKeys.PLACED_FEATURE, id("ore_pure_bauxite"));

public static final ScreenHandlerType<BlueprintTableScreenHandler> BLUEPRINT_TABLE_SCREEN = Registry.register(Registries.SCREEN_HANDLER, id("blueprint_table"),
new ExtendedScreenHandlerType<>(BlueprintTableScreenHandler::new));

@Override
public void onInitialize() {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/io/github/teampropulsive/PropulsiveClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.github.teampropulsive.keybind.ShipDownKeybind;
import io.github.teampropulsive.keybind.ShipThrottleDownKeybind;
import io.github.teampropulsive.keybind.ShipThrottleUpKeybind;
import io.github.teampropulsive.screen.BlueprintTableScreen;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
Expand Down Expand Up @@ -66,6 +67,7 @@ public void onInitializeClient() {
ShipThrottleDownKeybind.shipThrottleDownKeybind();
ShipDownKeybind.shipDownKeybind();

HandledScreens.register(Propulsive.BLUEPRINT_TABLE_SCREEN, BlueprintTableScreen::new);
}

// Returns contributors from git repo or from the fallback list in the JAR if network is unavailable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ public BlockRenderType getRenderType(BlockState state) {

@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {

if (!world.isClient) {
NamedScreenHandlerFactory screenHandlerFactory = state.createScreenHandlerFactory(world, pos);
if (screenHandlerFactory != null) {
player.openHandledScreen(screenHandlerFactory);
}
}
return ActionResult.SUCCESS;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
package io.github.teampropulsive.block;

import io.github.teampropulsive.screen.BlueprintTableScreenHandler;
import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerFactory;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.screen.NamedScreenHandlerFactory;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3i;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;

import static io.github.teampropulsive.block.Blocks.*;
import static io.github.teampropulsive.block.Blocks.LAUNCH_PAD;

public class BlueprintTableBlockEntity extends BlockEntity implements NamedScreenHandlerFactory {
public class BlueprintTableBlockEntity extends BlockEntity implements ExtendedScreenHandlerFactory {
public int tower_size = 0;
public int pad_size = 0;
public boolean show_bounding_box = true;
public BlueprintTableBlockEntity(BlockPos pos, BlockState state) {
super(BLUEPRINT_TABLE_BLOCK_ENTITY, pos, state);
}



public void update_area(World world, BlockPos pos) {
int max_pad_size = 10;
int max_tower_size = 10;
Expand Down Expand Up @@ -88,14 +91,21 @@ public BlockPos get_pad_offset(World world, BlockPos pos) {
}
return null;
} // Gets the relative position of the pad base's center

@Override
public Text getDisplayName() {
return null;
return Text.translatable(this.getCachedState().getBlock().getTranslationKey());
}

@Nullable
@Override
public ScreenHandler createMenu(int syncId, PlayerInventory playerInventory, PlayerEntity player) {
return null;
return new BlueprintTableScreenHandler(syncId, playerInventory);
}

@Override
public void writeScreenOpeningData(ServerPlayerEntity player, PacketByteBuf buf) {
// write data into buf
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.github.teampropulsive.screen;

import io.github.teampropulsive.Propulsive;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;

public class BlueprintTableScreen extends HandledScreen<BlueprintTableScreenHandler> {
private static final Identifier TEXTURE = Propulsive.id("textures/gui/blueprint_table.png");

public BlueprintTableScreen(BlueprintTableScreenHandler handler, PlayerInventory inventory, Text title) {
super(handler, inventory, title);
}

@Override
protected void drawBackground(DrawContext context, float delta, int mouseX, int mouseY) {
context.drawTexture(TEXTURE, this.x, this.y, 0, 0, this.backgroundWidth, this.backgroundHeight);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package io.github.teampropulsive.screen;

import io.github.teampropulsive.Propulsive;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.screen.slot.Slot;

public class BlueprintTableScreenHandler extends ScreenHandler {
public BlueprintTableScreenHandler(int syncId, PlayerInventory inventory, PacketByteBuf buf) {
this(syncId, inventory);
// read data from buf
}

public BlueprintTableScreenHandler(int syncId, PlayerInventory inventory) {
super(Propulsive.BLUEPRINT_TABLE_SCREEN, syncId);

for (int m = 0; m < 3; m++) {
for (int l = 0; l < 9; l++) {
this.addSlot(new Slot(inventory, l + m * 9 + 9, 8 + l * 18, 84 + m * 18));
}
}
for (int m = 0; m < 9; m++) {
this.addSlot(new Slot(inventory, m, 8 + m * 18, 142));
}
}

@Override
public ItemStack quickMove(PlayerEntity player, int slot) {
return null;
}

@Override
public boolean canUse(PlayerEntity player) {
return true;
}
}

0 comments on commit 024319d

Please sign in to comment.