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

Bring SimpleTeleporters to 1.17 #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
9 changes: 2 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '0.4-SNAPSHOT'
id 'fabric-loom' version '0.8-SNAPSHOT'
}

sourceCompatibility = JavaVersion.VERSION_1_8
Expand All @@ -24,14 +24,9 @@ dependencies {
processResources {
inputs.property "version", project.version

from(sourceSets.main.resources.srcDirs) {
include "fabric.mod.json"
filesMatching("fabric.mod.json") {
expand "version": project.version
}

from(sourceSets.main.resources.srcDirs) {
exclude "fabric.mod.json"
}
}

idea {
Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx1G

minecraft_version=1.16-rc1
yarn_mappings=1.16-rc1+build.12
loader_version=0.8.8+build.202
minecraft_version=1.17
yarn_mappings=1.17+build.7
loader_version=0.11.3

#Fabric api
fabric_version=0.13.1+build.370-1.16
fabric_version=0.34.10+1.17

mod_version=2.2.0
mod_version=2.3.0
archives_base_name=simpleteleporters
maven_group=party.lemons
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.5.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pluginManagement {
jcenter()
maven {
name = 'Fabric'
url = 'http://maven.fabricmc.net/'
url = 'https://maven.fabricmc.net/'
}
gradlePluginPortal()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
import net.fabricmc.fabric.api.event.client.ClientTickCallback;

import net.minecraft.client.render.RenderLayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;

import net.minecraft.util.registry.Registry;
import party.lemons.simpleteleporters.init.SimpleTeleportersBlocks;
import party.lemons.simpleteleporters.init.SimpleTeleportersItems;

Expand All @@ -25,11 +22,11 @@ public void onInitializeClient() {
for (Hand hand : Hand.values()) {
ItemStack stack = client.player.getStackInHand(hand);
if (!stack.isEmpty() && stack.getItem() == SimpleTeleportersItems.TELE_CRYSTAL) {
CompoundTag tags = stack.getTag();
NbtCompound tags = stack.getTag();
if (tags != null) {
String s = tags.getString("dim");
Identifier id = new Identifier(s);
if (client.player.world.getDimensionRegistryKey().getValue().equals(id)) {
if (client.player.world.getRegistryKey().getValue().equals(id)) {
BlockPos telePos = new BlockPos(tags.getInt("x"), tags.getInt("y"), tags.getInt("z"));
if (distanceBetween(client.player.getBlockPos(), telePos) < 15) {
client.world.addParticle(ParticleTypes.MYCELIUM, // originally
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import net.minecraft.block.*;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityTicker;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.fluid.FluidState;
Expand Down Expand Up @@ -29,13 +31,13 @@
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;

import net.minecraft.world.WorldAccess;
import org.jetbrains.annotations.Nullable;
import party.lemons.simpleteleporters.block.entity.TeleporterBlockEntity;
import party.lemons.simpleteleporters.init.SimpleTeleportersBlockEntities;
import party.lemons.simpleteleporters.init.SimpleTeleportersItems;

import java.util.Collections;
import java.util.EnumSet;
import java.util.Random;

public class TeleporterBlock extends BlockWithEntity {
Expand All @@ -47,6 +49,11 @@ public TeleporterBlock(Settings settings) {
super(settings);
this.setDefaultState(this.getStateManager().getDefaultState().with(ON, false).with(WATERLOGGED, false));
}

@Nullable
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state, BlockEntityType<T> type) {
return world.isClient ? null : checkType(type, SimpleTeleportersBlockEntities.TELE_BE, TeleporterBlockEntity::serverTick);
}

@Override
public void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) {
Expand All @@ -69,7 +76,7 @@ public void onEntityCollision(BlockState state, World world, BlockPos pos, Entit
splayer.velocityModified = true;

Vec3d playerPos = new Vec3d(teleporterPos.getX() + 0.5, teleporterPos.getY(), teleporterPos.getZ() + 0.5);
splayer.networkHandler.teleportRequest(playerPos.getX(), playerPos.getY(), playerPos.getZ(), entity.yaw, entity.pitch, Collections.EMPTY_SET);
splayer.networkHandler.requestTeleport(playerPos.getX(), playerPos.getY(), playerPos.getZ(), entity.getYaw(), entity.getPitch(), Collections.EMPTY_SET);

splayer.setVelocity(0, 0, 0);
splayer.velocityDirty = true;
Expand All @@ -78,7 +85,7 @@ public void onEntityCollision(BlockState state, World world, BlockPos pos, Entit
teleporter.setCooldown(10);

BlockEntity down = world.getBlockEntity(teleporterPos.down());
if (down != null && down instanceof TeleporterBlockEntity) {
if (down instanceof TeleporterBlockEntity) {
((TeleporterBlockEntity) down).setCooldown(10);
}
}
Expand Down Expand Up @@ -148,9 +155,9 @@ public BlockState getStateForNeighborUpdate(BlockState state, Direction facing,

return super.getStateForNeighborUpdate(state, facing, neighborState, world, pos, neighborPos);
}

@Override
public VoxelShape getRayTraceShape(BlockState state, BlockView world, BlockPos pos) {
public VoxelShape getRaycastShape(BlockState state, BlockView world, BlockPos pos) {
return TELE_AABB;
}

Expand All @@ -171,11 +178,6 @@ protected void appendProperties(StateManager.Builder<Block, BlockState> st) {
st.add(ON).add(WATERLOGGED);
}

@Override
public BlockEntity createBlockEntity(BlockView blockView) {
return new TeleporterBlockEntity();
}

@Override
public BlockRenderType getRenderType(BlockState var1) {
return BlockRenderType.MODEL;
Expand All @@ -196,4 +198,10 @@ public BlockState getPlacementState(ItemPlacementContext ctx) {
boolean isWater = fs.getFluid().equals(Fluids.WATER);
return this.getDefaultState().with(WATERLOGGED, isWater);
}

@Nullable
@Override
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
return new TeleporterBlockEntity(pos, state);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,22 @@
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.Tickable;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.math.BlockPos;

import net.minecraft.world.World;
import party.lemons.simpleteleporters.init.SimpleTeleportersBlockEntities;

public class TeleporterBlockEntity extends BlockEntity implements Tickable {
public class TeleporterBlockEntity extends BlockEntity {
private ItemStack stack = ItemStack.EMPTY;
private int cooldown = 0;

public TeleporterBlockEntity() {
super(SimpleTeleportersBlockEntities.TELE_BE);
public TeleporterBlockEntity(BlockPos pos, BlockState state) {
super(SimpleTeleportersBlockEntities.TELE_BE, pos, state);
}

@Override
public void tick() {
if (isCoolingDown()) {
this.setCooldown(this.getCooldown() - 1);

public static void serverTick(World world, BlockPos pos, BlockState state, TeleporterBlockEntity blockEntity) {
if (blockEntity.isCoolingDown()) {
blockEntity.setCooldown(blockEntity.getCooldown() - 1);
}
}

Expand All @@ -33,11 +31,11 @@ public boolean isInDimension(Entity entityIn) {
if (getCrystal().isEmpty())
return false;

CompoundTag tags = getCrystal().getTag();
NbtCompound tags = getCrystal().getTag();
if (tags == null)
return false;

return tags.getString("dim").equals(entityIn.world.getDimensionRegistryKey().getValue().toString());
return tags.getString("dim").equals(entityIn.world.getRegistryKey().getValue().toString());
}

public ItemStack getCrystal() {
Expand All @@ -57,7 +55,7 @@ public BlockPos getTeleportPosition() {
if (!hasCrystal())
return null;

CompoundTag tags = getCrystal().getTag();
NbtCompound tags = getCrystal().getTag();
if (tags == null)
return null;

Expand All @@ -69,12 +67,10 @@ public BlockPos getTeleportPosition() {
}

@Override
public void fromTag(BlockState state, CompoundTag tag)
public void readNbt(NbtCompound tag)
{
super.fromTag(state, tag);

if (tag.contains("item")) {
stack = ItemStack.fromTag(tag.getCompound("item"));
stack = ItemStack.fromNbt(tag.getCompound("item"));
} else {
stack = ItemStack.EMPTY;
}
Expand All @@ -87,11 +83,11 @@ public void fromTag(BlockState state, CompoundTag tag)


@Override
public CompoundTag toTag(CompoundTag compound) {
compound = super.toTag(compound);
public NbtCompound writeNbt(NbtCompound compound) {
compound = super.writeNbt(compound);

if (!stack.isEmpty()) {
CompoundTag tagCompound = stack.toTag(new CompoundTag());
NbtCompound tagCompound = stack.writeNbt(new NbtCompound());
compound.put("item", tagCompound);
}
compound.putInt("cooldown", cooldown);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package party.lemons.simpleteleporters.init;

import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder;
import net.minecraft.block.Block;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;

import party.lemons.simpleteleporters.block.entity.TeleporterBlockEntity;

import java.util.function.Supplier;

import static party.lemons.simpleteleporters.SimpleTeleporters.MODID;

public class SimpleTeleportersBlockEntities {
Expand All @@ -19,7 +17,7 @@ public static void init() {
TELE_BE = registerBlockEntityType("teleporter", TeleporterBlockEntity::new, SimpleTeleportersBlocks.TELEPORTER);
}

public static <T extends BlockEntity> BlockEntityType<T> registerBlockEntityType(String name, Supplier<T> be, Block... blocks) {
return Registry.register(Registry.BLOCK_ENTITY_TYPE, new Identifier(MODID, name), BlockEntityType.Builder.create(be, blocks).build(null));
public static <T extends BlockEntity> BlockEntityType<T> registerBlockEntityType(String name, FabricBlockEntityTypeBuilder.Factory<T> be, Block... blocks) {
return Registry.register(Registry.BLOCK_ENTITY_TYPE, new Identifier(MODID, name), FabricBlockEntityTypeBuilder.create(be, blocks).build(null));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUsageContext;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.Style;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Formatting;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.World;
import net.minecraft.world.dimension.DimensionType;

import java.util.List;

Expand All @@ -28,20 +26,20 @@ public TeleportCrystalItem(Settings settings) {
public ActionResult useOnBlock(ItemUsageContext ctx) {
PlayerEntity player = ctx.getPlayer();

if (player.isSneaking()) {
if (player.isSneaking() && !player.world.isClient()) {
ItemStack stack = ctx.getStack();
CompoundTag tags = stack.getTag();
NbtCompound tags = stack.getTag();
if (tags == null) {
stack.setTag(new CompoundTag());
stack.setTag(new NbtCompound());
tags = stack.getTag();
}

BlockPos offPos = ctx.getBlockPos().offset(ctx.getSide());
tags.putInt("x", offPos.getX());
tags.putInt("y", offPos.getY());
tags.putInt("z", offPos.getZ());
tags.putString("dim", player.world.getDimensionRegistryKey().getValue().toString());
tags.putFloat("direction", player.yaw);
tags.putString("dim", player.world.getRegistryKey().getValue().toString());
tags.putFloat("direction", player.getYaw());

TranslatableText msg = new TranslatableText("text.teleporters.crystal_info", offPos.getX(), offPos.getY(), offPos.getZ());
msg.setStyle(Style.EMPTY.withColor(Formatting.GREEN));
Expand All @@ -56,7 +54,7 @@ public ActionResult useOnBlock(ItemUsageContext ctx) {

@Override
public void appendTooltip(ItemStack stack, World world, List<Text> tooltip, TooltipContext options) {
CompoundTag tags = stack.getTag();
NbtCompound tags = stack.getTag();
if (tags == null) {
TranslatableText unlinked = new TranslatableText("text.teleporters.unlinked");
unlinked.setStyle(Style.EMPTY.withColor(Formatting.RED));
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
]
},
"depends": {
"fabricloader": ">=0.6.0",
"fabricloader": ">=0.8.0",
"fabric": "*"
}
}