Skip to content

Commit 4dc1917

Browse files
committed
Update to 7.2-pre2!
1 parent 543787e commit 4dc1917

19 files changed

+160
-44
lines changed

build.gradle

+10-2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ repositories {
7272
}
7373
metadataSources { artifact() }
7474
}
75+
ivy {
76+
url = "https://github.com/MartinSVK12"
77+
patternLayout {
78+
artifact "[organisation]/releases/download/1.6.5/[module]-[revision].jar"
79+
m2compatible = true
80+
}
81+
metadataSources { artifact() }
82+
}
7583
}
7684

7785
dependencies {
@@ -85,9 +93,9 @@ dependencies {
8593
// If you do not need Halplibe you can comment this line out or delete this line
8694
modImplementation "bta-halplibe:halplibe:${project.halplibe_version}"
8795

88-
modImplementation "ModMenu:ModMenu:2.0.3"
96+
modImplementation "ModMenu:ModMenu:2.0.6"
8997

90-
modImplementation "catalyst:catalyst-core:1.1.1"
98+
modImplementation "catalyst:catalyst-core:1.4.4"
9199

92100
implementation "org.slf4j:slf4j-api:1.8.0-beta4"
93101
implementation "org.apache.logging.log4j:log4j-slf4j18-impl:2.16.0"

gradle.properties

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
org.gradle.jvmargs=-Xmx2G
22

33
# BTA
4-
bta_version=7.1-pre1a
4+
bta_version=7.2-pre2
55

66
# Loader
7-
loader_version=0.14.19-babric.3-bta
7+
loader_version=0.15.6-babric.6-bta
88

99
# HalpLibe
10-
halplibe_version=3.1.2
10+
halplibe_version=4.1.3
1111

1212
# Mod
13-
mod_version=1.0.2
13+
mod_version=1.0.3
1414
mod_group=sunsetsatellite
1515
mod_name=computers

src/main/java/dan200/client/FixedWidthFontRenderer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import net.minecraft.client.GLAllocation;
1010
import net.minecraft.client.option.GameSettings;
1111
import net.minecraft.client.render.RenderEngine;
12-
import net.minecraft.client.render.Tessellator;
12+
import net.minecraft.client.render.tessellator.Tessellator;
1313
import net.minecraft.core.util.helper.ChatAllowedCharacters;
1414
import org.lwjgl.opengl.GL11;
1515

src/main/java/dan200/shared/BlockComputer.java

+9-8
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@
1212
import net.minecraft.core.block.entity.TileEntity;
1313
import net.minecraft.core.block.material.Material;
1414
import net.minecraft.core.entity.player.EntityPlayer;
15+
import net.minecraft.core.util.helper.Side;
1516
import net.minecraft.core.world.World;
1617
import net.minecraft.core.world.WorldSource;
1718
import sunsetsatellite.computers.Computers;
1819
import sunsetsatellite.computers.packets.PacketComputers;
19-
import turniplabs.halplibe.helper.TextureHelper;
2020

2121
import java.util.Random;
2222

2323
public class BlockComputer extends BlockTileEntityRotatable {
2424
private Random random = new Random();
2525

26-
public int[] blockTextures = new int[]{
26+
/*public int[] blockTextures = new int[]{
2727
Block.texCoordToIndex(TextureHelper.getOrCreateBlockTexture(Computers.MOD_ID,"computer/0.png")[0]
2828
,TextureHelper.getOrCreateBlockTexture(Computers.MOD_ID,"computer/0.png")[1]),
2929
Block.texCoordToIndex(TextureHelper.getOrCreateBlockTexture(Computers.MOD_ID,"computer/1.png")[0]
@@ -32,8 +32,8 @@ public class BlockComputer extends BlockTileEntityRotatable {
3232
,TextureHelper.getOrCreateBlockTexture(Computers.MOD_ID,"computer/2.png")[1]),
3333
Block.texCoordToIndex(TextureHelper.getOrCreateBlockTexture(Computers.MOD_ID,"computer/3.png")[0]
3434
,TextureHelper.getOrCreateBlockTexture(Computers.MOD_ID,"computer/3.png")[1]),
35-
};
36-
public int blinkTexture = 0;
35+
};*/
36+
//public int blinkTexture = 0;
3737

3838
public BlockComputer(String id, int i) {
3939
super(id, i, Material.stone);
@@ -104,19 +104,20 @@ public int getBlockTextureFromSide(int i) {
104104
return this.blockTextures[1];
105105
}*/
106106

107-
public boolean blockActivated(World world, int x, int y, int z, EntityPlayer entityplayer) {
107+
@Override
108+
public boolean onBlockRightClicked(World world, int x, int y, int z, EntityPlayer player, Side side, double xHit, double yHit) {
108109
if (Computers.isMultiplayerClient()) {
109110
return true;
110111
}
111-
if (!entityplayer.isSneaking()) {
112+
if (!player.isSneaking()) {
112113
TileEntityComputer computer = (TileEntityComputer) world.getBlockTileEntity(x, y, z);
113114
if (computer != null) {
114115
PacketComputers packet = new PacketComputers();
115116
packet.packetType = 1;
116117
packet.dataInt = new int[]{x, y, z};
117-
Computers.sendToPlayer(entityplayer, packet);
118+
Computers.sendToPlayer(player, packet);
118119
computer.setSwitchedOn(true);
119-
computer.updateClient(entityplayer);
120+
computer.updateClient(player);
120121
}
121122
return true;
122123
}

src/main/java/dan200/shared/BlockDiskDrive.java

+8-7
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
import net.minecraft.core.block.entity.TileEntity;
1313
import net.minecraft.core.block.material.Material;
1414
import net.minecraft.core.entity.player.EntityPlayer;
15+
import net.minecraft.core.util.helper.Side;
1516
import net.minecraft.core.world.World;
1617
import sunsetsatellite.computers.Computers;
17-
import turniplabs.halplibe.helper.TextureHelper;
1818

1919
public class BlockDiskDrive
2020
extends BlockTileEntityRotatable {
21-
public int[] blockTextures = new int[]{
21+
/*public int[] blockTextures = new int[]{
2222
Block.texCoordToIndex(TextureHelper.getOrCreateBlockTexture(Computers.MOD_ID,"diskdrive/0.png")[0]
2323
,TextureHelper.getOrCreateBlockTexture(Computers.MOD_ID,"diskdrive/0.png")[1]),
2424
Block.texCoordToIndex(TextureHelper.getOrCreateBlockTexture(Computers.MOD_ID,"diskdrive/1.png")[0]
@@ -27,7 +27,7 @@ public class BlockDiskDrive
2727
,TextureHelper.getOrCreateBlockTexture(Computers.MOD_ID,"diskdrive/2.png")[1]),
2828
Block.texCoordToIndex(TextureHelper.getOrCreateBlockTexture(Computers.MOD_ID,"diskdrive/3.png")[0]
2929
,TextureHelper.getOrCreateBlockTexture(Computers.MOD_ID,"diskdrive/3.png")[1]),
30-
};
30+
};*/
3131

3232
public BlockDiskDrive(String id, int i) {
3333
super(id, i, Material.stone);
@@ -75,14 +75,15 @@ public int getBlockTextureFromSide(int i) {
7575
return this.blockTextures[1];
7676
}*/
7777

78-
public boolean blockActivated(World world, int i, int j, int k, EntityPlayer entityplayer) {
78+
@Override
79+
public boolean onBlockRightClicked(World world, int x, int y, int z, EntityPlayer player, Side side, double xHit, double yHit) {
7980
if (Computers.isMultiplayerClient()) {
8081
return true;
8182
}
82-
if (!entityplayer.isSneaking()) {
83-
TileEntityDiskDrive drive = (TileEntityDiskDrive) world.getBlockTileEntity(i, j, k);
83+
if (!player.isSneaking()) {
84+
TileEntityDiskDrive drive = (TileEntityDiskDrive) world.getBlockTileEntity(x, y, z);
8485
if (drive != null) {
85-
Computers.openDiskDriveGUI(entityplayer, drive);
86+
Computers.openDiskDriveGUI(player, drive);
8687
}
8788
return true;
8889
}

src/main/java/dan200/shared/ItemDisk.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@ public class ItemDisk
2828
private static Map serverLabelRequests = new HashMap();
2929
private static boolean labelsChanged = false;
3030

31-
public ItemDisk(int i) {
32-
super(i);
33-
this.setMaxStackSize(1);
31+
public ItemDisk(String name, int id) {
32+
super(name, id);
3433
}
3534

3635
private static int getNewDiskID(World world) {

src/main/java/dan200/shared/TileEntityComputer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ public void playRecord(String record) {
239239
}
240240
Computers.sendToAllPlayers(packet);
241241
} else {
242-
this.worldObj.playRecord(record, this.x, this.y, this.z);
242+
this.worldObj.playRecord(record, "unknown", this.x, this.y, this.z);
243243
}
244244
}
245245

src/main/java/sunsetsatellite/computers/Computers.java

+125-18
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
import net.fabricmc.api.ModInitializer;
88
import net.minecraft.client.Minecraft;
99
import net.minecraft.client.entity.player.EntityPlayerSP;
10+
import net.minecraft.client.render.block.model.BlockModelHorizontalRotation;
11+
import net.minecraft.client.render.block.model.BlockModelRotatable;
12+
import net.minecraft.client.render.stitcher.AtlasStitcher;
13+
import net.minecraft.client.render.stitcher.TextureRegistry;
1014
import net.minecraft.core.block.Block;
1115
import net.minecraft.core.block.entity.TileEntity;
1216
import net.minecraft.core.block.tag.BlockTags;
@@ -24,29 +28,34 @@
2428
import org.slf4j.Logger;
2529
import org.slf4j.LoggerFactory;
2630
import sunsetsatellite.computers.packets.PacketComputers;
27-
import turniplabs.halplibe.helper.BlockBuilder;
28-
import turniplabs.halplibe.helper.EntityHelper;
29-
import turniplabs.halplibe.helper.ItemHelper;
31+
import turniplabs.halplibe.helper.*;
32+
import turniplabs.halplibe.util.ClientStartEntrypoint;
33+
import turniplabs.halplibe.util.GameStartEntrypoint;
3034
import turniplabs.halplibe.util.RecipeEntrypoint;
3135
import turniplabs.halplibe.util.TomlConfigHandler;
3236
import turniplabs.halplibe.util.toml.Toml;
3337

3438
import java.io.File;
39+
import java.io.IOException;
3540
import java.lang.reflect.Field;
36-
import java.util.Arrays;
37-
import java.util.List;
41+
import java.net.URI;
42+
import java.net.URISyntaxException;
43+
import java.nio.file.*;
44+
import java.nio.file.FileSystem;
45+
import java.util.*;
3846
import java.util.stream.Collectors;
47+
import java.util.stream.Stream;
3948

4049

41-
public class Computers implements ModInitializer, RecipeEntrypoint {
50+
public class Computers implements ModInitializer, RecipeEntrypoint, ClientStartEntrypoint {
4251
public static final String MOD_ID = "computers";
4352
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
4453
public static final TomlConfigHandler config;
4554
private static int availableBlockId = 1300;
4655
private static int availableItemId = 17300;
4756

48-
public static final RecipeNamespace COMPUTERS = new RecipeNamespace();
49-
public static final RecipeGroup<RecipeEntryCrafting<?,?>> WORKBENCH = new RecipeGroup<>(new RecipeSymbol(new ItemStack(Block.workbench)));
57+
public static RecipeNamespace COMPUTERS;
58+
public static RecipeGroup<RecipeEntryCrafting<?,?>> WORKBENCH;
5059

5160
static {
5261
Toml configToml = new Toml("Computers configuration file.");
@@ -87,20 +96,22 @@ public class Computers implements ModInitializer, RecipeEntrypoint {
8796
public static String luaFolder = "/mods/computers/lua";
8897

8998
public static final BlockComputer computer = (BlockComputer) new BlockBuilder(MOD_ID)
90-
.setSideTextures("computer/1.png")
91-
.setNorthTexture("computer/2.png")
92-
.setTopBottomTexture("computer/3.png")
99+
.setSideTextures("computers:block/1_computer")
100+
.setNorthTexture("computers:block/2_computer")
101+
.setTopBottomTextures("computers:block/3_computer")
93102
.setHardness(2)
94103
.setResistance(2)
104+
.setBlockModel(BlockModelHorizontalRotation::new)
95105
.build(new BlockComputer("computer",config.getInt("BlockIDs.computer")).withTags(BlockTags.MINEABLE_BY_PICKAXE));
96106
public static final BlockDiskDrive diskDrive = (BlockDiskDrive) new BlockBuilder(MOD_ID)
97-
.setSideTextures("diskdrive/1.png")
98-
.setNorthTexture("diskdrive/0.png")
99-
.setTopBottomTexture("diskdrive/3.png")
107+
.setSideTextures("computers:block/1_diskdrive")
108+
.setNorthTexture("computers:block/0_diskdrive")
109+
.setTopBottomTextures("computers:block/3_diskdrive")
100110
.setHardness(2)
101111
.setResistance(2)
112+
.setBlockModel(BlockModelHorizontalRotation::new)
102113
.build(new BlockDiskDrive("diskDrive",config.getInt("BlockIDs.diskDrive")).withTags(BlockTags.MINEABLE_BY_PICKAXE));
103-
public static final ItemDisk disk = (ItemDisk) ItemHelper.createItem(MOD_ID,new ItemDisk(config.getInt("ItemIDs.disk")),"computerDisk","floppy.png");
114+
public static final ItemDisk disk = new ItemBuilder(MOD_ID).setIcon("computers:item/floppy").build(new ItemDisk("computerDisk",config.getInt("ItemIDs.disk")));
104115

105116
public static int m_tickCount;
106117

@@ -121,8 +132,8 @@ public void onInitialize() {
121132
ItemToolPickaxe.miningLevels.put(computer,1);
122133
ItemToolPickaxe.miningLevels.put(diskDrive,1);
123134

124-
EntityHelper.Core.createTileEntity(TileEntityComputer.class,"Computer");
125-
EntityHelper.Core.createTileEntity(TileEntityDiskDrive.class,"Disk Drive");
135+
EntityHelper.createTileEntity(TileEntityComputer.class,"Computer");
136+
EntityHelper.createTileEntity(TileEntityDiskDrive.class,"Disk Drive");
126137
}
127138

128139
public static boolean isMultiplayerClient() {
@@ -199,8 +210,104 @@ public static boolean getCursorBlink() {
199210

200211
@Override
201212
public void onRecipesReady() {
213+
RecipeBuilder.Shaped(MOD_ID,"XXX","XYX","XZX")
214+
.addInput('X',"minecraft:stones")
215+
.addInput('Y',Item.dustRedstone)
216+
.addInput('Z',Block.glass)
217+
.create("computer",computer.getDefaultStack());
218+
RecipeBuilder.Shaped(MOD_ID,"XXX","XYX","XYX")
219+
.addInput('X',"minecraft:stones")
220+
.addInput('Y',Item.dustRedstone)
221+
.create("computer",diskDrive.getDefaultStack());
222+
RecipeBuilder.Shaped(MOD_ID,"XXX","XYX","XYX")
223+
.addInput('X',Item.paper)
224+
.addInput('Y',Item.dustRedstone)
225+
.create("computer",disk.getDefaultStack());
226+
}
227+
228+
@Override
229+
public void initNamespaces() {
230+
COMPUTERS = new RecipeNamespace();
231+
WORKBENCH = new RecipeGroup<>(new RecipeSymbol(new ItemStack(Block.workbench)));
202232
COMPUTERS.register("workbench",WORKBENCH);
203233
Registries.RECIPES.register("computers",COMPUTERS);
204-
DataLoader.loadRecipes("/assets/computers/workbench.json");
234+
}
235+
236+
//thanks kill05 ;) (and also why do i have to use this again?)
237+
public void loadTextures(AtlasStitcher stitcher){
238+
// This is awful, but required until 7.2-pre2 comes ou-- nuh uh, pre2 is here and this is still needed :abyss:
239+
String id = TextureRegistry.stitcherMap.entrySet().stream().filter((e)->e.getValue() == stitcher).map(Map.Entry::getKey).collect(Collectors.toSet()).stream().findFirst().orElse(null);
240+
if(id == null){
241+
throw new RuntimeException("Failed to load textures: invalid atlas provided!");
242+
}
243+
LOGGER.info("Loading "+id+" textures...");
244+
long start = System.currentTimeMillis();
245+
246+
String path = String.format("%s/%s/%s", "/assets", MOD_ID, stitcher.directoryPath);
247+
URI uri;
248+
try {
249+
uri = DataLoader.class.getResource(path).toURI();
250+
} catch (URISyntaxException e) {
251+
throw new RuntimeException(e);
252+
}
253+
FileSystem fileSystem = null;
254+
Path myPath;
255+
if (uri.getScheme().equals("jar")) {
256+
try {
257+
fileSystem = FileSystems.newFileSystem(uri, Collections.emptyMap());
258+
} catch (IOException e) {
259+
throw new RuntimeException(e);
260+
}
261+
myPath = fileSystem.getPath(path);
262+
} else {
263+
myPath = Paths.get(uri);
264+
}
265+
266+
Stream<Path> walk;
267+
try {
268+
walk = Files.walk(myPath, Integer.MAX_VALUE);
269+
} catch (IOException e) {
270+
throw new RuntimeException(e);
271+
}
272+
Iterator<Path> it = walk.iterator();
273+
274+
while (it.hasNext()) {
275+
Path file = it.next();
276+
String name = file.getFileName().toString();
277+
if (name.endsWith(".png")) {
278+
String path1 = file.toString().replace(file.getFileSystem().getSeparator(), "/");
279+
String cutPath = path1.split(path)[1];
280+
cutPath = cutPath.substring(0, cutPath.length() - 4);
281+
TextureRegistry.getTexture(MOD_ID + ":"+ id + cutPath);
282+
}
283+
}
284+
285+
walk.close();
286+
if (fileSystem != null) {
287+
try {
288+
fileSystem.close();
289+
} catch (IOException e) {
290+
throw new RuntimeException(e);
291+
}
292+
}
293+
294+
try {
295+
TextureRegistry.initializeAllFiles(MOD_ID, stitcher);
296+
} catch (URISyntaxException | IOException e) {
297+
throw new RuntimeException("Failed to load textures.", e);
298+
}
299+
LOGGER.info(String.format("Loaded "+id+" textures (took %sms).", System.currentTimeMillis() - start));
300+
}
301+
302+
@Override
303+
public void beforeClientStart() {
304+
305+
}
306+
307+
@Override
308+
public void afterClientStart() {
309+
loadTextures(TextureRegistry.blockAtlas);
310+
loadTextures(TextureRegistry.itemAtlas);
311+
Minecraft.getMinecraft(Minecraft.class).renderEngine.refreshTextures(new ArrayList<>());
205312
}
206313
}

0 commit comments

Comments
 (0)