Skip to content

Commit

Permalink
Merge pull request #103 from mystchonky/dev/travel-staff
Browse files Browse the repository at this point in the history
  • Loading branch information
Rover656 authored Aug 11, 2023
2 parents 2bee055 + 95219c0 commit 3da498e
Show file tree
Hide file tree
Showing 52 changed files with 1,622 additions and 137 deletions.
8 changes: 8 additions & 0 deletions src/api/java/com/enderio/api/integration/Integration.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,12 @@ default void onModConstruct() {
default Optional<BlockState> getFacadeOf(ItemStack stack) {
return Optional.empty();
}

/**
* @param player The Player that wants to teleport
* @return whether the player can teleport to a nearby block
*/
default boolean canBlockTeleport(Player player) {
return false;
}
}
14 changes: 9 additions & 5 deletions src/api/java/com/enderio/api/integration/IntegrationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.function.*;

public class IntegrationManager {

Expand Down Expand Up @@ -50,7 +47,7 @@ public static void executeIf(Predicate<Integration> condition, Consumer<Integrat
consumer.accept(integration);
}
}

public static <T> List<T> getIf(Predicate<Integration> condition, Function<Integration, T> mapper) {
List<T> list = new ArrayList<>();
for (Integration integration : ALL_INTEGRATIONS) {
Expand All @@ -59,4 +56,11 @@ public static <T> List<T> getIf(Predicate<Integration> condition, Function<Integ
}
return list;
}

public static <T> T collectAll(T empty, Function<Integration, T> function, BiConsumer<T, T> merge) {
for (Integration integration : ALL_INTEGRATIONS) {
merge.accept(empty, function.apply(integration));
}
return empty;
}
}
21 changes: 21 additions & 0 deletions src/api/java/com/enderio/api/travel/ITravelTarget.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.enderio.api.travel;

import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;

public interface ITravelTarget {
ResourceLocation getSerializationName();

BlockPos getPos();

CompoundTag save();

int getItem2BlockRange();

int getBlock2BlockRange();

default boolean canTravelTo() {
return true;
}
}
9 changes: 9 additions & 0 deletions src/api/java/com/enderio/api/travel/TravelEntry.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.enderio.api.travel;

import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.common.util.Lazy;

import java.util.function.Function;
public record TravelEntry<T extends ITravelTarget>(ResourceLocation serializationName, Function<CompoundTag, T> constructor,
Lazy<TravelRenderer<T>> renderer) {}
45 changes: 45 additions & 0 deletions src/api/java/com/enderio/api/travel/TravelRegistry.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.enderio.api.travel;

import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.common.util.Lazy;
import org.jetbrains.annotations.ApiStatus;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;

@ApiStatus.Internal
public class TravelRegistry {

private static final Map<ResourceLocation, TravelEntry<?>> registry = new HashMap<>();

public static <T extends ITravelTarget> void addTravelEntry(ResourceLocation serializationName, Function<CompoundTag, T> constructor,
Lazy<TravelRenderer<T>> renderer) {
registry.put(serializationName, new TravelEntry<>(serializationName, constructor, renderer));
}

public static <T extends ITravelTarget> void addTravelEntry(TravelEntry<?> travelEntry) {
registry.put(travelEntry.serializationName(), travelEntry);
}

public static <T extends ITravelTarget> TravelRenderer<T> getRenderer(T entry) {
return (TravelRenderer<T>) registry.get(entry.getSerializationName()).renderer().get();
}

public static Optional<ITravelTarget> deserialize(CompoundTag nbt) {
return Optional.ofNullable(registry.get(new ResourceLocation(nbt.getString("name")))).map(entry -> entry.constructor().apply(nbt.getCompound("data")));
}

public static boolean isRegistered(ITravelTarget target) {
return registry.containsKey(target.getSerializationName());
}

public static CompoundTag serialize(ITravelTarget travelData) {
CompoundTag nbt = new CompoundTag();
nbt.putString("name", travelData.getSerializationName().toString());
nbt.put("data", travelData.save());
return nbt;
}
}
8 changes: 8 additions & 0 deletions src/api/java/com/enderio/api/travel/TravelRenderer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.enderio.api.travel;

import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.renderer.LevelRenderer;

public interface TravelRenderer<T extends ITravelTarget> {
void render(T travelData, LevelRenderer levelRenderer, PoseStack poseStack, double distanceSquared, boolean active);
}
5 changes: 5 additions & 0 deletions src/api/java/com/enderio/api/travel/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@javax.annotation.ParametersAreNonnullByDefault
@net.minecraft.MethodsReturnNonnullByDefault
@com.tterrag.registrate.util.nullness.FieldsAreNonnullByDefault

package com.enderio.api.travel;
8 changes: 8 additions & 0 deletions src/core/java/com/enderio/core/CoreNBTKeys.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,12 @@ public class CoreNBTKeys {
public static final String SYNC_DATA = "Data";

// endregion

//region Travel Target

public static final String ANCHOR_NAME = "AnchorName";
public static final String ANCHOR_ICON = "AnchorIcon";
public static final String ANCHOR_VISIBILITY = "AnchorVisibility";

//endregion
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.enderio.core.common.network.slot;

import net.minecraft.nbt.StringTag;
import net.minecraft.nbt.Tag;
import net.minecraft.network.FriendlyByteBuf;

import java.util.function.Consumer;
import java.util.function.Supplier;

public class StringNetworkDataSlot extends NetworkDataSlot<String> {
public StringNetworkDataSlot(Supplier<String> getter, Consumer<String> setter) {
super(getter, setter);
}

@Override
public Tag serializeValueNBT(String value) {
return StringTag.valueOf(value);
}

@Override
protected String valueFromNBT(Tag nbt) {
if (nbt instanceof StringTag stringTag) {
return stringTag.getAsString();
} else {
throw new IllegalStateException("Invalid string tag was passed over the network.");
}
}

@Override
public void toBuffer(FriendlyByteBuf buf, String value) {
buf.writeUtf(value);
}

@Override
public String valueFromBuffer(FriendlyByteBuf buf) {
try {
return buf.readUtf();
} catch (Exception e) {
throw new IllegalStateException("Invalid string buffer was passed over the network.");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "enderio:block/travel_anchor"
}
}
}
4 changes: 4 additions & 0 deletions src/generated/resources/assets/enderio/lang/en_ud.json
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@
"block.enderio.soularium_block": "ʞɔoןᗺ ɯnıɹɐןnoS",
"block.enderio.soularium_pressure_plate": "ǝʇɐןԀ ǝɹnssǝɹԀ ɯnıɹɐןnoS",
"block.enderio.stirling_generator": "ɹoʇɐɹǝuǝ⅁ buıןɹıʇS",
"block.enderio.travel_anchor": "ɹoɥɔuⱯ ןǝʌɐɹ⟘",
"block.enderio.vacuum_chest": "ʇsǝɥƆ ɯnnɔɐΛ",
"block.enderio.vapor_of_levity": "ʎʇıʌǝꞀ ɟO ɹodɐΛ",
"block.enderio.vibrant_alloy_block": "ʞɔoןᗺ ʎoןןⱯ ʇuɐɹqıΛ",
Expand Down Expand Up @@ -279,6 +280,8 @@
"gui.enderio.spawner.too_many_mob": "sqoɯ ʎuɐɯ oo⟘",
"gui.enderio.spawner.too_many_spawner": "sɹǝuʍɐds ʎuɐɯ oo⟘",
"gui.enderio.spawner.unknown": "qoɯ uʍouʞu∩",
"gui.enderio.visible.false": "uǝppıH",
"gui.enderio.visible.true": "ǝןqısıΛ",
"guidebook.enderio.book_title": "ǝןʇı⟘ ʞooᗺ",
"guidebook.enderio.landing_text": "ʇxǝ⟘ buıpuɐꞀ",
"hint.enderio.connected_textures.text": "ʇuǝıןɔ ɹnoʎ uo ɐuǝɥʇⱯ ןןɐʇsuı oʇ ʇuɐʍ ʇɥbıɯ noʎ 'ʞuɐq ɹoʇıɔɐdɐɔ ǝɥʇ uo sǝɹnʇxǝʇ pǝʇɔǝuuoɔ ɹoɟ buıʞooן ǝɹɐ noʎ ɟI",
Expand Down Expand Up @@ -425,6 +428,7 @@
"item.enderio.soularium_ingot": "ʇobuI ɯnıɹɐןnoS",
"item.enderio.soularium_nugget": "ʇǝbbnN ɯnıɹɐןnoS",
"item.enderio.staff_of_levity": "ʎʇıʌǝꞀ ɟO ɟɟɐʇS",
"item.enderio.staff_of_travelling": "buıןןǝʌɐɹ⟘ ɟO ɟɟɐʇS",
"item.enderio.stone_gear": "ɹɐǝ⅁ punodɯoƆ ǝuoʇS",
"item.enderio.vapor_of_levity_bucket": "ʇǝʞɔnᗺ ʎʇıʌǝꞀ ɟO ɹodɐΛ",
"item.enderio.vibrant_alloy_grinding_ball": "ןןɐᗺ buıpuıɹ⅁ ʎoןןⱯ ʇuɐɹqıΛ",
Expand Down
4 changes: 4 additions & 0 deletions src/generated/resources/assets/enderio/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@
"block.enderio.soularium_block": "Soularium Block",
"block.enderio.soularium_pressure_plate": "Soularium Pressure Plate",
"block.enderio.stirling_generator": "Stirling Generator",
"block.enderio.travel_anchor": "Travel Anchor",
"block.enderio.vacuum_chest": "Vacuum Chest",
"block.enderio.vapor_of_levity": "Vapor Of Levity",
"block.enderio.vibrant_alloy_block": "Vibrant Alloy Block",
Expand Down Expand Up @@ -279,6 +280,8 @@
"gui.enderio.spawner.too_many_mob": "Too many mobs",
"gui.enderio.spawner.too_many_spawner": "Too many spawners",
"gui.enderio.spawner.unknown": "Unknown mob",
"gui.enderio.visible.false": "Hidden",
"gui.enderio.visible.true": "Visible",
"guidebook.enderio.book_title": "Book Title",
"guidebook.enderio.landing_text": "Landing Text",
"hint.enderio.connected_textures.text": "If you are looking for connected textures on the capacitor bank, you might want to install Athena on your client",
Expand Down Expand Up @@ -425,6 +428,7 @@
"item.enderio.soularium_ingot": "Soularium Ingot",
"item.enderio.soularium_nugget": "Soularium Nugget",
"item.enderio.staff_of_levity": "Staff Of Levity",
"item.enderio.staff_of_travelling": "Staff Of Travelling",
"item.enderio.stone_gear": "Stone Compound Gear",
"item.enderio.vapor_of_levity_bucket": "Vapor Of Levity Bucket",
"item.enderio.vibrant_alloy_grinding_ball": "Vibrant Alloy Grinding Ball",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "enderio:item/staff_of_travelling"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "enderio:block/travel_anchor"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"type": "minecraft:block",
"pools": [
{
"bonus_rolls": 0.0,
"entries": [
{
"type": "minecraft:item",
"functions": [
{
"function": "minecraft:copy_nbt",
"ops": [
{
"op": "replace",
"source": "",
"target": "BlockEntityTag"
}
],
"source": "block_entity"
}
],
"name": "enderio:travel_anchor"
}
],
"rolls": 1.0
}
],
"random_sequence": "enderio:blocks/travel_anchor"
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"enderio:powered_spawner",
"enderio:vacuum_chest",
"enderio:xp_vacuum",
"enderio:travel_anchor",
"enderio:energetic_photovoltaic_module",
"enderio:pulsating_photovoltaic_module",
"enderio:vibrant_photovoltaic_module",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"enderio:powered_spawner",
"enderio:vacuum_chest",
"enderio:xp_vacuum",
"enderio:travel_anchor",
"enderio:crafter"
]
}
12 changes: 12 additions & 0 deletions src/machines/java/com/enderio/machines/EIOMachines.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,22 @@

import com.enderio.EnderIO;
import com.enderio.base.data.EIODataProvider;
import com.enderio.api.integration.IntegrationManager;
import com.enderio.api.travel.TravelRegistry;
import com.enderio.machines.client.rendering.travel.TravelAnchorRenderer;
import com.enderio.machines.common.blockentity.solar.SolarPanelTier;
import com.enderio.machines.common.config.MachinesConfig;
import com.enderio.machines.common.init.*;
import com.enderio.machines.common.init.MachineBlockEntities;
import com.enderio.machines.common.init.MachineBlocks;
import com.enderio.machines.common.init.MachineMenus;
import com.enderio.machines.common.init.MachineRecipes;
import com.enderio.machines.common.integrations.EnderIOMachinesSelfIntegration;
import com.enderio.machines.common.lang.MachineLang;
import com.enderio.machines.common.network.MachineNetwork;
import com.enderio.machines.common.tag.MachineTags;
import com.enderio.machines.data.advancements.MachinesAdvancementGenerator;
import com.enderio.machines.common.travel.AnchorTravelTarget;
import com.enderio.machines.data.recipes.*;
import com.enderio.machines.data.souldata.SoulDataProvider;
import com.enderio.machines.data.tag.MachineEntityTypeTagsProvider;
Expand Down Expand Up @@ -53,6 +62,9 @@ public static void onConstruct(FMLConstructModEvent event) {

// Remap
MinecraftForge.EVENT_BUS.addListener(EIOMachines::missingMappings);

IntegrationManager.addIntegration(EnderIOMachinesSelfIntegration.INSTANCE);
TravelRegistry.addTravelEntry(EnderIO.loc("travel_anchor"), AnchorTravelTarget::new, TravelAnchorRenderer::new);
}

@SubscribeEvent
Expand Down
Loading

0 comments on commit 3da498e

Please sign in to comment.