Skip to content

Commit

Permalink
[#23/#25] Fixed BlockSenderGUI (it opens now)
Browse files Browse the repository at this point in the history
Added ButtonReceiver (not functional right now)
Added Button partly (also not functional)
  • Loading branch information
Danielxs01 committed Jan 6, 2022
1 parent bd65f5d commit 8ffe835
Show file tree
Hide file tree
Showing 27 changed files with 857 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ protected BlockButtonReceiverFunctionEntity() {

@Override
public ItemStack onPick() {
ItemStack is = new ItemStack(CustomItems.ITEMBLOCKRECEIVER, 1);
ItemStack is = new ItemStack(CustomItems.ITEMBLOCKBUTTONRECEIVER, 1);
TagCompound tag = is.getTagCompound();
tag.setString("itemId", entity.getContentPackBlockId());
is.setTagCompound(tag);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,9 @@ public boolean onClick(Player player, Hand hand, Facing facing, Vec3d hit) {
if (signalPos != null) {

getWorld().keepLoaded(signalPos);
if (getWorld().hasBlockEntity(signalPos, BlockSignalStorageEntity.class)) {
BlockSignalStorageEntity signalEntity = getWorld().getBlockEntity(signalPos, BlockSignalStorageEntity.class);
OpenSenderGui packet = new OpenSenderGui(getPos(), SignalContainer.of(signalEntity));
packet.sendToPlayer(player);
} else if (getWorld().hasBlockEntity(signalPos, BlockMultisignalStorageEntity.class)) {
BlockMultisignalStorageEntity signalEntity = getWorld().getBlockEntity(signalPos, BlockMultisignalStorageEntity.class);
OpenSenderGui packet = new OpenSenderGui(getPos(), SignalContainer.of(signalEntity));

if (SignalContainer.isSignal(getWorld(), signalPos)) {
OpenSenderGui packet = new OpenSenderGui(getPos(), SignalContainer.of(getWorld(), signalPos));
packet.sendToPlayer(player);
} else {
entity.signals.remove(signalPos);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import net.landofrails.stellwand.content.entities.rendering.BlockButtonReceiverRenderEntity;
import net.landofrails.stellwand.content.entities.storage.versionmapper.VersionMapper;
import net.landofrails.stellwand.contentpacks.Content;
import net.landofrails.stellwand.contentpacks.entries.buttonreceiver.BlockReceiverEntryBlock;
import net.landofrails.stellwand.contentpacks.entries.buttonreceiver.BlockButtonReceiverEntryBlock;
import net.landofrails.stellwand.contentpacks.entries.parent.ContentPackEntry;
import net.landofrails.stellwand.contentpacks.entries.parent.ContentPackEntryBlock;
import net.landofrails.stellwand.utils.StellwandUtils;
Expand Down Expand Up @@ -73,7 +73,7 @@ public static void prepare() {
ModCore.Mod.error("Error while loading blocknotfound.obj: %s", e.getMessage());
}
// Add contentpack stuff
for (Map.Entry<ContentPackEntry, String> entry : Content.getBlockReceivers().entrySet()) {
for (Map.Entry<ContentPackEntry, String> entry : Content.getBlockButtonReceivers().entrySet()) {
String name = null;
String type = null;
ContentPackEntryBlock cpeb = null;
Expand All @@ -84,7 +84,7 @@ public static void prepare() {
cpeb = entry.getKey().getBlock();
name = blockId;
type = cpe.getType() != null ? cpe.getType().name() : "null";
BlockReceiverEntryBlock block = cpe.getBlock(BlockReceiverEntryBlock.class);
BlockButtonReceiverEntryBlock block = cpe.getBlock(BlockButtonReceiverEntryBlock.class);
String objPath = cpe.getModel();
Identifier id = new Identifier("stellwand", objPath);
OBJModel m = new OBJModel(id, 0);
Expand Down Expand Up @@ -122,7 +122,7 @@ public boolean getActive() {
}

public void setWallMounted(boolean wallMounted) {
if (wallMountable.containsKey(contentPackBlockId) && wallMountable.get(contentPackBlockId).booleanValue())
if (wallMountable.containsKey(contentPackBlockId) && Boolean.TRUE.equals(wallMountable.get(contentPackBlockId)))
this.wallMounted = wallMounted;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@
import cam72cam.mod.gui.screen.Button;
import cam72cam.mod.gui.screen.IScreen;
import cam72cam.mod.gui.screen.IScreenBuilder;
import cam72cam.mod.item.CustomItem;
import cam72cam.mod.item.ItemStack;
import cam72cam.mod.serialization.TagCompound;
import net.landofrails.stellwand.content.items.CustomItems;
import net.landofrails.stellwand.contentpacks.Content;
import net.landofrails.stellwand.contentpacks.entries.ContentPack;
import net.landofrails.stellwand.contentpacks.types.EntryType;
import net.landofrails.stellwand.utils.exceptions.ContentPackException;

import java.util.*;
import java.util.function.Consumer;
Expand All @@ -39,12 +36,9 @@ public static void setEntryType(EntryType type, Map.Entry<ItemStack, Consumer<It

@Override
public void init(IScreenBuilder screen) {

ItemStack itemStack = MinecraftClient.getPlayer().getHeldItem(Player.Hand.PRIMARY);
this.entryType = getEntryTypeFromItem(itemStack);

this.entryType = EntryType.getEntryTypeFromItem(itemStack);
generateContentPackButtons(screen, Content.getContentPacksFor(entryType));

}

@Override
Expand All @@ -56,7 +50,6 @@ public void onEnterKey(IScreenBuilder builder) {
public void onClose() {
if (current != null)
ENTRYTYPES.get(entryType).getValue().accept(current);
// Reset variables
entryType = null;
}

Expand All @@ -68,7 +61,7 @@ public void draw(IScreenBuilder builder) {
private List<ItemStack> getItemStackForContentPack(ContentPack pack, EntryType type) {
List<ItemStack> items = new ArrayList<>();
Content.getBlocks(pack, type).forEach((cpe, value) -> {
ItemStack is = new ItemStack(getCustomItemForEntryType(Objects.requireNonNull(type)), 1);
ItemStack is = new ItemStack(type.getCustomItem(), 1);
TagCompound tag = is.getTagCompound();
tag.setString("itemId", cpe.getBlockId(value));
is.setTagCompound(tag);
Expand All @@ -79,23 +72,6 @@ private List<ItemStack> getItemStackForContentPack(ContentPack pack, EntryType t
return items;
}

private CustomItem getCustomItemForEntryType(EntryType type) {
switch (type) {
case BLOCKMULTISIGNAL:
return CustomItems.ITEMBLOCKMULTISIGNAL;
case BLOCKSENDER:
return CustomItems.ITEMBLOCKSENDER;
case BLOCKSIGNAL:
return CustomItems.ITEMBLOCKSIGNAL;
case BLOCKFILLER:
return CustomItems.ITEMBLOCKFILLER;
case BLOCKRECEIVER:
return CustomItems.ITEMBLOCKRECEIVER;
default:
throw new ContentPackException("I must have forgot to add this EntryType to this method: " + type);
}
}

private void generateContentPackButtons(IScreenBuilder screen, Collection<ContentPack> contentPacks) {
int index = 0;
for (ContentPack contentPack : contentPacks) {
Expand All @@ -122,21 +98,6 @@ public void onClick(Player.Hand hand) {
}
}

private EntryType getEntryTypeFromItem(ItemStack itemStack) {
if (itemStack.is(CustomItems.ITEMBLOCKFILLER)) {
return EntryType.BLOCKFILLER;
} else if (itemStack.is(CustomItems.ITEMBLOCKMULTISIGNAL)) {
return EntryType.BLOCKMULTISIGNAL;
} else if (itemStack.is(CustomItems.ITEMBLOCKRECEIVER)) {
return EntryType.BLOCKRECEIVER;
} else if (itemStack.is(CustomItems.ITEMBLOCKSENDER)) {
return EntryType.BLOCKSENDER;
} else if (itemStack.is(CustomItems.ITEMBLOCKSIGNAL)) {
return EntryType.BLOCKSIGNAL;
}
return null;
}

/**
* Method to open this GUI with arguments
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

public class CustomItems {


private CustomItems() {

}
Expand All @@ -27,7 +28,9 @@ private CustomItems() {
public static final ItemBlockSignal ITEMBLOCKSIGNAL = new ItemBlockSignal();
public static final ItemBlockSender ITEMBLOCKSENDER = new ItemBlockSender();
public static final ItemBlockMultisignal ITEMBLOCKMULTISIGNAL = new ItemBlockMultisignal();
public static final ItemBlockButtonReceiver ITEMBLOCKRECEIVER = new ItemBlockButtonReceiver();
// TODO: Implement
public static final ItemBlockButton ITEMBLOCKBUTTON = null;
public static final ItemBlockButtonReceiver ITEMBLOCKBUTTONRECEIVER = new ItemBlockButtonReceiver();

public static void register() {
itemList.add(ITEMCONNECTOR1);
Expand All @@ -39,7 +42,7 @@ public static void register() {
ItemRender.register(ITEMBLOCKSIGNAL, ItemBlockSignal.getModelFor());
ItemRender.register(ITEMBLOCKSENDER, ItemBlockSender.getModelFor());
ItemRender.register(ITEMBLOCKMULTISIGNAL, ItemBlockMultisignal.getModelFor());
ItemRender.register(ITEMBLOCKRECEIVER, ItemBlockButtonReceiver.getModelFor());
ItemRender.register(ITEMBLOCKBUTTONRECEIVER, ItemBlockButtonReceiver.getModelFor());

}

Expand Down
Loading

0 comments on commit 8ffe835

Please sign in to comment.