Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port the Ender IO #946

Draft
wants to merge 8 commits into
base: dev/1.21.1
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;

public interface TravelTarget {
Codec<TravelTarget> CODEC = EnderIORegistries.TRAVEL_TARGET_SERIALIZERS.byNameCodec()
Expand Down Expand Up @@ -43,6 +45,21 @@ default boolean canJumpTo() {
return canTravelTo();
}

/**
* @return Whether the target can have a special action performed from long distances.
*/
default boolean canPerformSpecialAction() {
return false;
}

/**
* Execute a special action.
* @return true if action was successful
*/
default boolean executeSpecialAction(Level level, Player player) {
return false;
}

TravelTargetType<?> type();

TravelTargetSerializer<?> serializer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ public static boolean blockTeleport(Level level, Player player, boolean sendToSe
.isPresent();
}

public static boolean specialAction(Level level, Player player) {
return getSpecialActionTarget(player)
.filter(iTravelTarget -> specialActionOnTarget(level, player, iTravelTarget))
.isPresent();
}

public static boolean blockElevatorTeleport(Level level, Player player, Direction direction, boolean sendToServer) {
if (direction.getStepY() != 0) {
return getElevatorAnchorTarget(player, direction)
Expand Down Expand Up @@ -133,6 +139,10 @@ public static boolean blockTeleportTo(Level level, Player player, TravelTarget t
return false;
}

private static boolean specialActionOnTarget(Level level, Player player, TravelTarget target) {
return target.executeSpecialAction(level, player);
}

public static Optional<Vec3> teleportPosition(Level level, Player player) {
@Nullable
BlockPos target = null;
Expand Down Expand Up @@ -225,6 +235,18 @@ private static BlockPos traversalCheck(Level level, BlockPos traversePos) {
return null;
}

public static Optional<TravelTarget> getSpecialActionTarget(Player player) {
Vec3 positionVec = player.position().add(0, player.getEyeHeight(), 0);

return TravelTargetApi.INSTANCE.getInItemRange(player.level(), player.blockPosition())
.filter(target -> target.canPerformSpecialAction())
.filter(target -> target.pos().distToCenterSqr(player.position()) > MIN_TELEPORTATION_DISTANCE_SQUARED)
.filter(target -> Math.abs(getAngleRadians(positionVec, target.pos(), player.getYRot(),
player.getXRot())) <= Math.toRadians(15))
.min(Comparator.comparingDouble(target -> Math
.abs(getAngleRadians(positionVec, target.pos(), player.getYRot(), player.getXRot()))));
}

public static Optional<TravelTarget> getTeleportAnchorTarget(Player player) {
Vec3 positionVec = player.position().add(0, player.getEyeHeight(), 0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ public boolean performAction(Level level, Player player, ItemStack stack) {
if (TravelHandler.blockTeleport(level, player)) {
player.getCooldowns().addCooldown(this, BaseConfig.COMMON.ITEMS.TRAVELLING_BLINK_DISABLED_TIME.get());
return true;
} else if (TravelHandler.specialAction(level, player)) {
player.getCooldowns().addCooldown(this, BaseConfig.COMMON.ITEMS.TRAVELLING_BLINK_DISABLED_TIME.get());
return true;
}
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public Collection<TravelTarget> getTravelTargets() {

public Stream<TravelTarget> getTravelTargetsInItemRange(BlockPos center) {
return travelTargets.entrySet().stream().
filter(entry -> center.distSqr(entry.getKey()) < entry.getValue().item2BlockRange()*entry.getValue().item2BlockRange())
filter(entry -> entry.getValue().item2BlockRange() == Integer.MAX_VALUE || center.distSqr(entry.getKey()) < entry.getValue().item2BlockRange()*entry.getValue().item2BlockRange())
.map(Map.Entry::getValue);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "enderio:block/enderface"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"block.enderio.creative_power": "Creative Power",
"block.enderio.drain": "Drain",
"block.enderio.enchanter": "Enchanter",
"block.enderio.enderface": "Ender IO",
"block.enderio.energetic_photovoltaic_module": "Energetic Photovoltaic Module",
"block.enderio.fluid_tank": "Fluid Tank",
"block.enderio.impulse_hopper": "Impulse Hopper",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"parent": "minecraft:block/cube_all",
"render_type": "minecraft:translucent",
"textures": {
"all": "enderio:block/enderface"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "enderio:block/enderface"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"type": "minecraft:block",
"pools": [
{
"bonus_rolls": 0.0,
"entries": [
{
"type": "minecraft:item",
"functions": [
{
"function": "minecraft:copy_components",
"source": "block_entity"
}
],
"name": "enderio:enderface"
}
],
"rolls": 1.0
}
],
"random_sequence": "enderio:blocks/enderface"
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"enderio:fluid_tank",
"enderio:pressurized_fluid_tank",
"enderio:enchanter",
"enderio:enderface",
"enderio:primitive_alloy_smelter",
"enderio:alloy_smelter",
"enderio:painting_machine",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"enderio:fluid_tank",
"enderio:pressurized_fluid_tank",
"enderio:enchanter",
"enderio:enderface",
"enderio:primitive_alloy_smelter",
"enderio:alloy_smelter",
"enderio:painting_machine",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.enderio.machines.EnderIOMachines;
import com.enderio.machines.client.rendering.item.FluidTankBEWLR;
import com.enderio.machines.client.rendering.model.IOOverlayBakedModel;
import com.enderio.machines.client.rendering.travel.EnderfaceRenderer;
import com.enderio.machines.client.rendering.travel.TravelAnchorHud;
import com.enderio.machines.client.rendering.travel.TravelAnchorRenderer;
import com.enderio.machines.common.init.MachineBlocks;
Expand Down Expand Up @@ -35,6 +36,7 @@ public EnderIOMachinesClient(ModContainer modContainer) {
@SubscribeEvent
public static void registerTravelRenderers(RegisterTravelRenderersEvent event) {
event.register(MachineTravelTargets.TRAVEL_ANCHOR_TYPE.get(), TravelAnchorRenderer::new);
event.register(MachineTravelTargets.ENDERFACE_TYPE.get(), EnderfaceRenderer::new);
}

@SubscribeEvent
Expand Down
Loading
Loading