瀏覽代碼

add more sign logic, fix RenderUtils not taking into account model dependency textures

1.12
Adrian Siekierka 1 年之前
父節點
當前提交
80d31b543d

+ 16
- 1
src/main/java/pl/asie/charset/lib/utils/RenderUtils.java 查看文件

@@ -392,13 +392,28 @@ public final class RenderUtils {
public static IModel getModelWithTextures(ResourceLocation location, TextureMap map) {
IModel model = getModel(location);
if (model != null) {
for (ResourceLocation tlocation : model.getTextures()) {
for (ResourceLocation tlocation : getAllTextures(model)) {
map.registerSprite(tlocation);
}
}
return model;
}

public static Collection<ResourceLocation> getAllTextures(IModel model) {
Collection<ResourceLocation> textures = new ArrayList<>(model.getTextures());

LinkedList<ResourceLocation> locs = new LinkedList<>();
locs.addAll(model.getDependencies());
while (!locs.isEmpty()) {
IModel m = RenderUtils.getModel(locs.remove());
if (m != null) {
textures.addAll(m.getTextures());
locs.addAll(m.getDependencies());
}
}
return textures;
}

private static int getSelectionMask(int y, int x, int z) {
return 1 << (y * 4 + x * 2 + z);
}

+ 164
- 0
src/main/java/pl/asie/charset/module/decoration/signs/TileSign.java 查看文件

@@ -19,7 +19,171 @@

package pl.asie.charset.module.decoration.signs;

import net.minecraft.command.CommandException;
import net.minecraft.command.CommandResultStats;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.nbt.NBTTagString;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextComponentUtils;
import net.minecraft.util.text.event.ClickEvent;
import net.minecraft.world.World;
import net.minecraftforge.common.util.Constants;
import pl.asie.charset.lib.block.TileBase;
import pl.asie.charset.lib.block.TraitMaterial;
import pl.asie.charset.lib.material.ItemMaterialRegistry;
import pl.asie.charset.lib.notify.Notice;
import pl.asie.charset.lib.notify.component.NotificationComponentTextComponent;

import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class TileSign extends TileBase {
protected TraitMaterial material;
private final List<ITextComponent> lines = new ArrayList<>();
private final CommandResultStats stats = new CommandResultStats();

public TileSign() {
registerTrait("material", material = new TraitMaterial("material", ItemMaterialRegistry.INSTANCE.getDefaultMaterialByType("plank")));
}

@Override
public void readNBTData(NBTTagCompound compound, boolean isClient) {
lines.clear();
if (compound.hasKey("lines", Constants.NBT.TAG_LIST)) {
NBTTagList list = compound.getTagList("lines", Constants.NBT.TAG_STRING);
for (int i = 0; i < list.tagCount(); i++) {
ITextComponent component = ITextComponent.Serializer.jsonToComponent(list.getStringTagAt(i));

try {
component = TextComponentUtils.processComponent(new CommandSender(), component, null);
} catch (CommandException e) {
// pass
}

lines.add(component);
}
}

if (!isClient) {
stats.readStatsFromNBT(compound);
}
}

@Override
public NBTTagCompound writeNBTData(NBTTagCompound compound, boolean isClient) {
NBTTagList list = new NBTTagList();
for (ITextComponent component : lines) {
list.appendTag(new NBTTagString(ITextComponent.Serializer.componentToJson(component)));
}
compound.setTag("lines", list);

if (!isClient) {
stats.writeStatsToNBT(compound);
}

return compound;
}

@Override
public boolean onlyOpsCanSetNbt() {
return true;
}

public boolean executeCommand(EntityPlayer player) {
boolean executed = false;
ICommandSender icommandsender = new CommandSender(player);

for (ITextComponent component : lines) {
if (component.getStyle().getClickEvent() != null) {
ClickEvent clickevent = component.getStyle().getClickEvent();

if (clickevent.getAction() == ClickEvent.Action.RUN_COMMAND) {
Objects.requireNonNull(player.getServer()).getCommandManager().executeCommand(icommandsender, clickevent.getValue());
executed = true;
}
}
}

return executed;
}

public CommandResultStats getStats() {
return stats;
}

public class CommandSender implements ICommandSender {
private final EntityPlayer player;

public CommandSender() {
this.player = null;
}

public CommandSender(EntityPlayer player) {
this.player = player;
}

@Override
public String getName() {
return player != null ? player.getName() : "Sign";
}

@Override
public ITextComponent getDisplayName() {
return player != null ? player.getDisplayName() : new TextComponentString("Sign");
}

@Override
public void sendMessage(ITextComponent component) {
// TODO: Is this a good idea?
new Notice(TileSign.this, new NotificationComponentTextComponent(component)).sendToAll();
}

@Override
public Entity getCommandSenderEntity() {
return player;
}

@Override
public boolean canUseCommand(int permLevel, String commandName) {
return permLevel <= 2;
}

@Override
public World getEntityWorld() {
return getWorld();
}

@Override
public BlockPos getPosition() {
return getPos();
}

@Override
public Vec3d getPositionVector() {
return new Vec3d(getPosition()).add(0.5D, 0.5D, 0.5D);
}

@Override
public void setCommandStat(CommandResultStats.Type type, int amount) {
if (TileSign.this.world != null && !TileSign.this.world.isRemote) {
TileSign.this.stats.setCommandStatForSender(TileSign.this.world.getMinecraftServer(), this, type, amount);
}
}

@Nullable
@Override
public MinecraftServer getServer() {
return player != null ? player.getServer() : getWorld().getMinecraftServer();
}
}
}

+ 3
- 5
src/main/java/pl/asie/simplelogic/gates/ProxyClient.java 查看文件

@@ -19,10 +19,7 @@

package pl.asie.simplelogic.gates;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.function.Function;

import gnu.trove.map.TIntObjectMap;
@@ -42,6 +39,7 @@ import net.minecraftforge.fml.relauncher.SideOnly;

import pl.asie.charset.lib.render.ArrowHighlightHandler;
import pl.asie.charset.lib.render.sprite.PixelOperationSprite;
import pl.asie.charset.lib.utils.RenderUtils;
import pl.asie.simplelogic.gates.render.GateRenderDefinitions;
import pl.asie.simplelogic.gates.render.RendererGate;
import pl.asie.charset.lib.utils.RegistryUtils;
@@ -103,7 +101,7 @@ public class ProxyClient extends ProxyCommon {

// step 2: gather textures
for (IModel model : def.getAllModels()) {
textures.addAll(model.getTextures());
textures.addAll(RenderUtils.getAllTextures(model));
}

for (GateRenderDefinitions.Layer layer : def.layers) {

Loading…
取消
儲存