From 8c78815092b0181a12cd21ef1b147b4c1a5ee090 Mon Sep 17 00:00:00 2001 From: Srendi Date: Wed, 6 Apr 2022 14:54:16 +0200 Subject: [PATCH] 1.18 --- build.gradle | 10 +++--- gradle.properties | 2 +- gradle/wrapper/gradle-wrapper.properties | 2 +- .../srendi/cctutorial/cctutorial/CCBlock.java | 35 ++++++++++--------- .../cctutorial/cctutorial/CCPeripheral.java | 17 ++++----- .../cctutorial/cctutorial/CCTileEntity.java | 17 +++++---- .../cctutorial/cctutorial/CCtutorial.java | 6 +--- .../cctutorial/cctutorial/Registration.java | 26 +++++++------- 8 files changed, 60 insertions(+), 55 deletions(-) diff --git a/build.gradle b/build.gradle index 626a64a..847b44d 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ buildscript { mavenCentral() } dependencies { - classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '4.1.+', changing: true + classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '5.1.+', changing: true } } @@ -14,10 +14,10 @@ group = 'de.srendi.cctutorial' version = '1.0' archivesBaseName = 'cctutorial' -java.toolchain.languageVersion = JavaLanguageVersion.of(8) +java.toolchain.languageVersion = JavaLanguageVersion.of(17) minecraft { - mappings channel: 'snapshot', version: '20210309-1.16.5' + mappings channel: 'official', version: '1.18.2' runs { client { @@ -88,9 +88,9 @@ dependencies { // Specify the version of Minecraft to use, If this is any group other then 'net.minecraft' it is assumed // that the dep is a ForgeGradle 'patcher' dependency. And it's patches will be applied. // The userdev artifact is a special name and will get all sorts of transformations applied to it. - minecraft 'net.minecraftforge:forge:1.16.5-36.1.23' + minecraft 'net.minecraftforge:forge:1.18.2-40.0.40' - implementation fg.deobf("org.squiddev:cc-tweaked-1.16.4:${cc_version}") + implementation fg.deobf("org.squiddev:cc-tweaked-1.18.2:${cc_version}") } diff --git a/gradle.properties b/gradle.properties index ceeef23..ca3d81e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ org.gradle.jvmargs=-Xmx3G org.gradle.daemon=false -cc_version=1.95.3 +cc_version=1.100.4 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 28ff446..b1159fc 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/de/srendi/cctutorial/cctutorial/CCBlock.java b/src/main/java/de/srendi/cctutorial/cctutorial/CCBlock.java index b9b2b86..ac9187b 100644 --- a/src/main/java/de/srendi/cctutorial/cctutorial/CCBlock.java +++ b/src/main/java/de/srendi/cctutorial/cctutorial/CCBlock.java @@ -1,29 +1,32 @@ package de.srendi.cctutorial.cctutorial; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.material.Material; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.IBlockReader; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.EntityBlock; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.Material; +import org.jetbrains.annotations.NotNull; import javax.annotation.Nullable; -public class CCBlock extends Block { +/** + * This is our block. To tell minecraft that this block has a block entity, we need to implement {@link EntityBlock} + */ +public class CCBlock extends Block implements EntityBlock { public CCBlock() { - super(Properties.create(Material.IRON).hardnessAndResistance(5, 10)); + super(Properties.of(Material.METAL).strength(5, 5)); } - //Create a new tile entity with our registry object + /** + * This is the method from {@link EntityBlock} to create a new block entity for our block + * + * @return A new block entity from our registry object + */ @Nullable @Override - public TileEntity createTileEntity(BlockState state, IBlockReader world) { - return Registration.CC_TILEENTITY.get().create(); - } - - //Say minecraft, our CCBlock has a tile entity. - @Override - public boolean hasTileEntity(BlockState state) { - return true; + public BlockEntity newBlockEntity(@NotNull BlockPos pos, @NotNull BlockState state) { + return Registration.CC_TILEENTITY.get().create(pos, state); } } diff --git a/src/main/java/de/srendi/cctutorial/cctutorial/CCPeripheral.java b/src/main/java/de/srendi/cctutorial/cctutorial/CCPeripheral.java index 59eaee6..8de7c3f 100644 --- a/src/main/java/de/srendi/cctutorial/cctutorial/CCPeripheral.java +++ b/src/main/java/de/srendi/cctutorial/cctutorial/CCPeripheral.java @@ -3,8 +3,9 @@ package de.srendi.cctutorial.cctutorial; import dan200.computercraft.api.lua.LuaFunction; import dan200.computercraft.api.peripheral.IComputerAccess; import dan200.computercraft.api.peripheral.IPeripheral; -import net.minecraft.util.text.StringTextComponent; -import net.minecraftforge.fml.server.ServerLifecycleHooks; +import net.minecraft.Util; +import net.minecraft.network.chat.TextComponent; +import net.minecraftforge.server.ServerLifecycleHooks; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -19,7 +20,7 @@ public class CCPeripheral implements IPeripheral { /** * A list of all our connected computers. We need this for event usages. */ - List connectedComputers = new ArrayList<>(); + private final List connectedComputers = new ArrayList<>(); /** * This is our tile entity, we set the tile entity when we create a new peripheral. We use this tile entity to access the block or the world @@ -27,7 +28,6 @@ public class CCPeripheral implements IPeripheral { private final CCTileEntity tileEntity; /** - * * @param tileEntity the tile entity of this peripheral */ public CCPeripheral(CCTileEntity tileEntity) { @@ -79,10 +79,11 @@ public class CCPeripheral implements IPeripheral { */ @LuaFunction public final void sendMessage(String message) { - //Used to get the current server and all online players. + // Used to get the current server and all online players. ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayers().forEach(player -> { - //Now, send the message - player.sendStatusMessage(new StringTextComponent(message), false); + // Now, send the message + // To send a message, we need a Component(We use a TextComponent) and a sender UUID. We just pass an empty uuid in here + player.sendMessage(new TextComponent(message), Util.NIL_UUID); }); } @@ -91,7 +92,7 @@ public class CCPeripheral implements IPeripheral { */ @LuaFunction(mainThread = true) public final boolean isRaining() { - return getTileEntity().getWorld().getRainStrength(0) > 0; + return getTileEntity().getLevel().getRainLevel(0) > 0; } } diff --git a/src/main/java/de/srendi/cctutorial/cctutorial/CCTileEntity.java b/src/main/java/de/srendi/cctutorial/cctutorial/CCTileEntity.java index 3f3f478..a224ba7 100644 --- a/src/main/java/de/srendi/cctutorial/cctutorial/CCTileEntity.java +++ b/src/main/java/de/srendi/cctutorial/cctutorial/CCTileEntity.java @@ -1,17 +1,20 @@ package de.srendi.cctutorial.cctutorial; import dan200.computercraft.api.peripheral.IPeripheral; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.Direction; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.util.LazyOptional; +import org.jetbrains.annotations.NotNull; import static dan200.computercraft.shared.Capabilities.CAPABILITY_PERIPHERAL; -public class CCTileEntity extends TileEntity { +public class CCTileEntity extends BlockEntity { - public CCTileEntity() { - super(Registration.CC_TILEENTITY.get()); + public CCTileEntity(BlockPos pos, BlockState state) { + super(Registration.CC_TILEENTITY.get(), pos, state); } /** @@ -22,9 +25,11 @@ public class CCTileEntity extends TileEntity { /** * When a computer modem tries to wrap our block, the modem will call getCapability to receive our peripheral. + * Then we just simply return a {@link LazyOptional} with our Peripheral */ @Override - public LazyOptional getCapability(Capability cap, Direction direction) { + @NotNull + public LazyOptional getCapability(@NotNull Capability cap, Direction direction) { if (cap == CAPABILITY_PERIPHERAL) { if (peripheralCap == null) { peripheralCap = LazyOptional.of(() -> peripheral); diff --git a/src/main/java/de/srendi/cctutorial/cctutorial/CCtutorial.java b/src/main/java/de/srendi/cctutorial/cctutorial/CCtutorial.java index 765f55c..c8854b0 100644 --- a/src/main/java/de/srendi/cctutorial/cctutorial/CCtutorial.java +++ b/src/main/java/de/srendi/cctutorial/cctutorial/CCtutorial.java @@ -2,17 +2,13 @@ package de.srendi.cctutorial.cctutorial; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.Mod; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; // The value here should match an entry in the META-INF/mods.toml file @Mod("cctutorial") public class CCtutorial { - //Our mod id + // Our mod id public static final String MODID = "cctutorial"; - // Directly reference a log4j logger. - private static final Logger LOGGER = LogManager.getLogger(); public CCtutorial() { Registration.register(); diff --git a/src/main/java/de/srendi/cctutorial/cctutorial/Registration.java b/src/main/java/de/srendi/cctutorial/cctutorial/Registration.java index fdba30a..ff428b3 100644 --- a/src/main/java/de/srendi/cctutorial/cctutorial/Registration.java +++ b/src/main/java/de/srendi/cctutorial/cctutorial/Registration.java @@ -1,16 +1,16 @@ package de.srendi.cctutorial.cctutorial; import com.google.common.collect.Sets; -import net.minecraft.block.Block; -import net.minecraft.item.BlockItem; -import net.minecraft.item.Item; -import net.minecraft.item.ItemGroup; -import net.minecraft.tileentity.TileEntityType; +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.Item; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraftforge.eventbus.api.IEventBus; -import net.minecraftforge.fml.RegistryObject; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.ForgeRegistries; +import net.minecraftforge.registries.RegistryObject; import java.util.function.Supplier; @@ -18,25 +18,25 @@ public class Registration { public static final DeferredRegister BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, CCtutorial.MODID); public static final DeferredRegister ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, CCtutorial.MODID); - public static final DeferredRegister> TILE_ENTITIES = DeferredRegister.create(ForgeRegistries.TILE_ENTITIES, CCtutorial.MODID); + public static final DeferredRegister> BLOCK_ENTITIES = DeferredRegister.create(ForgeRegistries.BLOCK_ENTITIES, CCtutorial.MODID); - //Blocks + // Blocks public static final RegistryObject CC_BLOCK = register("tutorial_block", CCBlock::new); private static RegistryObject register(String name, Supplier block) { RegistryObject registryObject = BLOCKS.register(name, block); - ITEMS.register(name, ()->new BlockItem(registryObject.get(), new Item.Properties().group(ItemGroup.REDSTONE))); + ITEMS.register(name, () -> new BlockItem(registryObject.get(), new Item.Properties().tab(CreativeModeTab.TAB_REDSTONE))); return registryObject; } - //Tile Entities - public static final RegistryObject> CC_TILEENTITY = Registration.TILE_ENTITIES.register("tutorial_block", () -> new TileEntityType<>(CCTileEntity::new, Sets.newHashSet(CC_BLOCK.get()), null)); + // Tile Entities + public static final RegistryObject> CC_TILEENTITY = Registration.BLOCK_ENTITIES.register("tutorial_block", () -> new BlockEntityType<>(CCTileEntity::new, Sets.newHashSet(CC_BLOCK.get()), null)); - //Register our stuff + // Register our stuff public static void register() { IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); BLOCKS.register(modEventBus); ITEMS.register(modEventBus); - TILE_ENTITIES.register(modEventBus); + BLOCK_ENTITIES.register(modEventBus); } } \ No newline at end of file