1.18
This commit is contained in:
parent
349e3b7721
commit
8c78815092
8 changed files with 60 additions and 55 deletions
10
build.gradle
10
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}")
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
org.gradle.jvmargs=-Xmx3G
|
||||
org.gradle.daemon=false
|
||||
cc_version=1.95.3
|
||||
cc_version=1.100.4
|
||||
|
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<IComputerAccess> connectedComputers = new ArrayList<>();
|
||||
private final List<IComputerAccess> 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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 <T> LazyOptional<T> getCapability(Capability<T> cap, Direction direction) {
|
||||
@NotNull
|
||||
public <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap, Direction direction) {
|
||||
if (cap == CAPABILITY_PERIPHERAL) {
|
||||
if (peripheralCap == null) {
|
||||
peripheralCap = LazyOptional.of(() -> peripheral);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, CCtutorial.MODID);
|
||||
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, CCtutorial.MODID);
|
||||
public static final DeferredRegister<TileEntityType<?>> TILE_ENTITIES = DeferredRegister.create(ForgeRegistries.TILE_ENTITIES, CCtutorial.MODID);
|
||||
public static final DeferredRegister<BlockEntityType<?>> BLOCK_ENTITIES = DeferredRegister.create(ForgeRegistries.BLOCK_ENTITIES, CCtutorial.MODID);
|
||||
|
||||
//Blocks
|
||||
// Blocks
|
||||
public static final RegistryObject<Block> CC_BLOCK = register("tutorial_block", CCBlock::new);
|
||||
|
||||
private static <T extends Block> RegistryObject<T> register(String name, Supplier<T> block) {
|
||||
RegistryObject<T> 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<TileEntityType<CCTileEntity>> CC_TILEENTITY = Registration.TILE_ENTITIES.register("tutorial_block", () -> new TileEntityType<>(CCTileEntity::new, Sets.newHashSet(CC_BLOCK.get()), null));
|
||||
// Tile Entities
|
||||
public static final RegistryObject<BlockEntityType<CCTileEntity>> 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);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue